File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 3333 # nix run nixpkgs#vim -- --help
3434 ```
3535
36+ * Run the default app from the current directory with arguments:
37+
38+ ``` console
39+ # nix run . -- arg1 arg2
40+ ```
41+
42+ Note: The first positional argument is always treated as the * installable* ,
43+ even after ` -- ` . To pass arguments to the default installable, specify it
44+ explicitly: ` nix run . -- arg1 arg2 ` or ` nix run -- . arg1 arg2 ` .
45+
3646# Description
3747
3848` nix run ` builds and runs [ * installable* ] ( ./nix.md#installables ) , which must evaluate to an
Original file line number Diff line number Diff line change @@ -55,5 +55,41 @@ echo "_=..." >> "$TEST_ROOT"/actual-env
5555sort " $TEST_ROOT " /actual-env | uniq > " $TEST_ROOT " /actual-env.sorted
5656diff " $TEST_ROOT " /expected-env.sorted " $TEST_ROOT " /actual-env.sorted
5757
58+ # Test for issue #13994: verify behavior of -- separator with installable
59+ # Create a flake with an app that prints its arguments
5860clearStore
61+ rm -rf " $TEST_HOME " /.cache " $TEST_HOME " /.config " $TEST_HOME " /.local
62+ cd " $TEST_HOME "
63+
64+ cat << 'EOF ' > print-args.sh
65+ #!/bin/sh
66+ printf "ARGS:"
67+ for arg in "$@"; do
68+ printf " %s" "$arg"
69+ done
70+ printf "\n"
71+ EOF
72+ chmod +x print-args.sh
73+
74+ cat << EOF > flake.nix
75+ {
76+ outputs = {self}: {
77+ apps.$system .default = {
78+ type = "app";
79+ program = "\$ {self}/print-args.sh";
80+ };
81+ };
82+ }
83+ EOF
84+
85+ # Test correct usage: installable before --
86+ output=$( nix run --no-write-lock-file . -- myarg1 myarg2 2>&1 )
87+ [[ " $output " == " ARGS: myarg1 myarg2" ]] || fail " Expected 'ARGS: myarg1 myarg2', got '$output '"
88+
89+ # Test that first positional argument is still treated as installable after -- (issue #13994)
90+ output=$( nix run --no-write-lock-file -- . myarg1 myarg2 2>&1 )
91+ [[ " $output " == " ARGS: myarg1 myarg2" ]] || fail " Expected 'ARGS: myarg1 myarg2', got '$output '"
92+
93+ # And verify that a non-installable first argument causes an error
94+ expectStderr 1 nix run --no-write-lock-file -- myarg1 myarg2 | grepQuiet " error.*myarg1"
5995
You can’t perform that action at this time.
0 commit comments