mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-28 14:22:50 +03:00
documize-module: refactor and add more options
This commit is contained in:
parent
6a73992cfa
commit
5fb48557f5
@ -3,65 +3,136 @@
|
|||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.services.documize;
|
cfg = config.services.documize;
|
||||||
|
|
||||||
in
|
mkParams = optional: concatMapStrings (name: let
|
||||||
|
predicate = optional -> cfg.${name} != null;
|
||||||
|
template = " -${name} '${toString cfg.${name}}'";
|
||||||
|
in optionalString predicate template);
|
||||||
|
|
||||||
{
|
in {
|
||||||
options.services.documize = {
|
options.services.documize = {
|
||||||
enable = mkEnableOption "Documize Wiki";
|
enable = mkEnableOption "Documize Wiki";
|
||||||
|
|
||||||
offline = mkEnableOption "Documize offline mode";
|
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
default = pkgs.documize-community;
|
|
||||||
type = types.package;
|
type = types.package;
|
||||||
|
default = pkgs.documize-community;
|
||||||
description = ''
|
description = ''
|
||||||
Which package to use for documize.
|
Which package to use for documize.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
db = mkOption {
|
salt = mkOption {
|
||||||
type = types.str;
|
type = types.nullOr types.str;
|
||||||
example = "host=localhost port=5432 sslmode=disable user=admin password=secret dbname=documize";
|
default = null;
|
||||||
|
example = "3edIYV6c8B28b19fh";
|
||||||
description = ''
|
description = ''
|
||||||
The DB connection string to use for the database.
|
The salt string used to encode JWT tokens, if not set a random value will be generated.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
dbtype = mkOption {
|
cert = mkOption {
|
||||||
type = types.enum [ "postgresql" "percona" "mariadb" "mysql" ];
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Which database to use for storage.
|
The <filename>cert.pem</filename> file used for https.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
key = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
The <filename>key.pem</filename> file used for https.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
type = types.port;
|
type = types.port;
|
||||||
example = 3000;
|
default = 5001;
|
||||||
description = ''
|
description = ''
|
||||||
Which TCP port to serve.
|
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 <literal>true</literal> 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:
|
||||||
|
<simplelist type='inline'>
|
||||||
|
<member><literal>mysql</literal></member>
|
||||||
|
<member><literal>percona</literal></member>
|
||||||
|
<member><literal>mariadb</literal></member>
|
||||||
|
<member><literal>postgresql</literal></member>
|
||||||
|
<member><literal>sqlserver</literal></member>
|
||||||
|
</simplelist>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
db = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = ''
|
||||||
|
Database specific connection string for example:
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem><para>MySQL/Percona/MariaDB:
|
||||||
|
<literal>user:password@tcp(host:3306)/documize</literal>
|
||||||
|
</para></listitem>
|
||||||
|
<listitem><para>MySQLv8+:
|
||||||
|
<literal>user:password@tcp(host:3306)/documize?allowNativePasswords=true</literal>
|
||||||
|
</para></listitem>
|
||||||
|
<listitem><para>PostgreSQL:
|
||||||
|
<literal>host=localhost port=5432 dbname=documize user=admin password=secret sslmode=disable</literal>
|
||||||
|
</para></listitem>
|
||||||
|
<listitem><para>MSSQL:
|
||||||
|
<literal>sqlserver://username:password@localhost:1433?database=Documize</literal> or
|
||||||
|
<literal>sqlserver://sa@localhost/SQLExpress?database=Documize</literal>
|
||||||
|
</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
location = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
reserved
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
systemd.services.documize-server = {
|
systemd.services.documize-server = {
|
||||||
|
description = "Documize Wiki";
|
||||||
|
documentation = [ https://documize.com/ ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
script = ''
|
|
||||||
${cfg.package}/bin/documize \
|
|
||||||
-db "${cfg.db}" \
|
|
||||||
-dbtype ${cfg.dbtype} \
|
|
||||||
-port ${toString cfg.port} \
|
|
||||||
-offline ${if cfg.offline then "1" else "0"}
|
|
||||||
'';
|
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
ExecStart = concatStringsSep " " [
|
||||||
|
"${cfg.package}/bin/documize"
|
||||||
|
(mkParams false [ "db" "dbtype" "port" ])
|
||||||
|
(mkParams true [ "offline" "location" "forcesslport" "key" "cert" "salt" ])
|
||||||
|
];
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
DynamicUser = "yes";
|
DynamicUser = "yes";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user