How to cache (reuse from cache) commonly used nix packages for offline working

Sometimes I need to work without internet connectivity.

How can I cache or download commonly used packages on my system so that the command that work last time with internet connection, will also work in the absence of internet connection.

like a command
nix-shell -p jupyterlab --run jupyter-lab
works and download all the packages.
but same command fails if the internet is not available.

They are cached, but I don’t think it is persistent between reboots.
There are wrappers like comma that also allow disabling network features and look in the nix store.
But the simplest way is probably to just install the package through your config (i am sure you already thought of that beforehand, but I just wanted to throw that in here)

A very convenient way is to use Flakes and direnv. With the flake you pin your inputs, so e.g. you always use the same jupyterlab, even when you update your system. direnv can cache the environment generated by the devshell of the flake.

1 Like

nix-direnv and lorri can cache the evaluation after first use. I don’t know about nix-direnv, but lorri does not support flakes, however.

1 Like

It shouldn’t, assuming your channels didn’t change and you didn’t run a garbage collection in between.