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 1/7] 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. From 3b4c6073c14a9e4a4b9ec003de7e9c2ee2707fed Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:17:32 -0500 Subject: [PATCH 2/7] applyPatches: use extendMkDerivation machinery for arg inheritance --- pkgs/build-support/trivial-builders/default.nix | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index bf93fa840a39..7ebde268f9f0 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1017,9 +1017,6 @@ rec { 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 ( @@ -1044,10 +1041,6 @@ rec { { inherit name - src - patches - prePatch - postPatch ; preferLocalBuild = true; allowSubstitutes = false; @@ -1060,15 +1053,7 @@ rec { }) // (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 From 4b67bd98f4cd63c91cb54dd40143e9fdac4a892b Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:21:13 -0500 Subject: [PATCH 3/7] applyPatches: remove explicit phases --- pkgs/build-support/trivial-builders/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 7ebde268f9f0..ed447c9be101 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1044,7 +1044,11 @@ rec { ; preferLocalBuild = true; allowSubstitutes = false; - phases = "unpackPhase patchPhase installPhase"; + + dontConfigure = true; + dontBuild = true; + doCheck = false; + installPhase = "cp -R ./ $out"; } # Carry (and merge) information from the underlying `src` if present. From 9268517647203e379f54eb98736457d5e8892045 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:50:24 -0500 Subject: [PATCH 4/7] applyPatches: remove inherited meta.position --- pkgs/build-support/trivial-builders/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index ed447c9be101..3051885345ae 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1053,7 +1053,7 @@ rec { } # Carry (and merge) information from the underlying `src` if present. // (optionalAttrs (src ? meta) { - inherit (src) meta; + meta = removeAttrs src.meta [ "position" ]; }) // (optionalAttrs (extraPassthru != { } || src ? passthru) { passthru = extraPassthru // src.passthru or { }; From 315a3525ceca8f442d419114233b98cd5bd57cb1 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:50:24 -0500 Subject: [PATCH 5/7] applyPatches: reorganize name handling, and fix meta.position --- .../trivial-builders/default.nix | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 3051885345ae..88e4ef6dbe88 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1007,16 +1007,6 @@ rec { 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", ... }@args: assert lib.assertMsg ( @@ -1039,9 +1029,23 @@ rec { ); in { - inherit - name - ; + name = + args.name or ( + if builtins.isPath src then + baseNameOf src + "-patched" + else if builtins.isAttrs src && (src ? name) then + let + srcName = builtins.parseDrvName src; + 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; From c7609637eb119bf0bd54ee6f52067ae826b967b4 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:50:24 -0500 Subject: [PATCH 6/7] applyPatches: unconditionally set attrsets that are always set regardless --- pkgs/build-support/trivial-builders/default.nix | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 88e4ef6dbe88..6a4daf3809ac 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1054,14 +1054,12 @@ rec { doCheck = false; installPhase = "cp -R ./ $out"; - } - # Carry (and merge) information from the underlying `src` if present. - // (optionalAttrs (src ? meta) { - meta = removeAttrs src.meta [ "position" ]; - }) - // (optionalAttrs (extraPassthru != { } || src ? passthru) { + passthru = extraPassthru // src.passthru or { }; - }); + + # Carry (and merge) information from the underlying `src` if present. + meta = lib.optionalAttrs (src ? meta) removeAttrs src.meta [ "position" ]; + }; }; # TODO: move docs to Nixpkgs manual From 652080d15f0945d249f2c6ab9fbb945995fffa12 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:09:53 -0500 Subject: [PATCH 7/7] applyPatches: ensure overrides are carried down --- .../trivial-builders/default.nix | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 6a4daf3809ac..686271082928 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1018,24 +1018,24 @@ rec { 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 src) ( + extraPassthru = lib.optionalAttrs (lib.isAttrs finalAttrs.src) ( keepAttrs [ "rev" "tag" "url" "outputHash" "outputHashAlgo" - ] src + ] finalAttrs.src ); in { name = args.name or ( - if builtins.isPath src then - baseNameOf src + "-patched" - else if builtins.isAttrs src && (src ? name) then + if builtins.isPath finalAttrs.src then + baseNameOf finalAttrs.src + "-patched" + else if builtins.isAttrs finalAttrs.src && (finalAttrs.src ? name) then let - srcName = builtins.parseDrvName src; + srcName = builtins.parseDrvName finalAttrs.src.name; in "${srcName.name}-patched${lib.optionalString (srcName.version != "") "-${srcName.version}"}" else @@ -1055,10 +1055,13 @@ rec { installPhase = "cp -R ./ $out"; - passthru = extraPassthru // src.passthru or { }; + # passthru the git and hash info for nix-update, as well + # as all the src's passthru attrs. + passthru = extraPassthru // finalAttrs.src.passthru or { }; # Carry (and merge) information from the underlying `src` if present. - meta = lib.optionalAttrs (src ? meta) removeAttrs src.meta [ "position" ]; + # If there is not src.meta, this meta block will be blank regardless. + meta = lib.optionalAttrs (finalAttrs.src ? meta) removeAttrs finalAttrs.src.meta [ "position" ]; }; };