feat: fell back to pinned bunx package for bun2nix generation
- Added a fallback to the pinned bunx package when generating Nix bun dependencies without an active Nix environment. - Updated generator resolution logic and corresponding tests.
This commit is contained in:
@@ -620,7 +620,7 @@ Build and smoke-test the distributable Nix package with `nix build .#omp`. Wayla
|
|||||||
bun run gen:nix
|
bun run gen:nix
|
||||||
```
|
```
|
||||||
|
|
||||||
The command uses `bun2nix` from `nix develop` when available, otherwise enters the development shell through Nix. Do not edit `nix/bun.nix` manually.
|
The command uses `bun2nix` from `nix develop` when available, otherwise enters the development shell through Nix, then falls back to the pinned `bunx bun2nix@2.1.2`. Do not edit `nix/bun.nix` manually.
|
||||||
|
|
||||||
For a non-interactive smoke check:
|
For a non-interactive smoke check:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { resolveNixBunDepsGenerator } from "./gen-nix-bun";
|
import { BUN2NIX_NPM_SPEC, resolveNixBunDepsGenerator } from "./gen-nix-bun";
|
||||||
|
|
||||||
describe("resolveNixBunDepsGenerator", () => {
|
describe("resolveNixBunDepsGenerator", () => {
|
||||||
test("prefers bun2nix from the active development shell", () => {
|
test("prefers bun2nix from the active development shell", () => {
|
||||||
@@ -17,9 +17,10 @@ describe("resolveNixBunDepsGenerator", () => {
|
|||||||
expect(generator).toEqual({ kind: "nix", executable: "/usr/bin/nix" });
|
expect(generator).toEqual({ kind: "nix", executable: "/usr/bin/nix" });
|
||||||
});
|
});
|
||||||
|
|
||||||
test("fails before a release mutates files when no generator is available", () => {
|
test("falls back to the pinned portable bunx package", () => {
|
||||||
expect(() => resolveNixBunDepsGenerator(() => null)).toThrow(
|
expect(resolveNixBunDepsGenerator(() => null)).toEqual({
|
||||||
"Generating nix/bun.nix requires bun2nix from `nix develop`, or Nix to enter that shell.",
|
kind: "bunx",
|
||||||
);
|
package: BUN2NIX_NPM_SPEC,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+15
-5
@@ -6,10 +6,16 @@ import { $which } from "../packages/utils/src/which";
|
|||||||
|
|
||||||
const repoRoot = path.join(import.meta.dir, "..");
|
const repoRoot = path.join(import.meta.dir, "..");
|
||||||
|
|
||||||
|
/** Pinned npm package matching flake.lock's bun2nix revision (`0f2a1f…`). */
|
||||||
|
export const BUN2NIX_NPM_SPEC = "bun2nix@2.1.2";
|
||||||
|
|
||||||
type FindExecutable = (command: string) => string | null;
|
type FindExecutable = (command: string) => string | null;
|
||||||
|
|
||||||
/** The executable path and invocation mode for the pinned Bun dependency generator. */
|
/** The executable path and invocation mode for the pinned Bun dependency generator. */
|
||||||
export type NixBunDepsGenerator = { kind: "bun2nix"; executable: string } | { kind: "nix"; executable: string };
|
export type NixBunDepsGenerator =
|
||||||
|
| { kind: "bun2nix"; executable: string }
|
||||||
|
| { kind: "nix"; executable: string }
|
||||||
|
| { kind: "bunx"; package: typeof BUN2NIX_NPM_SPEC };
|
||||||
|
|
||||||
/** Resolve the generator needed by releases before they mutate repository state. */
|
/** Resolve the generator needed by releases before they mutate repository state. */
|
||||||
export function resolveNixBunDepsGenerator(findExecutable: FindExecutable = $which): NixBunDepsGenerator {
|
export function resolveNixBunDepsGenerator(findExecutable: FindExecutable = $which): NixBunDepsGenerator {
|
||||||
@@ -19,7 +25,7 @@ export function resolveNixBunDepsGenerator(findExecutable: FindExecutable = $whi
|
|||||||
const nix = findExecutable("nix");
|
const nix = findExecutable("nix");
|
||||||
if (nix) return { kind: "nix", executable: nix };
|
if (nix) return { kind: "nix", executable: nix };
|
||||||
|
|
||||||
throw new Error("Generating nix/bun.nix requires bun2nix from `nix develop`, or Nix to enter that shell.");
|
return { kind: "bunx", package: BUN2NIX_NPM_SPEC };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Regenerate the checked-in Bun dependency expression with the pinned bun2nix input. */
|
/** Regenerate the checked-in Bun dependency expression with the pinned bun2nix input. */
|
||||||
@@ -28,10 +34,14 @@ export async function generateNixBunDeps(generator: NixBunDepsGenerator = resolv
|
|||||||
await $`${generator.executable} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
|
await $`${generator.executable} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (generator.kind === "nix") {
|
||||||
|
await $`${generator.executable} --extra-experimental-features ${"nix-command flakes"} --accept-flake-config develop --command bun2nix -l bun.lock -c ../ -o nix/bun.nix`.cwd(
|
||||||
|
repoRoot,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await $`${generator.executable} --extra-experimental-features ${"nix-command flakes"} --accept-flake-config develop --command bun2nix -l bun.lock -c ../ -o nix/bun.nix`.cwd(
|
await $`bunx ${generator.package} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
|
||||||
repoRoot,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (import.meta.main) await generateNixBunDeps();
|
if (import.meta.main) await generateNixBunDeps();
|
||||||
|
|||||||
Reference in New Issue
Block a user