Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be mindful about the default arguments passed to nixpkgs in nix-shell #5543

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/nix-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ output=$(NIX_PATH=nixpkgs="$shellDotNix" nix-shell --pure -p foo bar --run 'echo
output=$(NIX_PATH=nixpkgs="$shellDotNix" nix-shell --pure -p foo --argstr fooContents baz --run 'echo "$(foo)"')
[ "$output" = "baz" ]

# Test that we are compatible with an old nixpkgs that doesn't accept the
# inNixShell attribute
output=$(NIX_PATH=nixpkgs="$PWD/shell-no-in-nix-shell.nix" nix-shell --pure -p foo)
[ "$output" = "noInNixShell" ]

# Test that passing arguments that aren't part of the formals (of the outer
# shell expression) are still passed into the expression while *not* passing
# inNixShell
output=$(NIX_PATH=nixpkgs="$PWD/shell-no-in-nix-shell.nix" nix-shell --pure -p foo --argstr fooContents zes)
[ "$output" = "zes" ]


# Test nix-shell shebang mode
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh
chmod a+rx $TEST_ROOT/shell.shebang.sh
Expand Down
3 changes: 3 additions & 0 deletions tests/shell-no-in-nix-shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This tries to replicate old nixpkgs behavior where `inNixShell` wasn't a supported attribute
args@{ ... }:
({ fooContents ? "noInNixShell" }: import ./shell.sh { inherit fooContents; }) args
12 changes: 9 additions & 3 deletions tests/shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{ inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }:

let cfg = import ./config.nix; in
# This file should resemble the function signature of Nixpkgs as it is used to
# simulate nixpkgs within the nix-shell tests.
{ ... }@args:
let
cfg = import ./config.nix;
inNixShell = args.inNixShell or false;
contentAddressed = args.contentAddressed or false;
fooContents = args.fooContents or "foo";
in
with cfg;

let
Expand Down