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";
13 outputs = { self, nixpkgs, etherpad-lite, flake-utils }: flake-utils.lib.eachSystem ["x86_64-linux"] (system:
15 pkgs = import nixpkgs { inherit system; overlays = []; };
16 version = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.etherpad-lite.original.ref;
17 inherit (pkgs) callPackage;
19 packages.etherpad-lite = callPackage ./. { src = etherpad-lite // { inherit version; }; };
20 defaultPackage = packages.etherpad-lite;
21 legacyPackages.etherpad-lite = packages.etherpad-lite;
23 build = defaultPackage;
28 etherpad-lite = final: prev: {
29 etherpad-lite = self.defaultPackage."${final.system}";
32 overlay = overlays.etherpad-lite;
33 nixosModule = { lib, pkgs, config, ... }:
35 name = "etherpad-lite";
36 cfg = config.services.etherpad-lite;
39 options.services.etherpad-lite = {
40 enable = lib.mkEnableOption "Enable Etherpad lite’s service";
44 description = "User account under which Etherpad lite runs";
46 group = lib.mkOption {
49 description = "Group under which Etherpad lite runs";
51 dataDir = lib.mkOption {
52 type = lib.types.path;
53 default = "/var/lib/${name}";
55 The directory where Etherpad lite stores its data.
58 socketsDir = lib.mkOption {
59 type = lib.types.path;
60 default = "/run/${name}";
62 The directory where Etherpad lite stores its sockets.
65 configFile = lib.mkOption {
66 type = lib.types.path;
68 The config file path for Etherpad lite.
71 sessionKeyFile = lib.mkOption {
72 type = lib.types.path;
74 The Session key file path for Etherpad lite.
77 apiKeyFile = lib.mkOption {
78 type = lib.types.path;
80 The API key file path for Etherpad lite.
83 package = lib.mkOption {
84 type = lib.types.package;
85 default = pkgs.etherpad-lite;
87 Etherpad lite package to use.
89 example = lib.literalExample ''
90 pkgs.webapps.etherpad-lite.withModules (p: [ p.ep_align ]);
93 modules = lib.mkOption {
94 type = lib.types.listOf lib.types.package;
97 Etherpad lite modules to use.
98 DEPRECATED: use package directly
102 workdir = lib.mkOption {
103 type = lib.types.package;
104 default = cfg.package.withModules (_: cfg.modules);
106 Adjusted Etherpad lite package with plugins
110 systemdStateDirectory = lib.mkOption {
111 type = lib.types.str;
112 # Use ReadWritePaths= instead if varDir is outside of /var/lib
113 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
114 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
116 Adjusted Etherpad lite data directory for systemd
120 systemdRuntimeDirectory = lib.mkOption {
121 type = lib.types.str;
122 # Use ReadWritePaths= instead if socketsDir is outside of /run
123 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
124 lib.strings.removePrefix "/run/" cfg.socketsDir;
126 Adjusted Etherpad lite sockets directory for systemd
130 sockets = lib.mkOption {
131 type = lib.types.attrsOf lib.types.path;
133 node = "${cfg.socketsDir}/etherpad-lite.sock";
137 Etherpad lite sockets
142 config = lib.mkIf cfg.enable {
143 nixpkgs.overlays = [ self.overlay ];
144 systemd.services.etherpad-lite = {
145 description = "Etherpad-lite";
146 wantedBy = [ "multi-user.target" ];
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}/src/node/server.js \
157 --sessionkey ${cfg.sessionKeyFile} \
158 --apikey ${cfg.apiKeyFile} \
159 --settings ${cfg.configFile}
163 while [ ! -S ${cfg.sockets.node} ]; do
166 chmod a+w ${cfg.sockets.node}
172 WorkingDirectory = cfg.workdir;
174 NoNewPrivileges = true;
175 PrivateDevices = true;
177 ProtectControlGroups = true;
178 ProtectKernelModules = true;
182 RuntimeDirectory = cfg.systemdRuntimeDirectory;
183 StateDirectory= cfg.systemdStateDirectory;
185 "+${pkgs.coreutils}/bin/install -d -m 0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dataDir}/ep_initialized"
186 "+${pkgs.coreutils}/bin/chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir} ${cfg.configFile} ${cfg.sessionKeyFile} ${cfg.apiKeyFile}"