Checkpointedbuilds: add derivation override functions

One can use this functions to allow incremental builds of derivations
This commit is contained in:
Martin Messer 2022-04-06 16:14:42 +02:00
parent 2453c821f0
commit 3f4e3a862f
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,37 @@
{ pkgs }:
rec {
/* Prepare a derivation for local builds.
*
* This function adds an additional outout for a derivation,
* containing the build output.
* The build output can be used later to allow incremental builds
* by passing the `buildOut` output to the `mkIncrementalBuild` function.
*/
prepareIncrementalBuild = drv: drv.overrideAttrs (old: {
outputs = (old.outputs or [ "out" ]) ++ [ "buildOut" ];
installPhase = pkgs.lib.optionalString (!(builtins.hasAttr "outputs" old)) ''
mkdir -p $out
'' + (old.installPhase or "") + ''
mkdir -p $buildOut
cp -r ./* $buildOut/
'';
});
/* Build a derivation incrementally based on the output generated by
* the `prepareIncrementalBuild function.
*
* Usage:
* let
* buildOutput = (prepareIncrementalBuild drv).buildOut
* in mkIncrementalBuild drv buildOutput
*/
mkIncrementalBuild = drv: previousBuildArtifacts: drv.overrideAttrs (old: {
prePatch = ''
for file in $(diff -r ./ ${previousBuildArtifacts} --brief | grep "Files" |sed 's/^Only in \([^:]*\): /\1\//' | sed 's/^Files \(.*\) and .* differ/\1/')
do
touch $file
done
${pkgs.rsync}/bin/rsync -cutU --chown=$USER:$USER --chmod=+w -r ${previousBuildArtifacts}/* .
'' + (old.prePatch or "");
});
}

View File

@ -429,6 +429,8 @@ with pkgs;
camunda-modeler = callPackage ../applications/misc/camunda-modeler { }; camunda-modeler = callPackage ../applications/misc/camunda-modeler { };
inncrementalBuildTools = callPackage ../build-support/build-incremental.nix {};
caroline = callPackage ../development/libraries/caroline { }; caroline = callPackage ../development/libraries/caroline { };
cartridges = callPackage ../applications/misc/cartridges { }; cartridges = callPackage ../applications/misc/cartridges { };