Bun2nix v2 - Testers wanted

Hey everyone, after a couple weeks of on and off work I’ve just opened a PR for a version 2 for bun2nix, which I originally announced here.

This includes some goodies and long awaited features like:

  • Git and tarball dependencies
  • Proper creation of an offline bun install cache instead of an (admittedly scuffed) manual creation of node_modules
  • An NPM packaged WASM CLI for usage in cross platform teams

It’s fairly close to being ready, but before I go and make a bunch of breaking changes, I’d like to first make sure it actually works in real world situations before merging it, so if you have any feedback, please let me know.

4 Likes

Amazing! Excited to see that this should solve my checkPhase issue.

Trying this out now; from reading docs/src/v2-update-guide.md it seems like all I should need to do for my project (which just uses bun2nix.lib.${system}.mkBunDerivation and provides bunNix via "${bun2nix.packages.${system}.default}/bin/bun2nix") is this:

diff --git a/flake.nix b/flake.nix
index a2ad564..91a4056 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,7 +3,7 @@
     nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
     flake-utils.url = "github:numtide/flake-utils";
     bun2nix = {
-      url = "github:baileyluTCD/bun2nix";
+      url = "github:fleek-platform/bun2nix";
       inputs.nixpkgs.follows = "nixpkgs";
     };
   };
@@ -20,7 +20,7 @@
         pkgs = import nixpkgs { inherit system; };
       in
       {
-        packages.default = bun2nix.lib.${system}.mkBunDerivation {
+        packages.default = bun2nix.packages.${system}.default.mkDerivation {
           packageJson = ./package.json;
           src = ./.;
           bunNix = (

But I’m getting this error when I run nix build:

error: function 'extendDrvArgs' called without required argument 'bunDeps'

Is this a bug, or is there some additional change I need that isn’t covered by the V2 update guide, or does my IFD strategy (to avoid checking bun.nix into Git) simply not work with bun2nix v2?

Thanks for giving it a look - you’re missing this

Before

bunNix = <whatever ifd expression>;

After

bunDeps = bun2nix.fetchBunDeps {
  bunNix = <whatever ifd expression>;
};

I made this change so that:

  • Importing the bun dependencies is the same for both the new setup hook and the mkDerivation function
  • It matches up with the node/yarn builders from nixpkgs
  • You can customise how the bun cache is built further to give users more control - check out the overrides attr, for example, which you can use to make nix specific patches to dependencies

I did have a nice error message working for when you’re missing bunDeps when you use the setup hook, but it seems I need to patch it to also work for the mkDerivation function.

1 Like

Thank you, that gets me past my earlier error! Apologies, I now see that that is indeed in the update guide and I just missed it.

Question: in your message just now, and also in the v2 update guide, you seem to imply that I can just write bun2nix.mkDerivation/bun2nix.fetchBunDeps instead of the more verbose bun2nix.packages.${system}.default.mkDerivation/bun2nix.packages.${system}.default.fetchBunDeps; but that doesn’t work for me. In what context would that actually work?

Regardless, I unfortunately now get a different error:

warning: Git tree '/Users/samueles/github/samestep/website' has uncommitted changes
error: Cannot build '/nix/store/qn6ya6avvx8pv8ld9qnvphb73yz3jw6x-bun2nix-cache-entry-creator-2.0.0.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/glzjkkmkn95hjpm72qa357qz2xkqynzp-bun2nix-cache-entry-creator-2.0.0
       Last 25 log lines:
       >    (0mq(B zig build-exe cache_entry_creator ReleaseFast native 1 errors
       > /nix/var/nix/builds/nix-44489-1391865801/tmp.meruiG3Mwp/p/clap-0.11.0-oBajB-TnAQC7yPLnZRT5WzHZ_4Ly4dX2OILskli74b9H/clap.zig:148:42: error: missing struct field: allocator
       >     var list = std.ArrayList(Param(Help)){
       >                ~~~~~~~~~~~~~~~~~~~~~~~~~~^
       > /nix/store/wplkljlxs57ab2hcs0n11907px1g81lz-zig-0.14.1/lib/zig/std/array_list.zig:31:12: note: struct declared here
       >     return struct {
       >            ^~~~~~
       > /nix/var/nix/builds/nix-44489-1391865801/tmp.meruiG3Mwp/p/clap-0.11.0-oBajB-TnAQC7yPLnZRT5WzHZ_4Ly4dX2OILskli74b9H/clap.zig:100:31: note: called from here
       >     _ = parseParamsIntoSliceEx(&res, str, &end) catch {
       >         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
       > src/main.zig:35:40: note: called from here
       > const params = clap.parseParamsComptime(
       >                ~~~~~~~~~~~~~~~~~~~~~~~~^
       > referenced by:
       >     main: src/main.zig:57:38
       >     main: /nix/store/wplkljlxs57ab2hcs0n11907px1g81lz-zig-0.14.1/lib/zig/std/start.zig:660:37
       >     3 reference(s) hidden; use '-freference-trace=5' to see all references
       > error: the following command failed with 1 compilation errors:
       > /nix/store/wplkljlxs57ab2hcs0n11907px1g81lz-zig-0.14.1/bin/zig build-exe -OReleaseFast --dep clap -Mroot=/nix/var/nix/builds/nix-44489-1391865801/cache-entry-creator/src/main.zig -OReleaseFast -Mclap=/nix/var/nix/builds/nix-44489-1391865801/tmp.meruiG3Mwp/p/clap-0.11.0-oBajB-TnAQC7yPLnZRT5WzHZ_4Ly4dX2OILskli74b9H/clap.zig --cache-dir /nix/var/nix/builds/nix-44489-1391865801/cache-entry-creator/.zig-cache --global-cache-dir /nix/var/nix/builds/nix-44489-1391865801/tmp.meruiG3Mwp --name cache_entry_creator --zig-lib-dir /nix/store/wplkljlxs57ab2hcs0n11907px1g81lz-zig-0.14.1/lib/zig/ --listen=-
       > Build Summary: 0/3 steps succeeded; 1 failed
       > install transitive failure
       > (0mq(B install cache_entry_creator transitive failure
       >    (0mq(B zig build-exe cache_entry_creator ReleaseFast native 1 errors
       > error: the following build command failed with exit code 1:
       > /nix/var/nix/builds/nix-44489-1391865801/cache-entry-creator/.zig-cache/o/a815cf93b2ac23944a84b2472445d67c/build /nix/store/wplkljlxs57ab2hcs0n11907px1g81lz-zig-0.14.1/bin/zig /nix/store/wplkljlxs57ab2hcs0n11907px1g81lz-zig-0.14.1/lib/zig /nix/var/nix/builds/nix-44489-1391865801/cache-entry-creator /nix/var/nix/builds/nix-44489-1391865801/cache-entry-creator/.zig-cache /nix/var/nix/builds/nix-44489-1391865801/tmp.meruiG3Mwp --seed 0xf124a8f7 -Zb05059f030927c30 --release=fast
       For full logs, run:
         nix log /nix/store/qn6ya6avvx8pv8ld9qnvphb73yz3jw6x-bun2nix-cache-entry-creator-2.0.0.drv
error: Cannot build '/nix/store/i79a7gd3ixmm802qxki9lw4bzax8w6wy-bun-pkg--resvg-resvg-js-2.6.2.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/ri3l84ddpqajdqf0z2cw7hi4lqawb2mc-bun-pkg--resvg-resvg-js-2.6.2
error: Cannot build '/nix/store/jlp35fdjzcdj2lnz1gxk82a2izl4id8y-bun-cache.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/826j73rahd6hki5cc3439wq4n5y0myxg-bun-cache
error: Cannot build '/nix/store/2fs4z7y59nsd4mbsvgx8v35bdgr1mag5-website-0.0.0.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/gb19gxdi8z4ycr5ilqspzs17qb8d3skh-website-0.0.0

Ah, so I should probably be more explicit about when I’m referring to the bun2nix package Vs the bun2nix flake but the general ideas are:

  1. pkgs.callPackage
# caller.nix (probably a flake in most cases)
my-package = pkgs.callPackage ./default.nix {
  inherit (inputs.bun2nix.${pkgs.system}) bun2nix;
};

# default.nix
{bun2nix, ...}:
bun2nix.mkDerivation {
# <derivation args here>
};
  1. With the new overlay
let
  pkgs = import inputs.nixpkgs {
    inherit system;
    overlays = [ inputs.bun2nix.overlays.default ];
  };
in
pkgs.bun2nix.mkDerivation {
# <derivation args here>
}
  1. General use inherit
let
  inherit (inputs.bun2nix.${system}) bun2nix;
in
bun2nix.mkDerivation {
# <derivation args here>
}

Also, what nixpkgs version are you on? Building the cache entry creator requires zig version 0.15, so it’s probably that if it’s not a recent version.

1 Like

Ah nice, that overlay is great; I didn’t notice it since it wasn’t in the v2 update guide.

And yup, I was on Nixpkgs commit 6027c30; I updated to e1ebeec and now I no longer get that error either! Now I get a third different error:

Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/wn693i2snwpfi2hyiqlbp277xnwcic5z-qnb55kqwycxwszjxsbn37iymka7bb4kj-source
source root is qnb55kqwycxwszjxsbn37iymka7bb4kj-source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
patching script interpreter paths in .
./build.ts: interpreter directive changed from "#!/usr/bin/env bun" to "/nix/store/q77q60pidwk04lgw5q930a32w9zp7r0p-bun-1.3.1/bin/bun"
Running phase: bunSetInstallCacheDir
@nix { "action": "setPhase", "phase": "bunSetInstallCacheDir" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
no configure script, doing nothing
Running phase: bunNodeModulesInstallPhase
@nix { "action": "setPhase", "phase": "bunNodeModulesInstallPhase" }
bun install v1.3.1 (89fa0f34)
AccessDenied: Failed to open node_modules folder for chokidar in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules
AccessDenied: Failed to open node_modules folder for fsevents in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules
AccessDenied: Failed to open node_modules folder for anymatch in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules
AccessDenied: Failed to open node_modules folder for braces in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules
AccessDenied: Failed to open node_modules folder for glob-parent in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules
AccessDenied: Failed to open node_modules folder for is-binary-path in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules
AccessDenied: Failed to open node_modules folder for readdirp in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules
AccessDenied: Failed to open node_modules folder for on-finished in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/send/node_modules
AccessDenied: Failed to open node_modules folder for http-errors in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/serve-index/node_modules
AccessDenied: Failed to open node_modules folder for normalize-path in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/anymatch/node_modules
AccessDenied: Failed to open node_modules folder for fill-range in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/braces/node_modules
AccessDenied: Failed to open node_modules folder for is-glob in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/glob-parent/node_modules
AccessDenied: Failed to open node_modules folder for binary-extensions in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/is-binary-path/node_modules
AccessDenied: Failed to open node_modules folder for ms in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/debug/node_modules
AccessDenied: Failed to open node_modules folder for statuses in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/finalhandler/node_modules
AccessDenied: Failed to open node_modules folder for safe-buffer in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/basic-auth/node_modules
AccessDenied: Failed to open node_modules folder for depd in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/serve-index/node_modules/http-errors/node_modules
AccessDenied: Failed to open node_modules folder for inherits in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/serve-index/node_modules/http-errors/node_modules
AccessDenied: Failed to open node_modules folder for setprototypeof in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/serve-index/node_modules/http-errors/node_modules
AccessDenied: Failed to open node_modules folder for statuses in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/serve-index/node_modules/http-errors/node_modules
AccessDenied: Failed to open node_modules folder for braces in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules
AccessDenied: Failed to open node_modules folder for extend-shallow in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules
AccessDenied: Failed to open node_modules folder for is-number in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/braces/node_modules/fill-range/node_modules
AccessDenied: Failed to open node_modules folder for to-regex-range in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/braces/node_modules/fill-range/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/snapdragon/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/snapdragon-node/node_modules
AccessDenied: Failed to open node_modules folder for extend-shallow in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/split-string/node_modules
AccessDenied: Failed to open node_modules folder for extend-shallow in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/to-regex/node_modules
AccessDenied: Failed to open node_modules folder for safe-buffer in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/readable-stream/node_modules
AccessDenied: Failed to open node_modules folder for extend-shallow in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules/braces/node_modules
AccessDenied: Failed to open node_modules folder for fill-range in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules/braces/node_modules
AccessDenied: Failed to open node_modules folder for is-extendable in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules/extend-shallow/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/extglob/node_modules
AccessDenied: Failed to open node_modules folder for extend-shallow in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/nanomatch/node_modules
AccessDenied: Failed to open node_modules folder for extend-shallow in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/regex-not/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/live-server/node_modules/chokidar/node_modules/braces/node_modules/fill-range/node_modules/is-number/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/base/node_modules
AccessDenied: Failed to open node_modules folder for is-descriptor in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/snapdragon/node_modules/define-property/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/snapdragon-util/node_modules
AccessDenied: Failed to open node_modules folder for is-extendable in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/split-string/node_modules/extend-shallow/node_modules
AccessDenied: Failed to open node_modules folder for is-extendable in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/to-regex/node_modules/extend-shallow/node_modules
AccessDenied: Failed to open node_modules folder for safe-buffer in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/string_decoder/node_modules
AccessDenied: Failed to open node_modules folder for is-number in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules/braces/node_modules/fill-range/node_modules
AccessDenied: Failed to open node_modules folder for to-regex-range in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules/braces/node_modules/fill-range/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/expand-brackets/node_modules
AccessDenied: Failed to open node_modules folder for is-extendable in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/nanomatch/node_modules/extend-shallow/node_modules
AccessDenied: Failed to open node_modules folder for is-extendable in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/regex-not/node_modules/extend-shallow/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/class-utils/node_modules
AccessDenied: Failed to open node_modules folder for is-extendable in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/mixin-deep/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/micromatch/node_modules/braces/node_modules/fill-range/node_modules/is-number/node_modules
AccessDenied: Failed to open node_modules folder for is-descriptor in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/expand-brackets/node_modules/define-property/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/to-object-path/node_modules
AccessDenied: Failed to open node_modules folder for has-value in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/unset-value/node_modules
AccessDenied: Failed to open node_modules folder for is-descriptor in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/class-utils/node_modules/define-property/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/static-extend/node_modules
AccessDenied: Failed to open node_modules folder for is-number in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/has-values/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/has-values/node_modules
AccessDenied: Failed to open node_modules folder for has-values in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/unset-value/node_modules/has-value/node_modules
AccessDenied: Failed to open node_modules folder for isobject in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/unset-value/node_modules/has-value/node_modules
AccessDenied: Failed to open node_modules folder for is-descriptor in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/static-extend/node_modules/define-property/node_modules
AccessDenied: Failed to open node_modules folder for define-property in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/object-copy/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/object-copy/node_modules
AccessDenied: Failed to open node_modules folder for kind-of in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/has-values/node_modules/is-number/node_modules
AccessDenied: Failed to open node_modules folder for is-descriptor in /nix/var/nix/builds/nix-54589-3429636884/qnb55kqwycxwszjxsbn37iymka7bb4kj-source/node_modules/object-copy/node_modules/define-property/node_modules

+ @resvg/resvg-js@2.6.2
+ @types/bun@1.2.19
+ @types/markdown-it@14.1.2
+ chokidar@3.6.0
+ highlight.js@11.10.0
+ live-server@1.2.2
+ log-update@6.1.0
+ markdown-it@14.1.0
+ markdown-it-katex@2.0.3
+ preact@10.23.2
+ preact-render-to-string@6.5.9
+ prettier@3.3.3
+ prettier-plugin-organize-imports@4.0.0
+ qr@0.5.0
+ typescript@5.8.3

198 packages installed [56.00ms]
Failed to install 64 packages

This seems to only occur on my aarch64-darwin machine; I tried it on x86_64-linux and nix build succeeded without this error.

Interesting, it must be more particular about it being readonly on Mac, could you try setting the backend to either symlink or copyfile.

It might also be worth trying --linker=isolated too.

1 Like

Thanks! It works with --backend=copyfile and with --backend=symlink --linker=isolated. With just --backend=symlink by itself, I get this error:

Running phase: bunNodeModulesInstallPhase
@nix { "action": "setPhase", "phase": "bunNodeModulesInstallPhase" }
bun install v1.3.1 (89fa0f34)

+ @resvg/resvg-js@2.6.2
+ @types/bun@1.2.19
+ @types/markdown-it@14.1.2
+ chokidar@3.6.0
+ highlight.js@11.10.0
+ live-server@1.2.2
+ log-update@6.1.0
+ markdown-it@14.1.0
+ markdown-it-katex@2.0.3
+ preact@10.23.2
+ preact-render-to-string@6.5.9
+ prettier@3.3.3
+ prettier-plugin-organize-imports@4.0.0
+ qr@0.5.0
+ typescript@5.8.3

229 packages installed [223.00ms]
Running phase: bunLifecycleScriptsPhase
@nix { "action": "setPhase", "phase": "bunLifecycleScriptsPhase" }
bun install v1.3.1 (89fa0f34)

Checked 262 installs across 241 packages (no changes) [11.00ms]
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
$ ./build.ts
  🔍 Resolving [1/1]   🚚 preact [5/4]   🔍 Resolving [5/6]   🔍 @resvg/resvg-js-darwin-universal [7/6]   🔍 Resolving [6/7]   🔍 @resvg/resvg-js-darwin-arm64 [8/7]   🔍 Resolving [8/9]   🔍 uc.micro [16/15]   🔍 Resolving [16/16]   🔍 Resolving [17/16] error: ENOENT while resolving package '@resvg/resvg-js-darwin-arm64' from '/nix/store/6a3hq0nziksnriknghgax7j5v5x46slq-bun-pkg--resvg-resvg-js-2.6.2/share/bun-packages/@resvg/resvg-js@2.6.2/js-binding.js'

Bun v1.3.1 (macOS arm64)
error: script "build" exited with code 1
1 Like

Thanks, in that case I think it’s best to set defaults of:

  • “–backend=symlink --linker=isolated” on aarch64-darwin
  • “–linker=isolated” otherwise

Seeing as the benefits of isolated installs is all stuff that probably sounds generally nice to nix users.

Makes sense! I updated to the latest commit of the branch and now my project builds perfectly on both Linux and macOS, without any bunInstallFlags. Thanks again for making this awesome project!

1 Like

Hey @baileylu :), first of all, thank you for doing all of this work on v2 of bun2nix and also for the continued work on v1!

I’ve just tested v2 on our code base. We have three packages which we built with bun2nix and the transition for all of them was very smooth. Happy to report that v2 works well for us :tada:.

One thing which I’ve stumbled into while upgrading was that I needed to regenerate my bun.nix files. This makes sense of course but I somehow still didn’t think of it. It would be nice to have a note in the upgrade guide saying that you should regenerate your bun.nix files because v2 changes the format of those files.

1 Like

Nice catch, thank you, I’ll add a note and (probably) an error message which occurs when bun.nix has the wrong schema too, just to be sure.

1 Like

Hey @baileylu is there something special I need to do to use bun2nix with "workspaces"? For instance, in a simplified version of my use case, I have this in package.json:

{
  "name": "bun2nix-example-workspaces",
  "version": "0.0.0",
  "private": true,
  "workspaces": [
    "packages/*"
  ]
}

And this in packages/foo/package.json:

{
  "name": "foo",
  "version": "0.0.0"
}

So when I run bun install, this is the bun.lock I get:

{
  "lockfileVersion": 1,
  "configVersion": 0,
  "workspaces": {
    "": {},
    "packages/foo": {
      "name": "foo",
      "version": "0.0.0",
    },
  },
  "packages": {
    "foo": ["foo@workspace:packages/foo"],
  }
}

This is my flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    bun2nix = {
      url = "github:fleek-platform/bun2nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs =
    {
      self,
      nixpkgs,
      flake-utils,
      bun2nix,
    }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ bun2nix.overlays.default ];
        };
      in
      {
        packages.default = pkgs.bun2nix.mkDerivation {
          packageJson = ./package.json;
          src = ./.;
          bunDeps = pkgs.bun2nix.fetchBunDeps {
            bunNix = (
              pkgs.runCommand "bun.nix" { } ''
                ${pkgs.bun2nix}/bin/bun2nix -l ${./bun.lock} -o $out
              ''
            );
          };
          buildPhase = ''
            echo 42 > foo
          '';
          installPhase = ''
            mv foo $out
          '';
        };
        devShell = pkgs.mkShellNoCC {
          buildInputs = [
            pkgs.bun
          ];
        };
      }
    );
}

And in case it’s helpful, here’s my nix flake metadata:

Resolved URL:  git+file:///Users/samueles/scratch/bun-scratch
Locked URL:    git+file:///Users/samueles/scratch/bun-scratch?ref=refs/heads/main&rev=3112a40812d5541f9998b8b19c550a9182ce9d6b
Revision:      3112a40812d5541f9998b8b19c550a9182ce9d6b
Revisions:     4
Last modified: 2025-11-17 14:07:52
Fingerprint:   a08c9acb6448ea03d4ec455edcd0804f0e1afcda05b59e608db11c8ba67f3669
Inputs:
├───bun2nix: github:fleek-platform/bun2nix/f6f2111c199d9c9a1ecbb43a69994f1b20093e9d?narHash=sha256-2h9GOi9KyIVpmtBT3We2kEHCVPb62ttJEffTcdhE7Lg%3D (2025-11-10 10:25:26)
│   ├───flake-parts: github:hercules-ci/flake-parts/26d05891e14c88eb4a5d5bee659c0db5afb609d8?narHash=sha256-xxdepIcb39UJ94%2BYydGP221rjnpkDZUlykKuF54PsqI%3D (2025-11-06 14:41:10)
│   │   └───nixpkgs-lib: github:nix-community/nixpkgs.lib/719359f4562934ae99f5443f20aa06c2ffff91fc?narHash=sha256-b0yj6kfvO8ApcSE%2BQmA6mUfu8IYG6/uU28OFn4PaC8M%3D (2025-10-29 19:18:59)
│   ├───import-tree: github:vic/import-tree/90fa129798be99cde036b78658e89475710966a1?narHash=sha256-AJ96FNj50DU0bTyIzAPkPOjCZTHqjURVjok8qoXvmqM%3D (2025-11-05 07:31:41)
│   ├───nixpkgs follows input 'nixpkgs'
│   ├───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D (2023-04-09 08:27:08)
│   └───treefmt-nix: github:numtide/treefmt-nix/97a30861b13c3731a84e09405414398fbf3e109f?narHash=sha256-aF5fvoZeoXNPxT0bejFUBXeUjXfHLSL7g%2BmjR/p5TEg%3D (2025-11-06 06:21:11)
│       └───nixpkgs follows input 'bun2nix/nixpkgs'
├───flake-utils: github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D (2024-11-13 21:27:16)
│   └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D (2023-04-09 08:27:08)
└───nixpkgs: github:NixOS/nixpkgs/85a6c4a07faa12aaccd81b36ba9bfc2bec974fa1?narHash=sha256-3YJkOBrFpmcusnh7i8GXXEyh7qZG/8F5z5%2B717550Hk%3D (2025-11-16 17:00:02)

When I run nix build with this on aarch64-darwin, I get the following error:

error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'bun2nix-example-workspaces-0.0.0'
         whose name attribute is located at «github:NixOS/nixpkgs/85a6c4a07faa12aaccd81b36ba9bfc2bec974fa1?narHash=sha256-3YJkOBrFpmcusnh7i8GXXEyh7qZG/8F5z5%2B717550Hk%3D»/pkgs/stdenv/generic/make-derivation.nix:540:13

       … while evaluating attribute 'bunDeps' of derivation 'bun2nix-example-workspaces-0.0.0'
         at «github:fleek-platform/bun2nix/f6f2111c199d9c9a1ecbb43a69994f1b20093e9d?narHash=sha256-2h9GOi9KyIVpmtBT3We2kEHCVPb62ttJEffTcdhE7Lg%3D»/nix/mk-derivation.nix:112:28:
          111|
          112|             inherit (args) bunDeps;
             |                            ^
          113|

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: 'packages' is too short to be a valid store path

EDIT: the above still seems to be an issue, but I wrote the below before I realized that there were more recent commits to this bun2nix v2 branch that seem to no longer cause me to hit the NoAtInPackageIdentifier error.


OK, it looks like (at least for debugging purposes here) I can get past that error by generating bun.nix ahead of time instead of using IFD:

@@ -27,11 +27,7 @@
           packageJson = ./package.json;
           src = ./.;
           bunDeps = pkgs.bun2nix.fetchBunDeps {
-            bunNix = (
-              pkgs.runCommand "bun.nix" { } ''
-                ${pkgs.bun2nix}/bin/bun2nix -l ${./bun.lock} -o $out
-              ''
-            );
+            bunNix = ./bun.nix;
           };
           buildPhase = ''
             echo 42 > foo

But then I get this different error:

Running phase: extractPhase
@nix { "action": "setPhase", "phase": "extractPhase" }
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
patching script interpreter paths in /nix/store/5hphcy4gjcqrwfcnrhzcxkf5aajv946p-bun-pkg-foo/share/bun-packages
Running phase: cacheEntryPhase
@nix { "action": "setPhase", "phase": "cacheEntryPhase" }
error: NoAtInPackageIdentifier

I understand that in this simplified example I can simply rename the package:

@@ -1,4 +1,4 @@
 {
-  "name": "foo",
+  "name": "@bun2nix-example-workspaces/foo",
   "version": "0.0.0"
 }

But I can’t do that in my real project, because at least one of my packages is a VS Code extension, and those can’t have @ or / in the "name".

Could you try nix flake update bun2nix (master on fleek-platform org)? I just fixed a very similar error in our own testing and fingers crossed it should fix yours too.

Regenerating bun.nix post changes may fix the first issue too since I changed the formatting for workspace packages in bun.nix.

Yep thanks, that does work! The only remaining thing was that I was trying to figure out how to get it to work without committing bun.nix to my repo (that’d be a dealbreaker for me); it looks like I can just do this:

  bunDeps = pkgs.bun2nix.fetchBunDeps {
    bunNix = "${
      pkgs.runCommand "bun-nix" { } ''
        mkdir $out
        ln -s ${./packages} $out/packages
        ${pkgs.bun2nix}/bin/bun2nix -l ${./bun.lock} -o $out/bun.nix
      ''
    }/bun.nix";
  };

Excellent, the v2 release should be some point over the next day or two.

Once this PR lands, I plan to add a bunLock attribute to fetchBunDeps which will be able to do that without IFD (for npm packages, at least), since all the hash information we need is already in bun.lock, the issue is that Nix can’t read it yet (unless you want to do something crazy with regexes to strip the comments then use builtins.fromJSON).

2 Likes