Skip to content

Commit

Permalink
nix-shell -p: pass --arg values as nixpkgs params
Browse files Browse the repository at this point in the history
  • Loading branch information
ldesgoui committed Jul 31, 2021
1 parent 2b67cb7 commit 6eeb6f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static void main_nix_build(int argc, char * * argv)

if (packages) {
std::ostringstream joined;
joined << "with import <nixpkgs> { }; (pkgs.runCommandCC or pkgs.runCommand) \"shell\" { buildInputs = [ ";
joined << "{...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) \"shell\" { buildInputs = [ ";
for (const auto & i : left)
joined << '(' << i << ") ";
joined << "]; } \"\"";
Expand Down
4 changes: 4 additions & 0 deletions tests/nix-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ nix-instantiate shell.nix -A shellDrv --add-root $TEST_ROOT/shell
output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo bar --run 'echo "$(foo) $(bar)"')
[ "$output" = "foo bar" ]

# Test nix-shell -p --arg x y
output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo --argstr fooContents baz --run 'echo "$(foo)"')
[ "$output" = "baz" ]

# 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
4 changes: 2 additions & 2 deletions tests/shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ inNixShell ? false, contentAddressed ? false }:
{ inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }:

let cfg = import ./config.nix; in
with cfg;
Expand Down Expand Up @@ -62,7 +62,7 @@ let pkgs = rec {

foo = runCommand "foo" {} ''
mkdir -p $out/bin
echo 'echo foo' > $out/bin/foo
echo 'echo ${fooContents}' > $out/bin/foo
chmod a+rx $out/bin/foo
ln -s ${shell} $out/bin/bash
'';
Expand Down

0 comments on commit 6eeb6f9

Please sign in to comment.