nix-build: --add-root ignored

Created on 16 Mar 2018  Â·  6Comments  Â·  Source: NixOS/nix

What I did: nix-build '<nixpkgs>' -A hello --add-root test
Expected behaviour: test symlink to exist afterwards, or perhaps an error message complaining that --add-root is not a recognised option, or pointing me to -o
Actual behaviour: result symlink, no test symlink, no error message

Error Messages

Most helpful comment

Same thing with nix-shell. -o test doesn't create any symlink either. I think this is pretty serious in the nix-shell case, since now a common technique just silently fails.

All 6 comments

Same thing with nix-shell. -o test doesn't create any symlink either. I think this is pretty serious in the nix-shell case, since now a common technique just silently fails.

Is there any kind of workaround for this? Is it possible to create a GC root manually?

(I’m running into this issue in the context of https://github.com/commercialhaskell/stack/issues/4673. I have to run nix-store --gc every so often, because I don’t have that much drive space left, but then the next build of my Stack-based Haskell project takes 10 minutes of maxing out all of my CPU cores.)

@bdesham yes, nix-build will create a result symlink and make it a GC root by default. You can change the name of the symlink with the -o option. The issue I'm describing here is that the --add-root option is silently ignored instead of erroring or similar.

You have multiple ways available for creating GC roots:

  • Installing paths in your user profile, system profile, or home profile using nix-env or configuration.nix or home-manager respectively
  • using nix-build's default behaviour, with or without -o
  • using nix-store -r /nix/store/$hash-$name --add-root ./root-name --indirect
  • manually by making symlinks in /nix/var/nix/gcroots — I used this in a terribly ugly script at one point to root an entire build closure: https://github.com/lheckemann/dotfiles/blob/master/gcroots.sh

I just wasted like an hour trying to figure out what I was doing wrong. Turns out nix-build just silently ignores --add-root. Not cool. It appears that nix-shell also ignores it.

lol, @jakubgs. I guess the thousands of hours that other people spent on the project don't count in the balance.

How did you read that from my comment?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pjotrp picture pjotrp  Â·  37Comments

taktoa picture taktoa  Â·  35Comments

matthewbauer picture matthewbauer  Â·  64Comments

domenkozar picture domenkozar  Â·  53Comments

cbarrett picture cbarrett  Â·  49Comments