-
Notifications
You must be signed in to change notification settings - Fork 981
/
build-status-go.nix
97 lines (75 loc) · 2.72 KB
/
build-status-go.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{ buildGoPackage, go, xcodeWrapper, stdenv, utils }:
{ owner, repo, rev, version, goPackagePath, src, host,
nativeBuildInputs ? [],
buildPhase, buildMessage,
installPhase ? "",
postInstall ? "",
preFixup ? "",
outputs, meta } @ args':
with stdenv;
let
inherit (stdenv.lib) strings;
removeReferences = [ go ];
removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
args = removeAttrs args' [ "buildMessage" ]; # Remove our arguments from args before passing them on to buildGoPackage
buildStatusGo = buildGoPackage (args // {
pname = repo;
version = "${version}-${strings.substring 0 7 rev}-${host}";
nativeBuildInputs =
nativeBuildInputs ++
lib.optional isDarwin xcodeWrapper;
# Fixes Cgo related build failures (see https://github.com/NixOS/nixpkgs/issues/25959 )
hardeningDisable = [ "fortify" ];
# gomobile doesn't seem to be able to pass -ldflags with multiple values correctly to go build, so we just patch files here
patchPhase = ''
date=$(date -u '+%Y-%m-%d.%H:%M:%S')
substituteInPlace cmd/statusd/main.go --replace \
"buildStamp = \"N/A\"" \
"buildStamp = \"$date\""
substituteInPlace params/version.go --replace \
"var Version string" \
"var Version string = \"${version}\""
substituteInPlace params/version.go --replace \
"var GitCommit string" \
"var GitCommit string = \"${rev}\""
substituteInPlace vendor/github.com/ethereum/go-ethereum/metrics/metrics.go --replace \
"var EnabledStr = \"false\"" \
"var EnabledStr = \"true\""
'';
# Ensure XCode is present, instead of failing at the end of the build
preConfigure = lib.optionalString isDarwin utils.enforceXCodeAvailable;
buildPhase = ''
runHook preBuild
runHook renameImports
echo
echo "${buildMessage}"
echo
${buildPhase}
runHook postBuild
'';
installPhase = ''
runHook preInstall
${installPhase}
runHook postInstall
'';
# replace hardcoded paths to go package in /nix/store, otherwise Nix will fail the build
preFixup = ''
${preFixup}
find $out -type f -exec ${removeExpr removeReferences} '{}' + || true
return
'';
passthru = {
inherit owner version rev;
};
meta = {
# Add default meta information
inherit (meta) platforms;
description = meta.description or "The Status module that consumes go-ethereum.";
license = lib.licenses.mpl20;
} // meta // {
# add an extra maintainer to every package
maintainers = (meta.maintainers or []) ++
[ lib.maintainers.pombeirp ];
};
});
in buildStatusGo