summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/cryptpad.nix
blob: 69a89107d3102c57c3f90032aa6de37f5a362519 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.cryptpad;
in
{
  options.services.cryptpad = {
    enable = mkEnableOption "the Cryptpad service";

    package = mkOption {
      default = pkgs.cryptpad;
      defaultText = "pkgs.cryptpad";
      type = types.package;
      description = "
        Cryptpad package to use.
      ";
    };

    configFile = mkOption {
      type = types.path;
      default = "${cfg.package}/lib/node_modules/cryptpad/config/config.example.js";
      defaultText = "\${cfg.package}/lib/node_modules/cryptpad/config/config.example.js";
      description = ''
        Path to the JavaScript configuration file.

        See <link
        xlink:href="https://github.com/xwiki-labs/cryptpad/blob/master/config/config.example.js"/>
        for a configuration example.
      '';
    };
  };

  config = mkIf cfg.enable {
    systemd.services.cryptpad = {
      description = "Cryptpad Service";
      wantedBy = [ "multi-user.target" ];
      after = [ "networking.target" ];
      serviceConfig = {
        DynamicUser = true;
        Environment = [
          "CRYPTPAD_CONFIG=${cfg.configFile}"
          "HOME=%S/cryptpad"
        ];
        ExecStart = "${cfg.package}/bin/cryptpad";
        PrivateTmp = true;
        Restart = "always";
        StateDirectory = "cryptpad";
        WorkingDirectory = "%S/cryptpad";
      };
    };
  };
}