Specifying a drv file path that is a symlink causes nix-shell to fail with a syntax error on macOS.
This works and starts the shell successfully:
$ nix-shell /nix/store/zng8s969fmbcyany3b3nxx9nn5g4vxa7-nix-shell.drv
[nix-shell:~]$
This fails:
$ ln -s /nix/store/zng8s969fmbcyany3b3nxx9nn5g4vxa7-nix-shell.drv shell.drv
$ nix-shell shell.drv
error: syntax error, unexpected ',', expecting ')', at /nix/store/zng8s969fmbcyany3b3nxx9nn5g4vxa7-nix-shell.drv:1:15
I'm using Nix 2.0 on macOS 10.13.3.
The contents of /nix/store/zng8s969fmbcyany3b3nxx9nn5g4vxa7-nix-shell.drv are:
Derive([("out","/nix/store/qbb27qj7sf4xpali6z8b3s385p24n17m-nix-shell","","")],[("/nix/store/9swhg6583n478dmn4ax45wd9lv31xks3-git-crypt-scripts.drv",["out"]),("/nix/store/adbmcrygzwlpsw05x5gid2ky0d01lydd-stdenv-darwin.drv",["out"]),("/nix/store/mjg92sy9bs1zdsbf3zj55kc06ghpfs7y-bash-4.4-p12.drv",["out"]),("/nix/store/sypfk3kb48zfnkiqisb4q04ydql5v7sr-git-crypt-0.5.0.drv",["out"])],["/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"],"x86_64-darwin","/nix/store/19cc89zq5n68ibr53izy4zgcr5qg2rza-bash-4.4-p12/bin/bash",["-e","/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"],[("__impureHostDeps","/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation /bin/sh /usr/lib/libSystem.B.dylib /usr/lib/system/libunc.dylib /dev/zero /dev/random /dev/urandom /bin/sh"),("__propagatedImpureHostDeps",""),("__propagatedSandboxProfile",""),("__sandboxProfile",""),("buildInputs","/nix/store/ifmfjdnb2pc20i4hb7523k78wiln64w0-git-crypt-0.5.0 /nix/store/ajmxkq1py0gb1gnp5pqmva64gcy6r9ra-git-crypt-scripts"),("builder","/nix/store/19cc89zq5n68ibr53izy4zgcr5qg2rza-bash-4.4-p12/bin/bash"),("configureFlags",""),("depsBuildBuild",""),("depsBuildBuildPropagated",""),("depsBuildTarget",""),("depsBuildTargetPropagated",""),("depsHostBuild",""),("depsHostBuildPropagated",""),("depsTargetTarget",""),("depsTargetTargetPropagated",""),("name","nix-shell"),("nativeBuildInputs",""),("nobuildPhase","echo\necho \"This derivation is not meant to be built, aborting\";\necho\nexit 1\n"),("out","/nix/store/qbb27qj7sf4xpali6z8b3s385p24n17m-nix-shell"),("phases","nobuildPhase"),("propagatedBuildInputs",""),("propagatedNativeBuildInputs",""),("stdenv","/nix/store/vp6la88iirygv8gcfmqmsamdmgh5nf9p-stdenv-darwin"),("system","x86_64-darwin")])
Same on NixOS master.
Have you tried nix-shell $PWD/shell.drv, I think it requires a full path.
Tried with the full path, still fails when using the symlink.
I think this is the intended behavior (although that wasn't the case in Nix 1.11 and could have been documented): nix-shell interprets is argument as a derivation only when it is a store path (which imho is a good thing since it makes the heuristic less fragile)
For purposes of nix-shell, would it be problematic to just readlink the argument?
If this is desired behavior we can still do much better in terms of the error reported-- "derivations must be store paths" or whatever instead of blaming the poor comma :D.
I encountered this bug using direnv as documented here; I've updated that page to use readlink. Cheers @dtzWill :).
Having the same issue after updating to Nix 2.0
I think that was mostly fixed by
https://github.com/NixOS/nix/commit/12913ccf454c1bc82a51c59872f8185b40c533c5
and we can close this issue. (It shouldn鈥檛 happen from 2.1 onwards.)
Still have the same issue on Catalina. Also the readlink workaround does not work.
We now hit the very same issue on NixOS (!) with nix 2.3.1: https://github.com/target/lorri/issues/357
This here is the showcase of nix鈥檚 misbehavior: https://github.com/target/lorri/issues/357#issuecomment-603729686
Most helpful comment
For purposes of nix-shell, would it be problematic to just
readlinkthe argument?If this is desired behavior we can still do much better in terms of the error reported-- "derivations must be store paths" or whatever instead of blaming the poor comma :D.