Home Explore Blog CI



nix

doc/manual/source/package-management/garbage-collector-roots.md
5e81a2b8e190165c3cedb9019869ddb0693d7ec3495b6f0600000003000002d1
# 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 also searched for
symlinks. Symlinks to non-store paths are followed and searched for
roots, but symlinks to non-store paths *inside* the paths reached in
that way are not followed to prevent infinite recursion.

Chunks
cdc9aa52 (1st chunk of `doc/manual/source/package-management/garbage-collector-roots.md`)
Title: Garbage Collector Roots Explained
Summary
The garbage collector identifies roots as store paths that have symbolic links in the `prefix/nix/var/nix/gcroots` directory. Creating a symlink to a store path in this directory prevents the garbage collector from removing that path or its dependencies. Subdirectories within `prefix/nix/var/nix/gcroots` are also scanned for symlinks. Symlinks to non-store paths are followed to find roots, but symlinks within those paths are not, to prevent infinite loops.