Cross-posting from Unix & Linux Stack Exchange.
Saving it to file, and using that temporary file works fine,
$ curl $url > default.nix
$ nix-shell default.nix
but how can one do this without using a temporary file? Here’s what I tried so far:
$ curl $url | nix-shell -
This downloads the file and the … just nothing happens.
$ curl $url | nix-shell
This will throw an error that there is no
default.nix (of course).
<() operator (archive):
$ nix-shell <(curl $url)
# ... output...
error: getting status of '/dev/fd/pipe:': No such file or directory
But when I change
cat, it works, just as if I had saved the
curl output into a regular file, and printed its contents.
(Maybe hitting the same issue with this approach that is explained in Why doesn’t the process substitution <() work with ssh -F?)
(I know there is
nix-shell -E, but it would probably be problematic even if my specific example Nix expression didn’t contain comments…)
Maybe not the nicest way to do this, but behind an alias/function it’s probably okay-ish.
This works for me:
f=$(mktemp); cp shell.nix "$f"; nix-shell "$f"; rm "$f"
Obviously replace the
cp-invocation with your
Maybe also worth filing an issue over, as
cat ... | nix-shell - seems like it should work, but maybe it’s some subshell-stuff that makes it fail…
I.e., this also fails (given
true | nix-shell shell.nix
Thanks, I thought about taking the
alias route, but notion is that this should work out of the box when I’m switching computers. (Interestingly, the solution in the the linked Stackexchange thread is using zsh’s special process substitution operator
=(...) which is the same as your suggestion, but built into the shell itself.)
This problem seems to be the same as the one in the linked Stackexchange thread regarding
ssh -F, but I don’t know enough about the topic if that this is by design or by accident, and this is not that crucial anyway. Although, it is indeed baffling that
true | nix-shell shell.nix fails, thanks for finding this!
@jtojnar provided the answer on Stackexchange:
nix-shell -E "import (builtins.fetchurl $url)"
Also drew my attention to the
NixOS/nix issue of https://github.com/NixOS/nix/issues/2734 which describes the same problems I ran into when trying to use pipes or
<(...) so I updated it as well.