nix-packaging
Skill1 starsChanged 41 days agoMITView on GitHub
Nix derivations — stdenv.mkDerivation and the phase model, fixed-output hashes for src fetchers, language-builder dependency hashes (cargoHash, vendorHash, npmDepsHash), the lib.fakeHash → copy-real-hash workflow, and meta attributes. Use when writing, debugging, or reviewing a derivation, packaging a Rust/Go/Python/Node project, or fixing a hash mismatch. Triggers: mkDerivation, buildRustPackage, buildGoModule, vendorHash, cargoHash, fetchFromGitHub.
- Installs packages
2 other projects use a version of this.
Adopted by
Most recently taken up by
- Shangshui0302/some-NixOS-skillstheir own version, first seen Oct 7, 2026
- mattstruble/skillstheir own version, first seen Jul 22, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- mattstruble/skills★ 3same name
- Shangshui0302/some-NixOS-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-findingsSkill
- auditSkill
- codebase-onboardingSkill
- codex-reviewSkill
- compatibilitySkill
- debuggingSkill
- developSkill
- distributed-racesSkill
- memorySkill
- nix-dev-envSkill
- nix-flakesSkill
- nixosSkill
- nix-reviewSkill
- refactoringSkill
- retroSkill
- review-initSkill
- review-rulesSkill
- rust-architecture-reviewSkill
- rust-architectureSkill
- rust-cliSkill
- rust-cloud-nativeSkill
- rust-concurrencySkill
- rust-ecosystemSkill
- rust-embeddedSkill
- rust-errorsSkill
- rust-fintechSkill
- rust-idiomsSkill
- rust-macrosSkill
- rust-mlSkill
- rust-navigationSkill
- rust-ownershipSkill
- rust-performanceSkill
- rust-pluginsSkill
- rust-reviewSkill
- rust-securitySkill
- rust-testingSkill
- rust-traitsSkill
- rust-unsafeSkill
- rust-webSkill
- specsSkill
- sql-reviewSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 69
Every fetch* function is a fixed-output derivation: it may access the network, but the result must match the declared hash — any mismatch …
- Very specific: line 88
Use hash (SRI, sha256-<base64>) on new code — it is the current preferred form.
- Very specific: line 108
Run nix build (or nix-build).
- Very specific: line 115
Run nix build again — it succeeds.
- Very specific: line 135
Every derivation exposed as a package must carry a meta block.
- Very specific: line 155
Do not run cargo fetch, npm install, pip install, or go mod download inside buildPhase or installPhase without pre-vendoring.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Nix Packaging
A derivation is the fundamental build unit in Nix — a description of how to produce a store path
from inputs. stdenv.mkDerivation is the generic builder; language ecosystems add
buildRustPackage, buildGoModule, etc. on top of it. The rules are the same everywhere: every
input must be pinned with a hash, and the build sandbox must never reach the network.
stdenv.mkDerivation and the phase model
The minimal shape:
{ lib, stdenv, fetchFromGitHub }:
stdenv.mkDerivation {
pname = "mytool";
version = "1.2.3";
src = fetchFromGitHub {
owner = "example";
repo = "mytool";
rev = "v1.2.3";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
# build inputs available at compile time
nativeBuildInputs = [ ];
# runtime dependencies linked into the output
buildInputs = [ ];
meta = with lib; {
description = "A short, imperative sentence describing the tool";
license = licenses.mit;
mainProgram = "mytool"; # the binary nix run exposes
maintainers = [ ];
};
}Nix runs the build through a sequence of phases. The defaults handle the most common patterns; override only what you need:
| Phase | Default action | Override hook |
unpackPhase | tar xf $src (or cp for single files) | unpackPhase = "..."; |
patchPhase | Apply patches = [ ] list | patchPhase = "..."; |
configurePhase | ./configure --prefix=$out | configurePhase = "..."; |
buildPhase | make | buildPhase = "..."; |
checkPhase | make check (skipped unless doCheck = true) | checkPhase = "..."; |
installPhase | make install | installPhase = "..."; |
fixupPhase | patchelf, strip, wrap executables | rarely overridden |
Override a phase with a Bash string. Inside the string, $out is the derivation's store path:
installPhase = ''
install -Dm755 result/mytool $out/bin/mytool
'';Fixed-output hashes — src fetchers
Every fetch* function is a fixed-output derivation: it may access the network, but the result
must match the declared hash — any mismatch aborts the build. This makes fetches reproducible.
Common fetchers and their hash field:
# GitHub tarball
src = fetchFromGitHub {
owner = "org"; repo = "proj"; rev = "v1.0.0";
hash = "sha256-…"; # SRI format, preferred
};
# Generic URL
src = fetchzip {
url = "https://example.com/proj-1.0.0.tar.gz";
sha256 = "0000000000000000000000000000000000000000000000000000"; # base32 ok too
};Use hash (SRI, sha256-<base64>) on new code — it is the current preferred form. The older
sha256 (base32 / hex) works but is being phased out.
Language-builder dependency hashes
Language builders need a second hash for vendored dependencies. This hash covers the full dependency tree fetched separately from the source, so it is also a fixed-output derivation.
| Builder | Dep-hash field | What it covers |
buildRustPackage | cargoHash (current) or vendorHash (alias) | Cargo.lock dependency tree |
buildGoModule | vendorHash | Go module graph (go.sum) |
buildPythonPackage | no single field; use fetchPypi for src or poetry2nix / mach-nix | — |
buildNpmPackage | npmDepsHash | package-lock.json dependency tree |
The iterative lib.fakeHash → copy-real-hash flow
You never know the hash before the first build. The workflow:
- Set the hash field to
lib.fakeHash(a known-wrong but syntactically valid hash placeholder). - Run
nix build(ornix-build). The build fails with an error like:error: hash mismatch in fixed-output derivation '/nix/store/…': specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= got: sha256-<actual base64 hash> - Copy the
got:value back into the expression, replacinglib.fakeHash. - Run
nix buildagain — it succeeds.
Repeat for each hash field independently (src hash, then dep hash).
# Step 1 — placeholder
cargoHash = lib.fakeHash;
# Step 3 — paste the "got:" value
cargoHash = "sha256-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=";lib.fakeHash is defined in <nixpkgs/lib> — import lib from pkgs or the nixpkgs argument:
{ lib, pkgs, buildRustPackage, ... }:meta — required in review
Every derivation exposed as a package must carry a meta block. The three fields checked in
review:
meta = with lib; {
description = "Serve HTTP static files from a local directory"; # imperative, no trailing dot
license = licenses.mit; # from lib.licenses — use the attribute, not a string
mainProgram = "serve"; # enables `nix run` without specifying the binary name
maintainers = with maintainers; [ ]; # optional but conventional
homepage = "https://github.com/org/serve"; # optional, good practice
};Common lib.licenses values: mit, asl20, gpl3Only, gpl3Plus, bsd2, bsd3, mpl20,
unfree.
Never fetch impurely at build time
The Nix sandbox blocks network access during a normal derivation build. This means:
- Do not run
cargo fetch,npm install,pip install, orgo mod downloadinsidebuildPhaseorinstallPhasewithout pre-vendoring. - Language builders handle this by fetching dependencies as a separate fixed-output derivation (keyed by the dep hash) before the main build runs. The main build then works offline against the pre-fetched vendor directory.
- A bare
runCommandormkDerivationhas no such mechanism — it gets no network. If you need deps, use the appropriate language builder.
Impure fetches break on every nix build run on a machine that hasn't cached the result, and they
make the build non-reproducible. They are a blocking finding in nix-review.
Details → builders.md
Minimal correct derivations for each builder with all required hash fields: builders.md
Boundaries
- Wiring the derivation into a flake's
packagesoutput, pinning nixpkgs,follows→nix-flakes. - Review rubric for packaging quality, hash hygiene, meta completeness →
nix-review(consumes this skill's rules). - Dev shells,
mkShell,nix developpatterns →nix-dev-env. - NixOS module options,
nixosConfigurations→nixos.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

