diff options
Diffstat (limited to 'modules/webapps/diaspora.nix')
-rw-r--r-- | modules/webapps/diaspora.nix | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/modules/webapps/diaspora.nix b/modules/webapps/diaspora.nix deleted file mode 100644 index d9e9989..0000000 --- a/modules/webapps/diaspora.nix +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
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 | systemdStateDirectory = lib.mkOption { | ||
56 | type = lib.types.str; | ||
57 | # Use ReadWritePaths= instead if varDir is outside of /var/lib | ||
58 | default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir; | ||
59 | lib.strings.removePrefix "/var/lib/" cfg.dataDir; | ||
60 | description = '' | ||
61 | Adjusted Diaspora data directory for systemd | ||
62 | ''; | ||
63 | readOnly = true; | ||
64 | }; | ||
65 | systemdRuntimeDirectory = lib.mkOption { | ||
66 | type = lib.types.str; | ||
67 | # Use ReadWritePaths= instead if socketsDir is outside of /run | ||
68 | default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir; | ||
69 | lib.strings.removePrefix "/run/" cfg.socketsDir; | ||
70 | description = '' | ||
71 | Adjusted Diaspora sockets directory for systemd | ||
72 | ''; | ||
73 | readOnly = true; | ||
74 | }; | ||
75 | workdir = lib.mkOption { | ||
76 | type = lib.types.package; | ||
77 | default = cfg.package.override { | ||
78 | varDir = cfg.dataDir; | ||
79 | podmin_email = cfg.adminEmail; | ||
80 | config_dir = cfg.configDir; | ||
81 | }; | ||
82 | description = '' | ||
83 | Adjusted diaspora package with overriden values | ||
84 | ''; | ||
85 | readOnly = true; | ||
86 | }; | ||
87 | sockets = lib.mkOption { | ||
88 | type = lib.types.attrsOf lib.types.path; | ||
89 | default = { | ||
90 | rails = "${cfg.socketsDir}/diaspora.sock"; | ||
91 | eye = "${cfg.socketsDir}/eye.sock"; | ||
92 | }; | ||
93 | readOnly = true; | ||
94 | description = '' | ||
95 | Diaspora sockets | ||
96 | ''; | ||
97 | }; | ||
98 | pids = lib.mkOption { | ||
99 | type = lib.types.attrsOf lib.types.path; | ||
100 | default = { | ||
101 | eye = "${cfg.socketsDir}/eye.pid"; | ||
102 | }; | ||
103 | readOnly = true; | ||
104 | description = '' | ||
105 | Diaspora pids | ||
106 | ''; | ||
107 | }; | ||
108 | }; | ||
109 | |||
110 | config = lib.mkIf cfg.enable { | ||
111 | users.users = lib.optionalAttrs (cfg.user == name) { | ||
112 | "${name}" = { | ||
113 | inherit uid; | ||
114 | group = cfg.group; | ||
115 | description = "Diaspora user"; | ||
116 | home = cfg.dataDir; | ||
117 | packages = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby ]; | ||
118 | useDefaultShell = true; | ||
119 | }; | ||
120 | }; | ||
121 | users.groups = lib.optionalAttrs (cfg.group == name) { | ||
122 | "${name}" = { | ||
123 | inherit gid; | ||
124 | }; | ||
125 | }; | ||
126 | |||
127 | systemd.services.diaspora = { | ||
128 | description = "Diaspora"; | ||
129 | wantedBy = [ "multi-user.target" ]; | ||
130 | after = [ | ||
131 | "network.target" "redis.service" "postgresql.service" | ||
132 | ]; | ||
133 | wants = [ | ||
134 | "redis.service" "postgresql.service" | ||
135 | ]; | ||
136 | |||
137 | environment.RAILS_ENV = "production"; | ||
138 | environment.BUNDLE_PATH = "${cfg.workdir.gems}/${cfg.workdir.gems.ruby.gemPath}"; | ||
139 | environment.BUNDLE_GEMFILE = "${cfg.workdir.gems.confFiles}/Gemfile"; | ||
140 | environment.EYE_SOCK = cfg.sockets.eye; | ||
141 | environment.EYE_PID = cfg.pids.eye; | ||
142 | |||
143 | path = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby pkgs.curl pkgs.which pkgs.gawk ]; | ||
144 | |||
145 | preStart = '' | ||
146 | install -m 0755 -d ${cfg.dataDir}/uploads ${cfg.dataDir}/tmp ${cfg.dataDir}/log | ||
147 | install -m 0700 -d ${cfg.dataDir}/tmp/pids | ||
148 | if [ ! -f ${cfg.dataDir}/schedule.yml ]; then | ||
149 | echo "{}" > ${cfg.dataDir}/schedule.yml | ||
150 | fi | ||
151 | ./bin/bundle exec rails db:migrate | ||
152 | ''; | ||
153 | |||
154 | script = '' | ||
155 | exec ${cfg.workdir}/script/server | ||
156 | ''; | ||
157 | |||
158 | serviceConfig = { | ||
159 | User = cfg.user; | ||
160 | PrivateTmp = true; | ||
161 | Restart = "always"; | ||
162 | Type = "simple"; | ||
163 | WorkingDirectory = cfg.workdir; | ||
164 | StateDirectory = cfg.systemdStateDirectory; | ||
165 | RuntimeDirectory = cfg.systemdRuntimeDirectory; | ||
166 | StandardInput = "null"; | ||
167 | KillMode = "control-group"; | ||
168 | }; | ||
169 | |||
170 | unitConfig.RequiresMountsFor = cfg.dataDir; | ||
171 | }; | ||
172 | }; | ||
173 | } | ||