1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-10 02:37:07 +00:00
nix-darwin/pkgs/nix-tools/darwin-option.sh
Emily 4d0ae6980d nix-tools: overwrite $PATH rather than prepending
I don’t see any reason for these scripts to depend on more
environmental state than necessary.
2025-01-20 05:29:44 +00:00

74 lines
1.4 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#! @shell@
set -e
set -o pipefail
export PATH=@path@
evalNix() {
nix-instantiate --eval --strict "${extraEvalFlags[@]}" -E "with import <darwin> {}; $*" 2>/dev/null
}
evalOpt() {
evalNix "options.$option.$*"
}
evalOptAttrs() {
evalNix "builtins.concatStringsSep \"\\n\" (builtins.attrNames $*)" | jq -r .
}
evalOptText() {
evalNix "options.$option.$*" | jq -r .
}
showSyntax() {
echo "$0: [-I path] <option>" >&2
evalOptAttrs "options"
exit 1
}
# Parse the command line.
origArgs=("$@")
extraEvalFlags=()
option=
while [ "$#" -gt 0 ]; do
i="$1"; shift 1
case "$i" in
--help)
showSyntax
;;
-I)
if [ -z "$1" ]; then
echo "$0: $i requires an argument"
exit 1
fi
j="$1"; shift 1
extraEvalFlags+=("$i" "$j")
;;
*)
option="$i"
;;
esac
done
if [ -z "$option" ]; then showSyntax; fi
if [ "$(evalOpt "_type")" = '"option"' ]; then
echo "Value:"
evalOpt "value" || echo "no value"
echo
echo "Default:"
evalOpt "default" || evalOptText "defaultText" || echo "no default"
echo
echo "Example:"
if [ "$(evalOpt "example._type")" = '"literalExpression"' ]; then
evalOptText "example.text" || echo "no example"
else
evalOpt "example" || echo "no example"
fi
echo
echo "Description:"
evalOptText "description.text" || echo "no description"
echo
else
evalOptAttrs "options.$option"
fi