Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Building with bun2nix.mkDerivation

mkDerivation is provided as a library function to build Bun packages from the file generated by the bun2nix command line tool.

This function is intended for use building binaries with Bun. If you need to build something like a compiled React website, the more idiomatic choice is probably the bun2nix hook.

Example

Currently, basic usage would look something like:

{bun2nix, ...}:
bun2nix.mkDerivation {
  pname = "simple-bun-app";
  version = "1.0.0";

  src = ./.;

  bunDeps = bun2nix.fetchBunDeps {
    bunNix = ./bun.nix;
  };

  module = "index.ts";
}

or, in the more implicit style:

{bun2nix, ...}:
bun2nix.mkDerivation {
  packageJson = ./package.json;
  src = ./.;

  bunDeps = bun2nix.fetchBunDeps {
    bunNix = ./bun.nix;
  };
}

NOTE: building with the implicit package.json values makes a number of basic assumptions about your project that it expects to hold true in the name of convenience. Approximately, these are:

  • name is a field that is acceptable for use as the name of the binary produced by your package.
  • version is a field denoting your package version in proper semantic versioning.
  • module is a field pointing towards your index.ts file or equivalent. If you notice any strange errors while using the implicit build scheme try specifying the values manually and contribute a new descriptive assert message to mkDerivation.

Arguments

The full list of accepted arguments is:

Additionally, the full range of config options from the hook is available too.

ArgumentPurpose
packageJson(Optional) Your project's package.json. If supplied can be used to complete pname, version and module instead of requiring them manually.
pnameThe name of the package to build. Required if packageJson is not given.
versionYour package version. Required if packageJson is not given.
moduleThe index.{js,ts} file entry point to your Bun application. This should be a string containing the relative path from src. Required if packageJson is not given.