diff --git a/pkgs/build-support/build-incremental.nix b/pkgs/build-support/build-incremental.nix new file mode 100644 index 000000000000..b2a4fd461709 --- /dev/null +++ b/pkgs/build-support/build-incremental.nix @@ -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 ""); + }); +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 908f0f608fdc..9ff07d888b7f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -429,6 +429,8 @@ with pkgs; camunda-modeler = callPackage ../applications/misc/camunda-modeler { }; + inncrementalBuildTools = callPackage ../build-support/build-incremental.nix {}; + caroline = callPackage ../development/libraries/caroline { }; cartridges = callPackage ../applications/misc/cartridges { };