summary refs log tree commit diff
path: root/pkgs/servers/polaris/web.nix
blob: 4ef4f90ead6f66d260cf8e4ba6faa11bb4f690cf (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ lib
, stdenv
, pkgs
, fetchFromGitHub
, nodejs
, cypress
}:

stdenv.mkDerivation rec {
  pname = "polaris-web";
  version = "build-54";

  src = fetchFromGitHub {
    owner = "agersant";
    repo = "polaris-web";
    rev = "${version}";
    sha256 = "+Tpj4XgWL1U+Y33YbEruilfV/6WGl8Dtj9FdXm2JVNU=";
  };

  nativeBuildInputs = [
    nodejs
  ];

  buildPhase =
    let
      nodeDependencies = (import ./node-composition.nix {
        inherit pkgs nodejs;
        inherit (stdenv.hostPlatform) system;
      }).nodeDependencies.override (old: {
        # access to path '/nix/store/...-source' is forbidden in restricted mode
        src = src;
        dontNpmInstall = true;

        # ERROR: .../.bin/node-gyp-build: /usr/bin/env: bad interpreter: No such file or directory
        # https://github.com/svanderburg/node2nix/issues/275
        # There are multiple instances of it, hence the globstar
        preRebuild = ''
          shopt -s globstar
          sed -i -e "s|#!/usr/bin/env node|#! ${pkgs.nodejs}/bin/node|" \
            node_modules/**/node-gyp-build/bin.js \
        '';

        buildInputs = [ cypress ];
        # prevent downloading cypress, use the executable in path instead
        CYPRESS_INSTALL_BINARY = "0";

      });
    in
    ''
      runHook preBuild

      export PATH="${nodeDependencies}/bin:${nodejs}/bin:$PATH"

      # https://github.com/parcel-bundler/parcel/issues/8005
      export NODE_OPTIONS=--no-experimental-fetch

      ln -s ${nodeDependencies}/lib/node_modules .
      npm run production

      runHook postBuild
    '';


  installPhase = ''
    runHook preInstall

    mkdir -p $out/share
    cp -a dist $out/share/polaris-web

    runHook postInstall
  '';

  passthru.updateScript = ./update-web.sh;

  meta = with lib; {
    description = "Web client for Polaris";
    homepage = "https://github.com/agersant/polaris-web";
    license = licenses.mit;
    maintainers = with maintainers; [ pbsds ];
    platforms = platforms.unix;
  };
}