From Bas van Dijk:
To understand these things I would recommend using nix-repl:
$ nix-repl Welcome to Nix version 1.11.2. Type :? for help. nix-repl> name = "bar" nix-repl> ./foo + "${name}" /home/bas.van.dijk/foobarNote that the previous is equivalent to the simpler:
nix-repl> ./foo + name /home/bas.van.dijk/foobarThe reason that you get "foobar" is that we didn't include a "/". So lets try to do that:
nix-repl> ./foo/ + name error: syntax error, unexpected '+', at (string):1:8Apparently the Nix path parser doesn't like a slash at the end of a path literal. So lets try adding the slash dynamically:
nix-repl> ./foo + "/" + name /home/bas.van.dijk/foobarWhat happened here? Well, + is left associative so it is interpreted as:
(./foo + "/") + nameLets try evaluating that left expression alone:
nix-repl> ./foo + "/" /home/bas.van.dijk/fooApparently Nix performs normalization on paths since the final slash is not included. So lets put the parenthesis differently:
nix-repl> ./foo + ("/" + name) /home/bas.van.dijk/foo/barThat's better! Now we can shorten this using some antiquotation:
nix-repl> ./foo + "/${name}" /home/bas.van.dijk/foo/bar