about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/gotify/ui.nix
blob: 2933a6ca474b35af9ad8e5a8e7b274a13bdecebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ yarn2nix-moretea
, fetchFromGitHub, applyPatches
, fetchYarnDeps
}:

yarn2nix-moretea.mkYarnPackage rec {
  pname = "gotify-ui";

  packageJSON = ./package.json;

  offlineCache = fetchYarnDeps {
    yarnLock = "${src}/yarn.lock";
    hash = "sha256-ejHzo6NHCMlNiYePWvfMY9Blb58pj3UQ5PFI0V84flI=";
  };

  version = import ./version.nix;

  src_all = applyPatches {
    src = fetchFromGitHub {
      owner = "gotify";
      repo = "server";
      rev = "v${version}";
      sha256 = import ./source-sha.nix;
    };
    postPatch = ''
      substituteInPlace ui/yarn.lock \
        --replace \
          "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001237.tgz" \
          "https___registry.npmjs.org_caniuse_lite___caniuse_lite_1.0.30001237.tgz"
    '';
  };
  src = "${src_all}/ui";

  buildPhase = ''
    export HOME=$(mktemp -d)
    export WRITABLE_NODE_MODULES="$(pwd)/tmp"
    export NODE_OPTIONS=--openssl-legacy-provider
    mkdir -p "$WRITABLE_NODE_MODULES"

    # react-scripts requires a writable node_modules/.cache, so we have to copy the symlink's contents back
    # into `node_modules/`.
    # See https://github.com/facebook/create-react-app/issues/11263
    cd deps/gotify-ui
    node_modules="$(readlink node_modules)"
    rm node_modules
    mkdir -p "$WRITABLE_NODE_MODULES"/.cache
    cp -r $node_modules/* "$WRITABLE_NODE_MODULES"

    # In `node_modules/.bin` are relative symlinks that would be broken after copying them over,
    # so we take care of them here.
    mkdir -p "$WRITABLE_NODE_MODULES"/.bin
    for x in "$node_modules"/.bin/*; do
      ln -sfv "$node_modules"/.bin/"$(readlink "$x")" "$WRITABLE_NODE_MODULES"/.bin/"$(basename "$x")"
    done

    ln -sfv "$WRITABLE_NODE_MODULES" node_modules
    cd ../..

    yarn build

    cd deps/gotify-ui
    rm -rf node_modules
    ln -sf $node_modules node_modules
    cd ../..
  '';

}