A lot of new Nix users are surprised when deleting a file, switching a generation, or uninstalling a package doesn’t free up any disk space. The Nix store isn’t a temp folder that forgets what you touched. It’s a graph of referenced build artifacts, and it works by graph reachability, not user intuition. Once you get that, Nix’s behaviour makes a lot more sense. If Nix keeps something you thought was gone, the answer is almost always: somewhere, something still points at it. This isn’t Nix being stubborn—it’s Nix doing exactly what it’s supposed to do.
The Nix store keeps paths alive as long as they’re reachable from a garbage collection root. If something still points at a store path, that path is considered live and won’t be deleted. A garbage collection root is any reference that tells Nix to keep a store path around. Common roots include:
resultAs long as one of these roots exists, the referenced store paths and all their dependencies stay in the store. This is what makes safe rollbacks and reliable reuse possible. It’s also why disk usage can grow more than you expect.
Nix doesn’t care if you think something is gone. It cares if something still references it. That’s important. You might have:
and still have the underlying store paths hanging around because a root exists somewhere else.
One of the easiest ways to accidentally keep store paths is the
result symlink from commands like nix build.
For example:
nix build .#package
ls -l resultThat result symlink points into the Nix store. As long
as it exists, the target is considered live. Delete the symlink to
remove that root:
rm resultIf nothing else refers to the store path, it’s now eligible for garbage collection. Rollbacks work because old generations are kept. But those generations also keep store paths alive. So, removing a package from your config doesn’t always free space—older generations might still need it. That’s why just rebuilding doesn’t always shrink the store. The old state is still there on purpose.
Nix would be risky if it deleted things too aggressively. The store is built for safety:
Sometimes, symlinks pointing into the Nix store are left behind after builds or manual operations. These “dangling” symlinks can keep store paths alive unnecessarily. To find all symlinks in your home directory and subdirectories that point into the Nix store but whose targets no longer exist, you can use:
find ~ -type l -lname '/nix/store/*' \
! -exec test -e {} \; -printThis command searches for all symbolic links under your home directory that point to the Nix store and prints those whose targets are missing (dangling). Remove these symlinks if you no longer need them to allow garbage collection to clean up the store.
If disk space isn’t dropping, ask:
result symlink or other symlink into the
store?Only after checking these does it make sense to expect the store to shrink.
See also: