Nixos-rebuild switch and fetchurl of local file

I have a custom theme for slim in a local file, which was working but when I went to upgrade it broke:

# nixos-rebuild switch

trying file:///etc/nixos/cfg/rsrc/nixos-slim-theme-dark.tar.gz
curl: (37) Couldn’t open file /etc/nixos/cfg/rsrc/nixos-slim-theme-dark.tar.gz
error: cannot download nixos-slim-theme-dark.tar.gz from any mirror

Yet running curl from the command line works:

# curl file:///etc/nixos/cfg/rsrc/nixos-slim-theme-dark.tar.gz > /tmp/foo

Here is the relevant part of my configuration.nix:

  displayManager.slim = {
    enable = true;
    theme = pkgs.fetchurl {
      url    = "file:///etc/nixos/cfg/rsrc/nixos-slim-theme-dark.tar.gz";
      sha256 = "1ac8xhvw5gv95mql7684iimqrbvxwblpiwis21v3lw3l34pyrf1n";

What should I be doing so that this works first time every time?

1 Like

I think it should be simply theme = /path/file.tar.gz

But anyway, if the build is performed by nix daemon, this file won’t be available to the deamon. To make it so it should be ${/path/file.tar.gz}.

The ${...} probably isn’t necessary. Just using the path literal syntax should cause it to be copied to the store, rather than refer to the original path.

It depends (whether it’s captured in some other context), ${...} will capture it right here for sure.

Yea, that’s why I only said “probably” :stuck_out_tongue: The only way that wouldn’t be the case is if someone used toString for some reason, which isn’t common.

Thank you all. I used the simplest approach of just specifying the path as a path literal as suggested by @ip1981. That worked.

for relative paths this worked for me

	current_folder = builtins.toString ./.;
	stellarCollisionByKuldarleement = builtins.fetchurl {
	    url = "file://${current_folder}/stellar_collision_by_kuldarleement_d6kvnyd-pre.jpg";
	    sha256 = "sha256:0zks0jcs1bjn5qf1bjfq7zcqskyc2vcicqc19csrxfm783wnxc94";