PortValhalla/scripts/Common/Scripts/eval-flake.fish

40 lines
1,017 B
Fish
Raw Normal View History

2024-09-08 15:09:01 +00:00
#!/bin/env fish
function evalFlake --argument-names config property
set -l argv $argv[3..]
2024-10-06 19:25:34 +00:00
set -l flakePath "$(realpath (status dirname))/../../.."
2024-10-13 20:07:15 +00:00
argparse --ignore-unknown "apply=" "fallback=" json -- $argv
2024-09-08 15:09:01 +00:00
if [ -z "$_flag_json" ]
set -a argv --raw
else
set -a argv --json
end
if [ -z "$_flag_apply" ]
set _flag_apply "_: _"
end
2024-09-28 14:13:56 +00:00
if [ -n "$VALHALLA_FLAKE_ROOT" ]
set flakePath "$VALHALLA_FLAKE_ROOT"
end
2024-09-08 15:09:01 +00:00
if [ -n "$config" ]
set config ".$config"
set _flag_apply "_: ($_flag_apply) ((import $(realpath --relative-to (pwd) "$(status dirname)/../../../lib/eval-attribute.nix")) _)"
2024-09-08 15:09:01 +00:00
end
PROPERTY="$property" \
2024-10-06 19:25:34 +00:00
nix eval --impure --extra-experimental-features "nix-command flakes" \
2024-09-08 15:09:01 +00:00
--apply "$_flag_apply" \
2024-09-28 14:13:56 +00:00
"$flakePath#valhalla$config" \
2024-09-08 15:09:01 +00:00
$argv
2024-10-13 20:07:15 +00:00
or begin
if [ -n "$_flag_fallback" ]
echo "$_flag_fallback"
else
false
end
end
2024-09-08 15:09:01 +00:00
end