@@ -31763,6 +31763,11 @@ VPN Services
@item @code{public-key}
The peer public-key represented as a base64 string.
+@item @code{preshared-key} (default: @code{#f})
+An optional pre-shared key file for this peer. Giving a non-existent
+file name here will result in an invalid WireGuard configuration; the
+given file will not be autogenerated.
+
@item @code{allowed-ips}
A list of IP addresses from which incoming traffic for this peer is
allowed and to which incoming traffic for this peer is directed.
@@ -61,6 +61,7 @@ (define-module (gnu services vpn)
wireguard-peer-endpoint
wireguard-peer-allowed-ips
wireguard-peer-public-key
+ wireguard-peer-preshared-key
wireguard-peer-keep-alive
wireguard-configuration
@@ -709,6 +710,8 @@ (define-record-type* <wireguard-peer>
(endpoint wireguard-peer-endpoint
(default #f)) ;string
(public-key wireguard-peer-public-key) ;string
+ (preshared-key wireguard-peer-preshared-key
+ (default #f)) ;string
(allowed-ips wireguard-peer-allowed-ips) ;list of strings
(keep-alive wireguard-peer-keep-alive
(default #f))) ;integer
@@ -762,10 +765,18 @@ (define (wireguard-configuration-file config)
(format #f "PersistentKeepalive = ~a\n" keep-alive)
"\n"))))
+ (define (peers->preshared-keys peer keys)
+ (let ((public-key (wireguard-peer-public-key peer))
+ (preshared-key (wireguard-peer-preshared-key peer)))
+ (if preshared-key
+ (cons* public-key preshared-key keys)
+ keys)))
+
(match-record config <wireguard-configuration>
(wireguard interface addresses port private-key peers dns
pre-up post-up pre-down post-down table)
(let* ((config-file (string-append interface ".conf"))
+ (peer-keys (fold peers->preshared-keys (list) peers))
(peers (map peer->config peers))
(config
(computed-file
@@ -780,7 +791,7 @@ (define (wireguard-configuration-file config)
Address = ~a
~a
~a
-PostUp = ~a set %i private-key ~a
+PostUp = ~a set %i private-key ~a~{ peer ~a preshared-key ~a~}
~a
~a
~a
@@ -800,6 +811,7 @@ (define (wireguard-configuration-file config)
"\n"))
#$(file-append wireguard "/bin/wg")
#$private-key
+ '#$peer-keys
#$(if (null? post-up)
""
(string-join