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.
60 example = lib.literalExample ''
61 pkgs.webapps.etherpad-lite.withModules (p: [ p.ep_align ]);
64 modules = lib.mkOption {
65 type = lib.types.listOf lib.types.package;
68 Etherpad lite modules to use.
69 DEPRECATED: use package directly
73 workdir = lib.mkOption {
74 type = lib.types.package;
75 default = cfg.package.withModules (_: cfg.modules);
77 Adjusted Etherpad lite package with plugins
81 systemdStateDirectory = lib.mkOption {
83 # Use ReadWritePaths= instead if varDir is outside of /var/lib
84 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
85 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
87 Adjusted Etherpad lite data directory for systemd
91 systemdRuntimeDirectory = lib.mkOption {
93 # Use ReadWritePaths= instead if socketsDir is outside of /run
94 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
95 lib.strings.removePrefix "/run/" cfg.socketsDir;
97 Adjusted Etherpad lite sockets directory for systemd
101 sockets = lib.mkOption {
102 type = lib.types.attrsOf lib.types.path;
104 node = "${cfg.socketsDir}/etherpad-lite.sock";
108 Etherpad lite sockets
113 config = lib.mkIf cfg.enable {
114 systemd.services.etherpad-lite = {
115 description = "Etherpad-lite";
116 wantedBy = [ "multi-user.target" ];
117 after = [ "network.target" "postgresql.service" ];
118 wants = [ "postgresql.service" ];
120 environment.NODE_ENV = "production";
121 environment.HOME = cfg.workdir;
123 path = [ pkgs.nodejs ];
126 exec ${pkgs.nodejs}/bin/node ${cfg.workdir}/src/node/server.js \
127 --sessionkey ${cfg.sessionKeyFile} \
128 --apikey ${cfg.apiKeyFile} \
129 --settings ${cfg.configFile}
133 while [ ! -S ${cfg.sockets.node} ]; do
136 chmod a+w ${cfg.sockets.node}
142 WorkingDirectory = cfg.workdir;
144 NoNewPrivileges = true;
145 PrivateDevices = true;
147 ProtectControlGroups = true;
148 ProtectKernelModules = true;
152 RuntimeDirectory = cfg.systemdRuntimeDirectory;
153 StateDirectory= cfg.systemdStateDirectory;
155 "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/ep_initialized"
156 "+${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir} ${cfg.configFile} ${cfg.sessionKeyFile} ${cfg.apiKeyFile}"