nixpkgs/nixos/modules/services/web-servers/nginx/default.nix
Jaka Hudoklin c7429711b8 nixos/nginx: allow to specify which package to use
This enables to override which plugins to include with nginx by allowing to change
nginx package. I also removed webdav option in nginx nixos module, because you
can now specify this by overriding nginx package.
2013-10-20 22:52:02 +02:00

92 lines
1.9 KiB
Nix

{ config, pkgs, ... }:
with pkgs.lib;
let
cfg = config.services.nginx;
nginx = cfg.package;
configFile = pkgs.writeText "nginx.conf" ''
user ${cfg.user} ${cfg.group};
daemon off;
${cfg.config}
'';
in
{
options = {
services.nginx = {
enable = mkOption {
default = false;
description = "
Enable the nginx Web Server.
";
};
package = mkOption {
default = pkgs.nginx;
description = "
Nginx package to use.
";
};
config = mkOption {
default = "events {}";
description = "
Verbatim nginx.conf configuration.
";
};
stateDir = mkOption {
default = "/var/spool/nginx";
description = "
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.";
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ nginx ];
# TODO: test user supplied config file pases syntax test
systemd.services.nginx = {
description = "Nginx Web Server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = [ nginx ];
preStart =
''
mkdir -p ${cfg.stateDir}/logs
chown -R ${cfg.user}:${cfg.group} ${cfg.stateDir}
'';
serviceConfig = {
ExecStart = "${nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}";
};
};
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;
});
};
}