From 76063a641bd712c9a5947e876b714b9ed2b63636 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 7 Dec 2023 22:37:28 +0300 Subject: [PATCH] add missed script to generate configs for wg client --- misc/wg-client-conf.nix | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 misc/wg-client-conf.nix diff --git a/misc/wg-client-conf.nix b/misc/wg-client-conf.nix new file mode 100644 index 0000000..c7d5e5c --- /dev/null +++ b/misc/wg-client-conf.nix @@ -0,0 +1,42 @@ +# use nix-build -E (import /misc/wg-client-conf.nix {}) +{ pkgs ? import { } +, address +, privateKey +, dns ? "8.8.8.8" +, serverPublicKey +, serverEndpoint +}: + +let + toINI = pkgs.lib.generators.toINI { }; + + configs = toINI { + Interface = { + # "10.10.10.10/32" + Address = address; + # See /notes/vpn.md to generate private key and public key + PrivateKey = privateKey; + DNS = dns; + }; + Peer = { + # See /notes/vpn.md to generate private key and public key + PublicKey = serverPublicKey; + AllowedIPs = "0.0.0.0/0"; + # : + Endpoint = serverEndpoint; + PersistentKeepalive = 25; + }; + }; + + configFile = pkgs.writeText "wg-client.conf" configs; + + showQrcode = pkgs.writeScript "qrcode" '' + ${pkgs.qrencode}/bin/qrencode -t ansiutf8 < ${configFile} + ''; +in +pkgs.runCommand "wg-client" { } '' + mkdir $out; + + cp ${configFile} $out/wg-client.conf; + cp ${showQrcode} $out/qrcode; +''