Skip to content

Commit 1ac077a

Browse files
Merge pull request #2277 from onflow/janez/nix-flake
[Proposition] Add nix flake for flow-cli installation and development
2 parents c0a3d4f + 9c94481 commit 1ac077a

4 files changed

Lines changed: 181 additions & 1 deletion

File tree

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ main
3434
imports
3535

3636
# Goreleaser .env
37-
.release-env
37+
.release-env
38+
39+
# Nix build artifacts
40+
result
41+
result-*
42+
.direnv/

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ To run the repo:
3636
go run cmd/flow/main.go
3737
```
3838

39+
### Getting Started with Nix
40+
41+
If you use Nix with flakes enabled, you can just use:
42+
43+
```bash
44+
# Enter development shell
45+
nix develop
46+
47+
# Run the CLI
48+
go run cmd/flow/main.go
49+
50+
# Or build and run
51+
nix build
52+
./result/bin/flow
53+
```
54+
3955
## How Can I Contribute?
4056

4157
### Reporting Bugs

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
description = "Flow CLI - Command-line interface for the Flow blockchain";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = import nixpkgs { inherit system; };
13+
14+
# Version detection:
15+
# - When building from a git tag (e.g., nix build github:onflow/flow-cli/v2.14.2),
16+
# the version is extracted from the tag.
17+
# - For local development builds, version is "dev" (for nix metadata) and semver
18+
# is empty so build.go sets it to "undefined", matching Makefile behavior and
19+
# enabling isDevelopment() checks (skips version warnings and crash reporting).
20+
isRelease = (self ? ref) && (builtins.match "v[0-9]+\..+" self.ref != null);
21+
version =
22+
if isRelease
23+
then builtins.substring 1 (-1) self.ref # Remove 'v' prefix for nix version
24+
else "dev";
25+
# semver is what gets injected into the Go binary via ldflags.
26+
# Empty string → build.go init() sets it to "undefined" → isDevelopment() == true
27+
semver =
28+
if isRelease
29+
then self.ref # Full tag with 'v' prefix (e.g., "v2.14.2")
30+
else "";
31+
32+
shortRev = self.shortRev or "dev";
33+
in
34+
{
35+
packages = {
36+
flow-cli = pkgs.buildGoModule {
37+
pname = "flow-cli";
38+
version = version;
39+
src = ./.;
40+
41+
vendorHash = "sha256-EYQfXvHiRftod45Rvi7dUHF+3G5PyDtdM+HmJsE5r4I=";
42+
proxyVendor = true;
43+
44+
subPackages = [ "cmd/flow" ];
45+
46+
env = {
47+
CGO_ENABLED = "1";
48+
CGO_CFLAGS = "-O2 -D__BLST_PORTABLE__";
49+
};
50+
51+
ldflags = [
52+
"-s" "-w"
53+
"-X github.com/onflow/flow-cli/build.semver=${semver}"
54+
"-X github.com/onflow/flow-cli/build.commit=${shortRev}"
55+
"-X github.com/onflow/flow-cli/internal/accounts.accountToken=lilico:sF60s3wughJBmNh2"
56+
"-X github.com/onflow/flow-cli/internal/command.MixpanelToken=3fae49de272be1ceb8cf34119f747073"
57+
];
58+
59+
preCheck = ''
60+
export SKIP_NETWORK_TESTS=1
61+
'';
62+
63+
meta = with pkgs.lib; {
64+
description = "Command-line interface for the Flow blockchain";
65+
homepage = "https://developers.flow.com/tools/flow-cli";
66+
license = licenses.asl20;
67+
mainProgram = "flow";
68+
};
69+
};
70+
71+
default = self.packages.${system}.flow-cli;
72+
};
73+
74+
apps = {
75+
flow-cli = flake-utils.lib.mkApp {
76+
drv = self.packages.${system}.flow-cli;
77+
name = "flow";
78+
};
79+
default = self.apps.${system}.flow-cli;
80+
};
81+
82+
devShells.default = pkgs.mkShell {
83+
buildInputs = with pkgs; [
84+
go
85+
golangci-lint
86+
gotools
87+
gopls
88+
delve
89+
gnumake
90+
git
91+
];
92+
93+
CGO_ENABLED = 1;
94+
CGO_CFLAGS = "-O2 -D__BLST_PORTABLE__";
95+
};
96+
}
97+
);
98+
}

0 commit comments

Comments
 (0)