Refresh Nix Vendor Hash
Refresh the Go dependency hash used by buildGoModule, then verify the
package build. This is a metadata refresh, not a reason to change flake.lock.
When to run
Run this workflow when:
go.modorgo.sumchanges.nix build .#containerlab --no-linkreports a fixed-output hash mismatch.- The repository's Nix workflow reports a
got: sha256-...value. - A dependency upgrade changes the vendored Go module set.
Do not replace the hash when the Nix error is a compiler, test, fetch, or flake evaluation failure. Fix that failure first.
Preferred workflow
In
flake.nix, temporarily replace the existingvendorHashvalue with:vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";Run the build and save its output:
nix build .#containerlab --no-link 2>&1 \ | tee /tmp/containerlab-nix-build.log || trueExtract the reported hash without assuming
rgis installed:awk '/got:/{hash=$2} END{if (hash) print hash}' \ /tmp/containerlab-nix-build.logReplace the fake value in
flake.nixwith the extractedsha256-...value. The first build is expected to fail with the fake hash.Verify the real hash:
nix build .#containerlab --no-link git diff --check
Update only flake.nix for a vendor hash refresh. Do not update flake.lock
unless the nixpkgs input also changed.
Containerized Nix fallback
Use this when the host has no Nix installation. Mount the repository at a path and mark it as a Git safe directory: containerized Nix commonly runs as root while the mounted repository is owned by another user.
docker run --rm -it \
-v "$PWD:/workspace" \
-w /workspace \
nixos/nix:latest \
sh -lc '
git config --global --add safe.directory /workspace
nix --extra-experimental-features "nix-command flakes" \
build .#containerlab --no-link --option sandbox false
' 2>&1 | tee /tmp/containerlab-nix-build.log || true
Then extract the hash on the host with the awk command above, update
flake.nix, and rerun the container command without || true.
If Docker is unavailable, use the equivalent Podman command. If the container cannot reach the network, configure the container runtime before diagnosing the hash.
Final checks
- The build succeeds with the real hash.
flake.nixcontains the new hash and no fake hash.flake.lockis unchanged unless nixpkgs was intentionally updated.git diff --checkpasses.- Leave changes uncommitted unless the user explicitly requests a commit.