Pin declarations
A declaration file is a Nix function returning an attribute set keyed by Pin name. It can request pin, pkgs, and lib; declare only the arguments you need:
{ pin }: {
patchelf = pin.github "NixOS/patchelf";
}
Data hierarchy
- Pin: one Checker, one Version, and one or more Sources; the atomic unit of selection and updates.
- Source: one Fetcher, one source Hash, and that Source's patches and Packages.
- Package: one Builder with its dependency artifacts and Derived Hash.
pin.mk
Combine Checkers, Fetchers, and Packages independently. For a single Source, provide a top-level fetcher; the Source is named default:
{ pin }: {
demo = pin.mk {
checker = pin.checker.cmd "printf '0.18.0'";
fetcher = pin.fetcher.github {
target = "NixOS/patchelf";
};
};
}
| Field | Meaning |
|---|---|
checker | Required; from pin.checker.* |
sources | Optional nonempty attribute set of named Sources |
fetcher | Required when sources is absent; single-Source shorthand |
patches | Patch list for a single Source; defaults to [] |
postPatch | Patch script for a single Source; defaults to an empty string |
packages | Named Package attribute set for a single Source; defaults to {} |
For multiple Sources, put fetcher, patches, postPatch, and packages inside each Source. See Multiple Sources.
pin.github
Accepts an "owner/repo" string or structured arguments. Combines a GitHub release Checker with a GitHub Fetcher and creates only the default Source.
{ pin }: {
patchelf = pin.github {
target = "NixOS/patchelf";
rev = version: version;
};
}
Specify the target using either target or owner and repo; do not mix them. You can also set the Checker's includePrerelease, include, and exclude; the Fetcher's rev and fetcherArgs; and the Source's patches, postPatch, and packages.
pin.git
Accepts a repository URL string or structured arguments. Combines a Git Checker with a Git Fetcher and creates only the default Source. By default, it tracks Git HEAD:
{ pin }: {
patchelf = pin.git "https://github.com/NixOS/patchelf.git";
}
Structured arguments must use target. You can also set the Checker's mode, branch, ref, include, exclude, and sort; the Fetcher's rev and fetcherArgs; and the Source's patches, postPatch, and packages.
Use pin.mk for more complex combinations. Unknown declaration fields, Fetcher mapping errors, and deterministic configuration errors are reported before Checkers run.
pin.npm
Accepts a package name string or structured arguments. Combines the npm Checker and npm Fetcher for the same package and creates only the default Source:
{ pin }: {
vite = pin.npm "vite";
scoped = pin.npm {
target = "@scope/pkg";
distTag = "next";
registry = "https://registry.example/npm/";
version = version: version;
};
}
pin.npm "vite" is equivalent to pin.mk { checker = pin.checker.npm { target = "vite"; }; fetcher = pin.fetcher.npm { target = "vite"; }; }. Scoped strings such as pin.npm "@scope/pkg" also work. An empty string is invalid, not a default package.
Structured arguments require either target or name, never both. distTag goes only to the Checker and defaults to latest. registry, version, and fetcherArgs go only to the Fetcher. Source fields patches, postPatch, and packages default to [], "", and {}. These are the only accepted fields.
The Source is the original .tgz file, not an extracted directory; no npm dependencies are installed. Fetcher version changes the archive URL, not the locked Pin Version. registry does not configure the Checker; use --npm-registry-base separately. Use pin.mk for different Checker/Fetcher targets or multiple Sources.
pin.crate
Accepts a crate name string or structured arguments. Combines pin.checker.crate with pin.fetcher.url downloading from crates.io and creates only the default Source:
{ pin }: {
ripgrep = pin.crate "ripgrep";
bat = pin.crate {
target = "bat";
registry = "https://crates.io";
version = version: version;
packages.default = pin.rustPackage { pname = "bat"; root = "."; };
};
}
Structured arguments require either target or name, never both. registry defaults to https://crates.io (one trailing slash is removed) and builds ${registry}/api/v1/crates/${name}/${version}/download. fetcherArgs.name defaults to "${name}.tar.gz" so Nix unpack hooks and pin.rustPackage recognize the archive format. --crates-api-base controls the Checker only; configure registry separately for the download host.
pin.pypi
Accepts a PyPI project name string or structured arguments. Combines pin.checker.pypi with pin.fetcher.url downloading the standard source tarball and creates only the default Source:
{ pin }: {
requests = pin.pypi "requests";
custom = pin.pypi {
target = "requests";
registry = "https://files.pythonhosted.org";
version = version: version;
};
}
Structured arguments require either target or name, never both. registry defaults to https://files.pythonhosted.org and builds ${registry}/packages/source/${first}/${name}/${name}-${version}.tar.gz, keeping the original .tar.gz archive. --pypi-api-base controls the Checker only. Use pin.mk when the upstream archive filename differs from the project name or when downloading wheels.
Result references
pin.ref { pin = "upstream"; result = "version"; } identifies a stage result. pin.withInputs { name = reference; } (inputs: value) delays its input function until all referenced results are ready. Supported result kinds are version, source, patchedSource, derivedHash, and intermediate; Source and Package fields default to default. See Dependencies between Pins for complete examples and update semantics.