at 22.05-pre 4.3 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 defaultText = literalExpression "pkgs.documize-community"; 30 description = '' 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 = '' 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 = '' 48 The <filename>cert.pem</filename> file used for https. 49 ''; 50 }; 51 52 key = mkOption { 53 type = types.nullOr types.str; 54 default = null; 55 description = '' 56 The <filename>key.pem</filename> file used for https. 57 ''; 58 }; 59 60 port = mkOption { 61 type = types.port; 62 default = 5001; 63 description = '' 64 The http/https port number. 65 ''; 66 }; 67 68 forcesslport = mkOption { 69 type = types.nullOr types.port; 70 default = null; 71 description = '' 72 Redirect given http port number to TLS. 73 ''; 74 }; 75 76 offline = mkOption { 77 type = types.bool; 78 default = false; 79 description = '' 80 Set <literal>true</literal> 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 = '' 89 Specify the database provider: 90 <simplelist type='inline'> 91 <member><literal>mysql</literal></member> 92 <member><literal>percona</literal></member> 93 <member><literal>mariadb</literal></member> 94 <member><literal>postgresql</literal></member> 95 <member><literal>sqlserver</literal></member> 96 </simplelist> 97 ''; 98 }; 99 100 db = mkOption { 101 type = types.str; 102 description = '' 103 Database specific connection string for example: 104 <itemizedlist> 105 <listitem><para>MySQL/Percona/MariaDB: 106 <literal>user:password@tcp(host:3306)/documize</literal> 107 </para></listitem> 108 <listitem><para>MySQLv8+: 109 <literal>user:password@tcp(host:3306)/documize?allowNativePasswords=true</literal> 110 </para></listitem> 111 <listitem><para>PostgreSQL: 112 <literal>host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable</literal> 113 </para></listitem> 114 <listitem><para>MSSQL: 115 <literal>sqlserver://username:password@localhost:1433?database=Documize</literal> or 116 <literal>sqlserver://sa@localhost/SQLExpress?database=Documize</literal> 117 </para></listitem> 118 </itemizedlist> 119 ''; 120 }; 121 122 location = mkOption { 123 type = types.nullOr types.str; 124 default = null; 125 description = '' 126 reserved 127 ''; 128 }; 129 }; 130 131 config = mkIf cfg.enable { 132 systemd.services.documize-server = { 133 description = "Documize Wiki"; 134 documentation = [ "https://documize.com/" ]; 135 wantedBy = [ "multi-user.target" ]; 136 137 serviceConfig = { 138 ExecStart = concatStringsSep " " [ 139 "${cfg.package}/bin/documize" 140 (mkParams false [ "db" "dbtype" "port" ]) 141 (mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ]) 142 ]; 143 Restart = "always"; 144 DynamicUser = "yes"; 145 StateDirectory = cfg.stateDirectoryName; 146 WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}"; 147 }; 148 }; 149 }; 150}