Skip to content

Commit 696cce8

Browse files
authored
prometheus-chrony-exporter: add versionCheckHook and linker attrs (NixOS#394585)
2 parents 3a9e42b + 418465d commit 696cce8

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

pkgs/by-name/pr/prometheus-chrony-exporter/package.nix

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
buildGoModule,
44
fetchFromGitHub,
55
nix-update-script,
6+
versionCheckHook,
67
}:
7-
88
buildGoModule (finalAttrs: {
99
pname = "prometheus-chrony-exporter";
1010
version = "0.12.0";
@@ -13,18 +13,39 @@ buildGoModule (finalAttrs: {
1313
owner = "superq";
1414
repo = "chrony_exporter";
1515
tag = "v${finalAttrs.version}";
16-
hash = "sha256-ZXqCZZx0UG8050SYgVwD+wnTX0N41Bjv1dhdQmOHmR4=";
16+
hash = "sha256-W7MWshRuQdbxLm0XKkTHXN+pjwoX7wnCtjaeXyszr/Q=";
17+
leaveDotGit = true;
18+
postFetch = ''
19+
cd "$out"
20+
date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/BUILD_COMMIT_DATE
21+
find "$out" -name .git -print0 | xargs -0 rm -rf
22+
'';
1723
};
1824

19-
vendorHash = "sha256-3zL7BrCdMVnt7F1FiZ2eQnKVhmCeW3aYKKX9v01ms/k=";
25+
# do not use real BuildDate, but fixed imagenary (commit date) for binary reproducibility
26+
preBuild = ''
27+
ldflags+=" -X github.com/prometheus/common/version.BuildDate=$(cat BUILD_COMMIT_DATE)"
28+
'';
2029

2130
ldflags = [
2231
"-s"
2332
"-w"
33+
"-X github.com/prometheus/common/version.Version=${finalAttrs.version}"
34+
"-X github.com/prometheus/common/version.Revision=${finalAttrs.src.rev}"
35+
"-X github.com/prometheus/common/version.Branch=master"
36+
"-X github.com/prometheus/common/version.BuildUser=nix@nixpkgs"
2437
];
2538

39+
vendorHash = "sha256-3zL7BrCdMVnt7F1FiZ2eQnKVhmCeW3aYKKX9v01ms/k=";
40+
2641
passthru.updateScript = nix-update-script { };
2742

43+
nativeInstallCheckInputs = [ versionCheckHook ];
44+
45+
doInstallCheck = true;
46+
versionCheckProgram = "${placeholder "out"}/bin/chrony_exporter";
47+
versionCheckProgramArg = "--version";
48+
2849
meta = {
2950
changelog = "https://github.com/superq/chrony_exporter/releases/tag/v${finalAttrs.version}";
3051
homepage = "https://github.com/superq/chrony";

0 commit comments

Comments
 (0)