Merge pull request #5077 from ldesgoui/nix-shell-args

nix-shell -p: pass `--arg`s as nixpkgs parameters
This commit is contained in:
Eelco Dolstra 2021-08-01 21:57:14 +02:00 committed by GitHub
commit 94ec9e4703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View file

@ -269,7 +269,7 @@ static void main_nix_build(int argc, char * * argv)
if (packages) { if (packages) {
std::ostringstream joined; 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) for (const auto & i : left)
joined << '(' << i << ") "; joined << '(' << i << ") ";
joined << "]; } \"\""; joined << "]; } \"\"";

View file

@ -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=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo bar --run 'echo "$(foo) $(bar)"')
[ "$output" = "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 # Test nix-shell shebang mode
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh
chmod a+rx $TEST_ROOT/shell.shebang.sh chmod a+rx $TEST_ROOT/shell.shebang.sh

View file

@ -1,4 +1,4 @@
{ inNixShell ? false, contentAddressed ? false }: { inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }:
let cfg = import ./config.nix; in let cfg = import ./config.nix; in
with cfg; with cfg;
@ -62,7 +62,7 @@ let pkgs = rec {
foo = runCommand "foo" {} '' foo = runCommand "foo" {} ''
mkdir -p $out/bin mkdir -p $out/bin
echo 'echo foo' > $out/bin/foo echo 'echo ${fooContents}' > $out/bin/foo
chmod a+rx $out/bin/foo chmod a+rx $out/bin/foo
ln -s ${shell} $out/bin/bash ln -s ${shell} $out/bin/bash
''; '';