1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.cryptpad;
7in
8{
9 options.services.cryptpad = {
10 enable = mkEnableOption "the Cryptpad service";
11
12 package = mkOption {
13 default = pkgs.cryptpad;
14 defaultText = literalExpression "pkgs.cryptpad";
15 type = types.package;
16 description = "
17 Cryptpad package to use.
18 ";
19 };
20
21 configFile = mkOption {
22 type = types.path;
23 default = "${cfg.package}/lib/node_modules/cryptpad/config/config.example.js";
24 defaultText = literalExpression ''"''${package}/lib/node_modules/cryptpad/config/config.example.js"'';
25 description = ''
26 Path to the JavaScript configuration file.
27
28 See <link
29 xlink:href="https://github.com/xwiki-labs/cryptpad/blob/master/config/config.example.js"/>
30 for a configuration example.
31 '';
32 };
33 };
34
35 config = mkIf cfg.enable {
36 systemd.services.cryptpad = {
37 description = "Cryptpad Service";
38 wantedBy = [ "multi-user.target" ];
39 after = [ "networking.target" ];
40 serviceConfig = {
41 DynamicUser = true;
42 Environment = [
43 "CRYPTPAD_CONFIG=${cfg.configFile}"
44 "HOME=%S/cryptpad"
45 ];
46 ExecStart = "${cfg.package}/bin/cryptpad";
47 PrivateTmp = true;
48 Restart = "always";
49 StateDirectory = "cryptpad";
50 WorkingDirectory = "%S/cryptpad";
51 };
52 };
53 };
54}