Skip to content

Add Nix flake for installation without nixpkgs - #1733

Draft
stig wants to merge 1 commit into
mainfrom
add-nix-flake
Draft

Add Nix flake for installation without nixpkgs#1733
stig wants to merge 1 commit into
mainfrom
add-nix-flake

Conversation

@stig

@stig stig commented Aug 12, 2026

Copy link
Copy Markdown

Adds flake.nix and a pinned flake.lock so Nix users can install directly from the repo without waiting for a release to land in nixpkgs.

nix profile install github:CircleCI-Public/circleci-cli
nix run github:CircleCI-Public/circleci-cli -- version
nix develop github:CircleCI-Public/circleci-cli

The build uses buildGoModule, stamps the short Git rev as the version string, and installs bash/fish/zsh completions.

Trade-off to discuss: vendorHash

buildGoModule requires a vendorHash — a hash of all downloaded Go module sources. It must be updated whenever go.mod or go.sum change. The process is:

  1. Set vendorHash to any wrong value (or leave it as-is after a go.mod bump)
  2. Run nix build — it fails with the correct hash in the error output
  3. Paste the got: hash into flake.nix

This is a one-liner change, but it is an extra manual step on every dependency update.

Is that acceptable? The alternative explored was gomod2nix, which generates a committed lockfile (gomod2nix.toml) instead of a single hash. The maintenance burden is identical (run a tool after go mod tidy), but it doesn't work here because clikit is a local Go submodule referenced via a replace directive — gomod2nix only handles one go.mod at a time and can't see the submodule's packages at build time.

So vendorHash is the practical choice for this repo as it stands.

Lets folks install directly from the repo without waiting for a version
to land in nixpkgs:

    nix profile install github:CircleCI-Public/circleci-cli

Or to try it without installing:

    nix run github:CircleCI-Public/circleci-cli -- version

The flake builds the `cmd/circleci` subpackage, stamps the short Git
revision as the version, installs bash/fish/zsh completions, and also
exports a dev shell (`nix develop`) with `go` and `go-task`.

Also adds a `nix-build` CI job that installs Nix and runs `nix build`
on every branch, so flake regressions are caught before merge.

The `vendorHash` must be updated whenever `go.mod`/`go.sum` change.
The new hash is printed in the error output of `nix build`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant