From 2a9ff813e781c1160113a93ee4e33d44bfb7af32 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sat, 06 Jul 2024 02:00:15 +0000 Subject: [PATCH] refactor: move app-specific generators out of tree --- --- a/lib/fleetLib.nix +++ b/lib/fleetLib.nix @@ -65,14 +65,6 @@ ''; }; - mkGarage = {}: {mkSecretGenerator, ...}: mkSecretGenerator { - script = '' - mkdir $out - gh generate ed25519 -p $out/public -s $out/secret - gh decode -i $out/public | gh public -e hex -o $out/node_id - ''; - }; - mkX25519 = {encoding ? null}: {mkSecretGenerator, ...}: mkSecretGenerator { script = '' @@ -81,8 +73,6 @@ ${optionalString (encoding != null) "--encoding=${encoding}"} ''; }; - - mkWireguard = {}: mkX25519 {encoding = "base64";}; mkRsa = {size ? 4096}: { openssl, @@ -100,4 +90,31 @@ cat rsa_public.key | gh public -o $out/public ''; }; + + mkBytes = { + count ? 32, + encoding, + noNuls ? false, + }: {mkSecretGenerator, ...}: + mkSecretGenerator { + script = '' + mkdir $out + gh generate bytes --count=${toString count} --encoding=${encoding} -s $out/secret \ + ${optionalString noNuls "--no-nuls"} + ''; + }; + mkHexBytes = {count ? 32}: + mkBytes { + inherit count; + encoding = "hex"; + }; + mkBase64Bytes = {count ? 32}: + mkBytes { + inherit count; + encoding = "base64"; + }; + + # Wireguard + # mkWireguard = {}: mkX25519 {encoding = "base64";}; + # mkWireguardPsk = {}: mkBase64Bytes {count = 32;}; } -- gitstuff