Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active November 13, 2018 00:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obfusk/44bdca9caf5ef89e7ef0f4c985363d85 to your computer and use it in GitHub Desktop.
Save obfusk/44bdca9caf5ef89e7ef0f4c985363d85 to your computer and use it in GitHub Desktop.
nix quoting weirdness
so the problem was: the unquoted string was being pathname expanded and nullglob was set by $stdenv/setup
$ cat default.nix
{ pkgs ? import <nixpkgs> {} }: with pkgs;
let
x = builtins.toXML [ { foo = 1; bar = " baz "; } ];
y = runCommand "foo" { inherit x; } ''echo $x > $out'';
z = runCommand "foo" { inherit x; } ''echo "$x" > $out'';
in { inherit y z; }
$ nix-build
/nix/store/zflgjbm8jhrfrqjz2bxi14d5i8r36f9w-foo
/nix/store/6077l132s2mfcihk3f7g86v70yyliqlq-foo
# where did the `<?xml` go?
$ head /nix/store/zflgjbm8jhrfrqjz2bxi14d5i8r36f9w-foo /nix/store/6077l132s2mfcihk3f7g86v70yyliqlq-foo
==> /nix/store/zflgjbm8jhrfrqjz2bxi14d5i8r36f9w-foo <==
version='1.0' <expr> <list> [...]
==> /nix/store/6077l132s2mfcihk3f7g86v70yyliqlq-foo <==
<?xml version='1.0' encoding='utf-8'?>
[...]
# trying to reproduce by hand (and failing)
$ nix-shell -A y
nix-shell$ echo $x
<?xml version='1.0' encoding='utf-8'?> <expr> <list> [...]
nix-shell$ echo $shell
/nix/store/.../bin/bash
$ NIX_BUILD_SHELL=/nix/store/.../bin/bash nix-shell -A y --command "out=$PWD/_out; genericBuild"
$ cat _out
<?xml version='1.0' encoding='utf-8'?> <expr> <list> [...]
$ head default.nix *.sh
==> default.nix <==
{ pkgs ? import <nixpkgs> {} }: with pkgs;
let
snippet = "<? <! <foo> !> ?>";
in {
t1 = stdenv.mkDerivation { inherit snippet; name = "foo"; builder = ./x.sh; };
t2 = stdenv.mkDerivation { inherit snippet; name = "foo"; builder = ./y.sh; };
}
==> x.sh <==
source $stdenv/setup
# snippet='<? <! <foo> !> ?> <?bar baz?>qux'
echo $snippet >&2
echo $snippet > $out
==> y.sh <==
# source $stdenv/setup
# snippet='<? <! <foo> !> ?> <?bar baz?>qux'
echo $snippet >&2
echo $snippet > $out
$ nix-build -j1
these derivations will be built:
/nix/store/hq5v6n70ddv3avj5lskwz08j4gfa7zfw-foo.drv
/nix/store/zc7rgy8jv39ap9vynnphrh0r7fm2nnkw-foo.drv
building '/nix/store/hq5v6n70ddv3avj5lskwz08j4gfa7zfw-foo.drv'...
<! <foo> !>
building '/nix/store/zc7rgy8jv39ap9vynnphrh0r7fm2nnkw-foo.drv'...
<? <! <foo> !> ?>
/nix/store/2998f6pbdm28j20ppvhx3cp8qmxni3xf-foo
/nix/store/44g4lnzqm31kaxwg1z5g0a3x7xxpgdqz-foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment