Skip to content

Commit 472788f

Browse files
committed
[nix] Add package for official golang binaries
1 parent 304b7ee commit 472788f

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ jobs:
250250
runs-on: ubuntu-latest
251251
steps:
252252
- uses: actions/checkout@v4
253-
- uses: ./.github/actions/setup-go-for-project
254253
- uses: ./.github/actions/install-nix
255254
- run: nix develop --command echo "dependencies installed"
256255
- name: Run e2e tests

flake.nix

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
default = pkgs.mkShell {
3434
# The Nix packages provided in the environment
3535
packages = with pkgs; [
36+
# Local Go package
37+
(import ./nix/go.nix { inherit pkgs; })
38+
3639
# Monitoring tools
3740
promtail # Loki log shipper
3841
prometheus # Metrics collector

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/ava-labs/avalanchego
33
// - Changes to the minimum golang version must also be replicated in:
44
// - CONTRIBUTING.md
55
// - README.md
6+
// - nix/go.nix (update version and sha256 for supported arches)
67
// - go.mod (here)
78
//
89
// - If updating between minor versions (e.g. 1.23.x -> 1.24.x):

nix/go.nix

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{ pkgs }:
2+
let
3+
# Helper functions to derive Go arch from Nix arch
4+
nixArchToGoArch = arch: {
5+
"x86_64" = "amd64";
6+
"aarch64" = "arm64";
7+
}.${arch} or arch;
8+
9+
# Split system into arch and os
10+
parseSystem = system:
11+
let
12+
parts = builtins.split "-" system;
13+
arch = builtins.elemAt parts 0;
14+
os = builtins.elemAt parts 2;
15+
in {
16+
goarch = nixArchToGoArch arch;
17+
goos = os;
18+
goURLPath = "${os}-${nixArchToGoArch arch}";
19+
};
20+
21+
# Update the following to change the version:
22+
goVersion = "1.23.6";
23+
goSHA256s = {
24+
"linux-amd64" = "9379441ea310de000f33a4dc767bd966e72ab2826270e038e78b2c53c2e7802d";
25+
"linux-arm64" = "561c780e8f4a8955d32bf72e46af0b5ee5e0debe1e4633df9a03781878219202";
26+
"darwin-amd64" = "782da50ce8ec5e98fac2cd3cdc6a1d7130d093294fc310038f651444232a3fb0";
27+
"darwin-arm64" = "5cae2450a1708aeb0333237a155640d5562abaf195defebc4306054565536221";
28+
};
29+
30+
targetSystem = parseSystem pkgs.system;
31+
in
32+
pkgs.stdenv.mkDerivation {
33+
name = "go-${goVersion}";
34+
version = goVersion;
35+
36+
inherit (targetSystem) goos goarch;
37+
GOOS = targetSystem.goos;
38+
GOARCH = targetSystem.goarch;
39+
40+
src = pkgs.fetchurl {
41+
url = "https://go.dev/dl/go${goVersion}.${targetSystem.goURLPath}.tar.gz";
42+
sha256 = goSHA256s.${targetSystem.goURLPath} or (throw "Unsupported system: ${pkgs.system}");
43+
};
44+
45+
installPhase = ''
46+
mkdir -p $out
47+
cp -r ./* $out/
48+
chmod +x $out/bin/go
49+
'';
50+
}

0 commit comments

Comments
 (0)