mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
nix: Parse --file relative to shebang script
This commit is contained in:
parent
198bc22e3b
commit
466271568b
3 changed files with 24 additions and 3 deletions
|
@ -4,7 +4,7 @@
|
||||||
contents of any `#! nix` lines and the script's location to a single call.
|
contents of any `#! nix` lines and the script's location to a single call.
|
||||||
|
|
||||||
Verbatim strings may be passed in double backtick (```` `` ````) quotes.
|
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:
|
Some examples:
|
||||||
```
|
```
|
||||||
|
|
|
@ -442,8 +442,9 @@ Installables SourceExprCommand::parseInstallables(
|
||||||
auto e = state->parseStdin();
|
auto e = state->parseStdin();
|
||||||
state->eval(e, *vFile);
|
state->eval(e, *vFile);
|
||||||
}
|
}
|
||||||
else if (file)
|
else if (file) {
|
||||||
state->evalFile(lookupFileArg(*state, *file), *vFile);
|
state->evalFile(lookupFileArg(*state, *file, CanonPath::fromCwd(getCommandBaseDir())), *vFile);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
CanonPath dir(CanonPath::fromCwd(getCommandBaseDir()));
|
CanonPath dir(CanonPath::fromCwd(getCommandBaseDir()));
|
||||||
auto e = state->parseExprFromString(*expr, state->rootPath(dir));
|
auto e = state->parseExprFromString(*expr, state->rootPath(dir));
|
||||||
|
|
|
@ -123,6 +123,25 @@ echo "$@"
|
||||||
EOF
|
EOF
|
||||||
chmod +x $nonFlakeDir/shebang-inline-expr.sh
|
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
|
# Construct a custom registry, additionally test the --registry flag
|
||||||
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
|
nix registry add --registry "$registry" flake1 "git+file://$flake1Dir"
|
||||||
nix registry add --registry "$registry" flake2 "git+file://$percentEncodedFlake2Dir"
|
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.sh "bar") = "foo"$'\n'"bar" ]]
|
||||||
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
[[ $($nonFlakeDir/shebang-comments.sh ) = "foo" ]]
|
||||||
[[ $($nonFlakeDir/shebang-inline-expr.sh baz) = "foo"$'\n'"baz" ]]
|
[[ $($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?'
|
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 a new issue