Revert "applyPatches: to extendMkDerivation, fix meta.position"

This commit is contained in:
K900
2026-02-12 20:37:19 +03:00
committed by GitHub
parent 3f4a3c08f2
commit db847a48c0
+58 -52
View File
@@ -1019,70 +1019,76 @@ rec {
];
}
*/
applyPatches = lib.extendMkDerivation {
constructDrv = stdenvNoCC.mkDerivation;
extendDrvArgs =
finalAttrs:
{
src,
...
}@args:
assert lib.assertMsg (
!args ? meta
) "applyPatches will not merge 'meta', change it in 'src' instead";
assert lib.assertMsg (
!args ? passthru
) "applyPatches will not merge 'passthru', change it in 'src' instead";
applyPatches =
{
src,
name ?
(
if builtins.typeOf src == "path" then
baseNameOf src
else if builtins.isAttrs src && builtins.hasAttr "name" src then
src.name
else
throw "applyPatches: please supply a `name` argument because a default name can only be computed when the `src` is a path or is an attribute set with a `name` attribute."
)
+ "-patched",
patches ? [ ],
prePatch ? "",
postPatch ? "",
...
}@args:
assert lib.assertMsg (
!args ? meta
) "applyPatches will not merge 'meta', change it in 'src' instead";
assert lib.assertMsg (
!args ? passthru
) "applyPatches will not merge 'passthru', change it in 'src' instead";
if patches == [ ] && prePatch == "" && postPatch == "" then
src # nothing to do, so use original src to avoid additional drv
else
let
keepAttrs = names: lib.filterAttrs (name: val: lib.elem name names);
# enables tools like nix-update to determine what src attributes to replace
extraPassthru = lib.optionalAttrs (lib.isAttrs finalAttrs.src) (
extraPassthru = lib.optionalAttrs (lib.isAttrs src) (
keepAttrs [
"rev"
"tag"
"url"
"outputHash"
"outputHashAlgo"
] finalAttrs.src
] src
);
in
{
name =
args.name or (
if builtins.isPath finalAttrs.src then
baseNameOf finalAttrs.src + "-patched"
else if builtins.isAttrs finalAttrs.src && (finalAttrs.src ? name) then
let
srcName = builtins.parseDrvName finalAttrs.src.name;
in
"${srcName.name}-patched${lib.optionalString (srcName.version != "") "-${srcName.version}"}"
else
throw "applyPatches: please supply a `name` argument because a default name can only be computed when the `src` is a path or is an attribute set with a `name` attribute."
);
# Manually setting `name` can mess up positioning.
# This should fix it.
pos = builtins.unsafeGetAttrPos "src" args;
preferLocalBuild = true;
allowSubstitutes = false;
dontConfigure = true;
dontBuild = true;
doCheck = false;
installPhase = "cp -R ./ $out";
# passthru the git and hash info for nix-update, as well
# as all the src's passthru attrs.
passthru = extraPassthru // finalAttrs.src.passthru or { };
stdenvNoCC.mkDerivation (
{
inherit
name
src
patches
prePatch
postPatch
;
preferLocalBuild = true;
allowSubstitutes = false;
phases = "unpackPhase patchPhase installPhase";
installPhase = "cp -R ./ $out";
}
# Carry (and merge) information from the underlying `src` if present.
# If there is not src.meta, this meta block will be blank regardless.
meta = lib.optionalAttrs (finalAttrs.src ? meta) removeAttrs finalAttrs.src.meta [ "position" ];
};
};
// (optionalAttrs (src ? meta) {
inherit (src) meta;
})
// (optionalAttrs (extraPassthru != { } || src ? passthru) {
passthru = extraPassthru // src.passthru or { };
})
# Forward any additional arguments to the derivation
// (removeAttrs args [
"src"
"name"
"patches"
"prePatch"
"postPatch"
])
);
# TODO: move docs to Nixpkgs manual
# An immutable file in the store with a length of 0 bytes.