Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain more concretely the failure scenarios #20

Open
nh2 opened this issue Dec 24, 2020 · 2 comments
Open

Explain more concretely the failure scenarios #20

nh2 opened this issue Dec 24, 2020 · 2 comments

Comments

@nh2
Copy link

nh2 commented Dec 24, 2020

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!

@xzfc
Copy link
Owner

xzfc commented Dec 25, 2020

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"

@nh2
Copy link
Author

nh2 commented Dec 25, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants