1{ pkgs, lib, config, ... }:
2
3with lib;
4
5let
6 cfg = config.services.documize;
7
8 mkParams = optional: concatMapStrings (name: let
9 predicate = optional -> cfg.${name} != null;
10 template = " -${name} '${toString cfg.${name}}'";
11 in optionalString predicate template);
12
13in {
14 options.services.documize = {
15 enable = mkEnableOption (lib.mdDoc "Documize Wiki");
16
17 stateDirectoryName = mkOption {
18 type = types.str;
19 default = "documize";
20 description = lib.mdDoc ''
21 The name of the directory below {file}`/var/lib/private`
22 where documize runs in and stores, for example, backups.
23 '';
24 };
25
26 package = mkOption {
27 type = types.package;
28 default = pkgs.documize-community;
29 defaultText = literalExpression "pkgs.documize-community";
30 description = lib.mdDoc ''
31 Which package to use for documize.
32 '';
33 };
34
35 salt = mkOption {
36 type = types.nullOr types.str;
37 default = null;
38 example = "3edIYV6c8B28b19fh";
39 description = lib.mdDoc ''
40 The salt string used to encode JWT tokens, if not set a random value will be generated.
41 '';
42 };
43
44 cert = mkOption {
45 type = types.nullOr types.str;
46 default = null;
47 description = lib.mdDoc ''
48 The {file}`cert.pem` file used for https.
49 '';
50 };
51
52 key = mkOption {
53 type = types.nullOr types.str;
54 default = null;
55 description = lib.mdDoc ''
56 The {file}`key.pem` file used for https.
57 '';
58 };
59
60 port = mkOption {
61 type = types.port;
62 default = 5001;
63 description = lib.mdDoc ''
64 The http/https port number.
65 '';
66 };
67
68 forcesslport = mkOption {
69 type = types.nullOr types.port;
70 default = null;
71 description = lib.mdDoc ''
72 Redirect given http port number to TLS.
73 '';
74 };
75
76 offline = mkOption {
77 type = types.bool;
78 default = false;
79 description = lib.mdDoc ''
80 Set `true` for offline mode.
81 '';
82 apply = v: if true == v then 1 else 0;
83 };
84
85 dbtype = mkOption {
86 type = types.enum [ "mysql" "percona" "mariadb" "postgresql" "sqlserver" ];
87 default = "postgresql";
88 description = lib.mdDoc ''
89 Specify the database provider: `mysql`, `percona`, `mariadb`, `postgresql`, `sqlserver`
90 '';
91 };
92
93 db = mkOption {
94 type = types.str;
95 description = lib.mdDoc ''
96 Database specific connection string for example:
97 - MySQL/Percona/MariaDB:
98 `user:password@tcp(host:3306)/documize`
99 - MySQLv8+:
100 `user:password@tcp(host:3306)/documize?allowNativePasswords=true`
101 - PostgreSQL:
102 `host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable`
103 - MSSQL:
104 `sqlserver://username:password@localhost:1433?database=Documize` or
105 `sqlserver://sa@localhost/SQLExpress?database=Documize`
106 '';
107 };
108
109 location = mkOption {
110 type = types.nullOr types.str;
111 default = null;
112 description = lib.mdDoc ''
113 reserved
114 '';
115 };
116 };
117
118 config = mkIf cfg.enable {
119 systemd.services.documize-server = {
120 description = "Documize Wiki";
121 documentation = [ "https://documize.com/" ];
122 wantedBy = [ "multi-user.target" ];
123
124 serviceConfig = {
125 ExecStart = concatStringsSep " " [
126 "${cfg.package}/bin/documize"
127 (mkParams false [ "db" "dbtype" "port" ])
128 (mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ])
129 ];
130 Restart = "always";
131 DynamicUser = "yes";
132 StateDirectory = cfg.stateDirectoryName;
133 WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
134 };
135 };
136 };
137}