Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Commit

Permalink
add most basic nginx service
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Mar 3, 2013
1 parent d99fce2 commit 854a37a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/module-list.nix
Expand Up @@ -179,6 +179,7 @@
./services/ttys/agetty.nix
./services/web-servers/apache-httpd/default.nix
./services/web-servers/jboss/default.nix
./services/web-servers/nginx/default.nix
./services/web-servers/tomcat.nix
./services/x11/desktop-managers/default.nix
./services/x11/display-managers/auto.nix
Expand Down
65 changes: 65 additions & 0 deletions modules/services/web-servers/nginx/default.nix
@@ -0,0 +1,65 @@
{ config, pkgs, ... }:

with pkgs.lib;

let
cfg = config.services.nginx;
configFile = pkgs.writeText "nginx.conf" ''
${cfg.config}
'';
in

{
options = {
services.nginx = {
enable = mkOption {
default = false;
description = "
Enable the nginx Web Server.
";
};

config = mkOption {
default = "";
description = "
Verbatim nginx.conf configuration.
";
};

stateDir = mkOption {
default = "/var/spool/nginx";
description = "
Directory holding all state for nginx to run.
";
};
};

};

config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.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 = [ 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}";
};
};

users.extraUsers.nginx = {
group = "nginx";
};

users.extraGroups.nginx = {};
};
}

0 comments on commit 854a37a

Please sign in to comment.