volth
February 5, 2019, 12:06am
1
I have seen this snippet on the Internet
nix-shell -p git <<'HEREDOC'
git status
HEREDOC
This does not work for me.
Was it for an older version of Nix or merely a wish, implementing of this feature seems useful
Especially with nix-instantiate
and nix-build
, for writing quick bash scripts which require more flexibility than nix-shell
provides
nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/18.09.tar.gz <<'EOF'
let
inherit (import <nixpkgs> {}) lib buildGoPackage fetchgit;
in
buildGoPackage rec {
blablabla
}
EOF
aszlig
February 5, 2019, 12:41am
2
Have you tried the following?
nix-shell -p git --run "$SHELL" <<HEREDOC
git status
HEREDOC
Or equivalently: echo git status | nix-shell -p git --run "$SHELL"
1 Like
volth
February 5, 2019, 12:45am
3
No, I did not try to fix that @peel ’s example, it was just a source of inspiration for feeding nix-build
with sources.
1 Like
aszlig
February 5, 2019, 1:01am
4
Mhm, yeah, feeding the Nix expression via stdin
to nix-build would be quite helpful in some occasions, especially when writing wrappers (although one could still use a shell variable).
volth
February 5, 2019, 10:21pm
5
nix-build /dev/stdin <<'EOF'
let
inherit (import <nixpkgs> {}) lib buildGoPackage;
in buildGoPackage rec {
blablabla
}
EOF
fails with
error: getting status of '/tmp/sh-thd.d0byhc (deleted)': No such file or directory
dtzWill
February 5, 2019, 11:36pm
6
Might be a better way, but at least w/zsh
you can use =(
to do this sort of thing:
$ nix-build =(<<EOF 17:22:31 on 19-02-05
cmdsubst heredoc> let
cmdsubst heredoc> foo = import <nixpkgs> {};
cmdsubst heredoc> bar = foo.bash;
cmdsubst heredoc> in
cmdsubst heredoc> bar
cmdsubst heredoc> EOF
cmdsubst> )
The same with <(<<EOF
gives an error like yours.
I was looking into this for another program
and found this in the zsh man pages…
There might be a simpler way xD.
And by “might” I mean “surely, please”
~Will
volth
February 7, 2019, 7:07pm
7
aszlig
February 9, 2019, 2:21am
8
Didn’t look at the source code previously, but it turns out that at least for nix-build
, this already works (see also my comment ) by using nix-build -
.