Merge branch 'issue-3147-inNixShell-arg' of https://github.com/hercules-ci/nix

This commit is contained in:
Eelco Dolstra 2019-10-27 17:10:19 +01:00
commit 0e459d79a6
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 21 additions and 6 deletions

View file

@ -245,7 +245,21 @@ static void _main(int argc, char * * argv)
auto state = std::make_unique<EvalState>(myArgs.searchPath, store); auto state = std::make_unique<EvalState>(myArgs.searchPath, store);
state->repair = repair; state->repair = repair;
Bindings & autoArgs = *myArgs.getAutoArgs(*state); Bindings & autoArgs = *[&](){
Bindings *userAutoArgs = myArgs.getAutoArgs(*state);
if (runEnv) {
Bindings * res = state->allocBindings(userAutoArgs->size() + 1);
Value * tru = state->allocValue();
mkBool(*tru, true);
res->push_back(Attr(state->symbols.create("inNixShell"), tru));
for (auto & i : *userAutoArgs) {
res->push_back(i);
}
res->sort();
return res;
}
else return userAutoArgs;
}();
if (packages) { if (packages) {
std::ostringstream joined; std::ostringstream joined;

View file

@ -7,9 +7,9 @@ export IMPURE_VAR=foo
export SELECTED_IMPURE_VAR=baz export SELECTED_IMPURE_VAR=baz
export NIX_BUILD_SHELL=$SHELL export NIX_BUILD_SHELL=$SHELL
output=$(nix-shell --pure shell.nix -A shellDrv --run \ output=$(nix-shell --pure shell.nix -A shellDrv --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"') 'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $TEST_inNixShell"')
[ "$output" = " - foo - bar" ] [ "$output" = " - foo - bar - true" ]
# Test --keep # Test --keep
output=$(nix-shell --pure --keep SELECTED_IMPURE_VAR shell.nix -A shellDrv --run \ output=$(nix-shell --pure --keep SELECTED_IMPURE_VAR shell.nix -A shellDrv --run \
@ -19,10 +19,10 @@ output=$(nix-shell --pure --keep SELECTED_IMPURE_VAR shell.nix -A shellDrv --run
# Test nix-shell on a .drv # Test nix-shell on a .drv
[[ $(nix-shell --pure $(nix-instantiate shell.nix -A shellDrv) --run \ [[ $(nix-shell --pure $(nix-instantiate shell.nix -A shellDrv) --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"') = " - foo - bar" ]] 'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $TEST_inNixShell"') = " - foo - bar - false" ]]
[[ $(nix-shell --pure $(nix-instantiate shell.nix -A shellDrv) --run \ [[ $(nix-shell --pure $(nix-instantiate shell.nix -A shellDrv) --run \
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"') = " - foo - bar" ]] 'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX - $TEST_inNixShell"') = " - foo - bar - false" ]]
# Test nix-shell on a .drv symlink # Test nix-shell on a .drv symlink

View file

@ -1,4 +1,4 @@
{ }: { inNixShell ? false }:
with import ./config.nix; with import ./config.nix;
@ -22,6 +22,7 @@ let pkgs = rec {
name = "shellDrv"; name = "shellDrv";
builder = "/does/not/exist"; builder = "/does/not/exist";
VAR_FROM_NIX = "bar"; VAR_FROM_NIX = "bar";
TEST_inNixShell = if inNixShell then "true" else "false";
inherit stdenv; inherit stdenv;
}; };