1 { lib, pkgs, config, ... }:
3 name = "etherpad-lite";
4 cfg = config.services.etherpad-lite;
6 uid = config.ids.uids.etherpad-lite;
7 gid = config.ids.gids.etherpad-lite;
10 options.services.etherpad-lite = {
11 enable = lib.mkEnableOption "Enable Etherpad lite’s service";
15 description = "User account under which Etherpad lite runs";
17 group = lib.mkOption {
20 description = "Group under which Etherpad lite runs";
22 dataDir = lib.mkOption {
23 type = lib.types.path;
24 default = "/var/lib/${name}";
26 The directory where Etherpad lite stores its data.
29 socketsDir = lib.mkOption {
30 type = lib.types.path;
31 default = "/run/${name}";
33 The directory where Etherpad lite stores its sockets.
36 configFile = lib.mkOption {
37 type = lib.types.path;
39 The config file path for Etherpad lite.
42 sessionKeyFile = lib.mkOption {
43 type = lib.types.path;
45 The Session key file path for Etherpad lite.
48 apiKeyFile = lib.mkOption {
49 type = lib.types.path;
51 The API key file path for Etherpad lite.
54 package = lib.mkOption {
55 type = lib.types.package;
56 default = pkgs.webapps.etherpad-lite;
58 Etherpad lite package to use.
61 modules = lib.mkOption {
62 type = lib.types.listOf lib.types.package;
65 Etherpad lite modules to use.
69 workdir = lib.mkOption {
70 type = lib.types.package;
71 default = cfg.package.withModules cfg.modules;
73 Adjusted Etherpad lite package with plugins
77 systemdStateDirectory = lib.mkOption {
79 # Use ReadWritePaths= instead if varDir is outside of /var/lib
80 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
81 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
83 Adjusted Etherpad lite data directory for systemd
87 systemdRuntimeDirectory = lib.mkOption {
89 # Use ReadWritePaths= instead if socketsDir is outside of /run
90 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
91 lib.strings.removePrefix "/run/" cfg.socketsDir;
93 Adjusted Etherpad lite sockets directory for systemd
97 sockets = lib.mkOption {
98 type = lib.types.attrsOf lib.types.path;
100 node = "${cfg.socketsDir}/etherpad-lite.sock";
104 Etherpad lite sockets
109 config = lib.mkIf cfg.enable {
110 systemd.services.etherpad-lite = {
111 description = "Etherpad-lite";
112 wantedBy = [ "multi-user.target" ];
113 after = [ "network.target" "postgresql.service" ];
114 wants = [ "postgresql.service" ];
116 environment.NODE_ENV = "production";
117 environment.HOME = cfg.workdir;
119 path = [ pkgs.nodejs ];
122 exec ${pkgs.nodejs}/bin/node ${cfg.workdir}/src/node/server.js \
123 --sessionkey ${cfg.sessionKeyFile} \
124 --apikey ${cfg.apiKeyFile} \
125 --settings ${cfg.configFile}
129 while [ ! -S ${cfg.sockets.node} ]; do
132 chmod a+w ${cfg.sockets.node}
138 WorkingDirectory = cfg.workdir;
140 NoNewPrivileges = true;
141 PrivateDevices = true;
143 ProtectControlGroups = true;
144 ProtectKernelModules = true;
148 RuntimeDirectory = cfg.systemdRuntimeDirectory;
149 StateDirectory= cfg.systemdStateDirectory;
151 "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/ep_initialized"
152 "+${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir} ${cfg.configFile} ${cfg.sessionKeyFile} ${cfg.apiKeyFile}"