From 2fe88c3f4e5472078d25831c78d6404d893354e8 Mon Sep 17 00:00:00 2001 From: Ross Smyth <18294397+RossSmyth@users.noreply.github.com> Date: Mon, 9 Feb 2026 12:26:30 -0500 Subject: [PATCH] trivial-builders: Improve derivation positioning --- .../trivial-builders/default.nix | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index b350d51455cd..7a73baea2388 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -111,7 +111,7 @@ rec { allowSubstitutes ? false, preferLocalBuild ? true, derivationArgs ? { }, - }: + }@args: assert lib.assertMsg (destination != "" -> (lib.hasPrefix "/" destination && destination != "/")) '' destination must be an absolute path, relative to the derivation's out path, got '${destination}' instead. @@ -125,6 +125,7 @@ rec { runCommand name ( { + pos = builtins.unsafeGetAttrPos "name" args; inherit text executable @@ -333,7 +334,7 @@ rec { Type: Bool */ inheritPath ? true, - }: + }@args: writeTextFile { inherit name @@ -613,6 +614,13 @@ rec { "failOnMissing" ] // { + # Allow getting the proper position of the output derivation. + # Since one of these are required, it should be fairly accurate. + pos = + if args_ ? pname then + builtins.unsafeGetAttrPos "pname" args_ + else + builtins.unsafeGetAttrPos "name" args_; inherit preferLocalBuild allowSubstitutes; paths = mapPaths (path: "${path}${stripPrefix}") paths; passAsFile = [ "paths" ]; @@ -675,6 +683,14 @@ rec { in runCommand name { + # Get the position from the `entries` attrset if it exists. + # This is the best we can do since the other attrs are either defined here, or curried values that + # we cannot extract a position from + pos = + if lib.isAttrs entries then + builtins.unsafeGetAttrPos (builtins.head (builtins.attrNames entries)) entries + else + null; preferLocalBuild = true; allowSubstitutes = false; passthru.entries = entries'; @@ -744,12 +760,15 @@ rec { meta ? { }, passthru ? { }, substitutions ? { }, - }: + }@args: script: runCommand name ( substitutions // { + # Make the position of the derivation accurate. + # Since not having `name` is deprecated, this should be fairly accurate. + pos = lib.unsafeGetAttrPos "name" args; # TODO(@Artturin:) substitutions should be inside the env attrset # but users are likely passing non-substitution arguments through substitutions # turn off __structuredAttrs to unbreak substituteAll