How to get list of phases used to build package

I ran nix develop nixpkgs/nixos-22.11#freerdp to get build environment for freerdp package.
I can run build phases manually, for example unpackPhase or cmakeConfigurePhase.

What I want to do, is to run manually all phases which are used to build the original package it the right order. I was expecting to find something like $phases variable listing all phases, but I can’t see anything like that. How can I do it ?

Thank you for help.

1 Like

It looks that the only way to get list of phases is to do the same as genericBuild function does.

Actually,

running

nix develop nixpkgs/nixos-22.11#freerdp

if [ -z "${phases[*]:-}" ]; then
        phases="${prePhases[*]:-} unpackPhase patchPhase ${preConfigurePhases[*]:-} \
            configurePhase ${preBuildPhases[*]:-} buildPhase checkPhase \
            ${preInstallPhases[*]:-} installPhase ${preFixupPhases[*]:-} fixupPhase installCheckPhase \
            ${preDistPhases[*]:-} distPhase ${postPhases[*]:-}";
fi

gives me

echo $phases

unpackPhase patchPhase configurePhase buildPhase checkPhase glibPreInstallPhase installPhase glibPreFixupPhase fixupPhase installCheckPhase distPhase

which doesn’t look correct. For example freerdp is using cmakeConfigurePhase, not configurePhase.

I can get list of defined phases functions for my shell by running following command:

declare -F | grep -E ".*Phase"

declare -f buildPhase
declare -f checkPhase
declare -f cmakeConfigurePhase
declare -f cmakePcfileCheckPhase
declare -f configurePhase
declare -f distPhase
declare -f fixupPhase
declare -f glibPreFixupPhase
declare -f glibPreInstallPhase
declare -f installCheckPhase
declare -f installPhase
declare -f patchPhase
declare -f showPhaseFooter
declare -f showPhaseHeader
declare -f unpackPhase

this looks OK, but how do I know when cmakePcfileCheckPhase is executed ?

Use ‘grep’ on nixpkgs with ‘genericBuild’ and from builder.sh or setup.sh you see this call lots. In your nix-shell environment type ‘declare | less’ and look at the code.

This is some code from the nix-shell for nix itself:

genericBuild ()
{
    export GZIP_NO_TIMESTAMPS=1;
    if [ -f "${buildCommandPath:-}" ]; then
        source "$buildCommandPath";
        return;
    fi;
    if [ -n "${buildCommand:-}" ]; then
        eval "$buildCommand";
        return;
    fi;
    if [ -z "${phases[*]:-}" ]; then
        phases="${prePhases[*]:-} unpackPhase patchPhase ${preConfigurePhases[*]:-}             configurePhase ${preBuildPhases[*]:-} buildPhase checkPhase             ${preInstallPhases[*]:-} installPhase ${preFixupPhases[*]:-} fixupPhase installCheckPhase             ${preDistPhases[*]:-} distPhase ${postPhases[*]:-}";
    fi;
    for curPhase in ${phases[*]};
    do
        runPhase "$curPhase";
    done
}

Also have a look at Nixpkgs/Create and debug packages - NixOS Wiki

Check out nix-utils/nix-develop-interactive.bash at a2d8cf9b8b375d8364033cdee19d65e9e821ab6b · imincik/nix-utils · GitHub

a one-liner
nix-shell --command 'eval echo $(typeset -f genericBuild | grep "phases=" | perl -pe "s/^\s+phases=//")' "$drvPath" | tail -n 1

an example invocation

nix-shell --command 'eval echo $(typeset -f genericBuild | grep "phases=" | perl -pe "s/^\s+phases=//")' /nix/store/q6p65l7cxfhpisbn6qpz3hd91lkmzkbq-python3.10-pyarrow-16.1.0.drv | tail -n 1
 unpackPhase patchPhase  updateAutotoolsGnuConfigScriptsPhase configurePhase  buildPhase checkPhase  installPhase  pythonOutputDistPhase fixupPhase installCheckPhase  pythonCatchConflictsPhase pythonRemoveBinBytecodePhase pythonImportsCheckPhase distPhase 

a runnable nix command that lets you step in and invoke run-next-phase to run the next phase

  letsql-debug-drv-setup-script = pkgs.writeText "letsql-debug-drv-setup.sh" ''
    # we must define all of this inside of "--command" for it to persist
    alias get-phases='eval echo $(typeset -f genericBuild | grep "phases=" | perl -pe "s/^\s+phases=//")'
    alias set-phases='set $(get-phases); echo "$# phases: $@"'
    alias run-next-phase='phaseName=$1; shift; realPhaseName="''${!phaseName:-$phaseName}"; runPhase $phaseName; echo next phase: $1'
    set-phases
    echo next phase: $1
  '';

  letsql-debug-drv = pkgs.writeShellScriptBin "letsql-debug-drv" ''
    set -eux

    drvPath=$1
    name=$(
      nix-store --query --binding pname "$drvPath" 2>/dev/null || \
      nix-store --query --binding name "$drvPath" 2>/dev/null
    )
    export out=$(mktemp -d -t "nix-debug-$name.XXXXX")
    pushd "$out" || exit
    nix-shell --command "drvPath=\"$drvPath\"; source "${letsql-debug-drv-setup-script}"; return" "$drvPath"
  '';