From c54e477305b0f4d0973f5e2953224d476e369c32 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:15:30 -0500 Subject: [PATCH] applyPatches: migrate to extendMkDerivation naive translation --- .../trivial-builders/default.nix | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index b350d51455cd..bf93fa840a39 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1000,33 +1000,34 @@ rec { ]; } */ - 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 + applyPatches = lib.extendMkDerivation { + constructDrv = stdenvNoCC.mkDerivation; + + extendDrvArgs = + finalAttrs: + { + 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"; let keepAttrs = names: lib.filterAttrs (name: val: lib.elem name names); # enables tools like nix-update to determine what src attributes to replace @@ -1040,36 +1041,35 @@ rec { ] src ); in - 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. - // (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" - ]) - ); + { + 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. + // (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.