[Proposition] Add nix flake for flow-cli installation and development#2277
[Proposition] Add nix flake for flow-cli installation and development#2277janezpodhostnik wants to merge 1 commit intomasterfrom
Conversation
|
I’m not very familiar with Nix. What are the benefits compared to the additional maintenance this would introduce? |
|
This adds a very convenient way to try/install flow-cli on nixos (or nix-darwin for that matter). for instance you can just do There won't be any additional overhead for any other installation or any parts of the code. The flake.nix (and the lock) might need some adjusting from time to time for continued support of nix installation. I can do that for now, as I will be using it, and if someone complains down the line, they can update it or you can remove it. |
There was a problem hiding this comment.
Pull request overview
This pull request adds Nix flake support for installing and developing the Flow CLI on NixOS and systems with the Nix package manager. This provides an alternative installation and development method that complements the existing installation scripts and build tools (Makefile, goreleaser).
Changes:
- Added flake.nix with package definition, development shell, and version detection from git tags
- Added flake.lock to pin Nix dependencies
- Updated CONTRIBUTING.md with Nix-specific development instructions
- Updated .gitignore to exclude Nix build artifacts
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| flake.nix | Defines Nix package build for flow-cli using buildGoModule, development shell with Go tooling, and apps configuration |
| flake.lock | Locks Nix flake dependencies (nixpkgs and flake-utils) |
| CONTRIBUTING.md | Adds "Getting Started with Nix" section with instructions for nix develop and nix build |
| .gitignore | Adds Nix-specific artifacts (result, result-*, .direnv/) to gitignore |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| env = { | ||
| CGO_ENABLED = "1"; | ||
| CGO_CFLAGS = "-O2 -D__BLST_PORTABLE__"; |
There was a problem hiding this comment.
The CGO_CFLAGS setting is inconsistent with the rest of the codebase. In .goreleaser.yaml (line 18) and Makefile (lines 22, 42), CGO_CFLAGS includes "-std=gnu11" flag, but it's missing in the flake configuration. This could lead to different build behavior when building via Nix compared to other build methods. Add "-std=gnu11" to the CGO_CFLAGS value to maintain consistency.
| ]; | ||
|
|
||
| CGO_ENABLED = 1; | ||
| CGO_CFLAGS = "-O2 -D__BLST_PORTABLE__"; |
There was a problem hiding this comment.
The CGO_CFLAGS environment variable in the development shell is inconsistent with the production build settings. Similar to the package build configuration, this should include "-std=gnu11" to match the flags used in .goreleaser.yaml (line 18) and Makefile (lines 22, 42). This ensures that local development builds behave identically to production builds.
|
|
||
| ldflags = [ | ||
| "-s" "-w" | ||
| "-X github.com/onflow/flow-cli/build.semver=v${version}" |
There was a problem hiding this comment.
When building locally without a git tag, the version becomes "dev" and the ldflags inject "vdev" as the semver. This is inconsistent with the Makefile behavior (line 46), where an empty VERSION variable results in an empty semver value, which then gets set to "undefined" by build/build.go. Consider using just "dev" without the "v" prefix for consistency, or better yet, use an empty string so it becomes "undefined" to match the existing development build behavior that triggers isDevelopment() checks.
Description
I have been using this flake locally to install flow-cli on NixOs and on NixDarvin. I think it might be nice to add it for anyone else trying to use the flow-cli in a nix environment.
I will also update the install documentation to include Nix.
Eventually I would like to add this to https://github.com/NixOS/nixpkgs. so its even easier to use.
The nix instructions (that I will put in the docs) would be:
Installing Flow CLI with Nix
The Flow CLI can be installed on NixOS and systems with Nix package manager using Nix flakes.
Prerequisites
Ensure you have Nix installed with flakes enabled. Add to
/etc/nix/nix.confor~/.config/nix/nix.conf:Installation Methods
1. Try Without Installing
Run the latest version directly:
2. Install to User Profile
Install persistently:
3. Use in NixOS Configuration
Add to your
configuration.nix:4. Use in Home Manager
Add to your flake inputs and home configuration:
5. Development Shell
Enter a development environment with Flow CLI and Go tooling:
Or for local development:
cd flow-cli nix developInstalling Specific Versions
Install a specific version using git tags:
The flake automatically extracts the version from the git tag when building from a tagged ref.
Upgrading
Update to the latest version:
Uninstalling
Remove from profile:
For contributor use:
masterbranchFiles changedin the Github PR explorer