Add Nix support#165
Conversation
Adds a Nix flake so users can install and run bkt reproducibly: nix run github:avivsinai/bitbucket-cli -- --version nix build github:avivsinai/bitbucket-cli#default The flake exposes: - packages.default / packages.bkt — built via buildGoModule, stamping the short commit into internal/build.versionFromLdflags when building from a clean tree - apps.default — for `nix run` - devShells.default — go, gopls, gotools, golangci-lint A new .github/workflows/nix.yml builds and smoke-tests the flake on ubuntu-latest and macos-latest. It runs only when flake inputs or Go modules change to avoid duplicating the Go-native CI on every PR. Motivation: NixOS / nix-darwin users currently have no first-class install path (Homebrew/Scoop/go install are the documented options). For agents/tools that want a pinned, reproducible bkt without touching a Go toolchain, `nix run github:...` is the simplest entry point. Signed-off-by: Sridhar Ratnakumar <srid@srid.ca>
- README: add a Nix section between Go Install and Binary Downloads with `nix run`, `nix profile install`, and ref-pinning guidance. - nix.yml: drop the paths filter so the flake is built on every push and PR, catching Go module / vendor hash drift proactively. Signed-off-by: Sridhar Ratnakumar <srid@srid.ca>
Signed-off-by: Sridhar Ratnakumar <srid@srid.ca>
avivsinai
left a comment
There was a problem hiding this comment.
Triage note: the diff is scoped and reasonable, and I don't see a blocking code/design issue in the flake or workflow itself.
What is still missing is an actual Nix verification signal. This machine does not have nix installed, and the PR currently does not show a successful Nix workflow run, so the next action here is a real nix flake check / nix build .#default verification from an environment that has Nix available.
|
I can confirm |
avivsinai
left a comment
There was a problem hiding this comment.
I want to push back on one design choice before we merge this.
The flake currently sets doCheck = false in flake.nix, which disables the entire Go test suite for the Nix build. For an OSS project, I don't think we should ship that as the default unless there is a concrete, documented reason that the tests cannot run in the Nix sandbox.
Why I'm pushing on this:
buildGoModuleruns checks by default; the idiomatic direction is to keep checks on and only narrow them if specific tests are sandbox-incompatible.go test ./...passes on this repo today.- If a few tests need extra tools under Nix, the targeted fix is things like
nativeCheckInputs = [ pkgs.git ];and/or selectivecheckFlags, not a blanketdoCheck = false.
So I think this PR should do one of these before merge:
- Remove
doCheck = falseand make the test phase pass under Nix. - If there is a real blocker, document the exact failing tests/tooling constraint in the flake and scope the workaround as narrowly as possible.
The rest of the PR looks reasonable for a first flake integration:
- exposing
packages.default/apps.default/devShells.defaultis fine buildGoModule+vendorHash+subPackages = [ "cmd/bkt" ]is the right overall shape- the Linux/macOS workflow is the right platform coverage
Non-blocking notes:
nix flake check --no-buildis more of an eval pass than a real build check; the separatenix build .#defaultstep is what actually proves the package builds.cachix/install-nix-actionalready enablesnix-commandandflakes, so the explicitexperimental-featuresstanza is redundant, though harmless.
References:
- Nixpkgs Go packaging manual (
buildGoModule): https://ryantm.github.io/nixpkgs/languages-frameworks/go/ nix flake checkreference: https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-flake-checkinstall-nix-actiondefaults: https://github.com/marketplace/actions/install-nix
- Remove doCheck = false so buildGoModule runs go test (idiomatic default) - Switch from cachix/install-nix-action to nixbuild/nix-quick-install-action@v34 - Remove redundant experimental-features config
|
@avivsinai Done! |
|
https://github.com/nixbuild/nix-quick-install-action is also preferable because it is faster in general. And I've been using it in several projects. The AI defaults to cachix action (or DetSys action) for some reason. |
avivsinai
left a comment
There was a problem hiding this comment.
Thanks for pushing on Nix support. I think there are a few merge blockers here, mainly because this changes user-visible product behavior rather than just adding another packaging path.
-
flake.nix:14-30breaks the version contract for Nix installs. The flake derivesversionfromself.revand injects that short SHA intointernal/build.versionFromLdflags.internal/build/info.go:18-26then prefers that value over Go build metadata. That means a tag-pinned install likegithub:avivsinai/bitbucket-cli/v0.24.1will report a commit hash frombkt --version, not the release version. For a CLI, version output is part of the product contract; Nix installs should not behave differently from the official binaries. -
The Nix build currently drops the Cloud OAuth ldflags that the release binaries carry.
flake.nix:26-30only setsversionFromLdflags, while.goreleaser.yaml:22-28also injectspkg/oauth.cloudClientIDandpkg/oauth.cloudClientSecret. As a result,bkt auth login --kind cloud --webwill fail for Nix users atpkg/cmd/auth/auth.go:318-321. If Nix is presented in the README as a first-class install path, that auth flow needs to work or be called out explicitly. -
.github/workflows/nix.yml:25-27regresses the repo’s current GitHub Actions hardening by using floating action tags instead of pinned SHAs. The existing workflows already pin actions, for example.github/workflows/ci.yml:22-24, and I think we should keep the same supply-chain bar here.
Stepping back: gh itself is a useful reference point here. It treats packaging as part of the product surface, not just distribution plumbing. That means keeping version output stable, keeping auth behavior consistent, and keeping CI hygiene aligned with the rest of the repo.
Stop overriding versionFromLdflags with a short commit hash; the binary now falls through to Go build metadata or "dev", matching the product contract that only goreleaser release builds carry the real version.
Align with the repo's existing supply-chain hardening convention.
Nix builds don't embed OAuth client credentials; document the BKT_OAUTH_CLIENT_ID / BKT_OAUTH_CLIENT_SECRET fallback.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
avivsinai
left a comment
There was a problem hiding this comment.
Thanks for pushing this through. The mechanics are green now, and I’m happy with merging this as an additional packaging path.
Adds Nix flake support so
bktcan be installed and run reproducibly on NixOS, nix-darwin, Linux, and macOS:New to Nix? See Nix First.
Changes
flake.nix—packages.default,apps.default,devShells.default(go, gopls, gotools, golangci-lint). Version is stamped from the short git rev via ldflags..github/workflows/nix.yml— builds and smoke-tests the flake onubuntu-latestandmacos-latest.README.md— new Installation subsection coveringnix run/nix profile install/ ref-pinning.vendorHashis pinned to the currentgo.sum; CI fails loudly on drift. Commits are DCO-signed.Context: came up while wiring
bktinto srid/agency#10. Related: #121.