1 { lib, pkgs, config, ... }:
4 cfg = config.services.diaspora;
6 uid = config.ids.uids.diaspora;
7 gid = config.ids.gids.diaspora;
10 options.services.diaspora = {
11 enable = lib.mkEnableOption "Enable Diaspora’s service";
15 description = "User account under which Diaspora runs";
17 group = lib.mkOption {
20 description = "Group under which Diaspora runs";
22 adminEmail = lib.mkOption {
24 example = "admin@example.com";
25 description = "Admin e-mail for Diaspora";
27 dataDir = lib.mkOption {
28 type = lib.types.path;
29 default = "/var/lib/${name}";
31 The directory where Diaspora stores its data.
34 socketsDir = lib.mkOption {
35 type = lib.types.path;
36 default = "/run/${name}";
38 The directory where Diaspora puts runtime files and sockets.
41 configDir = lib.mkOption {
42 type = lib.types.path;
44 The configuration path for Diaspora.
47 package = lib.mkOption {
48 type = lib.types.package;
49 default = pkgs.webapps.diaspora;
51 Diaspora package to use.
55 systemdStateDirectory = lib.mkOption {
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;
61 Adjusted Diaspora data directory for systemd
65 systemdRuntimeDirectory = lib.mkOption {
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;
71 Adjusted Diaspora sockets directory for systemd
75 workdir = lib.mkOption {
76 type = lib.types.package;
77 default = cfg.package.override {
79 podmin_email = cfg.adminEmail;
80 config_dir = cfg.configDir;
83 Adjusted diaspora package with overriden values
87 sockets = lib.mkOption {
88 type = lib.types.attrsOf lib.types.path;
90 rails = "${cfg.socketsDir}/diaspora.sock";
91 eye = "${cfg.socketsDir}/eye.sock";
99 type = lib.types.attrsOf lib.types.path;
101 eye = "${cfg.socketsDir}/eye.pid";
110 config = lib.mkIf cfg.enable {
111 users.users = lib.optionalAttrs (cfg.user == name) {
115 description = "Diaspora user";
117 packages = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby ];
118 useDefaultShell = true;
121 users.groups = lib.optionalAttrs (cfg.group == name) {
127 systemd.services.diaspora = {
128 description = "Diaspora";
129 wantedBy = [ "multi-user.target" ];
131 "network.target" "redis.service" "postgresql.service"
134 "redis.service" "postgresql.service"
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;
143 path = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby pkgs.curl pkgs.which pkgs.gawk ];
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
151 ./bin/bundle exec rails db:migrate
155 exec ${cfg.workdir}/script/server
163 WorkingDirectory = cfg.workdir;
164 StateDirectory = cfg.systemdStateDirectory;
165 RuntimeDirectory = cfg.systemdRuntimeDirectory;
166 StandardInput = "null";
167 KillMode = "control-group";
170 unitConfig.RequiresMountsFor = cfg.dataDir;