1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-06 16:57:08 +00:00
nix-darwin/pkgs/nix-tools/darwin-option.sh
Emily b5b7888793 nix-tools: set $NIX_PATH
This will be important once most users are running `sudo
darwin-rebuild` and therefore not getting their environment’s
`$NIX_PATH` passed through.
2025-01-20 05:29:44 +00:00

76 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@
export NIX_PATH=${NIX_PATH:-@nixPath@}
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