From 902d4f604ffc001a3852f0a42f6adb6bd8f16465 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Tue, 22 Apr 2025 11:11:44 -0700 Subject: [PATCH] buildGoModule: add goSum attribute to make goModules rebuild (#399532) --- pkgs/build-support/go/module.nix | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/go/module.nix b/pkgs/build-support/go/module.nix index db494fc82b27..9b692b4f6dec 100644 --- a/pkgs/build-support/go/module.nix +++ b/pkgs/build-support/go/module.nix @@ -37,6 +37,9 @@ lib.extendMkDerivation { "buildGoModule: vendorHash is missing" ), + # The go.sum file to track which can cause rebuilds. + goSum ? null, + # Whether to delete the vendor folder supplied with the source. deleteVendor ? false, @@ -69,13 +72,24 @@ lib.extendMkDerivation { vendorHash deleteVendor proxyVendor + goSum ; goModules = if (finalAttrs.vendorHash == null) then "" else (stdenv.mkDerivation { - name = "${finalAttrs.name or "${finalAttrs.pname}-${finalAttrs.version}"}-go-modules"; + name = + let + prefix = "${finalAttrs.name or "${finalAttrs.pname}-${finalAttrs.version}"}-"; + + # If "goSum" is supplied then it can cause "goModules" to rebuild. + # Attach the hash name of the "go.sum" file so we can rebuild when it changes. + suffix = lib.optionalString ( + finalAttrs.goSum != null + ) "-${(lib.removeSuffix "-go.sum" (lib.removePrefix "${builtins.storeDir}/" finalAttrs.goSum))}"; + in + "${prefix}go-modules${suffix}"; nativeBuildInputs = (finalAttrs.nativeBuildInputs or [ ]) ++ [ go @@ -83,7 +97,7 @@ lib.extendMkDerivation { cacert ]; - inherit (finalAttrs) src modRoot; + inherit (finalAttrs) src modRoot goSum; # The following inheritance behavior is not trivial to expect, and some may # argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and