From b5fa96a90e07cc099cc5247540449263caeedb16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20H=C3=A4ring?= Date: Sun, 8 Oct 2023 14:13:59 +0200 Subject: [PATCH] feat: remove empty newlines from jq query When you do not have your pubkeys in your `secrets.nix` verbatim as string but read them from file like this: `desktop1 = builtins.readFile ./desktop1.pub;`, you will end up with empty newlines in the resulting list of keys, which will add `--recipient=''` arguments to your age call, failing the call. --- pkgs/agenix.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/agenix.sh b/pkgs/agenix.sh index f638b10..14b3a25 100644 --- a/pkgs/agenix.sh +++ b/pkgs/agenix.sh @@ -115,7 +115,7 @@ function cleanup { trap "cleanup" 0 2 3 15 function keys { - (@nixInstantiate@ --json --eval --strict -E "(let rules = import $RULES; in rules.\"$FILE\".publicKeys)" | @jqBin@ -r .[]) || exit 1 + (@nixInstantiate@ --json --eval --strict -E "(let rules = import $RULES; in rules.\"$FILE\".publicKeys)" | @jqBin@ -r 'map(rtrimstr("\n")) .[]') || exit 1 } function decrypt { @@ -185,7 +185,7 @@ function edit { } function rekey { - FILES=$( (@nixInstantiate@ --json --eval -E "(let rules = import $RULES; in builtins.attrNames rules)" | @jqBin@ -r .[]) || exit 1) + FILES=$( (@nixInstantiate@ --json --eval -E "(let rules = import $RULES; in builtins.attrNames rules)" | @jqBin@ -r 'map(rtrimstr("\n")) .[]') || exit 1) for FILE in $FILES do