tvl-depot/web/tvixbolt/default.nix
Ilan Joselevich 7ca32d9f0b refactor(web/tvixbolt): buildRustPackage -> crate2nix
With the recent changes to crate2nix and buildRustCrate in nixpkgs it is
now possible to build tvixbolt via crate2nix like we do for other tvix
crates. We can reuse a lot of the customizations done in //tvix in
tvixbolt to avoid repeating ourselves.

A script for serving tvixbolt locally for testing purposes is also
available now through the .serve attribute of tvixbolt.

This change supersedes https://cl.tvl.fyi/c/depot/+/11821.

Change-Id: I4864df8b75aec73cf5fee2428924ed4cfbb32902
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11952
Tested-by: BuildkiteCI
Autosubmit: Ilan Joselevich <personal@ilanjoselevich.com>
Reviewed-by: flokli <flokli@flokli.de>
2024-07-05 20:19:39 +00:00

30 lines
844 B
Nix

{ pkgs, lib, depot, ... }:
let
pkgsCross = pkgs.pkgsCross.wasm32-unknown-none;
in
(pkgsCross.callPackage ./Cargo.nix {
defaultCrateOverrides = (depot.tvix.utils.defaultCrateOverridesForPkgs pkgsCross) // {
tvixbolt = prev: {
src = depot.tvix.utils.filterRustCrateSrc { root = prev.src.origSrc; };
};
};
}).rootCrate.build.overrideAttrs (oldAttrs: {
installPhase = ''
${lib.getExe pkgs.wasm-bindgen-cli} \
--target web \
--out-dir $out \
--out-name ${oldAttrs.crateName} \
--no-typescript \
target/lib/${oldAttrs.crateName}-${oldAttrs.metadata}.wasm
mv src/*.{html,css} $out
'';
passthru.serve = pkgs.writeShellScriptBin "tvixbolt-serve" ''
${lib.getExe pkgs.simple-http-server} \
--index \
--nocache \
"$@" \
${depot.web.tvixbolt}
'';
})