I often use the shell to write little "glue" scripts, or trampolines to integrate my tooling and environments. My current need is a way to setup haskell-mode (for Emacs) to use nix-shell to run cabal commands.
The least common denominator of these tool interfaces is that there is a way to set the path to the tool in question, say cabal in this case. Given the current interface to nix-shell, it doesn't appear that I can use the --run and --command options with complex commands, because it expects the entire command to come as a single argument, and this causes quoting problems in shells...
I would like --run or --command to behave so every argument from the flag to the end of the array is treated as the command to run (+ args respectively), so I can use "$@" in my scripts for proper quoting behavior.
This would be nice, indeed, but we shouldn't reuse the --run or --command options for this, as it probably would break existing scripts.
I don't know if that's the right approach.. Of course, we could wait for the whole CLI to change. But to add this, I don't think having another set of --run-but-do-something-else and --command-but-do-something-else is gonna work.
The CLI feels very fragmented already, I suppose.. If we were to add --run-rest and --command-rest as a temporary hack, and wait for improvement/replacement when we finally do an overhaul/redesign of the interface (soon, I hope!), I wouldn't complain.
Yeah I agree this would be useful. I've added a note to https://gist.github.com/edolstra/efcadfd240c2d8906348 about this, namely something like
nix shell -c make -C target -j10
I.e. all arguments after -c are the positional parameters of the command to run.
@edolstra: I think -- is more idiomatic for a flag that ends the option flags.
The problem is that -- does not disambiguate between arguments to nix shell proper (namely package names) and to -c. E.g. normally nix shell -- foo bar would denote starting a shell with packages foo and bar in scope.
@edolstra: Why should "nix shell" assume that (arbitrary) command line arguments be interpreted as packages? I always specify them as "-p foo -p bar".
But yeah, I kind of see the problem. But I think "nix shell -p foo -p bar -- command with args" is a nice UI.
Yeah, I'd rather the -- be reserved for the actual invoked program's argv as well
Most helpful comment
But yeah, I kind of see the problem. But I think "nix shell -p foo -p bar -- command with args" is a nice UI.