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.jsonvalues makes a number of basic assumptions about your project that it expects to hold true in the name of convenience. Approximately, these are:
nameis a field that is acceptable for use as the name of the binary produced by your package.versionis a field denoting your package version in proper semantic versioning.moduleis a field pointing towards yourindex.tsfile 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 tomkDerivation.
Arguments
The full list of accepted arguments is:
Additionally, the full range of config options from the hook is available too.
| Argument | Purpose |
|---|---|
packageJson | (Optional) Your project's package.json. If supplied can be used to complete pname, version and module instead of requiring them manually. |
pname | The name of the package to build. Required if packageJson is not given. |
version | Your package version. Required if packageJson is not given. |
module | The 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. |