-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverlay.nix
46 lines (42 loc) · 2.06 KB
/
overlay.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(final: prev: {
# This is only required for Go < 1.24, it will be enabled by default after that.
go_1_21 = prev.go_1_21.overrideAttrs { GOEXPERIMENT = "cacheprog"; doCheck = false; };
go_1_22 = prev.go_1_22.overrideAttrs { GOEXPERIMENT = "cacheprog"; doCheck = false; };
go_1_23 = prev.go_1_23.overrideAttrs { GOEXPERIMENT = "cacheprog"; doCheck = false; };
nixGocacheprogHook = let const = import ./const.nix; in final.makeSetupHook {
name = "nix-gocacheprog-hook";
} (final.writeScript "nix-gocacheprog-hook.sh" ''
_nixGocacheprogHook() {
local client=${const.SandboxCacheDir}/client
if [[ ! -x $client ]]; then
echo "gocacheprog client not found, skipping GOCACHEPROG"
return
fi
export GOCACHEPROG=$client
echo "Setting GOCACHEPROG to $GOCACHEPROG"
# default value from https://go.dev/ref/mod
case "''${GOPROXY:=https://proxy.golang.org,direct}" in
off|file*) # main build, do nothing
;;
*) # module build
$client -mode goproxy &
export GOPROXY="http://localhost${const.ProxyListen},$GOPROXY"
echo "Using nix-gocacheprog module proxy"
echo "Setting GOPROXY to $GOPROXY"
;;
esac
}
postConfigureHooks+=(_nixGocacheprogHook)
'');
# Add our hook to nativeBuildInputs.
buildGoModule = args: prev.buildGoModule (
args // { nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ final.nixGocacheprogHook ]; });
buildGo121Module = args: prev.buildGo121Module (
args // { nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ final.nixGocacheprogHook ]; });
buildGo122Module = args: prev.buildGo122Module (
args // { nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ final.nixGocacheprogHook ]; });
buildGo123Module = args: prev.buildGo123Module (
args // { nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ final.nixGocacheprogHook ]; });
buildGo124Module = args: prev.buildGo124Module (
args // { nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ final.nixGocacheprogHook ]; });
})