aboutsummaryrefslogtreecommitdiff
path: root/src/nix/shell.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-02-27 15:17:37 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-02-27 15:17:37 +0100
commit2672a28bb4ba38a8358c306b8af4897c804b690d (patch)
tree6d4e3f704df4effe04c01e799d17d501c4178769 /src/nix/shell.cc
parent7cd9859e411c2254cc20558709e459d467372e6e (diff)
nix dev-shell: Add --command option
Note: like 'nix run', and unlike 'nix-shell', this takes an argv vector rather than a shell command. So nix dev-shell -c 'echo $PATH' doesn't work. Instead you need to do nix dev-shell -c bash -c 'echo $PATH'
Diffstat (limited to 'src/nix/shell.cc')
-rw-r--r--src/nix/shell.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/nix/shell.cc b/src/nix/shell.cc
index 6b3d02b6b..bee0bddcc 100644
--- a/src/nix/shell.cc
+++ b/src/nix/shell.cc
@@ -232,6 +232,22 @@ struct Common : InstallableCommand, MixProfile
struct CmdDevShell : Common, MixEnvironment
{
+ std::vector<std::string> command;
+
+ CmdDevShell()
+ {
+ mkFlag()
+ .longName("command")
+ .shortName('c')
+ .description("command and arguments to be executed insted of an interactive shell")
+ .labels({"command", "args"})
+ .arity(ArityAny)
+ .handler([&](std::vector<std::string> ss) {
+ if (ss.empty()) throw UsageError("--command requires at least one argument");
+ command = ss;
+ });
+ }
+
std::string description() override
{
return "run a bash shell that provides the build environment of a derivation";
@@ -270,6 +286,13 @@ struct CmdDevShell : Common, MixEnvironment
ss << fmt("rm -f '%s'\n", rcFilePath);
+ if (!command.empty()) {
+ std::vector<std::string> args;
+ for (auto s : command)
+ args.push_back(shellEscape(s));
+ ss << fmt("exec %s\n", concatStringsSep(" ", args));
+ }
+
writeFull(rcFileFd.get(), ss.str());
stopProgressBar();