about summary refs log tree commit diff
path: root/web/default.nix
blob: 5f73366b3c76898f04b896f18e49afcf6b98a23e (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
{ stdenv, lib, fetchFromGitHub, callPackage, yarn
, production ? true }:

let
  target = if production then "prod" else "dev";
  pkgInfo = lib.importJSON ./package.json;
  src = yarn2nix-lib.removePrefixes [ "node_modules" "dist" ] ./.;
#  yarn2nixSrc = /home/lukas/src/nix/yarn2nix;
  yarn2nixSrc = fetchFromGitHub {
    owner  = "sternenseemann";
    repo   = "yarn2nix";
    rev    = "b0825bbe4b40f39763d53ba0044431a44b5f25cf";
    sha256 = "1q8wc5rnb00xwzcqsgb6wfkmymipf2bv1g2i33l5wyadp0hd18cp";
  };
  yarn2nix = import yarn2nixSrc { };
  yarn2nix-lib = yarn2nix.nixLib;
  deps = yarn2nix-lib.callYarnLock ./yarn.lock { };
  template = yarn2nix-lib.callPackageJson ./package.json { };
  calledTemplate = template (yarn2nix-lib.buildNodeDeps deps);
  node_modules = yarn2nix-lib.linkNodeDeps {
    inherit (pkgInfo) name;
    dependencies = calledTemplate.nodeBuildInputs;
  };
  yarnFlags = lib.escapeShellArgs [ "--offline" "--frozen-lockfile" ];

in

stdenv.mkDerivation rec {
  pname = pkgInfo.name;
  inherit (pkgInfo) version;
  inherit src;

  buildInputs = [ yarn ];

  phases = [ "unpackPhase" "patchPhase" "buildPhase" "installPhase" ];

  postPatch = ''
    substituteInPlace ./package.json \
      --replace node_modules "${node_modules}"
  '';

  # make sure vis-network find vis-data
  NODE_PATH = "${node_modules}";

  buildPhase = ''
    # browserify won't look in NODE_PATH for modules
    # due to the symlink yarn will also add node_modules/.bin
    # to PATH, so we don't have to do it
    ln -s ${node_modules} node_modules
    yarn ${yarnFlags} run build:assets
    yarn ${yarnFlags} run build:${target}
  '';

  installPhase = ''
    mkdir -p $out/share/
    cp -R dist $out/share/${pname}
  '';

  meta = calledTemplate.meta // {
    description = "Frontend of likely music, a probabilistic music notation software";
    homepage = "https://github.com/sternenseemann/likely-music";
  };
}