diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 2f50d3c4a66a..220b3d7d5953 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -1026,16 +1026,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 ( @@ -1058,9 +1048,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;