git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #8429 from oconnorr/master

uwsgi: Add user/group for uwsgi service.

commit68dc809255228c8f970095b7ca52b80c0c25f69f authorlethalman <lucabru@src.gnome.org> dateThu 25 Jun 2015, 09:46 (11 years ago) parent59faa7546f06cc
2 files changed+37−7
nixos/modules/misc/ids.nix+2 nixos/modules/services/web-servers/uwsgi.nix+35−7
nixos/modules/misc/ids.nix+2
@@ -222,6 +222,7 @@
222222 ripple-rest = 198;
223223 nix-serve = 199;
224224 tvheadend = 200;
225+ uwsgi = 201;
225226
226227 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
227228
@@ -422,6 +423,7 @@
422423 #ripple-rest = 198; #unused
423424 #nix-serve = 199; #unused
424425 #tvheadend = 200; #unused
426+ uwsgi = 201;
425427
426428 # When adding a gid, make sure it doesn't match an existing
427429 # uid. Users and groups with the same name should have equal
nixos/modules/services/web-servers/uwsgi.nix+35−7
@@ -47,13 +47,19 @@ in {
4747
4848 options = {
4949 services.uwsgi = {
50−
50+
5151 enable = mkOption {
5252 type = types.bool;
5353 default = false;
5454 description = "Enable uWSGI";
5555 };
5656
57+ runDir = mkOption {
58+ type = types.string;
59+ default = "/run/uwsgi";
60+ description = "Where uWSGI communication sockets can live";
61+ };
62+
5763 instance = mkOption {
5864 type = types.attrs;
5965 default = {
@@ -66,7 +72,7 @@ in {
6672 moin = {
6773 type = "normal";
6874 python2Packages = self: with self; [ moinmoin ];
69− socket = "/run/uwsgi.sock";
75+ socket = "${config.services.uwsgi.runDir}/uwsgi.sock";
7076 };
7177 };
7278 }
@@ -89,24 +95,46 @@ in {
8995 description = "Plugins used with uWSGI";
9096 };
9197
92− };
98+ user = mkOption {
99+ type = types.str;
100+ default = "uwsgi";
101+ description = "User account under which uwsgi runs.";
102+ };
93103
104+ group = mkOption {
105+ type = types.str;
106+ default = "uwsgi";
107+ description = "Group account under which uwsgi runs.";
108+ };
109+ };
94110 };
95111
96112 config = mkIf cfg.enable {
97−
98113 systemd.services.uwsgi = {
99114 wantedBy = [ "multi-user.target" ];
100−
115+ preStart = ''
116+ mkdir -p ${cfg.runDir}
117+ chown ${cfg.user}:${cfg.group} ${cfg.runDir}
118+ '';
101119 serviceConfig = {
102120 Type = "notify";
103− ExecStart = "${uwsgi}/bin/uwsgi --json ${pkgs.writeText "uwsgi.json" (buildCfg cfg.instance)}";
121+ ExecStart = "${uwsgi}/bin/uwsgi --uid ${cfg.user} --gid ${cfg.group} --json ${pkgs.writeText "uwsgi.json" (buildCfg cfg.instance)}";
104122 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
105123 ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID";
106124 NotifyAccess = "main";
107125 KillSignal = "SIGQUIT";
108126 };
109−
110127 };
128+
129+ users.extraUsers = optionalAttrs (cfg.user == "uwsgi") (singleton
130+ { name = "uwsgi";
131+ group = cfg.group;
132+ uid = config.ids.uids.uwsgi;
133+ });
134+
135+ users.extraGroups = optionalAttrs (cfg.group == "uwsgi") (singleton
136+ { name = "uwsgi";
137+ gid = config.ids.gids.uwsgi;
138+ });
111139 };
112140}