From 78945a827cc5f2e5b97b7ca9807f7ac111086a1e Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 15 Apr 2024 00:50:38 -0700 Subject: stdenv: make inputDerivation never fixed-output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes using inputDerivation on derivations that are fixed-output. Previously: ``` nix-repl> drv = runCommand "huh" { outputHash = "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="; outputHashAlgo = "sha256"; outputHashType = "flat"; } "touch $out" nix-repl> drv.inputDerivation «derivation /nix/store/d8mjs6cmmvsr1fv7psm6imis5pmh9bcs-huh.drv» nix-repl> :b drv.inputDerivation error: fixed output derivation 'huh' is not allowed to refer to other store paths. You may need to use the 'unsafeDiscardReferences' derivation attribute, see the manual for more details. ``` Fixes: https://github.com/NixOS/nixpkgs/issues/304209 --- pkgs/stdenv/generic/make-derivation.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'pkgs/stdenv/generic') diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 08cded6642547..1214d01013838 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -574,6 +574,12 @@ let "The ‘env’ attribute set can only contain derivation, string, boolean or integer attributes. The ‘${n}’ attribute is of type ${builtins.typeOf v}."; v) env; + # Fixed-output derivations may not reference other paths, which means that + # for a fixed-output derivation, the corresponding inputDerivation should + # *not* be fixed-output. To achieve this we simply delete the attributes that + # would make it fixed-output. + deleteFixedOutputRelatedAttrs = lib.flip builtins.removeAttrs [ "outputHashAlgo" "outputHash" "outputHashMode" ]; + in extendDerivation @@ -584,7 +590,7 @@ extendDerivation # This allows easy building and distributing of all derivations # needed to enter a nix-shell with # nix-build shell.nix -A inputDerivation - inputDerivation = derivation (derivationArg // { + inputDerivation = derivation (deleteFixedOutputRelatedAttrs derivationArg // { # Add a name in case the original drv didn't have one name = derivationArg.name or "inputDerivation"; # This always only has one output -- cgit 1.4.1