xzfc / cached-nix-shell

Instant startup time for nix-shell
https://xzfc.github.io/cached-nix-shell/cached-nix-shell.1
The Unlicense
203 stars 16 forks source link

Prevent nix-collect-garbage from invalidating cache #34

Open unode opened 6 months ago

unode commented 6 months ago

Hi everyone,

First thank you for this project. It completely removes the slowdown seen with nix-shell scripts so I'm relying on it a lot these days. One issue I'm experiencing however is that the cache gets invalidated by nix-collect-garbage.

To avoid this I'm using nix-instantiate inside the script to pin (some of) the packages used.

A typical script looks like:

#!/usr/bin/env cached-nix-shell
#!nix-shell -i bash -p bash packageA packageB

nix-instantiate '<nixpkgs>' -A bash -A packageA -A packageB --indirect --add-root "$HOME/nix/pins/packageAB.drv"
(...)

However, this has the downside that for some packages nix-instantiate also takes some time to execute which removes some of the benefit of using cached-nix-shell.

Is there any way to pin the same packages that were used by the shell without this nix-instantiate hack?

Thanks