Subject: [PATCH] services: wireguard: Add the auto-start? field.
From: Carlo Zancanaro <[email-masked]>
To: [email-masked]
Date: Fri, 28 Feb 2025 21:31:10 +1100
List-Id: <debbugs-submit.debbugs.gnu.org>

* gnu/services/vpn.scm (<wireguard-configuration>): Add auto-start?.
(wireguard-shepherd-service): Pass auto-start? to Shepherd service.
* doc/guix.texi (VPN Services)[wireguard]: Document it.

Change-Id: I7880a8c8e9860250f875e845e94eb118a4b852fa
---

Does what it says on the tin.

This makes it possible to define a wireguard service without
automatically starting the service. This is convenient for connections
on desktops/laptops if they are not always used.

 doc/guix.texi        | 8 +++++++-
 gnu/services/vpn.scm | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 93380dc30d..c7ca21ef52 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -43,7 +43,7 @@
 Copyright @copyright{} 2017, 2018, 2019 Clément Lassieur@*
 Copyright @copyright{} 2017, 2018, 2020, 2021, 2022 Mathieu Othacehe@*
 Copyright @copyright{} 2017 Federico Beffa@*
-Copyright @copyright{} 2017, 2018, 2024 Carlo Zancanaro@*
+Copyright @copyright{} 2017, 2018, 2024, 2025 Carlo Zancanaro@*
 Copyright @copyright{} 2017 Thomas Danckaert@*
 Copyright @copyright{} 2017 humanitiesNerd@*
 Copyright @copyright{} 2017, 2021 Christine Lemmer-Webber@*
@@ -35570,6 +35570,12 @@ VPN Services
 altogether, and @code{"auto"} (the default) that adds routes to the
 default table and enables special handling of default routes.
 
+@item @code{auto-start?} (default: @code{#t"})
+Whether the Wireguard network should be started automatically by the
+Shepherd.  If it is @code{#f} the service has to be started manually
+with @code{herd start wireguard-$interface} (for example: @code{herd
+start wireguard-wg0}).
+
 @end table
 @end deftp
 
diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm
index c66622ad6c..478a0d543e 100644
--- a/gnu/services/vpn.scm
+++ b/gnu/services/vpn.scm
@@ -13,6 +13,7 @@
 ;;; Copyright © 2022 Timo Wilken <[email-masked]>
 ;;; Copyright © 2023 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2024 Richard Sent <[email-masked]>
+;;; Copyright © 2025 Carlo Zancanaro <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -88,6 +89,7 @@ (define-module (gnu services vpn)
             wireguard-configuration-pre-down
             wireguard-configuration-post-down
             wireguard-configuration-table
+            wireguard-configuration-auto-start?
 
             wireguard-service-type))
 
@@ -764,7 +766,9 @@ (define-record-type* <wireguard-configuration>
   (post-down              wireguard-configuration-post-down ;list of strings
                           (default '()))
   (table                  wireguard-configuration-table ;string
-                          (default "auto")))
+                          (default "auto"))
+  (auto-start?            wireguard-configuration-auto-start? ;boolean
+                          (default #t)))
 
 (define (wireguard-configuration-file config)
   (define (peer->config peer)
@@ -916,6 +920,7 @@ (define (wireguard-shepherd-service config)
   (match-record config <wireguard-configuration>
     (wireguard interface)
     (let ((wg-quick (file-append wireguard "/bin/wg-quick"))
+          (auto-start? (wireguard-configuration-auto-start? config))
           (config (wireguard-configuration-file config)))
       (list (shepherd-service
              (requirement '(networking))
@@ -926,6 +931,7 @@ (define (wireguard-shepherd-service config)
                        (invoke #$wg-quick "down" #$config)
                        #f))                       ;stopped!
              (actions (list (shepherd-configuration-action config)))
+             (auto-start? auto-start?)
              (documentation "Run the Wireguard VPN tunnel"))))))
 
 (define (wireguard-monitoring-jobs config)

base-commit: a76708a872e65230931f3c5c3b079d0a39d5cb84
-- 
2.48.1