diff options
author | ldesgoui <ldesgoui@gmail.com> | 2021-07-31 16:55:53 +0200 |
---|---|---|
committer | ldesgoui <ldesgoui@gmail.com> | 2021-07-31 17:25:10 +0200 |
commit | 6eeb6f9c8494f5d5ef5e4dd228c9121bcbe2c29f (patch) | |
tree | 86362266680e6cda3884165cb9a907e575bd8d63 | |
parent | 2b67cb7b8c8ac7953f7e341d760bdb3c021fe765 (diff) |
nix-shell -p: pass --arg values as nixpkgs params
-rwxr-xr-x | src/nix-build/nix-build.cc | 2 | ||||
-rw-r--r-- | tests/nix-shell.sh | 4 | ||||
-rw-r--r-- | tests/shell.nix | 4 |
3 files changed, 7 insertions, 3 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index 848b108dd..9e3538394 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -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 << "]; } \"\""; diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index f60102f9c..a31d35887 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -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 diff --git a/tests/shell.nix b/tests/shell.nix index 64817ed5c..4912d295a 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -1,4 +1,4 @@ -{ inNixShell ? false, contentAddressed ? false }: +{ inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }: let cfg = import ./config.nix; in with cfg; @@ -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 ''; |