2021-03-20 04:20:00 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.wiki-js;
|
|
|
|
|
|
|
|
format = pkgs.formats.json { };
|
|
|
|
|
|
|
|
configFile = format.generate "wiki-js.yml" cfg.settings;
|
|
|
|
in {
|
|
|
|
options.services.wiki-js = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "wiki-js");
|
2021-03-20 04:20:00 +00:00
|
|
|
|
|
|
|
environmentFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = "/root/wiki-js.env";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-12-28 21:21:41 +00:00
|
|
|
Environment file to inject e.g. secrets into the configuration.
|
2021-03-20 04:20:00 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
stateDirectoryName = mkOption {
|
|
|
|
default = "wiki-js";
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Name of the directory in {file}`/var/lib`.
|
2021-03-20 04:20:00 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = format.type;
|
|
|
|
options = {
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 3000;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-03-20 04:20:00 +00:00
|
|
|
TCP port the process should listen to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
bindIP = mkOption {
|
|
|
|
default = "0.0.0.0";
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-03-20 04:20:00 +00:00
|
|
|
IPs the service should listen to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
db = {
|
|
|
|
type = mkOption {
|
|
|
|
default = "postgres";
|
|
|
|
type = types.enum [ "postgres" "mysql" "mariadb" "mssql" ];
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Database driver to use for persistence. Please note that `sqlite`
|
2021-03-20 04:20:00 +00:00
|
|
|
is currently not supported as the build process for it is currently not implemented
|
2022-08-21 13:32:41 +00:00
|
|
|
in `pkgs.wiki-js` and it's not recommended by upstream for
|
2021-03-20 04:20:00 +00:00
|
|
|
production use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/run/postgresql";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-03-20 04:20:00 +00:00
|
|
|
Hostname or socket-path to connect to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
db = mkOption {
|
|
|
|
default = "wiki";
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-03-20 04:20:00 +00:00
|
|
|
Name of the database to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
default = "info";
|
|
|
|
type = types.enum [ "error" "warn" "info" "verbose" "debug" "silly" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-03-20 04:20:00 +00:00
|
|
|
Define how much detail is supposed to be logged at runtime.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
offline = mkEnableOption (lib.mdDoc "offline mode") // {
|
|
|
|
description = lib.mdDoc ''
|
2021-03-20 04:20:00 +00:00
|
|
|
Disable latest file updates and enable
|
2022-09-09 14:08:57 +00:00
|
|
|
[sideloading](https://docs.requarks.io/install/sideload).
|
2021-03-20 04:20:00 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Settings to configure `wiki-js`. This directly
|
|
|
|
corresponds to [the upstream configuration options](https://docs.requarks.io/install/config).
|
2021-03-20 04:20:00 +00:00
|
|
|
|
|
|
|
Secrets can be injected via the environment by
|
2022-09-09 14:08:57 +00:00
|
|
|
- specifying [](#opt-services.wiki-js.environmentFile)
|
|
|
|
to contain secrets
|
|
|
|
- and setting sensitive values to `$(ENVIRONMENT_VAR)`
|
|
|
|
with this value defined in the environment-file.
|
2021-03-20 04:20:00 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.wiki-js.settings.dataPath = "/var/lib/${cfg.stateDirectoryName}";
|
|
|
|
systemd.services.wiki-js = {
|
|
|
|
description = "A modern and powerful wiki app built on Node.js";
|
|
|
|
documentation = [ "https://docs.requarks.io/" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
path = with pkgs; [ coreutils ];
|
|
|
|
preStart = ''
|
|
|
|
ln -sf ${configFile} /var/lib/${cfg.stateDirectoryName}/config.yml
|
|
|
|
ln -sf ${pkgs.wiki-js}/server /var/lib/${cfg.stateDirectoryName}
|
|
|
|
ln -sf ${pkgs.wiki-js}/assets /var/lib/${cfg.stateDirectoryName}
|
|
|
|
ln -sf ${pkgs.wiki-js}/package.json /var/lib/${cfg.stateDirectoryName}/package.json
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
|
|
|
StateDirectory = cfg.stateDirectoryName;
|
|
|
|
WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
|
|
|
|
DynamicUser = true;
|
|
|
|
PrivateTmp = true;
|
2022-09-22 12:36:57 +00:00
|
|
|
ExecStart = "${pkgs.nodejs-16_x}/bin/node ${pkgs.wiki-js}/server";
|
2021-03-20 04:20:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ ma27 ];
|
|
|
|
}
|