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 workdir = lib.mkOption {
56 type = lib.types.package;
57 default = cfg.package.override {
59 podmin_email = cfg.adminEmail;
60 config_dir = cfg.configDir;
63 Adjusted diaspora package with overriden values
67 sockets = lib.mkOption {
68 type = lib.types.attrsOf lib.types.path;
70 rails = "${cfg.socketsDir}/diaspora.sock";
71 eye = "${cfg.socketsDir}/eye.sock";
79 type = lib.types.attrsOf lib.types.path;
81 eye = "${cfg.socketsDir}/eye.pid";
90 config = lib.mkIf cfg.enable {
91 users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton {
95 description = "Diaspora user";
97 packages = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby ];
98 useDefaultShell = true;
100 users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton {
105 systemd.services.diaspora = {
106 description = "Diaspora";
107 wantedBy = [ "multi-user.target" ];
109 "network.target" "redis.service" "postgresql.service"
112 "redis.service" "postgresql.service"
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;
121 path = [ cfg.workdir.gems pkgs.nodejs cfg.workdir.gems.ruby pkgs.curl pkgs.which pkgs.gawk ];
124 ./bin/bundle exec rails db:migrate
128 exec ${cfg.workdir}/script/server
136 WorkingDirectory = cfg.workdir;
137 StandardInput = "null";
138 KillMode = "control-group";
141 unitConfig.RequiresMountsFor = cfg.dataDir;
144 system.activationScripts.diaspora = {
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 \
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