From 68090d7ff19054e76bf90cb309c4fe57281443dc Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Sun, 2 Jun 2024 14:26:18 +0300 Subject: [PATCH] Fix empty outputsToInstall for InstallableAttrPath Fixes assertion failure if outputsToInstall is empty by defaulting to the "out" output. That is, behavior between the following commands should be consistent: $ nix build --no-link --json .#nothing-to-install-no-out error: derivation '/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-nothing-to-install-no-out.drv' does not have wanted outputs 'out' $ nix build --no-link --file default.nix --json nothing-to-install-no-out error: derivation '/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-nothing-to-install-no-out.drv' does not have wanted outputs 'out' Real-world example of this issue: $ nix build --json .#.legacyPackages.aarch64-linux.texlive.pkgs.iwona error: derivation '/nix/store/dj0h6b0pnlnan5nidnhqa0bmzq4rv6sx-iwona-0.995b.drv' does not have wanted outputs 'out' $ git rev-parse HEAD eee33247cf6941daea8398c976bd2dda7962b125 $ nix build --json --file . texlive.pkgs.iwona nix: src/libstore/outputs-spec.hh:46: nix::OutputsSpec::Names::Names(std::set >&&): Assertion `!empty()' failed. Aborted (core dumped) --- src/libcmd/installable-attr-path.cc | 2 ++ tests/functional/build.sh | 8 ++++++++ tests/functional/multiple-outputs.nix | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/src/libcmd/installable-attr-path.cc b/src/libcmd/installable-attr-path.cc index 3ec1c1614..8917e7a01 100644 --- a/src/libcmd/installable-attr-path.cc +++ b/src/libcmd/installable-attr-path.cc @@ -75,6 +75,8 @@ DerivedPathsWithInfo InstallableAttrPath::toDerivedPaths() std::set outputsToInstall; for (auto & output : packageInfo.queryOutputs(false, true)) outputsToInstall.insert(output.first); + if (outputsToInstall.empty()) + outputsToInstall.insert("out"); return OutputsSpec::Names { std::move(outputsToInstall) }; }, [&](const ExtendedOutputsSpec::Explicit & e) -> OutputsSpec { diff --git a/tests/functional/build.sh b/tests/functional/build.sh index 9fb4357be..a14e6d672 100755 --- a/tests/functional/build.sh +++ b/tests/functional/build.sh @@ -45,6 +45,14 @@ nix build -f multiple-outputs.nix --json e --no-link | jq --exit-status ' (.outputs | keys == ["a_a", "b"])) ' +# Tests that we can handle empty 'outputsToInstall' (assuming that default +# output "out" exists). +nix build -f multiple-outputs.nix --json nothing-to-install --no-link | jq --exit-status ' + (.[0] | + (.drvPath | match(".*nothing-to-install.drv")) and + (.outputs | keys == ["out"])) +' + # But not when it's overriden. nix build -f multiple-outputs.nix --json e^a_a --no-link nix build -f multiple-outputs.nix --json e^a_a --no-link | jq --exit-status ' diff --git a/tests/functional/multiple-outputs.nix b/tests/functional/multiple-outputs.nix index 413d392e4..6ba7c523d 100644 --- a/tests/functional/multiple-outputs.nix +++ b/tests/functional/multiple-outputs.nix @@ -96,6 +96,12 @@ rec { buildCommand = "mkdir $a_a $b $c"; }; + nothing-to-install = mkDerivation { + name = "nothing-to-install"; + meta.outputsToInstall = [ ]; + buildCommand = "mkdir $out"; + }; + independent = mkDerivation { name = "multiple-outputs-independent"; outputs = [ "first" "second" ];