cached-nix-shell
cached-nix-shell copied to clipboard
Explain more concretely the failure scenarios
From the README:
builtins.fetchurl
or other network builtins are used (e.g. in nixpkgs-mozilla)
Can we have a concrete example in the README that explains what kind of change it wouldn't catch?
Thanks!
In nix, builtins.fetchurl
caches files for tarball-ttl
seconds, default is 3600. C-n-s checks only local files, but do not check if tarball-ttl
is expired.
This issue is only related to live URLs, e.g. nixpkgs-mozilla fetches channel-rust-nightly.toml which is updated daily.
Note that c-n-s stores a single cache entry per nix-shell
invocation, and stale cache for cached-nix-shell ./foo.nix
won't affect cache for cached-nix-shell ./bar.nix
.
# 1.nix
let pkgs = import <nixpkgs> { };
in pkgs.mkShell {
date = builtins.elemAt (builtins.split "\n" (builtins.readFile
(builtins.fetchurl
"https://static.rust-lang.org/dist/channel-rust-nightly.toml"))) 2;
}
nix-shell
:
$ nix-shell ./1.nix --run 'echo $date'
date = "2020-12-25"
$ sleep 86400
$ nix-shell ./1.nix --run 'echo $date'
date = "2020-12-26"
cached-nix-shell
:
$ cached-nix-shell ./1.nix --run 'echo $date'
date = "2020-12-25"
$ sleep 86400
$ cached-nix-shell ./1.nix --run 'echo $date' # will be cached forever, unless file contents changes
date = "2020-12-25"
$ echo "# something" >> ./1.nix # file update invalidate the cache
$ cached-nix-shell ./1.nix --run 'echo $date'
date = "2020-12-26"
@xzfc That's great, thanks a lot. Could you add it to the README (or maybe link to a separate .md
file if it's too long)?
This is much less constraining than I thought, so I think it'd be very good for everyone to know that.