Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

debug failing nix-build in interactive bash shell

License

NotificationsYou must be signed in to change notification settings

milahu/nix-build-debug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

status

working prototype

what works

  • start a debug shell, for examplenix-build-debug '<nixpkgs>' -A hello
  • use therunPhase function to run phases, for examplerunPhase unpackPhase
  • auto-completion for therunPhase function.withrunPhase [Tab][Tab] all build phases are listed in order
  • stop and continue calls to therunPhase 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

why

usingnix-shell to debug a failing nix build is not ideal

stop on error

nix-build runs the build as a bash script withset -eso the build stops on the first error

nix-shell starts an interactive bash shell withset +eso 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

continue 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

usage

start shell

nix-build-debug '<nixpkgs>' -A hello

list phases

runPhase [Tab][Tab]

run phases

runPhase unpackPhaserunPhase configurePhaserunPhase buildPhaserunPhase installPhase

installPhase will install the build result in$NIX_BUILD_TOP/result*

continue running a phase

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

see also

keywords

  • 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

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp