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