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