nix-prefetch icon indicating copy to clipboard operation
nix-prefetch copied to clipboard

The fetchurl prefetcher fails with the default `TMPDIR` variable on macOS

Open midchildan opened this issue 4 years ago • 0 comments

I've found some peculiar behavior on macOS in which the fetchurl prefetcher works when invoked through nix run and nix-shell, but fails when invoked directly.

Namely, the following works:

❯ nix run 'nixpkgs#nix-prefetch' -- fetchurl --url https://pypi.io/packages/source/f/feeluown/feeluown-3.7.11.tar.gz
warning: unknown setting 'experimental-features'
warning: unknown setting 'experimental-features'
The fetcher will be called as follows:
> fetchurl {
>   sha256 = "sha256:0000000000000000000000000000000000000000000000000000";
>   url = "https://pypi.io/packages/source/f/feeluown/feeluown-3.7.11.tar.gz";
> }

sha256-cXN6W6LV0QnTgQTEFYvXYPgL3YggUdB7gh2TvjXnkHg=

But this doesn't:

❯ nix path-info 'nixpkgs#nix-prefetch'
/nix/store/8anr2v3g5xz5m93746732zckqbq2yz5w-nix-prefetch-0.4.1
❯ /nix/store/8anr2v3g5xz5m93746732zckqbq2yz5w-nix-prefetch-0.4.1/bin/nix-prefetch fetchurl --url https://pypi.io/packages/source/f/feeluown/feeluown-3.7.11.tar.gz
warning: unknown setting 'experimental-features'
warning: unknown setting 'experimental-features'
error: Could not determine the fetcher used by the source.

After further investigation, I've pinpointed the problem to the value of the TMPDIR environment variable. For some reason, nix-prefetch doesn't seem to like the default value of TMPDIR provided by the macOS system. Setting TMPDIR (or XDG_RUNTIME_DIR) to /tmp seems to fix the problem:

❯  TMPDIR=/tmp /nix/store/8anr2v3g5xz5m93746732zckqbq2yz5w-nix-prefetch-0.4.1/bin/nix-prefetch fetchurl --url https://pypi.io/packages/source/f/feeluown/feeluown-3.7.11.tar.gz
warning: unknown setting 'experimental-features'
warning: unknown setting 'experimental-features'
The fetcher will be called as follows:
> fetchurl {
>   sha256 = "sha256:0000000000000000000000000000000000000000000000000000";
>   url = "https://pypi.io/packages/source/f/feeluown/feeluown-3.7.11.tar.gz";
> }

sha256-cXN6W6LV0QnTgQTEFYvXYPgL3YggUdB7gh2TvjXnkHg=

Running nix-prefetch through nix run or nix-shell worked because Nix sets TMPDIR to /tmp, thus avoiding the problem.

I'm not sure how best to deal with this problem, but maybe nix-prefetch should ignore TMPDIR on macOS?

midchildan avatar Oct 11 '21 14:10 midchildan