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;
|
|
|
|
configFile = pkgs.writeText "nginx.conf" ''
|
|
|
|
${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 {
|
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
Verbatim nginx.conf configuration.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
default = "/var/spool/nginx";
|
|
|
|
description = "
|
|
|
|
Directory holding all state for nginx to run.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
};
|
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 {
|
|
|
|
environment.systemPackages = [ pkgs.nginx ];
|
|
|
|
|
|
|
|
# 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" ];
|
|
|
|
path = [ pkgs.nginx ];
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -p ${cfg.stateDir}/logs
|
|
|
|
chown -R nginx:nginx ${cfg.stateDir}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.nginx}/bin/nginx -c ${configFile} -p ${cfg.stateDir}";
|
|
|
|
};
|
|
|
|
};
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
users.extraUsers.nginx = {
|
|
|
|
group = "nginx";
|
|
|
|
};
|
2013-04-14 11:14:27 +02:00
|
|
|
|
2013-03-02 23:40:56 +01:00
|
|
|
users.extraGroups.nginx = {};
|
|
|
|
};
|
|
|
|
}
|