Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
breakpointHook: add for debugging failing builds
Browse files Browse the repository at this point in the history
Usuage: Add breakpointHook to your `buildInputs` like this:

  stdenv.mkDerivation rec {
    # ...
    buildInputs = [ breakpointHook ];
  });

When the build fails as show in this example:

  pkgs.hello.overrideAttrs (old: {
    buildInputs = [ breakpointHook ];
    postPatch = ''
      false
    '';
  });

It will halt execution printing the following message:

build failed in patchPhase with exit code 1
To attach to this build run the following command as root:

   cntr attach -t command cntr-/nix/store/ynyb4n82x2r7sldd58pbb405jdqh5f00-hello-2.10

Installing cntr and running the command will provide shell access to the
build sandbox of failed build:

sudo cntr attach -t command cntr-/nix/store/ynyb4n82x2r7sldd58pbb405jdqh5f00-hello-2.10
WARNING: bad ownership on /nix/var/nix/profiles/per-user/root, should be 1000
[nixbld@localhost:/var/lib/cntr]$

At /var/lib/cntr the sandbox filesystem is mounted. All commands and
files of the system are still accessible within the shell.
To execute commands from the sandbox use the `cntr exec` subcommand.
  • Loading branch information
Mic92 committed Oct 25, 2018
1 parent 84e915a commit f10b935
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkgs/build-support/setup-hooks/breakpoint-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
breakpointHook() {
local red='\033[0;31m'
local no_color='\033[0m'

echo -e "${red}build failed in ${curPhase} with exit code ${exitCode}${no_color}"
printf "To attach install cntr and run the following command as root:\n\n"
sh -c "echo ' cntr attach -t command cntr-${out}'; while true; do sleep 99999999; done"
}
failureHooks+=(breakpointHook)
3 changes: 3 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,9 @@ with pkgs;

bruteforce-luks = callPackage ../tools/security/bruteforce-luks { };

breakpointHook = assert stdenv.isLinux;
makeSetupHook { } ../build-support/setup-hooks/breakpoint-hook.sh;

bsod = callPackage ../misc/emulators/bsod { };

btrfs-progs = callPackage ../tools/filesystems/btrfs-progs { };
Expand Down

0 comments on commit f10b935

Please sign in to comment.