2 description = "Your self-hosted, globally interconnected microblogging community";
3 inputs.flake-utils.url = "github:numtide/flake-utils";
5 url = "github:NixOS/nixpkgs/840c782d507d60aaa49aa9e3f6d0b0e780912742";
8 inputs.etherpad-lite = {
9 url = "github:ether/etherpad-lite/1.8.3";
12 inputs.mypackages.url = "path:../mypackages";
14 outputs = { self, nixpkgs, etherpad-lite, flake-utils, mypackages }: flake-utils.lib.eachSystem ["x86_64-linux"] (system:
16 pkgs = import nixpkgs { inherit system; overlays = []; };
17 version = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.etherpad-lite.original.ref;
18 inherit (pkgs) callPackage;
20 packages.etherpad-lite = callPackage ./. { inherit (mypackages.mylibs) nodeEnv; src = etherpad-lite // { inherit version; }; };
21 defaultPackage = packages.etherpad-lite;
22 legacyPackages.etherpad-lite = packages.etherpad-lite;
24 build = defaultPackage;
29 etherpad-lite = final: prev: {
30 etherpad-lite = self.defaultPackage."${final.system}";
33 overlay = overlays.etherpad-lite;
34 nixosModule = { lib, pkgs, config, ... }:
36 name = "etherpad-lite";
37 cfg = config.services.etherpad-lite;
40 options.services.etherpad-lite = {
41 enable = lib.mkEnableOption "Enable Etherpad lite’s service";
45 description = "User account under which Etherpad lite runs";
47 group = lib.mkOption {
50 description = "Group under which Etherpad lite runs";
52 dataDir = lib.mkOption {
53 type = lib.types.path;
54 default = "/var/lib/${name}";
56 The directory where Etherpad lite stores its data.
59 socketsDir = lib.mkOption {
60 type = lib.types.path;
61 default = "/run/${name}";
63 The directory where Etherpad lite stores its sockets.
66 configFile = lib.mkOption {
67 type = lib.types.path;
69 The config file path for Etherpad lite.
72 sessionKeyFile = lib.mkOption {
73 type = lib.types.path;
75 The Session key file path for Etherpad lite.
78 apiKeyFile = lib.mkOption {
79 type = lib.types.path;
81 The API key file path for Etherpad lite.
84 package = lib.mkOption {
85 type = lib.types.package;
86 default = pkgs.etherpad-lite;
88 Etherpad lite package to use.
90 example = lib.literalExample ''
91 pkgs.webapps.etherpad-lite.withModules (p: [ p.ep_align ]);
94 modules = lib.mkOption {
95 type = lib.types.listOf lib.types.package;
98 Etherpad lite modules to use.
99 DEPRECATED: use package directly
103 workdir = lib.mkOption {
104 type = lib.types.package;
105 default = cfg.package.withModules (_: cfg.modules);
107 Adjusted Etherpad lite package with plugins
111 systemdStateDirectory = lib.mkOption {
112 type = lib.types.str;
113 # Use ReadWritePaths= instead if varDir is outside of /var/lib
114 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
115 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
117 Adjusted Etherpad lite data directory for systemd
121 systemdRuntimeDirectory = lib.mkOption {
122 type = lib.types.str;
123 # Use ReadWritePaths= instead if socketsDir is outside of /run
124 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
125 lib.strings.removePrefix "/run/" cfg.socketsDir;
127 Adjusted Etherpad lite sockets directory for systemd
131 sockets = lib.mkOption {
132 type = lib.types.attrsOf lib.types.path;
134 node = "${cfg.socketsDir}/etherpad-lite.sock";
138 Etherpad lite sockets
143 config = lib.mkIf cfg.enable {
144 nixpkgs.overlays = [ self.overlay ];
145 systemd.services.etherpad-lite-cleanup = {
146 description = "Etherpad-lite cleanup old mypads";
147 after = [ "network.target" "postgresql.service" ];
148 wants = [ "postgresql.service" ];
150 environment.NODE_ENV = "production";
151 environment.HOME = cfg.workdir;
153 path = [ cfg.workdir.nodejs ];
156 exec ${cfg.workdir.nodejs}/bin/node ${cfg.workdir}/node_modules/ep_mypads/scripts/mypads-jobqueue-minion.js \
157 --settings ${cfg.configFile} \
165 WorkingDirectory = "%T";
167 NoNewPrivileges = true;
168 PrivateDevices = true;
170 ProtectControlGroups = true;
171 ProtectKernelModules = true;
175 systemd.services.etherpad-lite = {
176 description = "Etherpad-lite";
177 wantedBy = [ "multi-user.target" ];
178 after = [ "network.target" "postgresql.service" ];
179 wants = [ "postgresql.service" ];
181 environment.NODE_ENV = "production";
182 environment.HOME = cfg.workdir;
184 path = [ cfg.workdir.nodejs ];
187 exec ${cfg.workdir.nodejs}/bin/node ${cfg.workdir}/src/node/server.js \
188 --sessionkey ${cfg.sessionKeyFile} \
189 --apikey ${cfg.apiKeyFile} \
190 --settings ${cfg.configFile}
194 while [ ! -S ${cfg.sockets.node} ]; do
197 chmod a+w ${cfg.sockets.node}
203 WorkingDirectory = cfg.workdir;
205 NoNewPrivileges = true;
206 PrivateDevices = true;
208 ProtectControlGroups = true;
209 ProtectKernelModules = true;
213 RuntimeDirectory = cfg.systemdRuntimeDirectory;
214 StateDirectory= cfg.systemdStateDirectory;
216 "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/var ${cfg.dataDir}/ep_initialized"
217 "+${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir} ${cfg.configFile} ${cfg.sessionKeyFile} ${cfg.apiKeyFile}"