- Notifications
You must be signed in to change notification settings - Fork0
debug failing nix-build in interactive bash shell
License
milahu/nix-build-debug
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
debug nix-build in a nix-shell
- run the build phases explicitly
- modify the build phases (they are stored in *.sh files)
- continue running build phases from a specified line number
working prototype
what works
- start a debug shell, for example
nix-build-debug '<nixpkgs>' -A hello
- use the
runPhase
function to run phases, for examplerunPhase unpackPhase
- auto-completion for the
runPhase
function.withrunPhase [Tab][Tab]
all build phases are listed in order - stop and continue calls to the
runPhase
function.this works by using abash
compiled with--disable-job-control
.sending Ctrl-Z (SIGTSTP) torunPhase
will stop the whole debug shell.see alsodoc/bash-trap-exit-try-catch.md
what is not tested
- continue phase from line N.example:
runPhase buildPhase 123
to continuebuildPhase
from line 123
usingnix-shell
to debug a failing nix build is not ideal
nix-build
runs the build as a bash script withset -e
so the build stops on the first error
nix-shell
starts an interactive bash shell withset +e
so that errors dont exit the shell.but withset +e
, the build does not stop on the first error,and continues executing commands after the error
example
$nix_expr=' with import <nixpkgs> {}; stdenv.mkDerivation { name = "x"; buildCommand = "echo buildCommand; false; echo still running"; }'$nix-build -E"$nix_expr"buildCommanderror: builder for '/nix/store/29zpgfmmsvf81m49piy26daxljpnli0s-x.drv' failed with exit code 1;$nix-shell -E"$nix_expr"$runPhase buildCommandRunning phase: buildCommandbuildCommandstill running
nix-build-debug
solves this problemby running the phase functions in subshells
runPhase() { curPhase=$1 (set -e;$curPhase )# run $curPhase in subshell (...)}
in these subshells,there isset -e
to stop the script on the first error.now, when a build phase fails, the subshell is terminated,but therunPhase
function keeps running, and the debug shell keeps running
nix-build-debug
also allows tocontinue running a build phase from a certain line in the build phase
example:thebuildPhase
fails on a command on line 10.now we can modify thebuildPhase.sh
scriptand continue running thebuildPhase
from line 10
nix-build-debug '<nixpkgs>' -A hello
runPhase [Tab][Tab]
runPhase unpackPhaserunPhase configurePhaserunPhase buildPhaserunPhase installPhase
installPhase
will install the build result in$NIX_BUILD_TOP/result*
when a phase fails, fix the phase script
nano $NIX_BUILD_TOP/.nix-build-debug/lib/buildPhase.sh
then continue running the phase, for example from line 123
runPhase buildPhase 123
- https://unix.stackexchange.com/questions/498435/how-do-i-diagnose-a-failing-nix-build
- https://github.com/NixOS/nixpkgs/blob/master/doc/stdenv/stdenv.chapter.md#building-a-stdenv-package-in-nix-shell-sec-building-stdenv-package-in-nix-shell
- https://discourse.nixos.org/t/nix-build-phases-run-nix-build-phases-interactively/36090
- https://nixos.wiki/wiki/Development_environment_with_nix-shell#stdenv.mkDerivation
- https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh
- nix-shell
- nix-shell with build dependencies of derivation
- nix develop
- rewrite nix-shell in bash
- generate rcfile for bash
- get-env.sh
- dump nix-shell environment to json file
- declare bash variables
- declare bash functions
- bashFunctions
- nix-build
- what would nix-build do
- debug build phases of nix-build
- debug a failing nix-build
- debug a failing nix build
- nix
- nixos
- nixpkgs
About
debug failing nix-build in interactive bash shell
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.