Home Explore Blog Models CI



nix

doc/manual/source/package-management/garbage-collector-roots.md
a005b895251620e82b1884d8f98f2a033db03d56e4c4410d00000003000002a2
# Garbage Collector Roots

The roots of the garbage collector are all store paths to which there
are symlinks in the directory `prefix/nix/var/nix/gcroots`. For
instance, the following command makes the path
`/nix/store/d718ef...-foo` a root of the collector:

```console
$ ln -s /nix/store/d718ef...-foo /nix/var/nix/gcroots/bar
```

That is, after this command, the garbage collector will not remove
`/nix/store/d718ef...-foo` or any of its dependencies.

Subdirectories of `prefix/nix/var/nix/gcroots` are searched
recursively. Symlinks to store paths count as roots. Symlinks to
non-store paths are ignored, unless the non-store path is itself a
symlink to a store path.

Chunks
3a5aae35 (1st chunk of `doc/manual/source/package-management/garbage-collector-roots.md`)
Title: Garbage Collector Roots in Nix
Summary
Garbage Collector (GC) roots are defined by symlinks located within the `prefix/nix/var/nix/gcroots` directory. When a symlink points to a store path (e.g., `/nix/store/d718ef...-foo`), that path and all its dependencies are protected from garbage collection. The system recursively searches subdirectories within `gcroots` for these symlinks. Symlinks to non-store paths are generally ignored, unless they ultimately resolve to a store path.