codchi gc
Perform garbage collection of old nix store paths.
Synopsis
codchi gc -d|--delete-old -a|--all-v|--verbose... -q|--quiet... --json -h|--help MACHINES
Description
All programs and system files reside in the append-only Nix Store. Over
time the store will grow in size noticably, because everytime a
codchi rebuild
is run, new files get added to the store. Therefore you
might want to perform a garbage collection from time to time.
By default, garbage collection will not delete old machine
generations in order to allow instantaneous rollbacks. The drawback is
that the store paths refered to in the old generations never get freed.
To also delete old generations, use --delete-old
with an optional
minimum age (in days). Note that only explicitly listed machines
(MACHINES...
) will be processed. To process all installed machines,
use --all
.
WARNING
In Codchi, the Nix Store is shared across all code machines, which means
that the garbage collector also shares a directory of roots ("gcroots")
that should be preserved, such as the current system configuration of
each code machine. On a vanilla NixOS system, local gcroots (such as
those created by nix build
or direnv) are automatically registered and
protected from garbage collection. However, this doesn't work in Codchi
at the moment, because the garbage collector has a different view on the
file system of each code machine. As a result, the local gcroots of
individual machines become invalid. For example, a gcroot pointing to
/home/codchi/result
on machine foo
is invalid from the perspective
of Codchi, as the correct path would be /data/machine/foo/result
.
This isn't a huge issue, as the deleted store paths can be redownloaded or rebuilt.
Options
- -d, --delete-old=AGE
Delete old machine generations. AGE is the minimum age in days to be deleted default: 0 - -a, --all
Process all machines. Requires--delete-old
- -v, --verbose
Increase logging verbosity - -q, --quiet
Decrease logging verbosity - --json
Produce output in JSON format, suitable for consumption by another program - -h, --help
Print help (see a summary with -h) - MACHINES
Machines to be processed. Requires--delete-old
Extra
Large WSL Distributions
On Windows, the store is inside the WSL distribution `codchistore'. By default WSL distributions only grow in size, once used disk space is not automatically reclaimed. Codchi will try to set the distribution to sparse mode which should automatically free unused space. If this doesn't work, you can do it automatically with
wsl.exe --manage codchistore --set-sparse true
Beware that WSL needs to be shut down for this which will close all running Linux programs.
If sparse mode somehow doesn't work correctly, you can manually shrink a WSL distribution like this:
wsl.exe --terminate codchistore
diskpart # this will need admin rights
select vdisk file="C:UsersYOUR_USERAppDataLocalcodchistoreext4.vhdx"
compact vdisk
exit
Examples
Delete generations older than one month of and :
codchi gc --delete-old 30 <MACHINE_1> <MACHINE_2>
Delete all but the current generation from each installed machine:
codchi gc --all --delete-old