From e73b7bfc68006ebe95ae4835c1d94c97ad5b1c35 Mon Sep 17 00:00:00 2001 From: Luna Nova Date: Wed, 5 Nov 2025 07:07:55 -0800 Subject: [PATCH] go: move tests to separate file for sharing between versions --- pkgs/development/compilers/go/1.24.nix | 17 ++++------- pkgs/development/compilers/go/1.25.nix | 38 ++++------------------- pkgs/development/compilers/go/tests.nix | 40 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 pkgs/development/compilers/go/tests.nix diff --git a/pkgs/development/compilers/go/1.24.nix b/pkgs/development/compilers/go/1.24.nix index b7c23511bc5e..005e92264d63 100644 --- a/pkgs/development/compilers/go/1.24.nix +++ b/pkgs/development/compilers/go/1.24.nix @@ -9,16 +9,13 @@ buildPackages, pkgsBuildTarget, targetPackages, - testers, - skopeo, buildGo124Module, + callPackage, }: let goBootstrap = buildPackages.callPackage ./bootstrap122.nix { }; - skopeoTest = skopeo.override { buildGoModule = buildGo124Module; }; - # We need a target compiler which is still runnable at build time, # to handle the cross-building case where build != host == target targetCC = pkgsBuildTarget.targetPackages.stdenv.cc; @@ -195,14 +192,10 @@ stdenv.mkDerivation (finalAttrs: { disallowedReferences = [ goBootstrap ]; passthru = { - inherit goBootstrap skopeoTest; - tests = { - skopeo = testers.testVersion { package = skopeoTest; }; - version = testers.testVersion { - package = finalAttrs.finalPackage; - command = "go version"; - version = "go${finalAttrs.version}"; - }; + inherit goBootstrap; + tests = callPackage ./tests.nix { + go = finalAttrs.finalPackage; + buildGoModule = buildGo124Module; }; }; diff --git a/pkgs/development/compilers/go/1.25.nix b/pkgs/development/compilers/go/1.25.nix index 20f8bc52a533..c26fc7c8304e 100644 --- a/pkgs/development/compilers/go/1.25.nix +++ b/pkgs/development/compilers/go/1.25.nix @@ -10,20 +10,13 @@ pkgsBuildTarget, targetPackages, # for testing - testers, - runCommand, - bintools, - skopeo, - clickhouse-backup, buildGo125Module, + callPackage, }: let goBootstrap = buildPackages.callPackage ./bootstrap122.nix { }; - skopeoTest = skopeo.override { buildGoModule = buildGo125Module; }; - clickhouse-backupTest = clickhouse-backup.override { buildGoModule = buildGo125Module; }; - # We need a target compiler which is still runnable at build time, # to handle the cross-building case where build != host == target targetCC = pkgsBuildTarget.targetPackages.stdenv.cc; @@ -200,31 +193,10 @@ stdenv.mkDerivation (finalAttrs: { disallowedReferences = [ goBootstrap ]; passthru = { - inherit goBootstrap skopeoTest; - tests = { - skopeo = testers.testVersion { package = skopeoTest; }; - version = testers.testVersion { - package = finalAttrs.finalPackage; - command = "go version"; - version = "go${finalAttrs.version}"; - }; - # Picked clickhouse-backup as a package that sets CGO_ENABLED=0 - # Running and outputting the right version proves a working ELF interpreter was picked - clickhouse-backup = testers.testVersion { package = clickhouse-backupTest; }; - clickhouse-backup-is-pie = runCommand "has-pie" { meta.broken = stdenv.hostPlatform.isStatic; } '' - ${lib.optionalString (!isCross) '' - if ${lib.getExe' bintools "readelf"} -p .comment ${lib.getExe clickhouse-backup} | grep -Fq "GCC: (GNU)"; then - echo "${lib.getExe clickhouse-backup} has a GCC .comment, but it should have used the internal go linker" - exit 1 - fi - ''} - if ${lib.getExe' bintools "readelf"} -h ${lib.getExe clickhouse-backup} | grep -q "Type:.*DYN"; then - touch $out - else - echo "ERROR: clickhouse-backup is NOT PIE" - exit 1 - fi - ''; + inherit goBootstrap; + tests = callPackage ./tests.nix { + go = finalAttrs.finalPackage; + buildGoModule = buildGo125Module; }; }; diff --git a/pkgs/development/compilers/go/tests.nix b/pkgs/development/compilers/go/tests.nix new file mode 100644 index 000000000000..74fcfeaebe62 --- /dev/null +++ b/pkgs/development/compilers/go/tests.nix @@ -0,0 +1,40 @@ +{ + lib, + stdenv, + go, + buildGoModule, + skopeo, + testers, + runCommand, + bintools, + clickhouse-backup, +}: +let + skopeo' = skopeo.override { buildGoModule = buildGoModule; }; + clickhouse-backup' = clickhouse-backup.override { buildGoModule = buildGoModule; }; +in +{ + skopeo = testers.testVersion { package = skopeo'; }; + version = testers.testVersion { + package = go; + command = "go version"; + version = "go${go.version}"; + }; + # Picked clickhouse-backup as a package that sets CGO_ENABLED=0 + # Running and outputting the right version proves a working ELF interpreter was picked + clickhouse-backup = testers.testVersion { package = clickhouse-backup'; }; + clickhouse-backup-is-pie = runCommand "has-pie" { meta.broken = stdenv.hostPlatform.isStatic; } '' + ${lib.optionalString (stdenv.buildPlatform == stdenv.targetPlatform) '' + if ${lib.getExe' bintools "readelf"} -p .comment ${lib.getExe clickhouse-backup'} | grep -Fq "GCC: (GNU)"; then + echo "${lib.getExe clickhouse-backup'} has a GCC .comment, but it should have used the internal go linker" + exit 1 + fi + ''} + if ${lib.getExe' bintools "readelf"} -h ${lib.getExe clickhouse-backup'} | grep -q "Type:.*DYN"; then + touch $out + else + echo "ERROR: clickhouse-backup is NOT PIE" + exit 1 + fi + ''; +}