Find a fetchurl file in /nix/store?

How do I find a file in the nix store which I have fetchurled in the past?

Here is my situation. I have a specialfile which I downloaded from, but has gone offline. Now I want to save a copy of specialfile. I know specialfile is in my /nix/store because derivations which depend on specialfile still succeed. I aquired specialfile like this:

  { url = "";
    sha256 = "sha256-EVA7G7f+eP0q3u0oGcD9RpbPIUn83ClrMddCIbyTVK4=";

I think nix hash to-nar sha256-EVA7G7f+eP0q3u0oGcD9RpbPIUn83ClrMddCIbyTVK4= would do the trick but that command doesn’t exist?

toString on the resulting derivation will give you the path. Assuming specialfile is already in your store you should be able to do something like this:

▶ nix repl
Welcome to Nix 2.7.0. Type :? for help.

nix-repl> builtins.fetchurl {
    url = "";
    sha256 = "sha256-EVA7G7f+eP0q3u0oGcD9RpbPIUn83ClrMddCIbyTVK4=";


In a cinch, and with a fast enough drive, find /nix/store/ -name '*specialfile*' can also do the trick.

1 Like

Thanks for the answers but I still can’t find the specialfile. I can see from /nix/store/npxpdhbi6azk4vcmjdqv9mnp8nx2ikz9-specialfile.drv that the "out" path for specialfile should be /nix/store/jlbm1nwc29ibpkxvxm4m2igqj73xh6kn-specialfile, but there is no such file.

I didn’t mention that I never did the fetchurl on this machine; actually someone else did the fetchurl and stored it in a central private cache and I’ve always gotten it from the cache. Does that make a difference? I think it shouldn’t?

What was going on here is that the specialfile was in the cache. I had never actually downloaded specialfile from the cache, I had only downloaded cached derivations which depended on specialfile.

Here’s how to query the cache, from @cdepillabout :

nix path-info --json --store | jq