Skip to content

Commit 2eff5f6

Browse files
Add nix flake for flow-cli installation and development
1 parent 97276d6 commit 2eff5f6

4 files changed

Lines changed: 174 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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 automatically extracted from the tag: "2.14.2"
17+
# - For local development builds, version is "dev"
18+
# This eliminates the need for a separate VERSION file and keeps version
19+
# management in sync with git tags used for releases.
20+
version =
21+
if (self ? ref) && (builtins.match "v[0-9]+\..+" self.ref != null)
22+
then builtins.substring 1 (-1) self.ref # Remove 'v' prefix from version tags
23+
else "dev";
24+
25+
shortRev = self.shortRev or "dev";
26+
in
27+
{
28+
packages = {
29+
flow-cli = pkgs.buildGoModule {
30+
pname = "flow-cli";
31+
version = version;
32+
src = ./.;
33+
34+
vendorHash = "sha256-EYQfXvHiRftod45Rvi7dUHF+3G5PyDtdM+HmJsE5r4I=";
35+
proxyVendor = true;
36+
37+
subPackages = [ "cmd/flow" ];
38+
39+
env = {
40+
CGO_ENABLED = "1";
41+
CGO_CFLAGS = "-O2 -D__BLST_PORTABLE__";
42+
};
43+
44+
ldflags = [
45+
"-s" "-w"
46+
"-X github.com/onflow/flow-cli/build.semver=v${version}"
47+
"-X github.com/onflow/flow-cli/build.commit=${shortRev}"
48+
"-X github.com/onflow/flow-cli/internal/accounts.accountToken=lilico:sF60s3wughJBmNh2"
49+
"-X github.com/onflow/flow-cli/internal/command.MixpanelToken=3fae49de272be1ceb8cf34119f747073"
50+
];
51+
52+
preCheck = ''
53+
export SKIP_NETWORK_TESTS=1
54+
'';
55+
56+
meta = with pkgs.lib; {
57+
description = "Command-line interface for the Flow blockchain";
58+
homepage = "https://developers.flow.com/tools/flow-cli";
59+
license = licenses.asl20;
60+
mainProgram = "flow";
61+
};
62+
};
63+
64+
default = self.packages.${system}.flow-cli;
65+
};
66+
67+
apps = {
68+
flow-cli = flake-utils.lib.mkApp {
69+
drv = self.packages.${system}.flow-cli;
70+
name = "flow";
71+
};
72+
default = self.apps.${system}.flow-cli;
73+
};
74+
75+
devShells.default = pkgs.mkShell {
76+
buildInputs = with pkgs; [
77+
go
78+
golangci-lint
79+
gotools
80+
gopls
81+
delve
82+
gnumake
83+
git
84+
];
85+
86+
CGO_ENABLED = 1;
87+
CGO_CFLAGS = "-O2 -D__BLST_PORTABLE__";
88+
};
89+
}
90+
);
91+
}

0 commit comments

Comments
 (0)