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?

1

1 Answer 1

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).

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). Commented May 27, 2016 at 14:56
  • You can follow this gist to get an idea of what's going on. Commented May 27, 2016 at 15:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.