Fetchurl failing on file:///

I use the file downloaded from http://someonewhocares.org/hosts/ipv6/hosts for quite some time to improve my browsing experience. The following derivation is how I have been incorporating that file into my configuration.nix. (Note: I originally tried downloading directly from the web site but the file changes frequently without any versioning and rebuilding my configuration always needed fixing because the hash was always different. That is why it is pulled from my repo rather than from the web site.)

  networking.extraHosts =
          blockedHosts = pkgs.fetchurl {
            url    = "file:///etc/nixos/hosts";
            sha256 = "f566ebf583650dcfa1e3370c81654ab18cde3b741e83f183aa8d7938a93f4d03";
        in ''
          ${builtins.readFile blockedHosts}

It was working for quite a while but has recently broken. Here is a fragment of the output from running nixos-rebuild switch:

trying file:///etc/nixos/hosts
curl: (37) Couldn't open file /etc/nixos/hosts
error: cannot download hosts from any mirror

I verified that the hash is correct for the file and that the file is accessible from that location. I can even use curl on the command line to fetch the file. But it fails under nixos-rebuild switch. Any suggestions how to proceed?

Note: I am not adverse to switching to a different approach or derivation which accomplishes the same thing.

I received a reply out of band which solves my problem. I repeat it here in case someone else has the same problem:

networking.extraHosts = builtins.readFile /etc/nixos/hosts;

1 Like