-
Notifications
You must be signed in to change notification settings - Fork 3
/
go-overlay.nix
38 lines (37 loc) · 1.18 KB
/
go-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
final: prev: {
buildGoModule = {
# target OS, or null for native
GOOS ? null,
# target architecture, or null for native
GOARCH ? null,
...
}@args': ((prev.buildGo119Module.override {
go = prev.go_1_19 // {
GOOS = if GOOS == null then prev.go_1_19.GOOS else GOOS;
GOARCH = if GOARCH == null then prev.go_1_19.GOARCH else GOARCH;
CGO_ENABLED = true;
};
}) args').overrideAttrs (origAttrs: {
CGO_ENABLED = true;
configurePhase = origAttrs.configurePhase + ''
# requires zigStdenv from zig-overlay
export CC=${prev.zig}/bin/cc
export LD=${prev.zig}/bin/cc
export NIX_CFLAGS_COMPILE=
export NIX_LDFLAGS=
${if prev.stdenv.isDarwin then ''
buildFlags="$buildFlags -buildmode=pie"
ldflags="$ldflags -s -w"
'' else ""}
'';
postConfigure = (origAttrs.postConfigure or "") + ''
export CGO_CFLAGS="$CFLAGS -Wno-expansion-to-defined -Wno-nullability-completeness"
'';
buildPhase = origAttrs.buildPhase + ''
if ! [ -z ''${ZIG_TARGET+x} ]; then
mv $GOPATH/bin/''${GOOS}_$GOARCH/* $GOPATH/bin
rmdir $GOPATH/bin/''${GOOS}_$GOARCH
fi
'';
});
}