doc: add missing phase hooks

This commit is contained in:
Pol Dellaiera 2025-04-19 22:02:30 +02:00
parent 540ddbcf2f
commit 47f000d991
9 changed files with 110 additions and 7 deletions

View file

@ -49,6 +49,8 @@ stdenvNoCC.mkDerivation (
''; '';
buildPhase = '' buildPhase = ''
runHook preBuild
substituteInPlace ./languages-frameworks/python.section.md \ substituteInPlace ./languages-frameworks/python.section.md \
--subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")" --subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")"
@ -84,9 +86,13 @@ stdenvNoCC.mkDerivation (
--section-toc-depth 1 \ --section-toc-depth 1 \
manual.md \ manual.md \
out/index.html out/index.html
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
dest="$out/share/doc/nixpkgs" dest="$out/share/doc/nixpkgs"
mkdir -p "$(dirname "$dest")" mkdir -p "$(dirname "$dest")"
mv out "$dest" mv out "$dest"
@ -97,6 +103,8 @@ stdenvNoCC.mkDerivation (
mkdir -p $out/nix-support/ mkdir -p $out/nix-support/
echo "doc manual $dest manual.html" >> $out/nix-support/hydra-build-products echo "doc manual $dest manual.html" >> $out/nix-support/hydra-build-products
echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products
runHook postInstall
''; '';
passthru = { passthru = {

View file

@ -27,8 +27,8 @@ let
} ":"; } ":";
}; };
# the INI file can now be given as plain old nix values
in in
# the INI file can now be given as plain old nix values
customToINI { customToINI {
main = { main = {
pushinfo = true; pushinfo = true;

View file

@ -208,8 +208,12 @@ mkDerivation {
libraryName = "IAL-1.3"; libraryName = "IAL-1.3";
buildPhase = '' buildPhase = ''
runHook preBuild
patchShebangs find-deps.sh patchShebangs find-deps.sh
make make
runHook postBuild
''; '';
} }
``` ```

View file

@ -110,8 +110,12 @@ pkgs.stdenv.mkDerivation {
]; ];
buildPhase = '' buildPhase = ''
runHook preBuild
cp --reflink=auto --no-preserve=mode -R $bowerComponents/bower_components . # note 2 cp --reflink=auto --no-preserve=mode -R $bowerComponents/bower_components . # note 2
${pkgs.nodePackages.gulp}/bin/gulp build # note 4 ${pkgs.nodePackages.gulp}/bin/gulp build # note 4
runHook postBuild
''; '';
installPhase = "mv gulpdist $out"; installPhase = "mv gulpdist $out";

View file

@ -47,6 +47,7 @@ One advantage is that when `pkgs.zlib` is updated, it will automatically update
env = (old.env or { }) // { env = (old.env or { }) // {
NIX_CFLAGS_COMPILE = ""; NIX_CFLAGS_COMPILE = "";
}; };
configurePhase = '' configurePhase = ''
# FIXME: Some tests require writing at $HOME # FIXME: Some tests require writing at $HOME
HOME=$TMPDIR HOME=$TMPDIR
@ -57,15 +58,29 @@ One advantage is that when `pkgs.zlib` is updated, it will automatically update
runHook postConfigure runHook postConfigure
''; '';
dontStrip = true; dontStrip = true;
outputs = [ "out" ]; outputs = [ "out" ];
buildPhase = '' buildPhase = ''
runHook preBuild
emmake make emmake make
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
emmake make install emmake make install
runHook postInstall
''; '';
checkPhase = '' checkPhase = ''
runHook preCheck
echo "================= testing zlib using node =================" echo "================= testing zlib using node ================="
echo "Compiling a custom test" echo "Compiling a custom test"
@ -84,6 +99,8 @@ One advantage is that when `pkgs.zlib` is updated, it will automatically update
echo "it seems to work! very good." echo "it seems to work! very good."
fi fi
echo "================= /testing zlib using node =================" echo "================= /testing zlib using node ================="
runHook postCheck
''; '';
postPatch = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin '' postPatch = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
@ -116,6 +133,7 @@ pkgs.buildEmscriptenPackage rec {
openjdk openjdk
json_c json_c
]; ];
nativeBuildInputs = [ nativeBuildInputs = [
pkg-config pkg-config
writableTmpDirAsHomeHook writableTmpDirAsHomeHook
@ -129,6 +147,8 @@ pkgs.buildEmscriptenPackage rec {
}; };
configurePhase = '' configurePhase = ''
runHook preConfigure
rm -f fastXmlLint.js* rm -f fastXmlLint.js*
# a fix for ERROR:root:For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was 234217728 # a fix for ERROR:root:For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was 234217728
# https://gitlab.com/odfplugfest/xmlmirror/issues/8 # https://gitlab.com/odfplugfest/xmlmirror/issues/8
@ -138,10 +158,16 @@ pkgs.buildEmscriptenPackage rec {
sed -e "s/\$(JSONC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(LIBXML20_LDFLAGS)/\$(JSONC_LDFLAGS) \$(LIBXML20_LDFLAGS) \$(ZLIB_LDFLAGS) /g" -i Makefile.emEnv sed -e "s/\$(JSONC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(LIBXML20_LDFLAGS)/\$(JSONC_LDFLAGS) \$(LIBXML20_LDFLAGS) \$(ZLIB_LDFLAGS) /g" -i Makefile.emEnv
# https://gitlab.com/odfplugfest/xmlmirror/issues/11 # https://gitlab.com/odfplugfest/xmlmirror/issues/11
sed -e "s/-o fastXmlLint.js/-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -o fastXmlLint.js/g" -i Makefile.emEnv sed -e "s/-o fastXmlLint.js/-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -o fastXmlLint.js/g" -i Makefile.emEnv
runHook postConfigure
''; '';
buildPhase = '' buildPhase = ''
runHook preBuild
make -f Makefile.emEnv make -f Makefile.emEnv
runHook postBuild
''; '';
outputs = [ outputs = [
@ -150,6 +176,8 @@ pkgs.buildEmscriptenPackage rec {
]; ];
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/share mkdir -p $out/share
mkdir -p $doc/share/${name} mkdir -p $doc/share/${name}
@ -163,9 +191,13 @@ pkgs.buildEmscriptenPackage rec {
cp *.json $out/share cp *.json $out/share
cp *.rng $out/share cp *.rng $out/share
cp README.md $doc/share/${name} cp README.md $doc/share/${name}
runHook postInstall
''; '';
checkPhase = ''
checkPhase = ''
runHook preCheck
runHook postCheck
''; '';
} }
``` ```

View file

@ -651,7 +651,11 @@ It's important to use the `--offline` flag. For example if you script is `"build
]; ];
buildPhase = '' buildPhase = ''
runHook preBuild
yarn --offline build yarn --offline build
runHook postBuild
''; '';
} }
``` ```

View file

@ -33,11 +33,15 @@ maven.buildMavenPackage rec {
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/share/jd-cli mkdir -p $out/bin $out/share/jd-cli
install -Dm644 jd-cli/target/jd-cli.jar $out/share/jd-cli install -Dm644 jd-cli/target/jd-cli.jar $out/share/jd-cli
makeWrapper ${jre}/bin/java $out/bin/jd-cli \ makeWrapper ${jre}/bin/java $out/bin/jd-cli \
--add-flags "-jar $out/share/jd-cli/jd-cli.jar" --add-flags "-jar $out/share/jd-cli/jd-cli.jar"
runHook postInstall
''; '';
meta = { meta = {
@ -301,16 +305,24 @@ stdenv.mkDerivation {
buildInputs = [ maven ]; buildInputs = [ maven ];
src = ./.; # or fetchFromGitHub, cleanSourceWith, etc src = ./.; # or fetchFromGitHub, cleanSourceWith, etc
buildPhase = '' buildPhase = ''
runHook preBuild
mvn package -Dmaven.repo.local=$out mvn package -Dmaven.repo.local=$out
runHook postBuild
''; '';
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
installPhase = '' installPhase = ''
runHook preInstall
find $out -type f \ find $out -type f \
-name \*.lastUpdated -or \ -name \*.lastUpdated -or \
-name resolver-status.properties -or \ -name resolver-status.properties -or \
-name _remote.repositories \ -name _remote.repositories \
-delete -delete
runHook postInstall
''; '';
# don't do any fixup # don't do any fixup
@ -354,8 +366,8 @@ Regardless of which strategy is chosen above, the step to build the derivation i
maven, maven,
callPackage, callPackage,
}: }:
# pick a repository derivation, here we will use buildMaven
let let
# pick a repository derivation, here we will use buildMaven
repository = callPackage ./build-maven-repository.nix { }; repository = callPackage ./build-maven-repository.nix { };
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@ -366,12 +378,20 @@ stdenv.mkDerivation rec {
buildInputs = [ maven ]; buildInputs = [ maven ];
buildPhase = '' buildPhase = ''
runHook preBuild
echo "Using repository ${repository}" echo "Using repository ${repository}"
mvn --offline -Dmaven.repo.local=${repository} package; mvn --offline -Dmaven.repo.local=${repository} package;
runHook postBuild
''; '';
installPhase = '' installPhase = ''
install -Dm644 target/${pname}-${version}.jar $out/share/java runHook preInstall
install -Dm644 target/${finalAttrs.pname}-${finalAttrs.version}.jar $out/share/java
runHook postInstall
''; '';
} }
``` ```
@ -430,11 +450,17 @@ stdenv.mkDerivation rec {
buildInputs = [ maven ]; buildInputs = [ maven ];
buildPhase = '' buildPhase = ''
runHook preBuild
echo "Using repository ${repository}" echo "Using repository ${repository}"
mvn --offline -Dmaven.repo.local=${repository} package; mvn --offline -Dmaven.repo.local=${repository} package;
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/bin mkdir -p $out/bin
classpath=$(find ${repository} -name "*.jar" -printf ':%h/%f'); classpath=$(find ${repository} -name "*.jar" -printf ':%h/%f');
@ -444,6 +470,8 @@ stdenv.mkDerivation rec {
makeWrapper ${jre}/bin/java $out/bin/${pname} \ makeWrapper ${jre}/bin/java $out/bin/${pname} \
--add-flags "-classpath $out/share/java/${pname}-${version}.jar:''${classpath#:}" \ --add-flags "-classpath $out/share/java/${pname}-${version}.jar:''${classpath#:}" \
--add-flags "Main" --add-flags "Main"
runHook postInstall
''; '';
} }
``` ```
@ -502,8 +530,8 @@ We will modify the derivation above to add a symlink to our repository so that i
makeWrapper, makeWrapper,
jre, jre,
}: }:
# pick a repository derivation, here we will use buildMaven
let let
# pick a repository derivation, here we will use buildMaven
repository = callPackage ./build-maven-repository.nix { }; repository = callPackage ./build-maven-repository.nix { };
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@ -515,11 +543,17 @@ stdenv.mkDerivation rec {
buildInputs = [ maven ]; buildInputs = [ maven ];
buildPhase = '' buildPhase = ''
runHook preBuild
echo "Using repository ${repository}" echo "Using repository ${repository}"
mvn --offline -Dmaven.repo.local=${repository} package; mvn --offline -Dmaven.repo.local=${repository} package;
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/bin mkdir -p $out/bin
# create a symbolic link for the repository directory # create a symbolic link for the repository directory
@ -530,6 +564,8 @@ stdenv.mkDerivation rec {
# this should be the paths from the dependency derivation # this should be the paths from the dependency derivation
makeWrapper ${jre}/bin/java $out/bin/${pname} \ makeWrapper ${jre}/bin/java $out/bin/${pname} \
--add-flags "-jar $out/share/java/${pname}-${version}.jar" --add-flags "-jar $out/share/java/${pname}-${version}.jar"
runHook postInstall
''; '';
} }
``` ```

View file

@ -106,12 +106,16 @@ stdenv.mkDerivation rec {
configurePhase = generated.configure; configurePhase = generated.configure;
installPhase = '' installPhase = ''
runHook preInstall
# This is a special function that invokes swiftpm to find the location # This is a special function that invokes swiftpm to find the location
# of the binaries it produced. # of the binaries it produced.
binPath="$(swiftpmBinPath)" binPath="$(swiftpmBinPath)"
# Now perform any installation steps. # Now perform any installation steps.
mkdir -p $out/bin mkdir -p $out/bin
cp $binPath/myproject $out/bin/ cp $binPath/myproject $out/bin/
runHook postInstall
''; '';
} }
``` ```

View file

@ -53,13 +53,23 @@ Often it is necessary to override or modify some aspect of the build. To make th
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "fnord"; pname = "fnord";
version = "4.5"; version = "4.5";
# ... # ...
buildPhase = '' buildPhase = ''
runHook preBuild
gcc foo.c -o foo gcc foo.c -o foo
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/bin mkdir -p $out/bin
cp foo $out/bin cp foo $out/bin
runHook postInstall
''; '';
} }
``` ```
@ -225,6 +235,7 @@ stdenv.mkDerivation rec {
makeWrapper makeWrapper
pkg-config pkg-config
]; ];
buildInputs = [ libseccomp ]; buildInputs = [ libseccomp ];
postInstall = '' postInstall = ''
@ -249,8 +260,8 @@ stdenv.mkDerivation rec {
util-linux util-linux
qemu qemu
]; ];
checkPhase = ''[elided] ''; checkPhase = ''[elided]'';
} })
``` ```
- `makeWrapper` is a setup hook, i.e., a shell script sourced by the generic builder of `stdenv`. - `makeWrapper` is a setup hook, i.e., a shell script sourced by the generic builder of `stdenv`.