Skip to content

[nix] Add package for official golang binaries #3824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = with pkgs; [
# Local Go package
(import ./nix/go.nix { inherit pkgs; })

# Monitoring tools
promtail # Loki log shipper
prometheus # Metrics collector
Expand All @@ -54,6 +57,14 @@
# macOS-specific frameworks
darwin.apple_sdk.frameworks.Security
];

shellHook = ''
# Ensure golang bin is in the path
GOBIN="$(go env GOPATH)/bin"
if [[ ":$PATH:" != *":$GOBIN:"* ]]; then
export PATH="$GOBIN:$PATH"
fi
'';
};
});

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/ava-labs/avalanchego
// - Changes to the minimum golang version must also be replicated in:
// - CONTRIBUTING.md
// - README.md
// - nix/go.nix (update version and sha256 for supported arches)
// - go.mod (here)
//
// - If updating between minor versions (e.g. 1.23.x -> 1.24.x):
Expand Down
50 changes: 50 additions & 0 deletions nix/go.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ pkgs }:
let
# Helper functions to derive Go arch from Nix arch
nixArchToGoArch = arch: {
"x86_64" = "amd64";
"aarch64" = "arm64";
}.${arch} or arch;

# Split system into arch and os
parseSystem = system:
let
parts = builtins.split "-" system;
arch = builtins.elemAt parts 0;
os = builtins.elemAt parts 2;
in {
goarch = nixArchToGoArch arch;
goos = os;
goURLPath = "${os}-${nixArchToGoArch arch}";
};

# Update the following to change the version:
goVersion = "1.23.6";
goSHA256s = {
"linux-amd64" = "9379441ea310de000f33a4dc767bd966e72ab2826270e038e78b2c53c2e7802d";
"linux-arm64" = "561c780e8f4a8955d32bf72e46af0b5ee5e0debe1e4633df9a03781878219202";
"darwin-amd64" = "782da50ce8ec5e98fac2cd3cdc6a1d7130d093294fc310038f651444232a3fb0";
"darwin-arm64" = "5cae2450a1708aeb0333237a155640d5562abaf195defebc4306054565536221";
};

targetSystem = parseSystem pkgs.system;
in
pkgs.stdenv.mkDerivation {
name = "go-${goVersion}";
version = goVersion;

inherit (targetSystem) goos goarch;
GOOS = targetSystem.goos;
GOARCH = targetSystem.goarch;

src = pkgs.fetchurl {
url = "https://go.dev/dl/go${goVersion}.${targetSystem.goURLPath}.tar.gz";
sha256 = goSHA256s.${targetSystem.goURLPath} or (throw "Unsupported system: ${pkgs.system}");
};

installPhase = ''
mkdir -p $out
cp -r ./* $out/
chmod +x $out/bin/go
'';
}