Reference

Fetchers

Fields and version mappings for GitHub, Git, Hugging Face, npm, URL, and archive fetchers.

A Fetcher uses the Version selected by a Checker to obtain contents and a source Hash. The Version remains unchanged in the Pins File; rev, url, or npm version mappings only change fetch arguments.

Common rules

  • rev, url, and npm version mappings must be Nix functions from a Version to a string.
  • Do not mix target with its corresponding legacy fields.
  • fetcherArgs supplies additional attributes to the Nixpkgs Fetcher. It cannot override target, version mapping, or hash fields managed by the tool.
  • Do not supply hash manually. update computes it and the Reader injects it.

GitHub — pin.fetcher.github

Use target = "owner/repo" or owner and repo. rev defaults to version: version. Uses pkgs.fetchFromGitHub underneath.

{ pin }: {
  example = pin.mk {
    checker = pin.checker.cmd "printf '0.18.0'";
    fetcher = pin.fetcher.github {
      target = "NixOS/patchelf";
      rev = version: version;
    };
  };
}

fetcherArgs cannot override owner, repo, rev, or hash. If the version lacks a v prefix but upstream tags include one, use rev = version: "v${version}". Check upstream naming first.

Git — pin.fetcher.git

Use target or url. By default, rev uses the Version directly. Uses pkgs.fetchgit; configure options such as fetchSubmodules through fetcherArgs.

{ pin }: {
  example = pin.mk {
    checker = pin.checker.git { target = "https://github.com/NixOS/patchelf.git"; };
    fetcher = pin.fetcher.git {
      target = "https://github.com/NixOS/patchelf.git";
      fetcherArgs.fetchSubmodules = true;
    };
  };
}

Reserved fields are url, rev, and hash.

Hugging Face — pin.fetcher.huggingface

Use target or repoId for the repository identifier. By default, rev uses the Version directly. Uses pkgs.fetchFromHuggingFace, with lfs as the default backend. Your Nixpkgs must provide this Fetcher.

{ pin }: {
  model = pin.mk {
    checker = pin.checker.git {
      target = "https://huggingface.co/bert-base-uncased";
    };
    fetcher = pin.fetcher.huggingface { target = "bert-base-uncased"; };
  };
}

Repository contents may include large model weights. Check storage capacity and access requirements before downloading. Reserved fields are repoId, rev, tag, and hash.

npm — pin.fetcher.npm

Use target or name for a package name such as vite or @scope/pkg; do not combine them. Empty names, whitespace, and extra path segments are rejected. Uses pkgs.fetchurl and keeps the original .tgz file without extracting it or installing npm dependencies.

{ pin }: {
  package = pin.mk {
    checker = pin.checker.cmd "printf v1.2.3";
    fetcher = pin.fetcher.npm {
      target = "@scope/pkg";
      registry = "https://registry.example/npm/";
      version = v: builtins.substring 1 (builtins.stringLength v - 1) v;
      fetcherArgs.name = "download.tgz";
    };
  };
}

registry defaults to https://registry.npmjs.org and must be a nonempty string. One trailing slash is removed; path prefixes are preserved. The standard paths are /pkg/-/pkg-VERSION.tgz and /@scope/pkg/-/pkg-VERSION.tgz. The example resolves to https://registry.example/npm/@scope/pkg/-/pkg-1.2.3.tgz; fetcherArgs.name changes only the Nix download name.

version defaults to the identity function. No v stripping or semver normalization happens automatically. The Fetcher constructs the URL directly, never reads dist.tarball, and provides no fallback for nonstandard registries. fetcherArgs reserves url and hash.

The lock stores resolved fetchurl arguments under npm. The Reader uses that locked URL even after the declaration changes. String context is retained. --npm-registry-base controls only the Checker; configure the Fetcher's registry separately. Use pin.npm to combine the npm Checker and Fetcher.

File — pin.fetcher.url

Requires url = version: "..." and uses pkgs.fetchurl. target is an alias for the same field and also requires a mapping function. Keeps downloaded contents as a file without extracting them.

{ pin }: {
  example = pin.mk {
    checker = pin.checker.cmd "printf '0.18.0'";
    fetcher = pin.fetcher.url {
      url = version: "https://github.com/NixOS/patchelf/archive/refs/tags/${version}.tar.gz";
    };
  };
}

Archive — pin.fetcher.zip

Accepts the same fields as url and uses pkgs.fetchzip. Despite its name, it can also extract tar and other archives supported by Nixpkgs. The hash covers the extracted contents.

{ pin }: {
  example = pin.mk {
    checker = pin.checker.cmd "printf '0.18.0'";
    fetcher = pin.fetcher.zip {
      url = version: "https://github.com/NixOS/patchelf/archive/refs/tags/${version}.tar.gz";
      fetcherArgs.stripRoot = true;
    };
  };
}

Both url and zip reserve url and hash. Switching from a file Fetcher to an archive Fetcher changes the contents being hashed, so run update again.

GitHub Release Asset — pin.fetcher.githubRelease

Use target = "owner/repo" (or owner and repo) with asset = version: "..." to download release assets from https://github.com/<owner>/<repo>/releases/download/<version>/<asset>. Set unpack = true to use pkgs.fetchzip instead of pkgs.fetchurl. Combine with pin.forSystems for multi-architecture prebuilt binaries:

{ pin }: {
  tool = pin.mk {
    checker = pin.checker.github { target = "acme/tool"; };
    sources = pin.forSystems {
      aarch64-darwin = pin.fetcher.githubRelease {
        target = "acme/tool";
        asset = v: "tool-${v}-aarch64-apple-darwin.tar.gz";
        unpack = true;
      };
      aarch64-linux = pin.fetcher.githubRelease {
        target = "acme/tool";
        asset = v: "tool-${v}-aarch64-unknown-linux-gnu.tar.gz";
        unpack = true;
      };
    };
  };
}

GitLab — pin.fetcher.gitlab

Uses pkgs.fetchFromGitLab. Supports target = "owner/repo" or nested "group/owner/repo", optional domain for self-hosted GitLab instances, rev mapping (default v: v), and fetcherArgs.

{ pin }: {
  service = pin.mk {
    checker = pin.checker.gitlab { target = "org/sub/service"; };
    fetcher = pin.fetcher.gitlab { target = "org/sub/service"; };
  };
}

Docker / OCI — pin.fetcher.docker

Uses pkgs.dockerTools.pullImage. Supports target / imageName, imageDigest (default v: v), optional finalImageName, finalImageTag, os, arch, and fetcherArgs.

{ pin }: {
  alpine = pin.mk {
    checker = pin.checker.oci { target = "alpine"; tag = "3.20"; platform = "linux/arm64"; };
    fetcher = pin.fetcher.docker { target = "alpine"; os = "linux"; arch = "arm64"; };
  };
}

Gitea / Forgejo / Codeberg — pin.fetcher.gitea

Uses pkgs.fetchFromGitea. Supports target = "owner/repo" (or owner and repo), optional domain (default "codeberg.org"), rev mapping (default v: v), and fetcherArgs.

{ pin }: {
  app = pin.mk {
    checker = pin.checker.gitea { target = "acme/app"; };
    fetcher = pin.fetcher.gitea { target = "acme/app"; };
  };
}