Skip to content

Commit e752db2

Browse files
authored
[nix] Extract Go derivation to nested flake for cross-repo reuse (#4406)
1 parent dfb132c commit e752db2

File tree

6 files changed

+83
-4
lines changed

6 files changed

+83
-4
lines changed

flake.lock

Lines changed: 17 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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
# Flake inputs
1010
inputs = {
1111
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2505.*.tar.gz";
12+
go-flake.url = "path:./nix/go";
13+
go-flake.inputs.nixpkgs.follows = "nixpkgs";
1214
};
1315

1416
# Flake outputs
15-
outputs = { self, nixpkgs }:
17+
outputs = { self, nixpkgs, go-flake }:
1618
let
1719
# Systems supported
1820
allSystems = [
@@ -39,8 +41,8 @@
3941
# Task runner
4042
go-task
4143

42-
# Local Go package
43-
(import ./nix/go.nix { inherit pkgs; })
44+
# Local Go package from nested flake
45+
go-flake.packages.${pkgs.system}.default
4446

4547
# Monitoring tools
4648
promtail # Loki log shipper

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module github.com/ava-labs/avalanchego
88
// - CONTRIBUTING.md
99
// - README.md
1010
// - go.mod (here)
11-
// - nix/go.nix (update version and sha256 for supported arches)
11+
// - nix/go/default.nix (update version and sha256 for supported arches)
1212
// - tools/go.mod
1313
//
1414
// - If updating between minor versions (e.g. 1.24.x -> 1.25.x):
File renamed without changes.

nix/go/flake.lock

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

nix/go/flake.nix

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
# To use locally: nix run ./nix/go
3+
# To use remotely: nix run 'github:ava-labs/avalanchego?dir=nix/go'
4+
# To use remotely at a specific revision: nix run 'github:ava-labs/avalanchego?dir=nix/go&ref=[SHA]'
5+
6+
description = "Go toolchain for Avalanche projects";
7+
8+
# Flake inputs
9+
inputs = {
10+
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2505.*.tar.gz";
11+
};
12+
13+
# Flake outputs
14+
outputs = { self, nixpkgs }:
15+
let
16+
# Systems supported
17+
allSystems = [
18+
"x86_64-linux" # 64-bit Intel/AMD Linux
19+
"aarch64-linux" # 64-bit ARM Linux
20+
"x86_64-darwin" # 64-bit Intel macOS
21+
"aarch64-darwin" # 64-bit ARM macOS
22+
];
23+
24+
# Helper to provide system-specific attributes
25+
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
26+
pkgs = import nixpkgs { inherit system; };
27+
});
28+
in
29+
{
30+
# Export the Go package for other flakes to consume
31+
packages = forAllSystems ({ pkgs }: {
32+
default = import ./. { inherit pkgs; };
33+
});
34+
};
35+
}

0 commit comments

Comments
 (0)