Merge pull request #159 from NixOS/nginx-fullWebDAV

Add options for user and group to run nginx as.
This commit is contained in:
roconnor 2013-05-12 15:32:59 -07:00
commit aa1289dd91
2 changed files with 32 additions and 9 deletions

View File

@ -74,6 +74,7 @@ in
wwwrun = 54; wwwrun = 54;
spamd = 56; spamd = 56;
nslcd = 58; nslcd = 58;
nginx = 60;
# When adding a uid, make sure it doesn't match an existing gid. # When adding a uid, make sure it doesn't match an existing gid.
@ -131,6 +132,7 @@ in
networkmanager = 57; networkmanager = 57;
nslcd = 58; nslcd = 58;
scanner = 59; scanner = 59;
nginx = 60;
# When adding a gid, make sure it doesn't match an existing uid. # When adding a gid, make sure it doesn't match an existing uid.

View File

@ -4,8 +4,9 @@ with pkgs.lib;
let let
cfg = config.services.nginx; cfg = config.services.nginx;
nginx = pkgs.nginx.override { fullWebDAV = cfg.fullWebDAV; };
configFile = pkgs.writeText "nginx.conf" '' configFile = pkgs.writeText "nginx.conf" ''
user nginx nginx; user ${cfg.user} ${cfg.group};
daemon off; daemon off;
${cfg.config} ${cfg.config}
''; '';
@ -34,12 +35,27 @@ in
Directory holding all state for nginx to run. 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 { config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.nginx ]; environment.systemPackages = [ nginx ];
# TODO: test user supplied config file pases syntax test # TODO: test user supplied config file pases syntax test
@ -47,21 +63,26 @@ in
description = "Nginx Web Server"; description = "Nginx Web Server";
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = [ pkgs.nginx ]; path = [ nginx ];
preStart = preStart =
'' ''
mkdir -p ${cfg.stateDir}/logs mkdir -p ${cfg.stateDir}/logs
chown -R nginx:nginx ${cfg.stateDir} chown -R ${cfg.user}:${cfg.group} ${cfg.stateDir}
''; '';
serviceConfig = { serviceConfig = {
ExecStart = "${pkgs.nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}"; ExecStart = "${nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}";
}; };
}; };
users.extraUsers.nginx = { users.extraUsers = optionalAttrs (cfg.user == "nginx") (singleton
{ name = "nginx";
group = "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;
});
}; };
} }