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
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:
nix-env or configuration.nix or home-manager respectivelynix-build's default behaviour, with or without -onix-store -r /nix/store/$hash-$name --add-root ./root-name --indirect/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.shI 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?
Most helpful comment
Same thing with
nix-shell.-o testdoesn't create any symlink either. I think this is pretty serious in the nix-shell case, since now a common technique just silently fails.