# Fixing Disk Space Issues on NixOS

**URL:** https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230
**Category:** Guides
**Created:** [January 3, 2025, 11:46am UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230 "2025-01-03T11:46:01Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![unitythemaker](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/unitythemaker/32/9533_2.png) [@unitythemaker](https://discourse.nixosstag.fcio.net/u/unitythemaker)
#### Post date: [January 3, 2025, 11:46am UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/1 "2025-01-03T11:46:01Z")

</div>

## The Problem

I recently encountered an unexpected disk space issue on my NixOS system. After running without a restart for 5 days, relying only on suspend/sleep and performing several system updates, I discovered my `/nix/store` directory had bloated to 100GB.

## Root Cause

The issue stemmed from:

1. Not restarting the system for an extended period (affected some GC roots)
2. Multiple system updates accumulating without a full restart
3. Components like the window manager waiting for a restart to complete updates
4. Old software versions and generations remaining in the store

## Simple Solution

Two steps resolved the issue:

1. Restart your system
2. Run `sudo nix-collect-garbage --delete-older-than 7d`

After these steps, my `/nix/store` size decreased to 44GB.

## Additional Cleanup Commands for Developers

### Development Tools Cache Cleanup

```bash
# Package Manager Caches
pnpm store prune --force # PNPM global store (Node.js)
rm -rf .gradle/caches # Gradle (Java/Android)
cargo clean -Z gc # Rust (nightly only)

# Go Caches
go clean -modcache
go clean -cache

# Docker
docker system prune -a -f # Removes all unused containers, networks, images (both dangling and unreferenced)

```

### Node.js Projects Cleanup

```bash
# Find node_modules directories (creates a review file)
find . -type d -name "node_modules" -not -path "*/node_modules/**/node_modules" | tee reviewed_node_modules.txt

# After reviewing, delete the selected directories
cat reviewed_node_modules.txt | xargs -I {} rm -rf {}
rm reviewed_node_modules.txt

```

### System Analysis and Additional Cleanup

```bash
# Analyze disk usage
nix-shell -p ncdu --command 'ncdu /'

# Devenv.sh cleanup
devenv gc

# Application cache cleanup
rm -rf .cache/spotify/Data

```

### Core Dumps Review (Optional)

```bash
# Locate core dumps (you need to manually delete them)
find / -type f -name 'core' 2>/dev/null

```

⚠ **Warning** : Exercise caution with these commands. They can cause data loss if used improperly. Always review what you’re deleting and ensure you have backups of important data.

## Tips

- Regularly restart your system after updates
- Use `ncdu` to identify space-consuming directories
- Review cleanup commands and their implications before execution
- Keep track of development tool caches, especially in large projects

I hope this helps others who might encounter similar issues!

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixosstag.fcio.net/u/NobbZ)
#### Post date: [January 3, 2025, 3:18pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/2 "2025-01-03T15:18:29Z")

</div>

“restarting” or “rebooting” doesn’t affect this.

What affects the store size is garbage collection, and blindly suggesting `--delete-old` is harmfull in my opinion, `--delete-older-than` is much more sensible for most users.

Also please keep in mind, that you have to use it with `sudo` (or as root) to get rid of old system profiles, while you have to run it as a regular user to clean up that user profiles generations.

---

<div class="post-metadata">

### Author: ![vcunat](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/vcunat/32/11_2.png) [@vcunat](https://discourse.nixosstag.fcio.net/u/vcunat)
#### Post date: [January 3, 2025, 4:09pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/3 "2025-01-03T16:09:51Z")

</div>

> [@NobbZ](#):
>
> “restarting” or “rebooting” doesn’t affect this.

It affects some GC roots, I believe, e.g. `/run/booted-system` (mainly for kernel but it’s kept whole surely), and other running SW like the display manager that people usually don’t restart except on reboots.

---

<div class="post-metadata">

### Author: ![polygon](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/polygon/32/4139_2.png) [@polygon](https://discourse.nixosstag.fcio.net/u/polygon)
#### Post date: [January 3, 2025, 4:26pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/4 "2025-01-03T16:26:15Z")

</div>

If you do a lot of development, especially when using `nix-direnv`, it can be a good idea to check under `/nix/var/nix/gcroots/*`. I noticed that even though I regularly run GC deleting old generations as both, root and regular user, my Nix store would keep growing. I do a lot of the aforementioned development and noticed that my Nix store kept getting bigger and bigger over time.

To get rid of them, just delete the `.direnv` folder in the project and things should be garbage collected. Though I’d prefer if `nix-direnv` had some form of tooling for that.

---

<div class="post-metadata">

### Author: ![unitythemaker](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/unitythemaker/32/9533_2.png) [@unitythemaker](https://discourse.nixosstag.fcio.net/u/unitythemaker)
#### Post date: [January 3, 2025, 4:27pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/5 "2025-01-03T16:27:04Z")

</div>

Yeah, I checked nix-store roots before and after, they were different.  
I also had devenv installed for various projects which also caused extra space to be taken because of different versions of the same programming language being installed.

---

<div class="post-metadata">

### Author: ![unitythemaker](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/unitythemaker/32/9533_2.png) [@unitythemaker](https://discourse.nixosstag.fcio.net/u/unitythemaker)
#### Post date: [January 3, 2025, 4:27pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/6 "2025-01-03T16:27:22Z")

</div>

Thank you. I updated my message.

---

<div class="post-metadata">

### Author: ![unitythemaker](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/unitythemaker/32/9533_2.png) [@unitythemaker](https://discourse.nixosstag.fcio.net/u/unitythemaker)
#### Post date: [January 3, 2025, 4:28pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/7 "2025-01-03T16:28:28Z")

</div>

Exactly, I researched for this over 2 hours yesterday. I ended up with a simple find and rm command afterwards.

---

<div class="post-metadata">

### Author: ![NobbZ](https://discourse.nixosstag.fcio.net/user_avatar/discourse.nixosstag.fcio.net/nobbz/32/7022_2.png) [@NobbZ](https://discourse.nixosstag.fcio.net/u/NobbZ)
#### Post date: [January 3, 2025, 4:34pm UTC](https://discourse.nixosstag.fcio.net/t/fixing-disk-space-issues-on-nixos/58230/8 "2025-01-03T16:34:43Z")

</div>

Indeed it affects running processes as roots, though the reboot is _usually_ not the relevant part in getting rid of cruft, but much more the fact that GCs are done at all.
