use nix-instantiate instead of nix eval

it has a more stable API
This commit is contained in:
Ryan Mulligan 2020-09-03 16:07:43 -07:00
parent ac8d259fb9
commit b381af08ec

View file

@ -23,7 +23,7 @@ function show_help () {
echo 'EDITOR environment variable of editor to use when editing FILE' echo 'EDITOR environment variable of editor to use when editing FILE'
echo ' ' echo ' '
echo 'RULES environment variable with path to Nix file specifying recipient public keys.' echo 'RULES environment variable with path to Nix file specifying recipient public keys.'
echo "Defaults to 'secrets.nix'" echo "Defaults to './secrets.nix'"
} }
test $# -eq 0 && (show_help && exit 1) test $# -eq 0 && (show_help && exit 1)
@ -68,7 +68,7 @@ while test $# -gt 0; do
esac esac
done done
RULES=''${RULES:-secrets.nix} RULES=''${RULES:-./secrets.nix}
function cleanup { function cleanup {
if [ ! -z ''${CLEARTEXT_DIR+x} ] if [ ! -z ''${CLEARTEXT_DIR+x} ]
@ -84,7 +84,8 @@ trap "cleanup" 0 2 3 15
function edit { function edit {
FILE=$1 FILE=$1
KEYS=$(nix eval -f "$RULES" --raw "\"$FILE\".public_keys" --apply "builtins.concatStringsSep \"\n\"") KEYS=$(nix-instantiate --eval -E "(let rules = import $RULES; in builtins.concatStringsSep \"\n\" rules.\"$FILE\".public_keys)" | sed 's/"//g' | sed 's/\\n/\n/g')
if [ -z "$KEYS" ] if [ -z "$KEYS" ]
then then
>&2 echo "There is no rule for $FILE in $RULES." >&2 echo "There is no rule for $FILE in $RULES."
@ -125,7 +126,8 @@ function edit {
function rekey { function rekey {
echo "rekeying..." echo "rekeying..."
FILES=$(nix eval -f "$RULES" --raw --apply "f: builtins.concatStringsSep \"\n\" (builtins.attrNames f)") FILES=$(nix-instantiate --eval -E "(let rules = import $RULES; in builtins.concatStringsSep \"\n\" (builtins.attrNames rules))" | sed 's/"//g' | sed 's/\\n/\n/g')
for FILE in $FILES for FILE in $FILES
do do
EDITOR=: edit $FILE EDITOR=: edit $FILE