Binary caches are an indispensable ally when it comes to avoiding tedious rebuilds by distributing Nix binaries. However, caches can hoard obsolete store paths that aren’t necessary anymore, which occupy precious storage space. As the cache swells beyond its storage capacity, these old store paths eventually have to be evicted. Cachix takes care of this routinely by initiating a process known as garbage collection.
Previously, the decision of what to remove from the cache was not in the hands of the users. Store paths were cleared based on the LRU (Least Recently Used) principle. This could lead to inadvertent removal of significant files that were not accessed regularly.
We’re excited to announce more granular control over garbage collection today, with a new feature we’re calling Pins.
Say Hello to Pins
Pins allow you to tag a store path with a name, ensuring its safe residency in the cache, untouched by the sweeping cycle of garbage collection.
This becomes a priceless asset when it comes to protecting releases and other essential binaries that you wish to preserve permanently.
The Mechanics of Pins
Start by choosing a name for your pin, something like v1.0
. While the choice of name is completely up to you, we suggest opting for something that carries meaning, such as the tool’s name, its version, or git revision.
Next up, you’ll need to input a store path and the cache name. This is how you do it:
$ cachix pin mycache v1.0 /nix/store/xxx-name-1.0
Preserving History and Managing Retention
By default, Pins keep the full history of revisions under the same name.
But if you prefer, you can opt to retain only the last X revisions or the last X days. You can do this with the --keep-revisions
or --keep-days
option, like so:
$ cachix pin mycache v1.0 /nix/store/xxx-name-1.0 --keep-days 3
Artifacts: Exposing Files from Within a Store Path
Pins also enable you to expose important files from within a store path.
For instance, if you want to expose /nix/store/xxx-name/etc/nginx.conf
, you can create an artifact using the --artifact
flag:
$ cachix pin mycache v1.0 /nix/store/xxx-name-1.0 --artifact etc/nginx.conf
This new Pins feature promises to offer enhanced control over your files and a command to ensure that critical binaries are always at your fingertips.
A Practical Illustration
For instance, if you wish to pin the go-1.7
and go-1.8
store paths, you would execute the following commands:
$ cachix pin mycache go-1.7 /nix/store/nd3ssg3hiqj6ivvkv2n5q7ppdwh0wqcf-go-1.7
$ cachix pin mycache go-1.8 /nix/store/canq1nwdhxk4d2yj8pgywz7lqhkpyq2d-go-1.8
You can then peek at the freshly tagged pins at mycache.cachix.org:
To utilize the cachix pin
command, upgrade to Cachix 1.5.
Happy pinning!
Domen