Reference

Package Builders

Dependency hashes for Go Modules, npm, pnpm, and Rust Cargo, and how to use them downstream.

Use these constructors in a Source's packages. The public Builders are pin.goModule, pin.npmPackage, pin.pnpmPackage, pin.rustPackage, and the generic escape hatch pin.fod.

Fields and artifacts

ConstructorRequired fieldsDerived HashDependency artifact
pin.goModulerootvendorHashgoModules
pin.npmPackagerootnpmDepsHashnpmDeps
pin.pnpmPackageroot, positive integer fetcherVersionpnpmDepsHashpnpmDeps
pin.rustPackagerootcargoHashcargoDeps
pin.fodhashName, build<hashName>fod

root is the dependency directory relative to the Source root. Set root = "." explicitly even for the root directory. Other arguments are forwarded to the corresponding Nixpkgs Builder. The tool injects the locked src, version, and dependency hash.

Go Modules

{ pin }: {
  fzf = pin.github {
    target = "junegunn/fzf";
    packages.default = pin.goModule { root = "."; };
  };
}

Uses pkgs.buildGoModule, mapping root to modRoot. The hash covers goModules, not the final application.

npm

{ pin }: {
  cpa = pin.github {
    target = "seakee/CPA-Manager-Plus";
    packages.web = pin.npmPackage { root = "."; };
  };
}

Uses pkgs.buildNpmPackage, mapping root to npmRoot and prefetching npmDeps. The upstream project needs matching package.json and package-lock.json files. The tool does not generate upstream lockfiles.

pnpm

{ pin, pkgs }: {
  app = pin.github {
    target = "QuantumNous/new-api";
    packages.web = pin.pnpmPackage {
      root = "web";
      fetcherVersion = 3;
      pnpm = pkgs.pnpm;
    };
  };
}

Uses pkgs.fetchPnpmDeps. fetcherVersion is the implementation version of the Nixpkgs dependency Fetcher, not the pnpm major version. Choose a value supported by your Nixpkgs. pnpm defaults to the supplied pkgs.pnpm; override it explicitly to use another major version.

This example demonstrates subdirectory configuration. The locked upstream version must provide a compatible pnpm-lock.yaml. root must be a nonempty string. The entire declared workspace is locked: nonempty pnpmWorkspaces and --filter, --filter-prod, or -F filters in pnpmInstallFlags are not accepted.

Rust Cargo

{ pin }: {
  bat = pin.github {
    target = "sharkdp/bat";
    packages.default = pin.rustPackage { root = "."; };
  };
}

Uses pkgs.rustPlatform.buildRustPackage (overridable via rustPlatform), mapping root to cargoRoot and computing cargoHash from the intermediate Cargo vendor derivation (cargoDeps.vendorStaging on fetchCargoVendor, or cargoDeps).

root must be a nonempty string, and the target directory in the upstream source must provide a Cargo.lock (use Source patches or postPatch if the upstream archive omits it). Setting cargoHash, cargoRoot, cargoDeps, cargoLock, or cargoVendorDir directly inside pin.rustPackage is rejected as a configuration error.

Yarn — pin.yarnPackage

Uses pkgs.fetchYarnDeps to lock yarnHash from yarn.lock (defaulting to ${src}/yarn.lock when root = ".", or ${src}/${root}/yarn.lock). Exposes the intermediate offline cache at packages.<pkg>.yarnDeps and rejects user-supplied hash or sha256.

{ pin }: {
  yarn-app = pin.github {
    target = "acme/yarn-app";
    packages.default = pin.yarnPackage { root = "."; };
  };
}

Custom FOD — pin.fod

For ecosystems without a built-in Builder (such as Yarn, Gradle, Maven, Zig, or .NET), pin.fod acts as a trusted escape hatch. Supply a hashName identifier (without .) and a build function { src, version, hash } -> derivation returning the intermediate fixed-output derivation:

{ pin, pkgs }: {
  yarn-app = pin.github {
    target = "acme/yarn-app";
    packages.default = pin.fod {
      hashName = "yarnHash";
      build = { src, version, hash }:
        pkgs.fetchYarnDeps {
          inherit src hash;
          pname = "yarn-app";
        };
    };
  };
}

The Reader exposes the locked hash under derived.<hashName> and the intermediate derivation at packages.<pkg> (and packages.<pkg>.fod). Multiple pin.fod Packages sharing the same hashName within one Source automatically qualify as <pkg>.<hashName>.

Downstream usage

Pass both the Pins File and configuration to the Reader to access named Packages.

A downstream Rust example:

let
  pkgs = import <nixpkgs> {};
  pins = import ../nix/pins.nix {
    inherit pkgs;
    file = ./pins.json;
    config = ./pins-config.nix;
  };
  source = pins.bat.sources.default;
in
pkgs.rustPlatform.buildRustPackage {
  pname = "bat";
  version = pins.bat.version;
  src = source.src;
  cargoDeps = source.packages.default.cargoDeps;
}

A downstream pnpm example:

let
  pkgs = import <nixpkgs> {};
  pins = import ../nix/pins.nix {
    inherit pkgs;
    file = ./pins.json;
    config = ./pins-config.nix;
  };
  source = pins.app.sources.default;
in
pkgs.stdenv.mkDerivation {
  pname = "app-web";
  version = pins.app.version;
  src = source.src;
  pnpmDeps = source.packages.web.pnpmDeps;
  pnpmRoot = "web";
  nativeBuildInputs = [ pkgs.nodejs pkgs.pnpm pkgs.pnpmConfigHook ];
  buildPhase = "pnpm run build";
  installPhase = ''
    mkdir -p $out
    cp -r web/dist/. $out/
  '';
}

Adjust application scripts, output directories, and installation steps for your project. Dependency prefetching and downstream installation should use the same pnpm package, Node.js, and root directory. The relative Reader path above follows the quick-start directory layout; other projects should use their own pinned Reader path.