about summary refs log tree commit diff
path: root/corp/tvixbolt/default.nix
blob: f210a520402a6eb11c2c6b61ba962afdf4a0f223 (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
{ depot, lib, pkgs, ... }:

let
  wasmRust = pkgs.rust-bin.stable.latest.default.override {
    targets = [ "wasm32-unknown-unknown" ];
  };

  cargoToml = with builtins; fromTOML (readFile ./Cargo.toml);

  wasmBindgenMatch =
    cargoToml.dependencies.wasm-bindgen == "= ${pkgs.wasm-bindgen-cli.version}";

  assertWasmBindgen = assert (lib.assertMsg wasmBindgenMatch ''
    Due to instability in the Rust WASM ecosystem, the trunk build
    tool enforces that the Cargo-dependency version of `wasm-bindgen`
    MUST match the version of the CLI supplied in the environment.

    This can get out of sync when nixpkgs is updated. To resolve it,
    wasm-bindgen must be bumped in the Cargo.toml file and cargo needs
    to be run to resolve the dependencies.

    Versions of `wasm-bindgen` in Cargo.toml:

      Expected: '= ${pkgs.wasm-bindgen-cli.version}'
      Actual:   '${cargoToml.dependencies.wasm-bindgen}'
  ''); pkgs.wasm-bindgen-cli;

  deps = [
    pkgs.binaryen
    pkgs.sass
    pkgs.trunk

    wasmRust
    assertWasmBindgen
  ];

  # Cargo.toml needs to be patched with the /nix/store source path of
  # tvix-eval.
  cargoTomlPatch = pkgs.writeText "tvix-eval-src.patch" ''
    diff --git a/Cargo.toml b/Cargo.toml
    index 2e6c793..67280e7 100644
    --- a/Cargo.toml
    +++ b/Cargo.toml
    @@ -18,5 +18,5 @@ git = "https://github.com/nix-community/rnix-parser.git"
     rev = "97b438e34be5211a4b48aeed9cc3ded489b4d6da"

     [dependencies.tvix-eval]
    -path = "../../tvix/eval"
    +path = "${depot.tvix.eval.src}"
     default-features = false
  '';

in
pkgs.rustPlatform.buildRustPackage rec {
  pname = "tvixbolt";
  version = "canon";
  src = lib.cleanSource ./.;

  cargoLock.lockFile = ./Cargo.lock;
  cargoLock.outputHashes = {
    "rnix-0.11.0-dev" = "sha256:1vvpnv0jbyr96z8cb1r6k613zqsryan9awi53f901q3qjc856iz0";
  };

  patches = [
    cargoTomlPatch
  ];

  buildPhase = ''
    export PATH=${lib.makeBinPath deps}:$PATH
    mkdir home
    export HOME=$PWD/home
    trunk build --release -d $out
  '';

  dontInstall = true;
}