Guides
Cross-platform configurations
Share one pins-config.nix and pins.json across macOS and Linux hosts without evaluation errors or rebuild ping-pong.
When a single Nix repository serves both macOS (aarch64-darwin) and Linux/NixOS (aarch64-linux, x86_64-linux) machines, nix-pins provides four complementary tools so both platforms share one pins-config.nix and one pins.json.
1. Platform-scoped Pins with systems
Declare systems on any Pin constructor to restrict evaluation and updates to matching platforms:
{ pin }: {
patchelf = pin.github {
target = "NixOS/patchelf";
tags = [ "core" ];
};
alpine-vm = pin.docker {
target = "alpine";
tag = "3.20";
platform = "linux/arm64";
os = "linux";
arch = "arm64";
systems = [ "aarch64-linux" "x86_64-linux" ];
tags = [ "vm" ];
};
}
- On
aarch64-darwin,nix-pins updateskipsalpine-vm's Fetcher/Package evaluation and preserves its existing locked entry inpins.json. - Target another platform explicitly with
--system aarch64-linux(orNIX_PINS_SYSTEM), or bypass filtering with--all-systems.
2. Multi-architecture prebuilt assets with pin.forSystems
Combine pin.forSystems with pin.fetcher.githubRelease to lock per-system binaries under a single Pin:
{ 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;
};
};
};
}
Consume the matching source for the current host system in your Flake via nix-pins.lib.sourceFor:
let
pins = nix-pins.lib.loadPins {
inherit pkgs;
file = ./pins.json;
};
toolSource = nix-pins.lib.sourceFor pkgs pins.tool;
in
toolSource.src
sourceFor selects pin.sources.${pkgs.stdenv.hostPlatform.system} when present and falls back to pin.sources.default.
3. Zero ping-pong rebuilds and parallel CI merging
- When macOS and Linux evaluate the same Pin to different fake-hash
.drvpaths that resolve to the same hash,nix-pinsautomatically records bothdrvPaths inSource.fingerprints. Subsequent runs on either host reuse the locked hash without rebuilding. - If a CI matrix updates macOS and Linux in parallel, merge the generated lockfiles into one unified
pins.json:
nix-pins merge pins-linux.json --json
nix-pins diff HEAD --format markdown
See examples/cross-platform/pins-config.nix for a complete runnable configuration.