From cdc84e9a8169c7049c59e3754667adcf3edeed80 Mon Sep 17 00:00:00 2001 From: Stevan Andjelkovic Date: Fri, 9 Apr 2021 14:03:16 +0200 Subject: [PATCH] nix(ldfi2, checker, scheduler): move stamping version out of buildPhase --- default.nix | 21 +++++++++++++++++++-- src/checker/default.nix | 4 +++- src/ldfi2/default.nix | 4 +++- src/scheduler/default.nix | 4 +++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/default.nix b/default.nix index 78eced92..8b567f96 100644 --- a/default.nix +++ b/default.nix @@ -39,9 +39,9 @@ stdenv.mkDerivation { then [] else [ ./bazel-bin/src ./bazel-out/k8-fastbuild-ST-578d10beb4b5/bin ]; - phases = [ "installPhase" "installCheckPhase" ]; + phases = [ "installPhase" "installCheckPhase" "postInstall" ]; - nativeBuildInputs = if stdenv.isLinux then [ patchelf ] else []; + nativeBuildInputs = (if stdenv.isLinux then [ patchelf ] else []) ++ [ hexdump xxd ]; propagatedBuildInputs = [ z3 ] ++ lib.optional (nix-build-all || nix-build-checker) [ checker ] @@ -131,4 +131,21 @@ stdenv.mkDerivation { # echo "version mismatch" #fi ''; + + # Patch the binaries replacing dummy git commits with the real current git + # commit hash. + postInstall = '' + export DUMMY_VERSION="$(echo -n 0000000000000000000000000000000000000000-nix \ + | 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 + # 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 + ''; } diff --git a/src/checker/default.nix b/src/checker/default.nix index 6fa5b04b..8e41ce49 100644 --- a/src/checker/default.nix +++ b/src/checker/default.nix @@ -18,7 +18,9 @@ in stdenv.mkDerivation rec { ++ lib.optional stdenv.isLinux [ freetype.dev ]; buildPhase = '' - export DETSYS_CHECKER_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`. + export DETSYS_CHECKER_VERSION="0000000000000000000000000000000000000000-nix" export CLASSPATH=$(find ${mavenRepository} -name "*.jar" -printf ':%h/%f') export builddir=$TMP/classes mkdir -p $builddir diff --git a/src/ldfi2/default.nix b/src/ldfi2/default.nix index 3d22fba9..b079f1f2 100644 --- a/src/ldfi2/default.nix +++ b/src/ldfi2/default.nix @@ -32,7 +32,9 @@ pkg.overrideAttrs (attrs: { pname = "detsys-ldfi2"; src = gitignoreSource ./.; configureFlags = - [ "--ghc-option=-D__GIT_HASH__=\"${nixpkgs.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`. + [ "--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 ]; }) diff --git a/src/scheduler/default.nix b/src/scheduler/default.nix index 78c968a4..c0041bc7 100644 --- a/src/scheduler/default.nix +++ b/src/scheduler/default.nix @@ -17,7 +17,9 @@ in stdenv.mkDerivation rec { buildInputs = [ clojure jdk11_headless graalvm11-ce ]; buildPhase = '' - export DETSYS_SCHEDULER_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`. + export DETSYS_SCHEDULER_VERSION="0000000000000000000000000000000000000000-nix" export CLASSPATH=$(find ${mavenRepository} -name "*.jar" -printf ':%h/%f') export builddir=$TMP/classes mkdir -p $builddir