Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty outputsToInstall for InstallableAttrPath #10825

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

tie
Copy link
Member

@tie tie commented Jun 2, 2024

Motivation

OutputsSpec::Names constructor requires a non-empty set of output names.

Names(const std::set<OutputName> & s)
: std::set<OutputName>(s)
{ assert(!empty()); }
/**
* Needs to be "inherited manually"
*/
Names(std::set<OutputName> && s)
: std::set<OutputName>(s)
{ assert(!empty()); }

Context

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<std::__cxx11::basic_string<char> >&&): Assertion `!empty()' failed.
Aborted (core dumped)

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

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<std::__cxx11::basic_string<char> >&&): Assertion `!empty()' failed.
	Aborted (core dumped)
@tie tie requested a review from edolstra as a code owner June 2, 2024 11:37
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jun 2, 2024
@roberth
Copy link
Member

roberth commented Jun 2, 2024

I think the root cause here is that InstallableAttrPath::toDerivedPaths() doesn't have a parameter that controls whether we query an installable for its installable outputs or all its outputs. Probably nix build should default to all outputs, unlike nix profile.
That would result in more sensible behavior, certainly in the example.

@tie
Copy link
Member Author

tie commented Jun 3, 2024

Yes, in the long run this seems like a more sensible behavior, although I’m not sure if this would be a breaking change since we already default to out for InstallableFlake (and InstallableAttrPath crashes Nix command-line tool right now).

if (outputsToInstall.empty())
outputsToInstall.insert("out");
return OutputsSpec::Names { std::move(outputsToInstall) };

For now, I think that the hot fix for a crash should be good enough and consistent with flake installables.

roberth referenced this pull request Jun 3, 2024
'nix profile install' will now install all outputs listed in the
package's meta.outputsToInstall attribute, or all outputs if that
attribute doesn't exist. This makes it behave consistently with
nix-env. Fixes #6385.

Furthermore, for consistency, all other 'nix' commands do this as
well. E.g. 'nix build' will build and symlink the outputs in
meta.outputsToInstall, defaulting to all outputs. Previously, it only
built/symlinked the first output. Note that this means that selecting
a specific output using attrpath selection (e.g. 'nix build
nixpkgs#libxml2.dev') no longer works. A subsequent PR will add a way
to specify the desired outputs explicitly.
@roberth
Copy link
Member

roberth commented Jun 3, 2024

I've tracked the cause down to 1ddabe1, which just adds the out behavior without any explanation.

It see multiple issues with it:

I'm ok to merge this as a hotfix, but this functionality is bad and should be replaced by something more intentional.

@roberth roberth added the bug label Jun 3, 2024
@roberth roberth merged commit b74a0df into NixOS:master Jun 3, 2024
10 checks passed
@roberth
Copy link
Member

roberth commented Jun 3, 2024

Thank you @tie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug with-tests Issues related to testing. PRs with tests have some priority
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants