From 9cd1c3aee7c2ef1b46621799d7ef0698c2326046 Mon Sep 17 00:00:00 2001 From: maru Date: Thu, 9 Oct 2025 03:40:18 +0000 Subject: [PATCH 1/2] [nix] Extract Go derivation to nested flake for cross-repo reuse Exposing the go derivation via a flake allows the firewood flake to use it to provide its go version without preventing the avalanchego flake from depending on the firewood flake. --- flake.lock | 17 +++++++++++++++++ flake.nix | 8 +++++--- go.mod | 2 +- nix/{go.nix => go/default.nix} | 0 nix/go/flake.lock | 25 +++++++++++++++++++++++++ nix/go/flake.nix | 31 +++++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 4 deletions(-) rename nix/{go.nix => go/default.nix} (100%) create mode 100644 nix/go/flake.lock create mode 100644 nix/go/flake.nix diff --git a/flake.lock b/flake.lock index bb003457f77a..aab029dc5dd2 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "go-flake": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "path": "./nix/go", + "type": "path" + }, + "original": { + "path": "./nix/go", + "type": "path" + }, + "parent": [] + }, "nixpkgs": { "locked": { "lastModified": 1752620740, @@ -16,6 +32,7 @@ }, "root": { "inputs": { + "go-flake": "go-flake", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index d7cfba673780..226cdbb228e3 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,12 @@ # Flake inputs inputs = { nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2505.*.tar.gz"; + go-flake.url = "path:./nix/go"; + go-flake.inputs.nixpkgs.follows = "nixpkgs"; }; # Flake outputs - outputs = { self, nixpkgs }: + outputs = { self, nixpkgs, go-flake }: let # Systems supported allSystems = [ @@ -39,8 +41,8 @@ # Task runner go-task - # Local Go package - (import ./nix/go.nix { inherit pkgs; }) + # Local Go package from nested flake + go-flake.packages.${pkgs.system}.default # Monitoring tools promtail # Loki log shipper diff --git a/go.mod b/go.mod index 88b33de2e7ba..84c3db977b94 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ module github.com/ava-labs/avalanchego // - CONTRIBUTING.md // - README.md // - go.mod (here) -// - nix/go.nix (update version and sha256 for supported arches) +// - nix/go/default.nix (update version and sha256 for supported arches) // - tools/go.mod // // - If updating between minor versions (e.g. 1.24.x -> 1.25.x): diff --git a/nix/go.nix b/nix/go/default.nix similarity index 100% rename from nix/go.nix rename to nix/go/default.nix diff --git a/nix/go/flake.lock b/nix/go/flake.lock new file mode 100644 index 000000000000..9825bc2af265 --- /dev/null +++ b/nix/go/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1759735786, + "narHash": "sha256-a0+h02lyP2KwSNrZz4wLJTu9ikujNsTWIC874Bv7IJ0=", + "rev": "20c4598c84a671783f741e02bf05cbfaf4907cff", + "revCount": 810859, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2505.810859%2Brev-20c4598c84a671783f741e02bf05cbfaf4907cff/0199bc43-02e2-7036-8e2c-e43f6d6b4ede/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.2505.%2A.tar.gz" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/go/flake.nix b/nix/go/flake.nix new file mode 100644 index 000000000000..30f5542c908b --- /dev/null +++ b/nix/go/flake.nix @@ -0,0 +1,31 @@ +{ + description = "Go toolchain for Avalanche projects"; + + # Flake inputs + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2505.*.tar.gz"; + }; + + # Flake outputs + outputs = { self, nixpkgs }: + let + # Systems supported + allSystems = [ + "x86_64-linux" # 64-bit Intel/AMD Linux + "aarch64-linux" # 64-bit ARM Linux + "x86_64-darwin" # 64-bit Intel macOS + "aarch64-darwin" # 64-bit ARM macOS + ]; + + # Helper to provide system-specific attributes + forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + # Export the Go package for other flakes to consume + packages = forAllSystems ({ pkgs }: { + default = import ./. { inherit pkgs; }; + }); + }; +} From 335c4d2236ce24e6f16d6ea250e8243f3407fe3c Mon Sep 17 00:00:00 2001 From: maru Date: Thu, 9 Oct 2025 03:57:33 +0000 Subject: [PATCH 2/2] fixup: Add flake comment documenting usage --- nix/go/flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nix/go/flake.nix b/nix/go/flake.nix index 30f5542c908b..0e19297c7251 100644 --- a/nix/go/flake.nix +++ b/nix/go/flake.nix @@ -1,4 +1,8 @@ { + # To use locally: nix run ./nix/go + # To use remotely: nix run 'github:ava-labs/avalanchego?dir=nix/go' + # To use remotely at a specific revision: nix run 'github:ava-labs/avalanchego?dir=nix/go&ref=[SHA]' + description = "Go toolchain for Avalanche projects"; # Flake inputs