Skip to content

Instantly share code, notes, and snippets.

@layus
Created January 26, 2022 17:47
Show Gist options
  • Select an option

  • Save layus/2a91694be330d5f2591dab9a52c47548 to your computer and use it in GitHub Desktop.

Select an option

Save layus/2a91694be330d5f2591dab9a52c47548 to your computer and use it in GitHub Desktop.
with import <nixpkgs> {};
with pkgs;
stdenv.mkDerivation {
name = "frankenDebugSymbols";
outputs = [ "out" "debug" ];
dontUnpack = true;
dontBuild = true;
installPhase = ''
mkdir $out
date > $out/file
mkdir $debug
cp $out/file $debug
cat > $debug/test.sh <<EOF
#! /usr/bin/env bash
if [ "\$(<$out/file)" == "\$(<$debug/file)" ]; then
echo -e "\033[0;32mOutputs match\033[0m"
else
echo -e "\033[0;31mOutputs mismatch\033[0m"
fi
EOF
'';
}
#! /usr/bin/env bash
set -ex
# Delete leftovers from previous runs.
out=$(nix-build -A out)
debug=$(nix-build -A debug)
rm -f ./result ./result-debug
nix-store --delete "$out" "$debug"
[ ! -e "$debug" ] # Just a trivial assert that it does no more exist
[ ! -e "$out" ] # Just a trivial assert that it does no more exist
# Now build both outputs afresh
out=$(nix-build -A out)
debug=$(nix-build -A debug)
bash $debug/test.sh # => Outputs match
# delete one of the outputs, and keep the other.
rm -f ./result-debug
nix-store --delete "$debug"
[ ! -e "$debug" ] # Just a trivial assert that it does no more exist
# Now rebuild the missing output.
debug2=$(nix-build -A debug)
[ "$debug" == "$debug2" ] # Obviously
[ -e "$debug2" ] # Another assert
# Now observe how the "debug" output does no more match the "out" output
# kept from the previous build.
bash $debug2/test.sh # => Outputs mismatch !
# Discarding $out when we rebuild is not a better option, as it may mismatch
# with other derivations depending on the previous version of "$out".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment