git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #116738 from Ma27/wiki-js

wiki-js: init at 2.5.191

commitae73ec2b68cb37166254570ba7fbb352abab2d66 authorMaximilian Bosch <maximilian@mbosch.me> dateSat 27 Mar 2021, 22:03 (6 years ago) parent144a99747cc45a
6 files changed+327
nixos/modules/module-list.nix+1 nixos/modules/services/web-apps/wiki-js.nix+139 nixos/tests/all-tests.nix+1 nixos/tests/wiki-js.nix+152 pkgs/servers/web-apps/wiki-js/default.nix+32 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -924,6 +924,7 @@
924924 ./services/web-apps/selfoss.nix
925925 ./services/web-apps/shiori.nix
926926 ./services/web-apps/virtlyst.nix
927+ ./services/web-apps/wiki-js.nix
927928 ./services/web-apps/whitebophir.nix
928929 ./services/web-apps/wordpress.nix
929930 ./services/web-apps/youtrack.nix
nixos/modules/services/web-apps/wiki-js.nixnew file+139
@@ -0,0 +1,139 @@
1+{ lib, pkgs, config, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.wiki-js;
7+
8+ format = pkgs.formats.json { };
9+
10+ configFile = format.generate "wiki-js.yml" cfg.settings;
11+in {
12+ options.services.wiki-js = {
13+ enable = mkEnableOption "wiki-js";
14+
15+ environmentFile = mkOption {
16+ type = types.nullOr types.path;
17+ default = null;
18+ example = "/root/wiki-js.env";
19+ description = ''
20+ Environment fiel to inject e.g. secrets into the configuration.
21+ '';
22+ };
23+
24+ stateDirectoryName = mkOption {
25+ default = "wiki-js";
26+ type = types.str;
27+ description = ''
28+ Name of the directory in <filename>/var/lib</filename>.
29+ '';
30+ };
31+
32+ settings = mkOption {
33+ default = {};
34+ type = types.submodule {
35+ freeformType = format.type;
36+ options = {
37+ port = mkOption {
38+ type = types.port;
39+ default = 3000;
40+ description = ''
41+ TCP port the process should listen to.
42+ '';
43+ };
44+
45+ bindIP = mkOption {
46+ default = "0.0.0.0";
47+ type = types.str;
48+ description = ''
49+ IPs the service should listen to.
50+ '';
51+ };
52+
53+ db = {
54+ type = mkOption {
55+ default = "postgres";
56+ type = types.enum [ "postgres" "mysql" "mariadb" "mssql" ];
57+ description = ''
58+ Database driver to use for persistence. Please note that <literal>sqlite</literal>
59+ is currently not supported as the build process for it is currently not implemented
60+ in <package>pkgs.wiki-js</package> and it's not recommended by upstream for
61+ production use.
62+ '';
63+ };
64+ host = mkOption {
65+ type = types.str;
66+ example = "/run/postgresql";
67+ description = ''
68+ Hostname or socket-path to connect to.
69+ '';
70+ };
71+ db = mkOption {
72+ default = "wiki";
73+ type = types.str;
74+ description = ''
75+ Name of the database to use.
76+ '';
77+ };
78+ };
79+
80+ logLevel = mkOption {
81+ default = "info";
82+ type = types.enum [ "error" "warn" "info" "verbose" "debug" "silly" ];
83+ description = ''
84+ Define how much detail is supposed to be logged at runtime.
85+ '';
86+ };
87+
88+ offline = mkEnableOption "offline mode" // {
89+ description = ''
90+ Disable latest file updates and enable
91+ <link xlink:href="https://docs.requarks.io/install/sideload">sideloading</link>.
92+ '';
93+ };
94+ };
95+ };
96+ description = ''
97+ Settings to configure <package>wiki-js</package>. This directly
98+ corresponds to <link xlink:href="https://docs.requarks.io/install/config">the upstream
99+ configuration options</link>.
100+
101+ Secrets can be injected via the environment by
102+ <itemizedlist>
103+ <listitem><para>specifying <xref linkend="opt-services.wiki-js.environmentFile" />
104+ to contain secrets</para></listitem>
105+ <listitem><para>and setting sensitive values to <literal>$(ENVIRONMENT_VAR)</literal>
106+ with this value defined in the environment-file.</para></listitem>
107+ </itemizedlist>
108+ '';
109+ };
110+ };
111+
112+ config = mkIf cfg.enable {
113+ services.wiki-js.settings.dataPath = "/var/lib/${cfg.stateDirectoryName}";
114+ systemd.services.wiki-js = {
115+ description = "A modern and powerful wiki app built on Node.js";
116+ documentation = [ "https://docs.requarks.io/" ];
117+ wantedBy = [ "multi-user.target" ];
118+
119+ path = with pkgs; [ coreutils ];
120+ preStart = ''
121+ ln -sf ${configFile} /var/lib/${cfg.stateDirectoryName}/config.yml
122+ ln -sf ${pkgs.wiki-js}/server /var/lib/${cfg.stateDirectoryName}
123+ ln -sf ${pkgs.wiki-js}/assets /var/lib/${cfg.stateDirectoryName}
124+ ln -sf ${pkgs.wiki-js}/package.json /var/lib/${cfg.stateDirectoryName}/package.json
125+ '';
126+
127+ serviceConfig = {
128+ EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile;
129+ StateDirectory = cfg.stateDirectoryName;
130+ WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
131+ DynamicUser = true;
132+ PrivateTmp = true;
133+ ExecStart = "${pkgs.nodejs}/bin/node ${pkgs.wiki-js}/server";
134+ };
135+ };
136+ };
137+
138+ meta.maintainers = with maintainers; [ ma27 ];
139+}
nixos/tests/all-tests.nix+1
@@ -426,6 +426,7 @@ in
426426 virtualbox = handleTestOn ["x86_64-linux"] ./virtualbox.nix {};
427427 vscodium = handleTest ./vscodium.nix {};
428428 wasabibackend = handleTest ./wasabibackend.nix {};
429+ wiki-js = handleTest ./wiki-js.nix {};
429430 wireguard = handleTest ./wireguard {};
430431 wordpress = handleTest ./wordpress.nix {};
431432 xandikos = handleTest ./xandikos.nix {};
nixos/tests/wiki-js.nixnew file+152
@@ -0,0 +1,152 @@
1+import ./make-test-python.nix ({ pkgs, lib, ...} : {
2+ name = "wiki-js";
3+ meta = with pkgs.lib.maintainers; {
4+ maintainers = [ ma27 ];
5+ };
6+
7+ machine = { pkgs, ... }: {
8+ virtualisation.memorySize = 2048;
9+ services.wiki-js = {
10+ enable = true;
11+ settings.db.host = "/run/postgresql";
12+ settings.db.user = "wiki-js";
13+ settings.logLevel = "debug";
14+ };
15+ services.postgresql = {
16+ enable = true;
17+ ensureDatabases = [ "wiki" ];
18+ ensureUsers = [
19+ { name = "wiki-js";
20+ ensurePermissions."DATABASE wiki" = "ALL PRIVILEGES";
21+ }
22+ ];
23+ };
24+ systemd.services.wiki-js = {
25+ requires = [ "postgresql.service" ];
26+ after = [ "postgresql.service" ];
27+ };
28+ environment.systemPackages = with pkgs; [ jq ];
29+ };
30+
31+ testScript = let
32+ payloads.finalize = pkgs.writeText "finalize.json" (builtins.toJSON {
33+ adminEmail = "webmaster@example.com";
34+ adminPassword = "notapassword";
35+ adminPasswordConfirm = "notapassword";
36+ siteUrl = "http://localhost:3000";
37+ telemetry = false;
38+ });
39+ payloads.login = pkgs.writeText "login.json" (builtins.toJSON [{
40+ operationName = null;
41+ extensions = {};
42+ query = ''
43+ mutation ($username: String!, $password: String!, $strategy: String!) {
44+ authentication {
45+ login(username: $username, password: $password, strategy: $strategy) {
46+ responseResult {
47+ succeeded
48+ errorCode
49+ slug
50+ message
51+ __typename
52+ }
53+ jwt
54+ mustChangePwd
55+ mustProvideTFA
56+ mustSetupTFA
57+ continuationToken
58+ redirect
59+ tfaQRImage
60+ __typename
61+ }
62+ __typename
63+ }
64+ }
65+ '';
66+ variables = {
67+ password = "notapassword";
68+ strategy = "local";
69+ username = "webmaster@example.com";
70+ };
71+ }]);
72+ payloads.content = pkgs.writeText "content.json" (builtins.toJSON [{
73+ extensions = {};
74+ operationName = null;
75+ query = ''
76+ mutation ($content: String!, $description: String!, $editor: String!, $isPrivate: Boolean!, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $scriptCss: String, $scriptJs: String, $tags: [String]!, $title: String!) {
77+ pages {
78+ create(content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, scriptCss: $scriptCss, scriptJs: $scriptJs, tags: $tags, title: $title) {
79+ responseResult {
80+ succeeded
81+ errorCode
82+ slug
83+ message
84+ __typename
85+ }
86+ page {
87+ id
88+ updatedAt
89+ __typename
90+ }
91+ __typename
92+ }
93+ __typename
94+ }
95+ }
96+ '';
97+ variables = {
98+ content = "# Header\n\nHello world!";
99+ description = "";
100+ editor = "markdown";
101+ isPrivate = false;
102+ isPublished = true;
103+ locale = "en";
104+ path = "home";
105+ publishEndDate = "";
106+ publishStartDate = "";
107+ scriptCss = "";
108+ scriptJs = "";
109+ tags = [];
110+ title = "Hello world";
111+ };
112+ }]);
113+ in ''
114+ machine.start()
115+ machine.wait_for_unit("multi-user.target")
116+ machine.wait_for_open_port(3000)
117+
118+ machine.succeed("curl -sSf localhost:3000")
119+
120+ with subtest("Setup"):
121+ result = machine.succeed(
122+ "set -o pipefail; curl -sSf localhost:3000/finalize -X POST -d "
123+ + "@${payloads.finalize} -H 'Content-Type: application/json' "
124+ + "| jq .ok | xargs echo"
125+ )
126+ assert result.strip() == "true", f"Expected true, got {result}"
127+
128+ # During the setup the service gets restarted, so we use this
129+ # to check if the setup is done.
130+ machine.wait_until_fails("curl -sSf localhost:3000")
131+ machine.wait_until_succeeds("curl -sSf localhost:3000")
132+
133+ with subtest("Base functionality"):
134+ auth = machine.succeed(
135+ "set -o pipefail; curl -sSf localhost:3000/graphql -X POST "
136+ + "-d @${payloads.login} -H 'Content-Type: application/json' "
137+ + "| jq '.[0].data.authentication.login.jwt' | xargs echo"
138+ ).strip()
139+
140+ assert auth
141+
142+ create = machine.succeed(
143+ "set -o pipefail; curl -sSf localhost:3000/graphql -X POST "
144+ + "-d @${payloads.content} -H 'Content-Type: application/json' "
145+ + f"-H 'Authorization: Bearer {auth}' "
146+ + "| jq '.[0].data.pages.create.responseResult.succeeded'|xargs echo"
147+ )
148+ assert create.strip() == "true", f"Expected true, got {create}"
149+
150+ machine.shutdown()
151+ '';
152+})
pkgs/servers/web-apps/wiki-js/default.nixnew file+32
@@ -0,0 +1,32 @@
1+{ stdenv, fetchurl, lib, nixosTests }:
2+
3+stdenv.mkDerivation rec {
4+ pname = "wiki-js";
5+ version = "2.5.197";
6+
7+ src = fetchurl {
8+ url = "https://github.com/Requarks/wiki/releases/download/${version}/${pname}.tar.gz";
9+ sha256 = "sha256-0xM9BtQvSt5WkbKBri+KxB+Ghc4wgY8/TUgI6PCFmm0=";
10+ };
11+
12+ sourceRoot = ".";
13+
14+ dontBuild = true;
15+ installPhase = ''
16+ runHook preInstall
17+
18+ mkdir $out
19+ cp -r . $out
20+
21+ runHook postInstall
22+ '';
23+
24+ passthru.tests = { inherit (nixosTests) wiki-js; };
25+
26+ meta = with lib; {
27+ homepage = "https://js.wiki/";
28+ description = "A modern and powerful wiki app built on Node.js";
29+ license = licenses.agpl3Only;
30+ maintainers = with maintainers; [ ma27 ];
31+ };
32+}
pkgs/top-level/all-packages.nix+2
@@ -30076,6 +30076,8 @@ in
3007630076 pythonPackages = python3Packages;
3007730077 };
3007830078
30079+ wiki-js = callPackage ../servers/web-apps/wiki-js { };
30080+
3007930081 winePackagesFor = wineBuild: lib.makeExtensible (self: with self; {
3008030082 callPackage = newScope self;
3008130083