1{ stdenv, fetchurl, lib, nixosTests, jq, moreutils }:
2
3stdenv.mkDerivation rec {
4 pname = "wiki-js";
5 version = "2.5.298";
6
7 src = fetchurl {
8 url = "https://github.com/Requarks/wiki/releases/download/v${version}/${pname}.tar.gz";
9 sha256 = "sha256-O7KQ134zh9ullYyQZimmxfdRwXeHkD8aAhy/pRzIjxo=";
10 };
11
12 # Implements nodejs 18 support as it's not planned to fix this before
13 # the release of v3[1] which is planned to happen in 2023, but not before
14 # NixOS 23.05. However, in the lifespan of 23.05 v16 will get EOLed, so
15 # we have to hack this on our own.
16 #
17 # The problem we fix here is that `exports."/public/"` in a `package.json`
18 # is prohibited, i.e. you cannot export full directories anymore.
19 #
20 # Unfortunately it's non-trivial to fix this because v10 of `extract-files`
21 # (where the problem is fixed) doesn't work for graphql-tools (which depends
22 # on this). Updating this as well is also quite complex because in later
23 # versions the package was split up into multiple smaller packages and
24 # thus a lot of parts of the code-base would need to be changed accordingly.
25 #
26 # Since this is the only breaking change of nodejs 17/18[2][3], this workaround
27 # will be necessary until we can upgrade to v3.
28 #
29 # [1] https://github.com/requarks/wiki/discussions/6388
30 # [2] https://nodejs.org/en/blog/release/v17.0.0
31 # [3] https://nodejs.org/en/blog/release/v18.0.0
32 nativeBuildInputs = [ jq moreutils ];
33 postPatch = ''
34 # Dirty hack to implement nodejs-18 support.
35 <./node_modules/extract-files/package.json jq '
36 # error out loud if the structure has changed and we need to change
37 # this expression
38 if .exports|has("./public/")|not then
39 halt_error(1)
40 else
41 .exports."./public/*" = "./public/*.js" | del(.exports."./public/")
42 end
43 ' | sponge ./node_modules/extract-files/package.json
44 '';
45
46 sourceRoot = ".";
47
48 dontBuild = true;
49 installPhase = ''
50 runHook preInstall
51
52 mkdir $out
53 cp -r . $out
54
55 runHook postInstall
56 '';
57
58 passthru = {
59 tests = { inherit (nixosTests) wiki-js; };
60 updateScript = ./update.sh;
61 };
62
63 meta = with lib; {
64 homepage = "https://js.wiki/";
65 description = "A modern and powerful wiki app built on Node.js";
66 license = licenses.agpl3Only;
67 maintainers = with maintainers; [ ma27 ];
68 };
69}