git.iko.soy/typeable/nixpkgs
on master help sign in
documize-module: refactor and add more options
commit5fb48557f57192685bc272e5d2b87f0000031890 authorelseym <elseym@me.com> dateSat 27 Apr 2019, 11:04 (8 years ago) parent6a73992
1 file changed+121−50
nixos/modules/services/web-apps/documize.nix+121−50
nixos/modules/services/web-apps/documize.nix+121−50
@@ -3,65 +3,136 @@
33with lib;
44
55let
6−
76 cfg = config.services.documize;
87
9−in
8+ mkParams = optional: concatMapStrings (name: let
9+ predicate = optional -> cfg.${name} != null;
10+ template = " -${name} '${toString cfg.${name}}'";
11+ in optionalString predicate template);
1012
11− {
12− options.services.documize = {
13− enable = mkEnableOption "Documize Wiki";
13+in {
14+ options.services.documize = {
15+ enable = mkEnableOption "Documize Wiki";
1416
15− offline = mkEnableOption "Documize offline mode";
17+ package = mkOption {
18+ type = types.package;
19+ default = pkgs.documize-community;
20+ description = ''
21+ Which package to use for documize.
22+ '';
23+ };
1624
17− package = mkOption {
18− default = pkgs.documize-community;
19− type = types.package;
20− description = ''
21− Which package to use for documize.
22− '';
23− };
25+ salt = mkOption {
26+ type = types.nullOr types.str;
27+ default = null;
28+ example = "3edIYV6c8B28b19fh";
29+ description = ''
30+ The salt string used to encode JWT tokens, if not set a random value will be generated.
31+ '';
32+ };
2433
25− db = mkOption {
26− type = types.str;
27− example = "host=localhost port=5432 sslmode=disable user=admin password=secret dbname=documize";
28− description = ''
29− The DB connection string to use for the database.
30− '';
31− };
34+ cert = mkOption {
35+ type = types.nullOr types.str;
36+ default = null;
37+ description = ''
38+ The <filename>cert.pem</filename> file used for https.
39+ '';
40+ };
3241
33− dbtype = mkOption {
34− type = types.enum [ "postgresql" "percona" "mariadb" "mysql" ];
35− description = ''
36− Which database to use for storage.
37− '';
38− };
42+ key = mkOption {
43+ type = types.nullOr types.str;
44+ default = null;
45+ description = ''
46+ The <filename>key.pem</filename> file used for https.
47+ '';
48+ };
3949
40− port = mkOption {
41− type = types.port;
42− example = 3000;
43− description = ''
44− Which TCP port to serve.
45− '';
46− };
50+ port = mkOption {
51+ type = types.port;
52+ default = 5001;
53+ description = ''
54+ The http/https port number.
55+ '';
56+ };
57+
58+ forcesslport = mkOption {
59+ type = types.nullOr types.port;
60+ default = null;
61+ description = ''
62+ Redirect given http port number to TLS.
63+ '';
64+ };
65+
66+ offline = mkOption {
67+ type = types.bool;
68+ default = false;
69+ description = ''
70+ Set <literal>true</literal> for offline mode.
71+ '';
72+ apply = v: if true == v then 1 else 0;
73+ };
74+
75+ dbtype = mkOption {
76+ type = types.enum [ "mysql" "percona" "mariadb" "postgresql" "sqlserver" ];
77+ default = "postgresql";
78+ description = ''
79+ Specify the database provider:
80+ <simplelist type='inline'>
81+ <member><literal>mysql</literal></member>
82+ <member><literal>percona</literal></member>
83+ <member><literal>mariadb</literal></member>
84+ <member><literal>postgresql</literal></member>
85+ <member><literal>sqlserver</literal></member>
86+ </simplelist>
87+ '';
4788 };
4889
49− config = mkIf cfg.enable {
50− systemd.services.documize-server = {
51− wantedBy = [ "multi-user.target" ];
52−
53− script = ''
54− ${cfg.package}/bin/documize \
55− -db "${cfg.db}" \
56− -dbtype ${cfg.dbtype} \
57− -port ${toString cfg.port} \
58− -offline ${if cfg.offline then "1" else "0"}
59− '';
60−
61− serviceConfig = {
62− Restart = "always";
63− DynamicUser = "yes";
64− };
90+ db = mkOption {
91+ type = types.str;
92+ description = ''
93+ Database specific connection string for example:
94+ <itemizedlist>
95+ <listitem><para>MySQL/Percona/MariaDB:
96+ <literal>user:password@tcp(host:3306)/documize</literal>
97+ </para></listitem>
98+ <listitem><para>MySQLv8+:
99+ <literal>user:password@tcp(host:3306)/documize?allowNativePasswords=true</literal>
100+ </para></listitem>
101+ <listitem><para>PostgreSQL:
102+ <literal>host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable</literal>
103+ </para></listitem>
104+ <listitem><para>MSSQL:
105+ <literal>sqlserver://username:password@localhost:1433?database=Documize</literal> or
106+ <literal>sqlserver://sa@localhost/SQLExpress?database=Documize</literal>
107+ </para></listitem>
108+ </itemizedlist>
109+ '';
110+ };
111+
112+ location = mkOption {
113+ type = types.nullOr types.str;
114+ default = null;
115+ description = ''
116+ reserved
117+ '';
118+ };
119+ };
120+
121+ config = mkIf cfg.enable {
122+ systemd.services.documize-server = {
123+ description = "Documize Wiki";
124+ documentation = [ https://documize.com/ ];
125+ wantedBy = [ "multi-user.target" ];
126+
127+ serviceConfig = {
128+ ExecStart = concatStringsSep " " [
129+ "${cfg.package}/bin/documize"
130+ (mkParams false [ "db" "dbtype" "port" ])
131+ (mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ])
132+ ];
133+ Restart = "always";
134+ DynamicUser = "yes";
65135 };
66136 };
67− }
137+ };
138+}