nixpkgs-suyu/nixos/modules/services/web-apps/documize.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

150 lines
4.2 KiB
Nix

{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.services.documize;
mkParams = optional: concatMapStrings (name: let
predicate = optional -> cfg.${name} != null;
template = " -${name} '${toString cfg.${name}}'";
in optionalString predicate template);
in {
options.services.documize = {
enable = mkEnableOption "Documize Wiki";
stateDirectoryName = mkOption {
type = types.str;
default = "documize";
description = lib.mdDoc ''
The name of the directory below {file}`/var/lib/private`
where documize runs in and stores, for example, backups.
'';
};
package = mkOption {
type = types.package;
default = pkgs.documize-community;
defaultText = literalExpression "pkgs.documize-community";
description = lib.mdDoc ''
Which package to use for documize.
'';
};
salt = mkOption {
type = types.nullOr types.str;
default = null;
example = "3edIYV6c8B28b19fh";
description = lib.mdDoc ''
The salt string used to encode JWT tokens, if not set a random value will be generated.
'';
};
cert = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
The {file}`cert.pem` file used for https.
'';
};
key = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
The {file}`key.pem` file used for https.
'';
};
port = mkOption {
type = types.port;
default = 5001;
description = lib.mdDoc ''
The http/https port number.
'';
};
forcesslport = mkOption {
type = types.nullOr types.port;
default = null;
description = lib.mdDoc ''
Redirect given http port number to TLS.
'';
};
offline = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
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:
<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 = lib.mdDoc ''
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";
StateDirectory = cfg.stateDirectoryName;
WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
};
};
};
}