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