mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-11 08:13:04 +00:00
577ffe768c
Part of #229910. Unfortunately this is a little hacky because upstream doesn't intend to support it for 2.5, but only for 3.0 which isn't out yet, however nodejs-16 will get out of maintenance during the support-span of NixOS 23.05[1]. The only breaking change is that `extract-files` uses a deprecated way of exposing modules, I went through the list of other breaking changes in v17 and v18[2][3] and couldn't spot any usage of removed features, also local testing didn't reveal further issues. Unfortunately fixing that breakage turned out to be non-trivial. Currently, `extract-files@9.0.0` is used with the problematic portions in its `package.json`, however it's only a transitive dependency of `@graphql-tools/url-loader` & `apollo-upload-client`. Unfortunately, the versions of that in use require v9 and don't work with a newer version of `extract-files` with the problem fixed[4]. Also, upgrading the dependencies in question is not a feasible option because `graphql-tools` was split up into multiple smaller packages in v8 and also some of the APIs in use in `wiki.js` were dropped there[5], so this would also be very time-consuming and non-trivial to fix. Since this was the only issue, I decided to go down the hacky route and patch the problem in `package.json` of `extract-files` manually during our `patchPhase`. [1] https://github.com/requarks/wiki/discussions/6388 [2] https://nodejs.org/en/blog/release/v17.0.0 [3] https://nodejs.org/en/blog/release/v18.0.0 [4] Upon local testing, this broke with the following error: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './public/extractFiles' is not defined by "exports" in /wiki/node_modules/extract-files/package.json [5] For instance `SchemaDirectiveVisitor` in `server/graph/directives/auth`.
143 lines
4.4 KiB
Nix
143 lines
4.4 KiB
Nix
{ 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 = {
|
|
enable = mkEnableOption (lib.mdDoc "wiki-js");
|
|
|
|
environmentFile = mkOption {
|
|
type = types.nullOr types.path;
|
|
default = null;
|
|
example = "/root/wiki-js.env";
|
|
description = lib.mdDoc ''
|
|
Environment file to inject e.g. secrets into the configuration.
|
|
'';
|
|
};
|
|
|
|
stateDirectoryName = mkOption {
|
|
default = "wiki-js";
|
|
type = types.str;
|
|
description = lib.mdDoc ''
|
|
Name of the directory in {file}`/var/lib`.
|
|
'';
|
|
};
|
|
|
|
settings = mkOption {
|
|
default = {};
|
|
type = types.submodule {
|
|
freeformType = format.type;
|
|
options = {
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = 3000;
|
|
description = lib.mdDoc ''
|
|
TCP port the process should listen to.
|
|
'';
|
|
};
|
|
|
|
bindIP = mkOption {
|
|
default = "0.0.0.0";
|
|
type = types.str;
|
|
description = lib.mdDoc ''
|
|
IPs the service should listen to.
|
|
'';
|
|
};
|
|
|
|
db = {
|
|
type = mkOption {
|
|
default = "postgres";
|
|
type = types.enum [ "postgres" "mysql" "mariadb" "mssql" ];
|
|
description = lib.mdDoc ''
|
|
Database driver to use for persistence. Please note that `sqlite`
|
|
is currently not supported as the build process for it is currently not implemented
|
|
in `pkgs.wiki-js` and it's not recommended by upstream for
|
|
production use.
|
|
'';
|
|
};
|
|
host = mkOption {
|
|
type = types.str;
|
|
example = "/run/postgresql";
|
|
description = lib.mdDoc ''
|
|
Hostname or socket-path to connect to.
|
|
'';
|
|
};
|
|
db = mkOption {
|
|
default = "wiki";
|
|
type = types.str;
|
|
description = lib.mdDoc ''
|
|
Name of the database to use.
|
|
'';
|
|
};
|
|
};
|
|
|
|
logLevel = mkOption {
|
|
default = "info";
|
|
type = types.enum [ "error" "warn" "info" "verbose" "debug" "silly" ];
|
|
description = lib.mdDoc ''
|
|
Define how much detail is supposed to be logged at runtime.
|
|
'';
|
|
};
|
|
|
|
offline = mkEnableOption (lib.mdDoc "offline mode") // {
|
|
description = lib.mdDoc ''
|
|
Disable latest file updates and enable
|
|
[sideloading](https://docs.requarks.io/install/sideload).
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
description = lib.mdDoc ''
|
|
Settings to configure `wiki-js`. This directly
|
|
corresponds to [the upstream configuration options](https://docs.requarks.io/install/config).
|
|
|
|
Secrets can be injected via the environment by
|
|
- specifying [](#opt-services.wiki-js.environmentFile)
|
|
to contain secrets
|
|
- and setting sensitive values to `$(ENVIRONMENT_VAR)`
|
|
with this value defined in the environment-file.
|
|
'';
|
|
};
|
|
};
|
|
|
|
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; [
|
|
# Needed for git storage.
|
|
git
|
|
# Needed for git+ssh storage.
|
|
openssh
|
|
];
|
|
|
|
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;
|
|
ExecStart = "${pkgs.nodejs_18}/bin/node ${pkgs.wiki-js}/server";
|
|
};
|
|
};
|
|
};
|
|
|
|
meta.maintainers = with maintainers; [ ma27 ];
|
|
}
|