2022-04-06 14:14:42 +00:00
|
|
|
{ pkgs }:
|
|
|
|
rec {
|
|
|
|
/* Prepare a derivation for local builds.
|
|
|
|
*
|
2022-06-15 09:10:47 +00:00
|
|
|
* This function prepares incremental builds by provinding,
|
|
|
|
* containing the build output and the sources for cross checking.
|
2022-04-06 14:14:42 +00:00
|
|
|
* The build output can be used later to allow incremental builds
|
2022-06-15 09:10:47 +00:00
|
|
|
* by passing the derivation output to the `mkIncrementalBuild` function.
|
2022-04-07 12:47:56 +00:00
|
|
|
*
|
|
|
|
* To build a project incrementaly follow these steps:
|
|
|
|
* - run prepareIncrementalBuild on the desired derivation
|
2022-06-15 09:10:47 +00:00
|
|
|
* e.G `incrementalBuildArtifacts = (pkgs.buildIncremental.prepareIncrementalBuild pkgs.virtualbox);`
|
2022-04-07 12:47:56 +00:00
|
|
|
* - change something you want in the sources of the package( e.G using source override)
|
|
|
|
* changedVBox = pkgs.virtuabox.overrideAttrs (old: {
|
|
|
|
* src = path/to/vbox/sources;
|
|
|
|
* }
|
|
|
|
* - use `mkIncrementalBuild changedVBox buildOutput`
|
|
|
|
* - enjoy shorter build times
|
2022-04-06 14:14:42 +00:00
|
|
|
*/
|
|
|
|
prepareIncrementalBuild = drv: drv.overrideAttrs (old: {
|
2022-06-15 09:10:47 +00:00
|
|
|
outputs = [ "out" ];
|
|
|
|
name = drv.name + "-incrementalBuildArtifacts";
|
|
|
|
preBuild = (old.preBuild or "") + ''
|
|
|
|
mkdir -p $out/sources
|
|
|
|
cp -r ./* $out/sources/
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/outputs
|
|
|
|
cp -r ./* $out/outputs/
|
2022-04-06 14:14:42 +00:00
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Build a derivation incrementally based on the output generated by
|
|
|
|
* the `prepareIncrementalBuild function.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* let
|
2022-06-15 09:10:47 +00:00
|
|
|
* incrementalBuildArtifacts = prepareIncrementalBuild drv
|
2022-04-07 14:27:49 +00:00
|
|
|
* in mkIncrementalBuild drv incrementalBuildArtifacts
|
2022-04-06 14:14:42 +00:00
|
|
|
*/
|
|
|
|
mkIncrementalBuild = drv: previousBuildArtifacts: drv.overrideAttrs (old: {
|
2022-06-15 09:10:47 +00:00
|
|
|
preBuild = (old.preBuild or "") + ''
|
|
|
|
set +e
|
|
|
|
diff -ur ${previousBuildArtifacts}/sources ./ > sourceDifference.patch
|
|
|
|
set -e
|
|
|
|
shopt -s extglob
|
|
|
|
rm -r !("sourceDifference.patch")
|
|
|
|
ls -al .
|
|
|
|
${pkgs.rsync}/bin/rsync -cutU --chown=$USER:$USER --chmod=+w -r ${previousBuildArtifacts}/outputs/* .
|
|
|
|
patch -p 1 -i sourceDifference.patch
|
|
|
|
'';
|
2022-04-06 14:14:42 +00:00
|
|
|
});
|
|
|
|
}
|