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