Here's a discussion of garbage collection approaches.
Problem statement
When restoring a Nix store from a cache, the store may contain old unnecessary paths.
These paths should be removed sometimes to limit cache size and ensure the fastest restore/save steps.
Approach 1
Produce a cache once, use it multiple times. Don't collect garbage.
Advantages:
Unnecessary paths are saved to a cache only during a new save.
Disadvantages:
Unnecessary paths can accumulate between new saves.
A job at the firs run produces a path A and saves a cache.
The job at the second run restores the cache, produces a path B, and saves a cache. The cache has both A and B.
etc.
Approach 2
Collect garbage before saving a cache.
Advantages:
Automatically keep cache at a minimal/limited size
Disadvantages:
No standard way to gc only old paths.
Hopefully working solutions
Use nix profile install to save any nix store path or installable from garbage collection.
Here's a discussion of garbage collection approaches.
Problem statement
When restoring a Nix store from a cache, the store may contain old unnecessary paths. These paths should be removed sometimes to limit cache size and ensure the fastest restore/save steps.
Approach 1
Produce a cache once, use it multiple times. Don't collect garbage.
Advantages:
Disadvantages:
A
and saves a cache.B
, and saves a cache. The cache has bothA
andB
.Approach 2
Collect garbage before saving a cache.
Advantages:
Disadvantages:
Hopefully working solutions
nix profile install
to save any nix store path or installable from garbage collection.inputs
vianix flake archive
as in https://github.com/NixOS/nix/issues/4250#issuecomment-1146878407nix flake show --json | jq '.packages."x86_64-linux"|keys[]'| xargs -I {}
onx86_64-linux
(https://github.com/NixOS/nix/issues/7165)atime
nix store gc
when a cache size reaches a certain limit.