trivial-builders: add runCommandLocalOverridable, like runCommand, but supports standard hooks like postBuild, etc.

This commit is contained in:
Colin 2024-05-20 06:13:46 +00:00
parent c21ddca1fd
commit 7fd527c9d6
2 changed files with 17 additions and 3 deletions

View File

@ -1,9 +1,22 @@
{ lib
, runCommandLocal
, rmDbusServicesInPlace
, runCommandLocalOverridable
, stdenv
, symlinkJoin
}:
{
# like `runCommandLocal`, but can be `.overrideAttrs` and supports standard phases/hooks like `postBuild`, etc.
runCommandLocalOverridable = name: env: buildPhase: stdenv.mkDerivation {
inherit name;
preferLocalBuild = true;
dontUnpack = true;
buildPhase = lib.concatStringsSep "\n" [
"runHook preBuild"
buildPhase
"runHook postBuild"
];
};
# given some package and a path, extract the item at `${package}/${path}` into
# its own package, but otherwise keeping the same path.
# this is done by copying the bits, so as to avoid including the item's neighbors
@ -12,7 +25,7 @@
paths = if lib.isList path then path else [ path ];
suffix = (lib.head paths) + (if paths != [ path ] then "-and-other-paths" else "");
in
runCommandLocal "${pkg.pname or pkg.name}-${suffix}" { } ''
runCommandLocalOverridable "${pkg.pname or pkg.name}-${suffix}" { } ''
for item in ${lib.escapeShellArgs paths}; do
mkdir -p "$out/$(dirname $item)"
cp -a "${pkg}/$item" "$out/$item"
@ -24,7 +37,7 @@
paths = if lib.isList path then path else [ path ];
suffix = (lib.head paths) + (if paths != [ path ] then "-and-other-paths" else "");
in
runCommandLocal "${pkg.pname or pkg.name}-${suffix}" { } ''
runCommandLocalOverridable "${pkg.pname or pkg.name}-${suffix}" { } ''
for item in ${lib.escapeShellArgs paths}; do
mkdir -p "$out/$(dirname $item)"
ln -s "${pkg}/$item" "$out/$item"

View File

@ -87,6 +87,7 @@ let
linkIntoOwnPackage
rmDbusServices
rmDbusServicesInPlace
runCommandLocalOverridable
;
unftp = callPackage ./additional/unftp { };
where-am-i = callPackage ./additional/where-am-i { };