diff --git a/pkgs/build-support/setup-hooks/die.sh b/pkgs/build-support/setup-hooks/die.sh new file mode 100644 index 00000000000..0db41e030f4 --- /dev/null +++ b/pkgs/build-support/setup-hooks/die.sh @@ -0,0 +1,21 @@ +# Exit with backtrace and error message +# +# Usage: die "Error message" +die() { + # Let us be a little sloppy with errors, because otherwise the final + # invocation of `caller` below will cause the script to exit. + set +e + + # Print our error message + printf "\nBuilder called die: %b\n" "$*" + printf "Backtrace:\n" + + # Print a backtrace. + local frame=0 + while caller $frame; do + ((frame++)); + done + printf "\n" + + exit 1 +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 971c939957a..8235f494c6a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -100,6 +100,8 @@ with pkgs; diffPlugins = (callPackage ../build-support/plugins.nix {}).diffPlugins; + dieHook = makeSetupHook {} ../build-support/setup-hooks/die.sh; + dockerTools = callPackage ../build-support/docker { }; docker_compose = pythonPackages.docker_compose; @@ -287,7 +289,8 @@ with pkgs; inherit contents compressor prepend; }; - makeWrapper = makeSetupHook { } ../build-support/setup-hooks/make-wrapper.sh; + makeWrapper = makeSetupHook { deps = [ dieHook ]; } + ../build-support/setup-hooks/make-wrapper.sh; makeModulesClosure = { kernel, rootModules, allowMissing ? false }: callPackage ../build-support/kernel/modules-closure.nix {