When doing upgrades (especially large ones) on NixOS with a relatively small root partition, I sometimes run out of space after a bunch of new packages are installed in /nix/store. Eg:

error: preallocating file of 716320 bytes: No space left on device

My usual approach has been to run


or even

nix-collect-garbage -d

which frees up space by deleting not only the old generations but also the new packages I'm installing.

The next download attempt will download the new packages all over again, and -- if enough space was freed -- may succeed.

Is there a way to delete only the older derivations?

  • 3
    How about cleaning before starting the update? Mar 24 '18 at 12:09
  • @MariusMatutiae Deleting old generations (particularly the last one booted from) is a little risky, and of course still doesn't guarantee that enough space will be freed to avoid downloading repeatedly. Sometimes you have to GC, do a partial update, GC again, and then finally finish the update. It can be pretty annoying without a way to tell whether enough space is available.
    – aij
    Mar 26 '18 at 14:44

I think you have 2 possible solutions here. Firstly rather than delete all old generations you can instead specify those for deletion. See the manual entry for the nix-env --delete-generations operation. Secondly the nix-store --optimise operation (ref) may be useful for you also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.