1

In my configuration.nix, it says

services.nginx.enable=true;
services.nginx.httpConfig="a";

(I tried a normal file and empty string and neither worked)

upon running nixos-rebuild switch, it says that the server was started, but curl localhost connection refuses.

When I run nginx from the command line, it responds could not open error log file: open() "/nix/store/HASHHERE-nginx-1.8.1/logs/error.log failed", read only filesystem.

I looked at the conf file there /nix/store/HASHHERE-nginx-1.8.1/conf/nginx.conf and it's the same as the default! ('diff nginx.conf nginx.conf.default' returns a blank line).

Why doesn't services.nginx.httpConfig change the config file?

Santa
  • 559
  • 5
  • 15
nixos
  • 53
  • 1
  • 4
  • 1
    you can easily check when systemd nginx unit is doing by typing (systemctl status -l nginx) also you might find implementation of nginx service easy to understand -> https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/web-servers/nginx/default.nix – Rok Garbas May 27 '16 at 11:47

1 Answers1

1

It does change the config file, but the config file doesn't get written into the nginx package. Instead it gets written to a new file in a new location.

It confused me a bit at first as well. I found it helpful to make sense of it by remembering that the nix store reflects the purity of the nix functional language - when you change something the original copy should remain the same, instead a new copy is created combined with whatever changes (it's this property that supports instant rollbacks). The same goes for your nginx config - the package is never touched, instead a new config file is created.

As Rok says you can quickly check where the location of the config file is with systemd status. You can also read through the config section for the nginx module to see how the whole thing is implemented. In that case you will see that your nginx.httpConfig text gets written to a configFile in /nix/store/HASHHERE-nginx.conf. That file then gets passed directly to your nginx binary via its -c option. So the nginx systemd unit execStart command is like ${pkgs.nginx}/bin/nginx -c ${configFile}..

PS that is also why your curl returns a connection refused - cos your nginx configuration is just 'a'! The default server is sitting in the nginx package but completely unreferenced (exactly the same thing happened to me).

brocking
  • 191
  • 2
  • PS make sure nginx.stateDir is somewhere nginx can write its logs to (the default is fine), not /nix/store/.. which only nix should write to (else you're tampering with its purity). – brocking May 27 '16 at 14:56
  • You can follow [this gist](https://gist.github.com/nick-b-h/7f63d6199f56abdf0c0954ca546f396d) to get an idea of what's going on. – brocking May 27 '16 at 15:59