summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/documize.nix
blob: 7f2ed82ee33e421a35e444bf21147c53cc8cac65 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{ pkgs, lib, config, ... }:

with lib;

let
  cfg = config.services.documize;

  mkParams = optional: concatMapStrings (name: let
    predicate = optional -> cfg.${name} != null;
    template = " -${name} '${toString cfg.${name}}'";
  in optionalString predicate template);

in {
  options.services.documize = {
    enable = mkEnableOption "Documize Wiki";

    stateDirectoryName = mkOption {
      type = types.str;
      default = "documize";
      description = ''
        The name of the directory below <filename>/var/lib/private</filename>
        where documize runs in and stores, for example, backups.
      '';
    };

    package = mkOption {
      type = types.package;
      default = pkgs.documize-community;
      defaultText = literalExpression "pkgs.documize-community";
      description = ''
        Which package to use for documize.
      '';
    };

    salt = mkOption {
      type = types.nullOr types.str;
      default = null;
      example = "3edIYV6c8B28b19fh";
      description = ''
        The salt string used to encode JWT tokens, if not set a random value will be generated.
      '';
    };

    cert = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        The <filename>cert.pem</filename> file used for https.
      '';
    };

    key = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        The <filename>key.pem</filename> file used for https.
      '';
    };

    port = mkOption {
      type = types.port;
      default = 5001;
      description = ''
        The http/https port number.
      '';
    };

    forcesslport = mkOption {
      type = types.nullOr types.port;
      default = null;
      description = ''
        Redirect given http port number to TLS.
      '';
    };

    offline = mkOption {
      type = types.bool;
      default = false;
      description = ''
        Set <literal>true</literal> for offline mode.
      '';
      apply = v: if true == v then 1 else 0;
    };

    dbtype = mkOption {
      type = types.enum [ "mysql" "percona" "mariadb" "postgresql" "sqlserver" ];
      default = "postgresql";
      description = ''
        Specify the database provider:
        <simplelist type='inline'>
          <member><literal>mysql</literal></member>
          <member><literal>percona</literal></member>
          <member><literal>mariadb</literal></member>
          <member><literal>postgresql</literal></member>
          <member><literal>sqlserver</literal></member>
        </simplelist>
      '';
    };

    db = mkOption {
      type = types.str;
      description = ''
        Database specific connection string for example:
        <itemizedlist>
        <listitem><para>MySQL/Percona/MariaDB:
          <literal>user:password@tcp(host:3306)/documize</literal>
        </para></listitem>
        <listitem><para>MySQLv8+:
          <literal>user:password@tcp(host:3306)/documize?allowNativePasswords=true</literal>
        </para></listitem>
        <listitem><para>PostgreSQL:
          <literal>host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable</literal>
        </para></listitem>
        <listitem><para>MSSQL:
          <literal>sqlserver://username:password@localhost:1433?database=Documize</literal> or
          <literal>sqlserver://sa@localhost/SQLExpress?database=Documize</literal>
        </para></listitem>
        </itemizedlist>
      '';
    };

    location = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        reserved
      '';
    };
  };

  config = mkIf cfg.enable {
    systemd.services.documize-server = {
      description = "Documize Wiki";
      documentation = [ "https://documize.com/" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        ExecStart = concatStringsSep " " [
          "${cfg.package}/bin/documize"
          (mkParams false [ "db" "dbtype" "port" ])
          (mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ])
        ];
        Restart = "always";
        DynamicUser = "yes";
        StateDirectory = cfg.stateDirectoryName;
        WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
      };
    };
  };
}