NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.85k stars 1.52k forks source link

"bad meta.outputsToInstall" error when installing packages #9340

Open jvns opened 1 year ago

jvns commented 1 year ago

Describe the bug

Sometimes when I run nix-env -iA nixpkgs.somepackage, I get a bad meta.outputsToInstall error, like this:

$  nix-env -iA nixpkgs.cheat
installing 'cheat-4.4.0'
this path will be fetched (6.23 MiB download, 16.11 MiB unpacked):
 /nix/store/k95iy2ajg4zipvpawk7fz83cpy9y1ha7-cheat-4.4.0
copying path '/nix/store/k95iy2ajg4zipvpawk7fz83cpy9y1ha7-cheat-4.4.0' from 'https://cache.nixos.org'...
error: this derivation has bad 'meta.outputsToInstall'

It happens when I try to install any package -- nix is just completely broken.

This happens every 2-3 months with no obvious-to-me pattern. The only way I know to fix it is to run this bash script, which always fixes the problem. I don't understand what that script does though.

Steps To Reproduce

I don't know, but I know it's happened to me repeatedly. Reporting it in case someone else can figure out how to reproduce it or is running into the same issue.

Expected behavior

It seems weird that I need to do a seemingly stateful thing like "rebuild my profile" since nix is supposed to be stateless -- it's surprising to me that the system just breaks for no apparent reason every few months.

nix-env --version output

nix-env (Nix) 2.11.1
mokshasoft commented 1 year ago

I had the same problem with bad meta.outputsToInstall. I couldn't install or uninstall anything, and the script you linked to didn't work either, but I found this and that helped me. Don't know why though and I don't know what I did to end up with this error.

senges commented 1 year ago

I had (and still have) the exact same issue with nix (Nix) 2.13.5 in docker. This is quite annoying, no topic nor any issue seems to properly address the root cause of this situation.

It seems some packages install tend to trigger it more than others (for me an good example is nixpkgs.dog) but I'm not even sure this is correlated.

TL;DR there are 2 workaround hacks:

nix-env -u --always
OR
nix-env --list-generations
nix-env --rollback

I'm still on the Nix learning phase tho, maybe this is just a normal behavior that is out of my understanding for some reason.

Edit: FYI I'm using channel nixpkgs-unstable but I had the exact same issue with Nix 2.11.1 and channels 22.05

sven commented 1 month ago

I also stumbled upon this problem and have a Dockerfile to reproduce it.

FROM nixos/nix:2.24.9
RUN nix-env -iA nixpkgs.gnused
RUN nix-env -iA nixpkgs.crane
RUN nix-env -iA nixpkgs.devenv

On my PC this always leads to: error: this derivation has bad 'meta.outputsToInstall' for the devenv package.

Interestingly, this doesn't happen if I change the order:

FROM nixos/nix:2.24.9
RUN nix-env -iA nixpkgs.devenv
RUN nix-env -iA nixpkgs.gnused
RUN nix-env -iA nixpkgs.crane

This builds without problems. The used build command is: docker build -t nix-test .

Maybe somebody can have a look into this to see why the environment breaks.

sven commented 1 month ago

Maybe I found something that could help debugging this issue. After installing crane, which seems to break nix-env, I looked into the manifest.nix and found this:

[
  {
    crane = ...
    meta =  {
      outputsToInstall = ["out"];
    };
    outputs = ["crane"];
  }
  ...
]

As you can see, the meta.outputsToInstall doesn't match the outputs list. Other packages that don't break nix-env like jq and gnused have matching values.