From 2e45d3f423976db8de8602b8a7bf1b1be4dd9322 Mon Sep 17 00:00:00 2001 From: oddlama Date: Sat, 15 Apr 2023 16:55:50 +0200 Subject: [PATCH] feat(wireguard): support printing multiple configs at once --- nix/apps/show-wireguard-qr.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/nix/apps/show-wireguard-qr.nix b/nix/apps/show-wireguard-qr.nix index 5d906fc..4468164 100644 --- a/nix/apps/show-wireguard-qr.nix +++ b/nix/apps/show-wireguard-qr.nix @@ -30,15 +30,14 @@ in | ${pkgs.coreutils}/bin/cut -d$'\t' -f1) [[ -n "$json_sel" ]] || exit 1 - # TODO for each output line - # TODO maybe just call a json -> make script that gives wireguard config to make this easier + while IFS= read -r line; do + wgName=$(${pkgs.jq}/bin/jq -r .wgName <<< "$line") + serverNode=$(${pkgs.jq}/bin/jq -r .serverNode <<< "$line") + peer=$(${pkgs.jq}/bin/jq -r .peer <<< "$line") + echo "======== $wgName.$serverNode.$peer ========" - wgName=$(${pkgs.jq}/bin/jq -r .wgName <<< "$json_sel") - serverNode=$(${pkgs.jq}/bin/jq -r .serverNode <<< "$json_sel") - peer=$(${pkgs.jq}/bin/jq -r .peer <<< "$json_sel") - - createConfigScript=$(nix build --no-link --print-out-paths --impure --show-trace --expr \ - 'let flk = builtins.getFlake "${../../.}"; in (flk.extraLib.wireguard "'"$wgName"'").wgQuickConfigScript "${pkgs.system}" "'"$serverNode"'" "'"$peer"'"') - - "$createConfigScript" | tee /dev/tty | ${pkgs.qrencode}/bin/qrencode -t ansiutf8 + createConfigScript=$(nix build --no-link --print-out-paths --impure --show-trace --expr \ + 'let flk = builtins.getFlake "${../../.}"; in (flk.extraLib.wireguard "'"$wgName"'").wgQuickConfigScript "${pkgs.system}" "'"$serverNode"'" "'"$peer"'"') + "$createConfigScript" | tee /dev/tty | ${pkgs.qrencode}/bin/qrencode -t ansiutf8 + done <<< "$json_sel" ''