Profpatsch/users/Profpatsch/go-deps-check

go-deps-check(1)

go-deps-check - report go-deps.nix pins that differ from the go.work versions

go-deps-check [-C root] [-v]

The Go programs in this repository are built by buildGo(7), which ignores go.mod and compiles whatever the go-deps.nix files pin. go test and editor tooling, on the other hand, use the versions the go.work workspace resolves. Nothing makes the two agree, so they drift.

The rule that keeps them together is that go.work decides and go-deps.nix follows. A workspace already picks exactly one version per module across all of its modules, which is the same shape as a set of Nix pins, so the pins can simply be that version. go-deps-check checks that they are: for every pin it prints a line if the pinned tag or commit is not the version go list -m all reports, and exits non-zero.

It does not fix anything. Bump the pin, update its hash, and rebuild the packages that use it.

-C root

The repository root. Defaults to the nearest parent of the working directory that holds a go.work.

-v

Also print pins that match, pins no workspace module needs, and go-deps.nix files that were skipped.

Every tracked go-deps.nix in a directory that go.work uses, or in a parent of one. A go-deps.nix anywhere else belongs to a project outside the workspace, which is free to pin what it likes, and is skipped.

Of each file, only the pins it defines itself, as 'name = depot.nix.buildGo.external { ... }', are checked. Project files re-export the shared file's pins; those are checked once, where they are defined.

A pin matches its module if the pin's import path is the module path or lies below it. A tag matches by name, ignoring the directory prefix nested modules are tagged with ('ansi/v0.10.1 is 'v0.10.1''). A commit matches the hash in a pseudo-version by prefix, or, for a tagged version, the commit the module cache records for that tag.

A pin no workspace module needs is not an error: nothing resolves a version for it to be compared against. -v lists them; they are candidates for deletion.

The pins are read by evaluating each file with nix-instantiate against stubbed fetchers and a stubbed buildGo.external() that return their arguments. Evaluating the real ones would mean fetching and analysing every dependency, because buildGo.external() imports from a derivation. A file that uses a fetcher other than fetchFromGitHub(), fetchFromGitLab() or fetchgit() fails to evaluate, and go-deps-check says so.

0

Every pin matches.

1

At least one pin differs.

2

The check could not be run.

After adding or upgrading a dependency in one module:

$ go -C users/Profpatsch/foo get example.com/bar@latest
$ go work sync
$ go-deps-check
mismatch users/Profpatsch/go-deps.nix: example-bar (example.com/bar)
  pinned v1.2.0, workspace has example.com/bar v1.3.0

The go work sync matters: it writes the workspace's choice back into every module's go.mod, so that each module still builds on its own (GOWORK=off), which is how buildGoModule() sees it. Commit the resulting go.mod and go.sum changes on their own.

buildGo(7)

Only versions are compared, not hashes; a pin whose rev is right but whose sha256 is stale fails at build time, as it always did.

The shared go-deps.nix lists each pin's deps by hand. A version bump can add imports, and go-deps-check cannot see those; the build does.