From fb7735e4cf3a1ee6337bf1f2ee15204bb11304b2 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Sat, 7 Nov 2020 15:00:22 +0100 Subject: [PATCH 1/3] nix develop: Preserve stdin with `-c` --- src/nix/develop.cc | 4 ++-- tests/nix-shell.sh | 1 + 2 files changed, 3 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..dfe8ed0c1 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -58,6 +58,7 @@ output=$($TEST_ROOT/shell.shebang.rb abc ruby) # Test 'nix develop'. nix develop -f shell.nix shellDrv -c bash -c '[[ -n $stdenv ]]' +echo foo | nix develop -f shell.nix shellDrv -c cat # preserve stdin with `-c` # Test 'nix print-dev-env'. source <(nix print-dev-env -f shell.nix shellDrv) From 579b953231599f111dcc9fac95491458c9f6ef08 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Mon, 9 Nov 2020 17:50:51 +0100 Subject: [PATCH 2/3] Make test case more precise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Théophane Hufschmitt --- tests/nix-shell.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index dfe8ed0c1..3b000a049 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -58,7 +58,8 @@ output=$($TEST_ROOT/shell.shebang.rb abc ruby) # Test 'nix develop'. nix develop -f shell.nix shellDrv -c bash -c '[[ -n $stdenv ]]' -echo foo | nix develop -f shell.nix shellDrv -c cat # preserve stdin with `-c` +# Preserve stdin with `-c` +echo foo | nix develop -f shell.nix shellDrv -c cat | grep -q foo # Test 'nix print-dev-env'. source <(nix print-dev-env -f shell.nix shellDrv) From 3f24a417dacd5a5964f781f4d704a5253401d380 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Mon, 9 Nov 2020 17:57:39 +0100 Subject: [PATCH 3/3] Add test case for incidentally fixed #4228 --- tests/nix-shell.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index 3b000a049..7b2be650a 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -58,9 +58,13 @@ output=$($TEST_ROOT/shell.shebang.rb abc ruby) # Test 'nix develop'. nix develop -f shell.nix shellDrv -c bash -c '[[ -n $stdenv ]]' -# Preserve stdin with `-c` + +# 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 ]]