Skip to content

Commit

Permalink
Merge pull request #212 from symbiont-io/version-cache
Browse files Browse the repository at this point in the history
nix(ldfi2, checker, scheduler): move stamping version out of buildPhase
  • Loading branch information
symbiont-stevan-andjelkovic authored Apr 9, 2021
2 parents b95df43 + cdc84e9 commit 62d8136
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
21 changes: 19 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down Expand Up @@ -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
'';
}
4 changes: 3 additions & 1 deletion src/checker/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/ldfi2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
})
4 changes: 3 additions & 1 deletion src/scheduler/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 62d8136

Please sign in to comment.