From 5fb48557f57192685bc272e5d2b87f0000031890 Mon Sep 17 00:00:00 2001 From: elseym Date: Sat, 27 Apr 2019 11:04:07 +0200 Subject: [PATCH] documize-module: refactor and add more options --- nixos/modules/services/web-apps/documize.nix | 175 +++++++++++++------ 1 file changed, 123 insertions(+), 52 deletions(-) diff --git a/nixos/modules/services/web-apps/documize.nix b/nixos/modules/services/web-apps/documize.nix index 206617b0e5ac..37359869cb64 100644 --- a/nixos/modules/services/web-apps/documize.nix +++ b/nixos/modules/services/web-apps/documize.nix @@ -3,65 +3,136 @@ with lib; let - cfg = config.services.documize; -in + mkParams = optional: concatMapStrings (name: let + predicate = optional -> cfg.${name} != null; + template = " -${name} '${toString cfg.${name}}'"; + in optionalString predicate template); - { - options.services.documize = { - enable = mkEnableOption "Documize Wiki"; +in { + options.services.documize = { + enable = mkEnableOption "Documize Wiki"; - offline = mkEnableOption "Documize offline mode"; - - package = mkOption { - default = pkgs.documize-community; - type = types.package; - description = '' - Which package to use for documize. - ''; - }; - - db = mkOption { - type = types.str; - example = "host=localhost port=5432 sslmode=disable user=admin password=secret dbname=documize"; - description = '' - The DB connection string to use for the database. - ''; - }; - - dbtype = mkOption { - type = types.enum [ "postgresql" "percona" "mariadb" "mysql" ]; - description = '' - Which database to use for storage. - ''; - }; - - port = mkOption { - type = types.port; - example = 3000; - description = '' - Which TCP port to serve. - ''; - }; + package = mkOption { + type = types.package; + default = pkgs.documize-community; + description = '' + Which package to use for documize. + ''; }; - config = mkIf cfg.enable { - systemd.services.documize-server = { - wantedBy = [ "multi-user.target" ]; + salt = mkOption { + type = types.nullOr types.str; + default = null; + example = "3edIYV6c8B28b19fh"; + description = '' + The salt string used to encode JWT tokens, if not set a random value will be generated. + ''; + }; - script = '' - ${cfg.package}/bin/documize \ - -db "${cfg.db}" \ - -dbtype ${cfg.dbtype} \ - -port ${toString cfg.port} \ - -offline ${if cfg.offline then "1" else "0"} - ''; + cert = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + The cert.pem file used for https. + ''; + }; - serviceConfig = { - Restart = "always"; - DynamicUser = "yes"; - }; + key = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + The key.pem file used for https. + ''; + }; + + port = mkOption { + type = types.port; + default = 5001; + description = '' + The http/https port number. + ''; + }; + + forcesslport = mkOption { + type = types.nullOr types.port; + default = null; + description = '' + Redirect given http port number to TLS. + ''; + }; + + offline = mkOption { + type = types.bool; + default = false; + description = '' + Set true for offline mode. + ''; + apply = v: if true == v then 1 else 0; + }; + + dbtype = mkOption { + type = types.enum [ "mysql" "percona" "mariadb" "postgresql" "sqlserver" ]; + default = "postgresql"; + description = '' + Specify the database provider: + + mysql + percona + mariadb + postgresql + sqlserver + + ''; + }; + + db = mkOption { + type = types.str; + description = '' + Database specific connection string for example: + + MySQL/Percona/MariaDB: + user:password@tcp(host:3306)/documize + + MySQLv8+: + user:password@tcp(host:3306)/documize?allowNativePasswords=true + + PostgreSQL: + host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable + + MSSQL: + sqlserver://username:password@localhost:1433?database=Documize or + sqlserver://sa@localhost/SQLExpress?database=Documize + + + ''; + }; + + location = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + reserved + ''; + }; + }; + + config = mkIf cfg.enable { + systemd.services.documize-server = { + description = "Documize Wiki"; + documentation = [ https://documize.com/ ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = concatStringsSep " " [ + "${cfg.package}/bin/documize" + (mkParams false [ "db" "dbtype" "port" ]) + (mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ]) + ]; + Restart = "always"; + DynamicUser = "yes"; }; }; - } + }; +}