2013-03-02 23:40:56 +01:00
|
|
|
{ config, pkgs, ... }:
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
with pkgs.lib;
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.nginx;
|
2013-05-05 21:44:06 +02:00
|
|
|
nginx = pkgs.nginx.override { fullWebDAV = cfg.fullWebDAV; };
|
2013-03-02 23:40:56 +01:00
|
|
|
configFile = pkgs.writeText "nginx.conf" ''
|
2013-05-05 21:44:06 +02:00
|
|
|
user ${cfg.user} ${cfg.group};
|
2013-04-14 11:17:16 +02:00
|
|
|
daemon off;
|
2013-03-02 23:40:56 +01:00
|
|
|
${cfg.config}
|
|
|
|
'';
|
|
|
|
in
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.nginx = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Enable the nginx Web Server.
|
|
|
|
";
|
|
|
|
};
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
config = mkOption {
|
2013-04-14 11:17:16 +02:00
|
|
|
default = "events {}";
|
2013-03-02 23:40:56 +01:00
|
|
|
description = "
|
|
|
|
Verbatim nginx.conf configuration.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
default = "/var/spool/nginx";
|
|
|
|
description = "
|
|
|
|
Directory holding all state for nginx to run.
|
|
|
|
";
|
|
|
|
};
|
2013-05-05 21:44:06 +02:00
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
2013-03-02 23:40:56 +01:00
|
|
|
};
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
};
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
config = mkIf cfg.enable {
|
2013-05-05 21:44:06 +02:00
|
|
|
environment.systemPackages = [ nginx ];
|
2013-03-02 23:40:56 +01:00
|
|
|
|
|
|
|
# TODO: test user supplied config file pases syntax test
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
systemd.services.nginx = {
|
|
|
|
description = "Nginx Web Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-05-05 21:44:06 +02:00
|
|
|
path = [ nginx ];
|
2013-03-02 23:40:56 +01:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p ${cfg.stateDir}/logs
|
2013-05-05 21:44:06 +02:00
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.stateDir}
|
2013-03-02 23:40:56 +01:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
2013-05-05 21:44:06 +02:00
|
|
|
ExecStart = "${nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}";
|
2013-03-02 23:40:56 +01:00
|
|
|
};
|
|
|
|
};
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-05-06 17:11:04 +02:00
|
|
|
users.extraUsers = optionalAttrs (cfg.user == "nginx") (singleton
|
|
|
|
{ name = "nginx";
|
|
|
|
group = "nginx";
|
|
|
|
uid = config.ids.uids.nginx;
|
|
|
|
});
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-05-06 17:11:04 +02:00
|
|
|
users.extraGroups = optionalAttrs (cfg.group == "nginx") (singleton
|
|
|
|
{ name = "nginx";
|
|
|
|
gid = config.ids.gids.nginx;
|
|
|
|
});
|
|
|
|
};
|
2013-03-02 23:40:56 +01:00
|
|
|
}
|