mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
nix: Parse --file relative to shebang script
This commit is contained in:
parent
198bc22e3b
commit
466271568b
@ -4,7 +4,7 @@
|
||||
contents of any `#! nix` lines and the script's location to a single call.
|
||||
|
||||
Verbatim strings may be passed in double backtick (```` `` ````) quotes.
|
||||
`--expr` resolves relative paths based on the shebang script location.
|
||||
`--file` and `--expr` resolve relative paths based on the script location.
|
||||
|
||||
Some examples:
|
||||
```
|
||||
|
@ -442,8 +442,9 @@ Installables SourceExprCommand::parseInstallables(
|
||||
auto e = state->parseStdin();
|
||||
state->eval(e, *vFile);
|
||||
}
|
||||
else if (file)
|
||||
state->evalFile(lookupFileArg(*state, *file), *vFile);
|
||||
else if (file) {
|
||||
state->evalFile(lookupFileArg(*state, *file, CanonPath::fromCwd(getCommandBaseDir())), *vFile);
|
||||
}
|
||||
else {
|
||||
CanonPath dir(CanonPath::fromCwd(getCommandBaseDir()));
|
||||
auto e = state->parseExprFromString(*expr, state->rootPath(dir));
|
||||
|
@ -123,6 +123,25 @@ echo "$@"
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-inline-expr.sh
|
||||
|
||||
cat > $nonFlakeDir/fooScript.nix <<"EOF"
|
||||
let flake = (builtins.getFlake (toString ../flake1)).packages;
|
||||
fooScript = flake.${builtins.currentSystem}.fooScript;
|
||||
in fooScript
|
||||
EOF
|
||||
|
||||
cat > $nonFlakeDir/shebang-file.sh <<EOF
|
||||
#! $(type -P env) nix
|
||||
EOF
|
||||
cat >> $nonFlakeDir/shebang-file.sh <<"EOF"
|
||||
#! nix --offline shell
|
||||
#! nix --impure --file ./fooScript.nix
|
||||
#! nix --no-write-lock-file --command bash
|
||||
set -ex
|
||||
foo
|
||||
echo "$@"
|
||||
EOF
|
||||
chmod +x $nonFlakeDir/shebang-file.sh
|
||||
|
||||
# Construct a custom registry, additionally test the --registry flag
|
||||
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
|
||||
nix registry add --registry "$registry" flake2 "git+file://$percentEncodedFlake2Dir"
|
||||
@ -571,4 +590,5 @@ expectStderr 1 nix flake metadata "$flake2Dir" --no-allow-dirty --reference-lock
|
||||
[[ $($nonFlakeDir/shebang.sh "bar") = "foo"$'\n'"bar" ]]
|
||||
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
||||
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
|
||||
[[ $($nonFlakeDir/shebang-file.sh baz) = "foo"$'\n'"baz" ]]
|
||||
expect 1 $nonFlakeDir/shebang-reject.sh 2>&1 | grepQuiet -F 'error: unsupported unquoted character in nix shebang: *. Use double backticks to escape?'
|
||||
|
Loading…
Reference in New Issue
Block a user