aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-11-10 10:51:48 +0100
committerGitHub <noreply@github.com>2020-11-10 10:51:48 +0100
commit3f680c1dccb71594e16e331b4763a022f3894b30 (patch)
tree449f9a184574b85f47919508ef09d4facf80ed46
parent0ed7c957bed18d963df65d55f0c0ffc79dee656d (diff)
parent3f24a417dacd5a5964f781f4d704a5253401d380 (diff)
Merge pull request #4233 from Kha/master
nix develop: Preserve stdin with `-c`
-rw-r--r--src/nix/develop.cc4
-rw-r--r--tests/nix-shell.sh6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index 8fea7ee9c..457d94382 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -474,9 +474,9 @@ struct CmdDevelop : Common, MixEnvironment
ignoreException();
}
- // If running a phase, don't want an interactive shell running after
+ // If running a phase or single command, don't want an interactive shell running after
// Ctrl-C, so don't pass --rcfile
- auto args = phase ? Strings{std::string(baseNameOf(shell)), rcFilePath}
+ auto args = phase || !command.empty() ? Strings{std::string(baseNameOf(shell)), rcFilePath}
: Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath};
restoreAffinity();
diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh
index 1228bb04f..7b2be650a 100644
--- a/tests/nix-shell.sh
+++ b/tests/nix-shell.sh
@@ -59,6 +59,12 @@ output=$($TEST_ROOT/shell.shebang.rb abc ruby)
# Test 'nix develop'.
nix develop -f shell.nix shellDrv -c bash -c '[[ -n $stdenv ]]'
+# Ensure `nix develop -c` preserves stdin
+echo foo | nix develop -f shell.nix shellDrv -c cat | grep -q foo
+
+# Ensure `nix develop -c` actually executes the command if stdout isn't a terminal
+nix develop -f shell.nix shellDrv -c echo foo |& grep -q foo
+
# Test 'nix print-dev-env'.
source <(nix print-dev-env -f shell.nix shellDrv)
[[ -n $stdenv ]]