Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e012384fe99b
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3913afdd69a5
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Oct 27, 2019

  1. Add inNixShell = true to nix-shell auto-call

    This is an alternative to the IN_NIX_SHELL environment variable,
    allowing the expression to adapt itself to nix-shell without
    triggering those adaptations when used as a dependency of another
    shell.
    
    Closes #3147
    roberth committed Oct 27, 2019
    Copy the full SHA
    9d612c3 View commit details
  2. Copy the full SHA
    0e459d7 View commit details
  3. Simplification

    edolstra committed Oct 27, 2019
    Copy the full SHA
    3913afd View commit details
Showing with 19 additions and 8 deletions.
  1. +13 −3 src/nix-build/nix-build.cc
  2. +4 −4 tests/nix-shell.sh
  3. +2 −1 tests/shell.nix
16 changes: 13 additions & 3 deletions src/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
@@ -245,7 +245,17 @@ static void _main(int argc, char * * argv)
auto state = std::make_unique<EvalState>(myArgs.searchPath, store);
state->repair = repair;

Bindings & autoArgs = *myArgs.getAutoArgs(*state);
auto autoArgs = myArgs.getAutoArgs(*state);

if (runEnv) {
auto newArgs = state->allocBindings(autoArgs->size() + 1);
auto tru = state->allocValue();
mkBool(*tru, true);
newArgs->push_back(Attr(state->symbols.create("inNixShell"), tru));
for (auto & i : *autoArgs) newArgs->push_back(i);
newArgs->sort();
autoArgs = newArgs;
}

if (packages) {
std::ostringstream joined;
@@ -299,9 +309,9 @@ static void _main(int argc, char * * argv)
state->eval(e, vRoot);

for (auto & i : attrPaths) {
Value & v(*findAlongAttrPath(*state, i, autoArgs, vRoot));
Value & v(*findAlongAttrPath(*state, i, *autoArgs, vRoot));
state->forceValue(v);
getDerivations(*state, v, "", autoArgs, drvs, false);
getDerivations(*state, v, "", *autoArgs, drvs, false);
}
}

8 changes: 4 additions & 4 deletions tests/nix-shell.sh
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ export IMPURE_VAR=foo
export SELECTED_IMPURE_VAR=baz
export NIX_BUILD_SHELL=$SHELL
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
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
[[ $(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 \
'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

3 changes: 2 additions & 1 deletion tests/shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ }:
{ inNixShell ? false }:

with import ./config.nix;

@@ -22,6 +22,7 @@ let pkgs = rec {
name = "shellDrv";
builder = "/does/not/exist";
VAR_FROM_NIX = "bar";
TEST_inNixShell = if inNixShell then "true" else "false";
inherit stdenv;
};