From 7c8c1dade5c8a9fedec608679e6bf5e1c0db9418 Mon Sep 17 00:00:00 2001 From: Russell O'Connor Date: Sun, 5 May 2013 15:44:06 -0400 Subject: [PATCH 1/3] Add options for user and group to run nginx as. Add option to compile in full WebDAV support. --- .../services/web-servers/nginx/default.nix | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/services/web-servers/nginx/default.nix b/modules/services/web-servers/nginx/default.nix index c9c242400f7..03f37d3518e 100644 --- a/modules/services/web-servers/nginx/default.nix +++ b/modules/services/web-servers/nginx/default.nix @@ -4,8 +4,9 @@ with pkgs.lib; let cfg = config.services.nginx; + nginx = pkgs.nginx.override { fullWebDAV = cfg.fullWebDAV; }; configFile = pkgs.writeText "nginx.conf" '' - user nginx nginx; + user ${cfg.user} ${cfg.group}; daemon off; ${cfg.config} ''; @@ -34,12 +35,27 @@ in Directory holding all state for nginx to run. "; }; + + user = mkOption { + default = "nginx"; + description = "User account under which nginx runs."; + }; + + group = mkOption { + default = "nginx"; + description = "Group account under which nginx runs."; + }; + + fullWebDAV = mkOption { + default = false; + description = "Compile in a third party module providing full WebDAV support"; + }; }; }; config = mkIf cfg.enable { - environment.systemPackages = [ pkgs.nginx ]; + environment.systemPackages = [ nginx ]; # TODO: test user supplied config file pases syntax test @@ -47,14 +63,14 @@ in description = "Nginx Web Server"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - path = [ pkgs.nginx ]; + path = [ nginx ]; preStart = '' mkdir -p ${cfg.stateDir}/logs - chown -R nginx:nginx ${cfg.stateDir} + chown -R ${cfg.user}:${cfg.group} ${cfg.stateDir} ''; serviceConfig = { - ExecStart = "${pkgs.nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}"; + ExecStart = "${nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}"; }; }; From 76b7dea8059ae9b64a217c98fcade20b84df8445 Mon Sep 17 00:00:00 2001 From: Russell O'Connor Date: Mon, 6 May 2013 10:49:23 -0400 Subject: [PATCH 2/3] Make nginx uid and gid optional. --- modules/misc/ids.nix | 2 ++ modules/services/web-servers/nginx/default.nix | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix index 2cb1ffe4429..fd76dfc47a1 100644 --- a/modules/misc/ids.nix +++ b/modules/misc/ids.nix @@ -74,6 +74,7 @@ in wwwrun = 54; spamd = 56; nslcd = 58; + nginx = 60; # When adding a uid, make sure it doesn't match an existing gid. @@ -131,6 +132,7 @@ in networkmanager = 57; nslcd = 58; scanner = 59; + nginx = 60; # When adding a gid, make sure it doesn't match an existing uid. diff --git a/modules/services/web-servers/nginx/default.nix b/modules/services/web-servers/nginx/default.nix index 03f37d3518e..da08751d0b5 100644 --- a/modules/services/web-servers/nginx/default.nix +++ b/modules/services/web-servers/nginx/default.nix @@ -74,10 +74,14 @@ in }; }; - users.extraUsers.nginx = { + users.extraUsers = optionalAttrs (cfg.user == "nginx") singleton + { name = "nginx"; group = "nginx"; + uid = config.ids.uids.nginx; }; - users.extraGroups.nginx = {}; - }; + users.extraGroups = optionalAttrs (cfg.group == "nginx") singleton + { name = "nginx"; + gid = config.ids.gids.nginx; + }; } From 9c6264527337b6065ff0534c2a7b412480e6687b Mon Sep 17 00:00:00 2001 From: Russell O'Connor Date: Mon, 6 May 2013 11:11:04 -0400 Subject: [PATCH 3/3] Add braces to fix compilation errors. I don't understand how Apache gets away without them. --- .../services/web-servers/nginx/default.nix | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/services/web-servers/nginx/default.nix b/modules/services/web-servers/nginx/default.nix index da08751d0b5..b26af1aa744 100644 --- a/modules/services/web-servers/nginx/default.nix +++ b/modules/services/web-servers/nginx/default.nix @@ -74,14 +74,15 @@ in }; }; - users.extraUsers = optionalAttrs (cfg.user == "nginx") singleton - { name = "nginx"; - group = "nginx"; - uid = config.ids.uids.nginx; - }; + users.extraUsers = optionalAttrs (cfg.user == "nginx") (singleton + { name = "nginx"; + group = "nginx"; + uid = config.ids.uids.nginx; + }); - users.extraGroups = optionalAttrs (cfg.group == "nginx") singleton - { name = "nginx"; - gid = config.ids.gids.nginx; - }; + users.extraGroups = optionalAttrs (cfg.group == "nginx") (singleton + { name = "nginx"; + gid = config.ids.gids.nginx; + }); + }; }