{ stdenv, lib, bun, coreutils, miso-lynx, ghc, }: let pname = "counter"; src = with lib.fileset; toSource rec { root = ./.; fileset = unions [ (root + "/LICENSE") (fileFilter ( file: lib.any file.hasExt [ "cabal" "hs" ] ) root) ]; }; haskellJS = ghc.callCabal2nix pname src { }; miso-lynx-node_modules = stdenv.mkDerivation { pname = "miso-lynx-node_modules"; src = miso-lynx; version = "0.0.0"; nativeBuildInputs = [ bun ]; dontConfigure = true; # ExplanationNote: fixed-output derivation # cannot reference Nix store paths, # and the fixup phase would change /usr/bin/… into /nix/store/… dontFixup = true; buildPhase = '' export BUN_INSTALL_CACHE_DIR=$(mktemp -d) cp -v ${../nix/pkgs/miso-lynx/bun.lock} bun.lock bun install --force --frozen-lockfile --no-progress --production ''; installPhase = '' mkdir -p $out/node_modules cp -R ./node_modules $out ''; # CorrectionNote: this has to be updated each time bun.lock is # eg. with `bun install --lockfile-only` outputHash = "sha256-9UsvyZt1PMlPrnEDxQGWN0SOutD826ORZ7ODxbSC8jo="; outputHashAlgo = "sha256"; outputHashMode = "recursive"; }; mainLynxBundle = stdenv.mkDerivation { inherit pname; version = haskellJS.version; src = miso-lynx; nativeBuildInputs = [ bun ]; configurePhase = '' runHook preConfigure cp -r ${miso-lynx-node_modules}/node_modules . substituteInPlace node_modules/.bin/rspack \ --replace-fail "#!/usr/bin/env" "#!${coreutils}/bin/env" runHook postConfigure ''; buildPhase = '' runHook preBuild bun run js cp -v ${haskellJS}/bin/counter.jsexe/all.js . bun build --minify all.js --target=bun --outfile=dist/all.js bun run bundle runHook postBuild ''; installPhase = '' runHook preInstall mkdir $out cp -v dist/main.lynx.bundle $out/ runHook postInstall ''; }; in mainLynxBundle