]>
Commit | Line | Data |
---|---|---|
7009832a IB |
1 | { lib, pkgs, config, ... }: |
2 | let | |
3 | name = "diaspora"; | |
4 | cfg = config.services.diaspora; | |
5 | ||
6 | uid = config.ids.uids.diaspora; | |
7 | gid = config.ids.gids.diaspora; | |
8 | in | |
9 | { | |
10 | options.services.diaspora = { | |
11 | enable = lib.mkEnableOption "Enable Diaspora’s service"; | |
12 | user = lib.mkOption { | |
13 | type = lib.types.str; | |
14 | default = name; | |
15 | description = "User account under which Diaspora runs"; | |
16 | }; | |
17 | group = lib.mkOption { | |
18 | type = lib.types.str; | |
19 | default = name; | |
20 | description = "Group under which Diaspora runs"; | |
21 | }; | |
22 | adminEmail = lib.mkOption { | |
23 | type = lib.types.str; | |
24 | example = "admin@example.com"; | |
25 | description = "Admin e-mail for Diaspora"; | |
26 | }; | |
27 | dataDir = lib.mkOption { | |
28 | type = lib.types.path; | |
29 | default = "/var/lib/${name}"; | |
30 | description = '' | |
31 | The directory where Diaspora stores its data. | |
32 | ''; | |
33 | }; | |
34 | socketsDir = lib.mkOption { | |
35 | type = lib.types.path; | |
36 | default = "/run/${name}"; | |
37 | description = '' | |
38 | The directory where Diaspora puts runtime files and sockets. | |
39 | ''; | |
40 | }; | |
41 | configDir = lib.mkOption { | |
42 | type = lib.types.path; | |
43 | description = '' | |
44 | The configuration path for Diaspora. | |
45 | ''; | |
46 | }; | |
47 | package = lib.mkOption { | |
48 | type = lib.types.package; | |
49 | default = pkgs.webapps.diaspora; | |
50 | description = '' | |
51 | Diaspora package to use. | |
52 | ''; | |
53 | }; | |
54 | # Output variables | |
55 | workdir = lib.mkOption { | |
56 | type = lib.types.package; | |
57 | default = cfg.package.override { | |
58 | varDir = cfg.dataDir; | |
59 | podmin_email = cfg.adminEmail; | |
60 | config_dir = cfg.configDir; | |
61 | }; | |
62 | description = '' | |
63 | Adjusted diaspora package with overriden values | |
64 | ''; | |
65 | readOnly = true; | |
66 | }; | |
67 | sockets = lib.mkOption { | |
68 | type = lib.types.attrsOf lib.types.path; | |
69 | default = { | |
70 | rails = "${cfg.socketsDir}/diaspora.sock"; | |
71 | eye = "${cfg.socketsDir}/eye.sock"; | |
72 | }; | |
73 | readOnly = true; | |
74 | description = '' | |
75 | Diaspora sockets | |
76 | ''; | |
77 | }; | |
78 | pids = lib.mkOption { | |
79 | type = lib.types.attrsOf lib.types.path; | |
80 | default = { | |
81 | eye = "${cfg.socketsDir}/eye.pid"; | |
82 | }; | |
83 | readOnly = true; | |
84 | description = '' | |
85 | Diaspora pids | |
86 | ''; | |
87 | }; | |
88 | }; | |
89 | ||
90 | config = lib.mkIf cfg.enable { | |
91 | users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton { | |
92 | inherit name; | |
93 | inherit uid; | |
94 | group = cfg.group; | |
95 | description = "Diaspora user"; | |
96 | home = cfg.dataDir; | |
97 | packages = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby ]; | |
98 | useDefaultShell = true; | |
99 | }); | |
100 | users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton { | |
101 | inherit name; | |
102 | inherit gid; | |
103 | }); | |
104 | ||
105 | systemd.services.diaspora = { | |
106 | description = "Diaspora"; | |
107 | wantedBy = [ "multi-user.target" ]; | |
108 | after = [ | |
109 | "network.target" "redis.service" "postgresql.service" | |
110 | ]; | |
111 | wants = [ | |
112 | "redis.service" "postgresql.service" | |
113 | ]; | |
114 | ||
115 | environment.RAILS_ENV = "production"; | |
116 | environment.BUNDLE_PATH = "${cfg.workdir.gems}/${cfg.workdir.gems.ruby.gemPath}"; | |
117 | environment.BUNDLE_GEMFILE = "${cfg.workdir.gems.confFiles}/Gemfile"; | |
118 | environment.EYE_SOCK = cfg.sockets.eye; | |
119 | environment.EYE_PID = cfg.pids.eye; | |
120 | ||
121 | path = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby pkgs.curl pkgs.which pkgs.gawk ]; | |
122 | ||
123 | preStart = '' | |
124 | ./bin/bundle exec rails db:migrate | |
125 | ''; | |
126 | ||
127 | script = '' | |
128 | exec ${cfg.workdir}/script/server | |
129 | ''; | |
130 | ||
131 | serviceConfig = { | |
132 | User = cfg.user; | |
133 | PrivateTmp = true; | |
134 | Restart = "always"; | |
135 | Type = "simple"; | |
136 | WorkingDirectory = cfg.workdir; | |
137 | StandardInput = "null"; | |
138 | KillMode = "control-group"; | |
139 | }; | |
140 | ||
141 | unitConfig.RequiresMountsFor = cfg.dataDir; | |
142 | }; | |
143 | ||
144 | system.activationScripts.diaspora = { | |
145 | deps = [ "users" ]; | |
146 | text = '' | |
147 | install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.socketsDir} | |
148 | install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} \ | |
149 | ${cfg.dataDir}/uploads ${cfg.dataDir}/tmp \ | |
150 | ${cfg.dataDir}/log | |
151 | install -m 0700 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}/tmp/pids | |
152 | if [ ! -f ${cfg.dataDir}/schedule.yml ]; then | |
153 | echo "{}" | $wrapperDir/sudo -u ${cfg.user} tee ${cfg.dataDir}/schedule.yml | |
154 | fi | |
155 | ''; | |
156 | }; | |
157 | ||
158 | }; | |
159 | } |