Nginx: "withSlice"?

I see here in the nginx package (derivation?) that there is something called withSlice:

How do I enable this? I would like to use nginx with this optional module compiled in, but not sure how to do this, or what the NixOS way of doing this is.

It sounds like what you’re looking for is an overlay. Overlays provide a way to modify package definitions without needing to update nixpkgs directly. See this section of the nixpkgs manual, or this NixOS Wiki page for more information.

Specifically, you would want the following overlay:

final: prev: {
  nginx = prev.nginx.override {
    withSlice = true;

Where you want to put this overlay depends on the effect you want to achieve. If you want any settings in your configuration.nix file which would cause nginx to be installed to use this modified nginx (for example, services.nginx.enable = true), then you should set the nixpkgs.overlays setting in your configuration.nix file so that it includes this overlay. You could do that as follows:

nixpkgs.overlays = [
  (final: prev: {
    nginx = prev.nginx.override {
      withSlice = true;

You could also include the overlay in a file, and reference that instead. For example:

# Assuming the above overlay is saved to overlays/nginx.nix, where the 'overlays' directory is in the same directory as 'configuration.nix'
nixpkgs.overlays = [ (import ./overlays/nginx.nix) ];

If you want to change the version of nginx that is installed by nix-env -iA nixpkgs.nginx or nix-shell -p nginx, you should but the overlay in a nix list in the file ~/.config/nixpkgs/overlays.nix (as with the value of nixpkgs.overlays above), or put the raw function in any nix file in ~/.config/nixpkgs/overlays/.

1 Like

Thank you!! For writing such an understandable explanation and pointing me in the right direction. In my case - in my flake I was using services.nginx.package = pkgs.nginxMainline; and it looks like It could modify that to this:

services.nginx.package = pkgs.nginxMainline.override { withSlice = true; };

And for services that don’t have a package = attribute, I now know what to do and where to look. So: much thanks!