stdenv: don't discard string context from ContentAddressed derivations

Without the change build for packages that use `disallowedReferences`
fails in `contentAddressedByDefault = true` mode:

    $ nix build -f. ruby_3_1 --arg config '{ contentAddressedByDefault = true; }'
    ...
    error: derivation contains an illegal reference specifier '/0j3hif3ni7zl5zhlzzr5q2q23z66136mnzp75pyiqp5c72q14im2'
    error: 1 dependencies of derivation '/nix/store/39ji7qp225pxvrm8cgvzmyjqsyis2n0h-ruby-3.1.2.drv' failed to build

Original intent of https://github.com/NixOS/nixpkgs/pull/211783 was to
avoid pulling in actual derivation for reference scanning purposes.

Unfortunately CA derivations's outputPath are placeholders until they
are instantiated.

Let's restore string context for CA derivations for now.
This commit is contained in:
Sergei Trofimovich 2024-03-14 23:53:56 +00:00
parent 504e3ecdd9
commit 075597b340

View File

@ -139,7 +139,7 @@ let
# Turn a derivation into its outPath without a string context attached.
# See the comment at the usage site.
unsafeDerivationToUntrackedOutpath = drv:
if isDerivation drv
if isDerivation drv && (!drv.__contentAddressed or false)
then builtins.unsafeDiscardStringContext drv.outPath
else drv;