Nixpkgs/Create and debug packages: Difference between revisions

imported>Bencoman
Undo revision 1221 by Bencoman (talk)
imported>Bencoman
more analysis of genericBuild() and running it directly; corrected $NIXREPOS to $NIXPKGS
Line 152: Line 152:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
mkdir -p /tmp/nix-shell-bc
$ mkdir -p ~/tmpdev/bc-build  &&  cd ~/tmp/bc-build
cd /tmp/nix-shell-bc
$ nix-shell $NIXPKGS -A bc
nix-shell $NIXREPOS/nixpkgs -A bc
export out=/tmp/foo/out
</syntaxhighlight>
</syntaxhighlight>


now we have find out which phases are specified for this package:
You would have seen the dependencies downloading, but the ''bc-build'' directory remains empty. The build system would next invoke '''genericBuild()'''.  This is a shell function defined by [https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh stdenv] that you can review like this...
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
typeset -f genericBuild | grep 'phases='
$ typeset -f genericBuild | less
</syntaxhighlight>
which shows when custom variables '''$buildCommandPath''' or '''$buildCommand''' are defined, those are evaluated exclusively.  Otherwise, if no custom '''$phases''' variable is set, the standard build phase order is used as shown here...
<syntaxhighlight lang="bash">
$ typeset -f genericBuild | grep 'phases='
phases="$prePhases unpackPhase patchPhase $preConfigurePhases configurePhase $preBuildPhases buildPhase checkPhase $preInstallPhases installPhase fixupPhase installCheckPhase $preDistPhases distPhase $postPhases";
phases="$prePhases unpackPhase patchPhase $preConfigurePhases configurePhase $preBuildPhases buildPhase checkPhase $preInstallPhases installPhase fixupPhase installCheckPhase $preDistPhases distPhase $postPhases";
</syntaxhighlight>
</syntaxhighlight>
Line 166: Line 168:
The phases can be defined either as a string to be eval'ed or as a shell function, [https://github.com/NixOS/nixpkgs/blob/5a0b79/pkgs/stdenv/generic/setup.sh#L818 this is how] Nix invokes it.
The phases can be defined either as a string to be eval'ed or as a shell function, [https://github.com/NixOS/nixpkgs/blob/5a0b79/pkgs/stdenv/generic/setup.sh#L818 this is how] Nix invokes it.


so when developing you need to run these phases in a row:
 
So to observe a full build, you can do...
<syntaxhighlight lang="bash">
$ export out=~/tmpdev/bc-build/out
$ set -x
$ genericBuild
</syntaxhighlight>
 
or while developing your own package, you need to individually run these phases in order:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
unpackPhase
unpackPhase
Line 181: Line 191:
{{Note|you do not need to run $preConfigurePhase explicitly as it is run, when running configurePhase already.}}
{{Note|you do not need to run $preConfigurePhase explicitly as it is run, when running configurePhase already.}}


list all functions which are declared in '''set''':
To list all functions which are declared in '''set''':
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
typeset -F
typeset -F