git.iko.soy/typeable/nixpkgs
on master help sign in
uwsgi-service: Add user/group for uwsgi service.
46f06ccRussell O'Connor
nixos/modules/misc/ids.nix+2
@@ -222,6 +222,7 @@
222 ripple-rest = 198;
222 ripple-rest = 198;
223 nix-serve = 199;
223 nix-serve = 199;
224 tvheadend = 200;
224 tvheadend = 200;
225+ uwsgi = 201;
225
226
226 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
227 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
227
228
@@ -422,6 +423,7 @@
422 #ripple-rest = 198; #unused
423 #ripple-rest = 198; #unused
423 #nix-serve = 199; #unused
424 #nix-serve = 199; #unused
424 #tvheadend = 200; #unused
425 #tvheadend = 200; #unused
426+ uwsgi = 201;
425
427
426 # When adding a gid, make sure it doesn't match an existing
428 # When adding a gid, make sure it doesn't match an existing
427 # uid. Users and groups with the same name should have equal
429 # 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 {
47
47
48 options = {
48 options = {
49 services.uwsgi = {
49 services.uwsgi = {
50−
50+
51 enable = mkOption {
51 enable = mkOption {
52 type = types.bool;
52 type = types.bool;
53 default = false;
53 default = false;
54 description = "Enable uWSGI";
54 description = "Enable uWSGI";
55 };
55 };
56
56
57+ runDir = mkOption {
58+ type = types.string;
59+ default = "/run/uwsgi";
60+ description = "Where uWSGI communication sockets can live";
61+ };
62+
57 instance = mkOption {
63 instance = mkOption {
58 type = types.attrs;
64 type = types.attrs;
59 default = {
65 default = {
@@ -66,7 +72,7 @@ in {
66 moin = {
72 moin = {
67 type = "normal";
73 type = "normal";
68 python2Packages = self: with self; [ moinmoin ];
74 python2Packages = self: with self; [ moinmoin ];
69− socket = "/run/uwsgi.sock";
75+ socket = "${config.services.uwsgi.runDir}/uwsgi.sock";
70 };
76 };
71 };
77 };
72 }
78 }
@@ -89,24 +95,46 @@ in {
89 description = "Plugins used with uWSGI";
95 description = "Plugins used with uWSGI";
90 };
96 };
91
97
98+ user = mkOption {
99+ type = types.str;
100+ default = "uwsgi";
101+ description = "User account under which uwsgi runs.";
92− };
102+ };
93
103
104+ group = mkOption {
105+ type = types.str;
106+ default = "uwsgi";
107+ description = "Group account under which uwsgi runs.";
108+ };
109+ };
94 };
110 };
95
111
96 config = mkIf cfg.enable {
112 config = mkIf cfg.enable {
97−
98 systemd.services.uwsgi = {
113 systemd.services.uwsgi = {
99 wantedBy = [ "multi-user.target" ];
114 wantedBy = [ "multi-user.target" ];
100−
115+ preStart = ''
116+ mkdir -p ${cfg.runDir}
117+ chown ${cfg.user}:${cfg.group} ${cfg.runDir}
118+ '';
101 serviceConfig = {
119 serviceConfig = {
102 Type = "notify";
120 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)}";
104 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
122 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
105 ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID";
123 ExecStop = "${pkgs.coreutils}/bin/kill -INT $MAINPID";
106 NotifyAccess = "main";
124 NotifyAccess = "main";
107 KillSignal = "SIGQUIT";
125 KillSignal = "SIGQUIT";
108 };
126 };
109−
110 };
127 };
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+ });
111 };
139 };
112}
140}