Is there a nix-clean command for the cache?

How should the nix cache be deleted? I am on MacOS Monterey. Is there a command for this or is it done by manually deleting directories?

Also is there is way to clean a particular store item for example I have an error on this one:

 building '/nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv'...

 ErrorErrorxexecuting ' **/nix/store/067f780bk90ghn7yhz914d5fykmll7a4-bash-5.1-p16/bin/bash** ': **Bad file descriptor**

What if I want suspect this store item is corrupted and want to rebuild and have it download this again?

Well I tried deleting the cache files but I guess that was not a good idea:

deano@Ds-MacBook-Pro nix % nix-build

**error:** getting status of ' **/Users/deano/.cache/nix/default.nix** ': **No such file or directory**

 deano@Ds-MacBook-Pro nix % sudo nix-build

**error:** getting status of ' **/Users/deano/.cache/nix/default.nix** ': **No such file or directory**

Can someone answer about correct way to clean the cache please?, and also if I need to reinstall or is there a way to reinit the cache and get the default.nix file back?

I’m not personally sure–but I don’t think I’ve looked before.

To clarify, you mean the cache(s) in ~/.cache/nix/ (or XDG_CACHE_HOME)?

1 Like

~/.cache/nix/ is probably what needs to be cleaned out

I grepped around in the source a bit and don’t see an obvious cleanup command.

I’m not sure if it’ll apply in your case, but you might want to try using --tarball-ttl 0 first to see if that skirts the issue without deleting anything.

It’s probably safe to delete in there, but I don’t have the confidence of someone who’s done it… :slight_smile:

2 Likes

Well I guess not then. Most package managers have a clean command. think nodejs etc tho

Maybe you’re looking for GC? This article seems relevant:

2 Likes

It depends on what you mean by “cache” and by “clean”. If you mean clean the /nix/store of unused packages, then yes, there is the nix-collect-garbage command. If you mean the evaluation cache, there is currently no command I am aware of, since it is still an experimental feature, but you can just manually delete ~/.cache/nix/eval-cache-v2 for now.

As far as deleting store paths, you can use nix-store --delete <store-path> to do so, as long as it is not still considered a “live” path, i.e. tied to a gc root.

6 Likes

I’ve rm -rf’d that user cache directory many times without noticing an issue.

4 Likes

well I did delete an individual item like that but what then will cause it to be updated? if I suspect an item in the cache is corrupt I want to delete it and then have it downloaded again. Is this possible?

Since my computer shut down in the middle of a rebuild I was thinking of clearing the cache before rebuilding again. So, should I delete everything in ~/.cache/nix/eval-cache-v2?