aboutsummaryrefslogtreecommitdiff
path: root/flakes/diaspora/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flakes/diaspora/flake.nix')
-rw-r--r--flakes/diaspora/flake.nix214
1 files changed, 214 insertions, 0 deletions
diff --git a/flakes/diaspora/flake.nix b/flakes/diaspora/flake.nix
new file mode 100644
index 0000000..21b05d6
--- /dev/null
+++ b/flakes/diaspora/flake.nix
@@ -0,0 +1,214 @@
1{
2 description = "A privacy-aware, distributed, open source social network.";
3 inputs.myuids = {
4 url = "path:../myuids";
5 };
6 inputs.flake-utils.url = "github:numtide/flake-utils";
7 inputs.nixpkgs = {
8 url = "github:NixOS/nixpkgs/840c782d507d60aaa49aa9e3f6d0b0e780912742";
9 flake = false;
10 };
11 inputs.diaspora = {
12 url = "github:diaspora/diaspora/v0.7.10.0";
13 flake = false;
14 };
15
16 outputs = { self, myuids, nixpkgs, diaspora, flake-utils }: flake-utils.lib.eachSystem ["x86_64-linux"] (system:
17 let
18 pkgs = import nixpkgs { inherit system; overlays = []; };
19 version = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.diaspora.original.ref;
20 inherit (pkgs) callPackage;
21 in rec {
22 packages.diaspora = callPackage ./. { src = diaspora // { inherit version; }; };
23 defaultPackage = packages.diaspora;
24 legacyPackages.diaspora = packages.diaspora;
25 checks = {
26 build = defaultPackage;
27 };
28 }
29 ) // rec {
30 overlays = {
31 diaspora = final: prev: {
32 diaspora = self.defaultPackage."${final.system}";
33 };
34 };
35 overlay = overlays.diaspora;
36 nixosModule = { lib, pkgs, config, ... }:
37 let
38 name = "diaspora";
39 cfg = config.services.diaspora;
40
41 uid = config.ids.uids.diaspora;
42 gid = config.ids.gids.diaspora;
43 in
44 {
45 options.services.diaspora = {
46 enable = lib.mkEnableOption "Enable Diaspora’s service";
47 user = lib.mkOption {
48 type = lib.types.str;
49 default = name;
50 description = "User account under which Diaspora runs";
51 };
52 group = lib.mkOption {
53 type = lib.types.str;
54 default = name;
55 description = "Group under which Diaspora runs";
56 };
57 adminEmail = lib.mkOption {
58 type = lib.types.str;
59 example = "admin@example.com";
60 description = "Admin e-mail for Diaspora";
61 };
62 dataDir = lib.mkOption {
63 type = lib.types.path;
64 default = "/var/lib/${name}";
65 description = ''
66 The directory where Diaspora stores its data.
67 '';
68 };
69 socketsDir = lib.mkOption {
70 type = lib.types.path;
71 default = "/run/${name}";
72 description = ''
73 The directory where Diaspora puts runtime files and sockets.
74 '';
75 };
76 configDir = lib.mkOption {
77 type = lib.types.path;
78 description = ''
79 The configuration path for Diaspora.
80 '';
81 };
82 package = lib.mkOption {
83 type = lib.types.package;
84 default = pkgs.diaspora;
85 description = ''
86 Diaspora package to use.
87 '';
88 };
89 withLdap = lib.mkEnableOption "Add ldap patch";
90 # Output variables
91 systemdStateDirectory = lib.mkOption {
92 type = lib.types.str;
93 # Use ReadWritePaths= instead if varDir is outside of /var/lib
94 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
95 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
96 description = ''
97 Adjusted Diaspora data directory for systemd
98 '';
99 readOnly = true;
100 };
101 systemdRuntimeDirectory = lib.mkOption {
102 type = lib.types.str;
103 # Use ReadWritePaths= instead if socketsDir is outside of /run
104 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
105 lib.strings.removePrefix "/run/" cfg.socketsDir;
106 description = ''
107 Adjusted Diaspora sockets directory for systemd
108 '';
109 readOnly = true;
110 };
111 workdir = lib.mkOption {
112 type = lib.types.package;
113 default = cfg.package.override {
114 varDir = cfg.dataDir;
115 podmin_email = cfg.adminEmail;
116 config_dir = cfg.configDir;
117 ldap = cfg.withLdap;
118 };
119 description = ''
120 Adjusted diaspora package with overriden values
121 '';
122 readOnly = true;
123 };
124 sockets = lib.mkOption {
125 type = lib.types.attrsOf lib.types.path;
126 default = {
127 rails = "${cfg.socketsDir}/diaspora.sock";
128 eye = "${cfg.socketsDir}/eye.sock";
129 };
130 readOnly = true;
131 description = ''
132 Diaspora sockets
133 '';
134 };
135 pids = lib.mkOption {
136 type = lib.types.attrsOf lib.types.path;
137 default = {
138 eye = "${cfg.socketsDir}/eye.pid";
139 };
140 readOnly = true;
141 description = ''
142 Diaspora pids
143 '';
144 };
145 };
146
147 config = lib.mkIf cfg.enable {
148 nixpkgs.overlays = [ self.overlay ];
149 users.users = lib.optionalAttrs (cfg.user == name) {
150 "${name}" = {
151 uid = myuids.lib.uids.diaspora;
152 group = cfg.group;
153 description = "Diaspora user";
154 home = cfg.dataDir;
155 packages = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby ];
156 useDefaultShell = true;
157 };
158 };
159 users.groups = lib.optionalAttrs (cfg.group == name) {
160 "${name}" = {
161 gid = myuids.lib.gids.diaspora;
162 };
163 };
164
165 systemd.services.diaspora = {
166 description = "Diaspora";
167 wantedBy = [ "multi-user.target" ];
168 after = [
169 "network.target" "redis.service" "postgresql.service"
170 ];
171 wants = [
172 "redis.service" "postgresql.service"
173 ];
174
175 environment.RAILS_ENV = "production";
176 environment.BUNDLE_PATH = "${cfg.workdir.gems}/${cfg.workdir.gems.ruby.gemPath}";
177 environment.BUNDLE_GEMFILE = "${cfg.workdir.gems.confFiles}/Gemfile";
178 environment.EYE_SOCK = cfg.sockets.eye;
179 environment.EYE_PID = cfg.pids.eye;
180
181 path = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby pkgs.curl pkgs.which pkgs.gawk ];
182
183 preStart = ''
184 install -m 0755 -d ${cfg.dataDir}/uploads ${cfg.dataDir}/tmp ${cfg.dataDir}/log
185 install -m 0700 -d ${cfg.dataDir}/tmp/pids
186 if [ ! -f ${cfg.dataDir}/schedule.yml ]; then
187 echo "{}" > ${cfg.dataDir}/schedule.yml
188 fi
189 ./bin/bundle exec rails db:migrate
190 '';
191
192 script = ''
193 exec ${cfg.workdir}/script/server
194 '';
195
196 serviceConfig = {
197 User = cfg.user;
198 PrivateTmp = true;
199 Restart = "always";
200 Type = "simple";
201 WorkingDirectory = cfg.workdir;
202 StateDirectory = cfg.systemdStateDirectory;
203 RuntimeDirectory = cfg.systemdRuntimeDirectory;
204 StandardInput = "null";
205 KillMode = "control-group";
206 };
207
208 unitConfig.RequiresMountsFor = cfg.dataDir;
209 };
210 };
211 };
212 };
213}
214