Skip to content

Commit

Permalink
nix(cli, db, debugger, ltl): move stamping version out of buildPhase
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Apr 12, 2021
1 parent 62d8136 commit 2b819c9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
12 changes: 10 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,21 @@ stdenv.mkDerivation {
| hexdump -ve '1/1 "%.2X"')"
export REAL_VERSION="$(echo -n ${pkgs.lib.commitIdFromGitRepo ./.git + "-nix"} \
| hexdump -ve '1/1 "%.2X"')"
for component in ldfi checker scheduler; do
for component in checker db debug ldfi ltl scheduler; do
# TODO(stevan): only do the next steps if --version returns the dummy version?
hexdump -ve '1/1 "%.2X"' $out/bin/detsys-$component \
| sed "s/$DUMMY_VERSION/$REAL_VERSION/" \
| xxd -r -p > $out/bin/detsys-$component-patched
mv $out/bin/detsys-$component-patched $out/bin/detsys-$component
chmod 755 $out/bin/detsys-$component
done
'';
# The cli binary doesn't follow the same naming convention as the other
# components, so we treat it separately.
hexdump -ve '1/1 "%.2X"' $out/bin/detsys \
| sed "s/$DUMMY_VERSION/$REAL_VERSION/" \
| xxd -r -p > $out/bin/detsys-patched
mv $out/bin/detsys-patched $out/bin/detsys
chmod 755 $out/bin/detsys
'';
}
4 changes: 3 additions & 1 deletion src/cli/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ buildGoModule rec {
vendorSha256 = "1b99x48mqbayfa4zsqq1nkbamqw6r1x46qcsnkn40bvddm99l5jx";

buildFlagsArray =
[ "-ldflags=-X main.version=${lib.commitIdFromGitRepo ./../../.git}-nix" ];
# This is a dummy git hash to avoid breaking the nix cache, it will be
# patched in the `postInstall` phase of the top-level `default.nix`.
[ "-ldflags=-X main.version=0000000000000000000000000000000000000000-nix" ];

preBuild = ''
# We need to put the source of the library in `../lib`, because
Expand Down
4 changes: 3 additions & 1 deletion src/db/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ buildGoModule rec {
vendorSha256 = "027028sx9dz7ixz31611xcbrv9z2h62rmiyl74fa405k5m1yaljc";

buildFlagsArray =
[ "-ldflags=-X main.version=${lib.commitIdFromGitRepo ./../../.git + "-nix"}" ];
# This is a dummy git hash to avoid breaking the nix cache, it will be
# patched in the `postInstall` phase of the top-level `default.nix`.
[ "-ldflags=-X main.version=0000000000000000000000000000000000000000-nix" ];

preBuild = ''
# We need to put the source of the library in `../lib`, because
Expand Down
4 changes: 3 additions & 1 deletion src/debugger/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ buildGoModule rec {
vendorSha256 = "1y6yq31zmhv1278wf2lpf9p90nlvj44iqcrka9fq8pihdqq3pv7n";

buildFlagsArray =
[ "-ldflags=-X main.version=${lib.commitIdFromGitRepo ./../../.git + "-nix"}" ];
# This is a dummy git hash to avoid breaking the nix cache, it will be
# patched in the `postInstall` phase of the top-level `default.nix`.
[ "-ldflags=-X main.version=0000000000000000000000000000000000000000-nix" ];

subPackages = [ "cmd/detsys-debug" ];

Expand Down
7 changes: 4 additions & 3 deletions src/ltl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ in
pkg.overrideAttrs (attrs: {
pname = "detsys-ltl";
src = gitignoreSource ./.;
configureFlags = [
"--ghc-option=-D__GIT_HASH__=\"${nixpkgs.lib.commitIdFromGitRepo ./../../.git + "-nix"}\""
];
configureFlags =
# This is a dummy git hash to avoid breaking the nix cache, it will be
# patched in the `postInstall` phase of the top-level `default.nix`.
[ "--ghc-option=-D__GIT_HASH__=\"0000000000000000000000000000000000000000-nix\"" ];
# this should probably check that attrs.checkInputs doesn't exist
checkInputs = [ nixpkgs.pkgs.haskell.packages.${compiler}.tasty-discover ];
})

0 comments on commit 2b819c9

Please sign in to comment.