Skip to content

Commit c57bded

Browse files
authored
Merge pull request #2142 from cachix/fix-2138
go: support overriding more pinned go module versions
2 parents f14599d + 2621a60 commit c57bded

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/modules/languages/go.nix

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ let
55

66
# Override the buildGoModule function to use the specified Go package.
77
buildGoModule = pkgs.buildGoModule.override { go = cfg.package; };
8+
# A helper function to rebuild a package with the specific Go version.
9+
# It expects the package to have a `buildGo*Module` argument in its override function.
10+
# This will override multiple buildGo*Module arguments if they exist.
811
buildWithSpecificGo = pkg:
912
let
1013
overrideArgs = lib.functionArgs pkg.override;
14+
goModuleArgs = lib.filterAttrs (name: _: lib.match "buildGo.*Module" name != null) overrideArgs;
15+
goModuleOverrides = lib.mapAttrs (_: _: buildGoModule) goModuleArgs;
1116
in
12-
if builtins.hasAttr "buildGoModule" overrideArgs then
13-
pkg.override { inherit buildGoModule; }
14-
else if builtins.hasAttr "buildGoLatestModule" overrideArgs then
15-
pkg.override { buildGoLatestModule = buildGoModule; }
17+
if goModuleOverrides != {} then
18+
pkg.override goModuleOverrides
1619
else
17-
throw "Package ${pkg.pname or "unknown"} does not accept buildGoModule or buildGoLatestModule arguments";
20+
throw ''
21+
`languages.go` failed to override the Go version for ${pkg.pname or "unknown"}.
22+
Expected to find a `buildGo*Module` argument in its override function.
23+
24+
Found: ${toString (lib.attrNames overrideArgs)}
25+
'';
1826
in
1927
{
2028
options.languages.go = {

0 commit comments

Comments
 (0)