GNU bug report logs - #73955
[PATCH 0/2] Improve customizability of WireGuard service

Previous Next

Package: guix-patches;

Reported by: Richard Sent <richard <at> freakingpenguin.com>

Date: Tue, 22 Oct 2024 21:25:02 UTC

Severity: normal

Tags: patch

Done: Mathieu Othacehe <othacehe <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Richard Sent <richard <at> freakingpenguin.com>
To: 73955 <at> debbugs.gnu.org
Cc: othacehe <at> gnu.org, Richard Sent <richard <at> freakingpenguin.com>, Ludovic Courtès <ludo <at> gnu.org>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Subject: [bug#73955] [PATCH v4 3/3] services: wireguard: Support lists of gexps for most fields.
Date: Wed,  4 Dec 2024 15:59:35 -0500
In order to support more flexibility in Wireguard configuration, ungexp the
configuration fields directly instead of ungexp-splicing a sexp
calculator. This allows for the fields to take arbitrary gexps instead of only
strings which is particularly helpful for the Pre/Post Up/Down commands.

* gnu/services/vpn.scm (wireguard-configuration-file): Ungexp configuration
lists instead of ungexp-splicing the code surrounding them.
* doc/guix.texi (VPN Services)[wireguard]: Document it.

Change-Id: If074cbb78473b6fd34e0e4e990d2ed268001d6c7
---
 doc/guix.texi        | 22 ++++++++++++++--------
 gnu/services/vpn.scm | 41 +++++++++++++++++++++--------------------
 2 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ece73a27ae..43aa1ad71a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -34603,13 +34603,15 @@ VPN Services
 The interface name for the VPN.
 
 @item @code{addresses} (default: @code{'("10.0.0.1/32")})
-The IP addresses to be assigned to the above interface.
+List of strings or G-expressions which represent the IP addresses to be
+assigned to the above interface.
 
 @item @code{port} (default: @code{51820})
 The port on which to listen for incoming connections.
 
 @item @code{dns} (default: @code{'())})
-The DNS server(s) to announce to VPN clients via DHCP.
+List of strings or G-expressions which represent the DNS server(s) to
+announce to VPN clients via DHCP.
 
 @item @code{monitor-ips?} (default: @code{#f})
 @cindex Dynamic IP, with Wireguard
@@ -34654,16 +34656,20 @@ VPN Services
 @var{wireguard-peer} records.
 
 @item @code{pre-up} (default: @code{'()})
-The script commands to be run before setting up the interface.
+List of strings or G-expressions.  These are script snippets which will
+be executed before setting up the interface.
 
 @item @code{post-up} (default: @code{'()})
-The script commands to be run after setting up the interface.
+List of strings or G-expressions.  These are script snippets which will
+be executed after setting up the interface.
 
 @item @code{pre-down} (default: @code{'()})
-The script commands to be run before tearing down the interface.
+List of strings or G-expressions.  These are script snippets which will
+be executed before tearing down the interface.
 
 @item @code{post-down} (default: @code{'()})
-The script commands to be run after tearing down the interface.
+List of strings or G-expressions.  These are script snippets which will
+be executed after tearing down the interface.
 
 @item @code{table} (default: @code{"auto"})
 The routing table to which routes are added, as a string.  There are two
@@ -34689,8 +34695,8 @@ VPN Services
 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.  The given file will not
-be autogenerated.
+An optional pre-shared key file for this peer that can be either a
+string or a G-expression.  The given file will not be autogenerated.
 
 @item @code{allowed-ips}
 A list of IP addresses from which incoming traffic for this peer is
diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm
index f9693fb099..8e90032c93 100644
--- a/gnu/services/vpn.scm
+++ b/gnu/services/vpn.scm
@@ -12,6 +12,7 @@
 ;;; Copyright © 2022 Cameron V Chaparro <cameron <at> cameronchaparro.com>
 ;;; Copyright © 2022 Timo Wilken <guix <at> twilken.net>
 ;;; Copyright © 2023 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
+;;; Copyright © 2024 Richard Sent <richard <at> freakingpenguin.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -800,33 +801,33 @@ (define (wireguard-configuration-file config)
                  (define lines
                    (list
                     "[Interface]"
-                    #$@(if (null? addresses)
-                           '()
-                           (list (format #f "Address = ~{~a~^, ~}"
-                                         addresses)))
+                    (if (null? '#$addresses)
+                        ""
+                        (format #f "Address = ~{~a~^, ~}"
+                                (list #$@addresses)))
                     (format #f "~@[Table = ~a~]" #$table)
-                    #$@(if (null? pre-up)
-                           '()
-                           (list (format #f "~{PreUp = ~a~%~}" pre-up)))
+                    (if (null? '#$pre-up)
+                        ""
+                        (format #f "~{PreUp = ~a~%~}" (list #$@pre-up)))
                     (if #$private-key
                         (format #f "PostUp = ~a set %i private-key ~a\
 ~{ peer ~a preshared-key ~a~}"
                                 #$(file-append wireguard "/bin/wg")
-                                #$private-key '#$peer-keys)
+                                #$private-key (list #$@peer-keys))
                         "")
-                    #$@(if (null? post-up)
-                           '()
-                           (list (format #f "~{PostUp = ~a~%~}" post-up)))
-                    #$@(if (null? pre-down)
-                           '()
-                           (list (format #f "~{PreDown = ~a~%~}" pre-down)))
-                    #$@(if (null? post-down)
-                           '()
-                           (list (format #f "~{PostDown = ~a~%~}" post-down)))
+                    (if (null? '#$post-up)
+                        ""
+                        (format #f "~{PostUp = ~a~%~}" (list #$@post-up)))
+                    (if (null? '#$pre-down)
+                        ""
+                        (format #f "~{PreDown = ~a~%~}" (list #$@pre-down)))
+                    (if (null? '#$post-down)
+                        ""
+                        (format #f "~{PostDown = ~a~%~}" (list #$@post-down)))
                     (format #f "~@[ListenPort = ~a~]" #$port)
-                    #$@(if (null? dns)
-                           '()
-                           (list (format #f "DNS = ~{~a~^, ~}" dns)))))
+                    (if (null? '#$dns)
+                        ""
+                        (format #f "DNS = ~{~a~^, ~}" (list #$@dns)))))
 
                  (mkdir #$output)
                  (chdir #$output)
-- 
2.46.0





This bug report was last modified 169 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.