@@ -5,72 +5,74 @@ with lib;
55let
66 cfg = config.services.pumpio;
77 dataDir = "/var/lib/pump.io";
8+ runDir = "/run/pump.io";
89 user = "pumpio";
910
11+ optionalSet = condition: value: if condition then value else {};
12+
13+ configScript = ./pump.io-configure.js;
1014 configOptions = {
11− driver = if cfg.driver == "disk" then null else cfg.driver;
12− params = ({ } //
13− (if cfg.driver == "disk" then {
14− dir = dataDir;
15− } else { }) //
16− (if cfg.driver == "mongodb" || cfg.driver == "redis" then {
17− host = cfg.dbHost;
18− port = cfg.dbPort;
19− dbname = cfg.dbName;
20− dbuser = cfg.dbUser;
21− dbpass = cfg.dbPassword;
22− } else { }) //
23− (if cfg.driver == "memcached" then {
24− host = cfg.dbHost;
25− port = cfg.dbPort;
26− } else { }) //
27− cfg.driverParams);
28−
29− secret = cfg.secret;
30−
31− address = cfg.address;
32− port = cfg.port;
33−
34− noweb = false;
35− urlPort = cfg.urlPort;
36− hostname = cfg.hostname;
37− favicon = cfg.favicon;
38−
39− site = cfg.site;
40− owner = cfg.owner;
41− ownerURL = cfg.ownerURL;
42−
43− key = cfg.sslKey;
44− cert = cfg.sslCert;
45− bounce = false;
46−
47− spamhost = cfg.spamHost;
48− spamclientid = cfg.spamClientId;
49− spamclientsecret = cfg.spamClientSecret;
50−
51− requireEmail = cfg.requireEmail;
52− smtpserver = cfg.smtpHost;
53− smtpport = cfg.smtpPort;
54− smtpuser = cfg.smtpUser;
55− smtppass = cfg.smtpPassword;
56− smtpusessl = cfg.smtpUseSSL;
57− smtpfrom = cfg.smtpFrom;
58−
59− nologger = false;
60− enableUploads = cfg.enableUploads;
61− datadir = dataDir;
62− debugClient = false;
63− firehose = cfg.firehose;
64− disableRegistration = cfg.disableRegistration;
65− } //
66− (if cfg.port < 1024 then {
67− serverUser = user; # have pump.io listen then drop privileges
68− } else { }) //
69− cfg.extraConfig;
70−
71−in
72−
73−{
15+ outputFile = "${runDir}/config.json";
16+ config =
17+ (optionalSet (cfg.driver != "disk") {
18+ driver = cfg.driver;
19+ }) //
20+ {
21+ params = (optionalSet (cfg.driver == "disk") { dir = dataDir; }) //
22+ (optionalSet (cfg.driver == "mongodb" || cfg.driver == "redis") {
23+ host = cfg.dbHost;
24+ port = cfg.dbPort;
25+ dbname = cfg.dbName;
26+ dbuser = cfg.dbUser;
27+ dbpass = cfg.dbPassword;
28+ }) //
29+ (optionalSet (cfg.driver == "memcached") {
30+ host = cfg.dbHost;
31+ port = cfg.dbPort;
32+ }) // cfg.driverParams;
33+ secret = cfg.secret;
34+
35+ address = cfg.address;
36+ port = cfg.port;
37+
38+ noweb = false;
39+ urlPort = cfg.urlPort;
40+ hostname = cfg.hostname;
41+ favicon = cfg.favicon;
42+
43+ site = cfg.site;
44+ owner = cfg.owner;
45+ ownerURL = cfg.ownerURL;
46+
47+ key = cfg.sslKey;
48+ cert = cfg.sslCert;
49+ bounce = false;
50+
51+ spamhost = cfg.spamHost;
52+ spamclientid = cfg.spamClientId;
53+ spamclientsecret = cfg.spamClientSecret;
54+
55+ requireEmail = cfg.requireEmail;
56+ smtpserver = cfg.smtpHost;
57+ smtpport = cfg.smtpPort;
58+ smtpuser = cfg.smtpUser;
59+ smtppass = cfg.smtpPassword;
60+ smtpusessl = cfg.smtpUseSSL;
61+ smtpfrom = cfg.smtpFrom;
62+
63+ nologger = false;
64+ enableUploads = cfg.enableUploads;
65+ datadir = dataDir;
66+ debugClient = false;
67+ firehose = cfg.firehose;
68+ disableRegistration = cfg.disableRegistration;
69+
70+ inherit (cfg) secretFile dbPasswordFile smtpPasswordFile spamClientSecretFile;
71+ } //
72+ (optionalSet (cfg.port < 1024) {
73+ serverUser = user; # have pump.io listen then drop privileges
74+ }) // cfg.extraConfig;
75+}; in {
7476 options = {
7577
7678 services.pumpio = {
@@ -78,7 +80,8 @@ in
7880 enable = mkEnableOption "Pump.io social streams server";
7981
8082 secret = mkOption {
81− type = types.str;
83+ type = types.nullOr types.str;
84+ default = null;
8285 example = "my dog has fleas";
8386 description = ''
8487 A session-generating secret, server-wide password. Warning:
@@ -86,6 +89,16 @@ in
8689 '';
8790 };
8891
92+ secretFile = mkOption {
93+ type = types.nullOr types.path;
94+ default = null;
95+ example = "/run/keys/pump.io-secret";
96+ description = ''
97+ A file containing the session-generating secret,
98+ server-wide password.
99+ '';
100+ };
101+
89102 site = mkOption {
90103 type = types.str;
91104 example = "Awesome Sauce";
@@ -126,7 +139,7 @@ in
126139
127140 hostname = mkOption {
128141 type = types.nullOr types.str;
129− default = null;
142+ default = "localhost";
130143 description = ''
131144 The hostname of the server, used for generating
132145 URLs. Defaults to "localhost" which doesn't do much for you.
@@ -263,6 +276,15 @@ in
263276 '';
264277 };
265278
279+ dbPasswordFile = mkOption {
280+ type = types.nullOr types.path;
281+ default = null;
282+ example = "/run/keys/pump.io-dbpassword";
283+ description = ''
284+ A file containing the password corresponding to dbUser.
285+ '';
286+ };
287+
266288 smtpHost = mkOption {
267289 type = types.nullOr types.str;
268290 default = null;
@@ -301,6 +323,17 @@ in
301323 '';
302324 };
303325
326+ smtpPasswordFile = mkOption {
327+ type = types.nullOr types.path;
328+ default = null;
329+ example = "/run/keys/pump.io-smtppassword";
330+ description = ''
331+ A file containing the password used to connect to SMTP
332+ server. Might not be necessary for some servers.
333+ '';
334+ };
335+
336+
304337 smtpUseSSL = mkOption {
305338 type = types.bool;
306339 default = false;
@@ -342,32 +375,55 @@ in
342375 stored in cleartext in the Nix store!
343376 '';
344377 };
378+ spamClientSecretFile = mkOption {
379+ type = types.nullOr types.path;
380+ default = null;
381+ example = "/run/keys/pump.io-spamclientsecret";
382+ description = ''
383+ A file containing the OAuth key for the spam server.
384+ '';
385+ };
345386 };
346387
347388 };
348389
349390 config = mkIf cfg.enable {
391+ warnings = let warn = k: optional (cfg.${k} != null)
392+ "config.services.pumpio.${k} is insecure. Use ${k}File instead.";
393+ in concatMap warn [ "secret" "dbPassword" "smtpPassword" "spamClientSecret" ];
394+
395+ assertions = [
396+ { assertion = !(isNull cfg.secret && isNull cfg.secretFile);
397+ message = "pump.io needs a secretFile configured";
398+ }
399+ ];
400+
350401 systemd.services."pump.io" =
351− { description = "pump.io social network stream server";
402+ { description = "Pump.io - stream server that does most of what people really want from a social network";
352403 after = [ "network.target" ];
353404 wantedBy = [ "multi-user.target" ];
354405
355406 preStart = ''
356407 mkdir -p ${dataDir}/uploads
357− chown pumpio:pumpio ${dataDir}/uploads
358− chmod 770 ${dataDir}/uploads
359− '';
408+ mkdir -p ${runDir}
409+ chown pumpio:pumpio ${dataDir}/uploads ${runDir}
410+ chmod 770 ${dataDir}/uploads ${runDir}
360411
361− serviceConfig.ExecStart = "${pkgs.pumpio}/bin/pump -c /etc/pump.io.json";
362− PermissionsStartOnly = true;
363− serviceConfig.User = if cfg.port < 1024 then "root" else user;
364− serviceConfig.Group = user;
365− };
412+ ${pkgs.nodejs}/bin/node ${configScript} <<EOF
413+ ${builtins.toJSON configOptions}
414+ EOF
415+
416+ chgrp pumpio ${configOptions.outputFile}
417+ chmod 640 ${configOptions.outputFile}
418+ '';
366419
367− environment.etc."pump.io.json" = {
368− mode = "0440";
369− gid = config.ids.gids.pumpio;
370− text = builtins.toJSON configOptions;
420+ serviceConfig = {
421+ ExecStart = "${pkgs.pumpio}/bin/pump -c ${configOptions.outputFile}";
422+ PermissionsStartOnly = true;
423+ User = if cfg.port < 1024 then "root" else user;
424+ Group = user;
425+ };
426+ environment = { NODE_ENV = "production"; };
371427 };
372428
373429 users.extraGroups.pumpio.gid = config.ids.gids.pumpio;