From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id ADpHOPQaGWdHeAAAe85BDQ:P1 (envelope-from ) for ; Wed, 23 Oct 2024 15:49:09 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id ADpHOPQaGWdHeAAAe85BDQ (envelope-from ) for ; Wed, 23 Oct 2024 17:49:09 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=uvPjgLmX; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=QFGdBZce; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1729698548; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=TVOpfyTX3eiW7fUSYS2zQjtVjVZtSWCcWX0G9xBrehQ=; b=QF87Zmc6FDP7l0o3zfdh6Y5cHQBH+zcacEn7pZ30zToo/XKELXtR6TBdcO5N5nyZFWkI/e DEk4quFvm/tLSJQCA/k14VNVtpKfPVxY7+2OW0GT0AiGyOhw4pqaRiKzrlCxaptGsrApBD PC0IcNvNIUIDGU1xJd7+bbh0ayOKmmrOKGLPhhDahM8Yu/3FJtGD9KW8WmgfbmkQP6sFJI 7jzU6KAKaawDbFdCWTkYYC+/JqlgL+4Eqtsp6f8atDG+5Q/Fi21PyyDK4VDI62ihvJhIK/ sflw1+dmb2qABd5O5+stytXWYlh3/V6d/pYXzElAuil9mjZyiNA0lpNKSQSMGg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=uvPjgLmX; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=QFGdBZce; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1729698548; a=rsa-sha256; cv=none; b=mXIjo6d35zu/OrmsGFpsxahq6teYE5SFt9h6cBmnQZjC4FqT+LAkOzNrblmFyNTVHaG5Xn G1JjleBU4yDES87Ipj7MaBKeT0+bIDNbjCt3o6KQ2pKm5bH8slmgyVOo87Vir7fmv05Of+ ajS4EKrRdX3Lp3B21HszPU0675aXT0njcdNc/UJtxh4ZAXE3lzy6DVYFGsuV9Ik21/Wd4M S7jGXnDEhlG8B2SvDgiC+fC8gqlx/WjwWmGBUy6kn0YI1uU1JOHrasFrjUsvodomSc6leh RLfnb8+qyDOG6uv5JzVwSbKltJ3tv99BsQ3L8GPH3ChvZ+xLyOV7Skr6ey/0/g== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6915B7DE48 for ; Wed, 23 Oct 2024 17:49:08 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3db9-0003Lu-SB; Wed, 23 Oct 2024 11:48:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3db8-0003LK-Ku for guix-patches@gnu.org; Wed, 23 Oct 2024 11:48:34 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3db8-0000d0-Bj; Wed, 23 Oct 2024 11:48:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=TVOpfyTX3eiW7fUSYS2zQjtVjVZtSWCcWX0G9xBrehQ=; b=uvPjgLmX9Zw3WiQpLGPRTMWD+EUTVlZP64iSw+KXSeZM+tZ0opxpWZExsGZ0Pc8eI37kemNz44EZWRkOPt7hB0sgStpI5KEtyu9vkl0h/w49034eke+E2RVVJGlOU6YxjCuw2VZbo9Y0wRKvuwXXKBdSPwsI2sp4dFND91ju8MFU5vVFBBnGjL3EpPEDRaUbmuesYi500ckd5lrECLZB+h7Ce1J/VDyo/yoBU3alHpNbVK5NrfhEGa6xko7NDoXFWl8eC0NwFDIkVitFKoQ9J9MGvTCfJK4hzqelE8OzB04VZjoY5lcnava8vCEafb+EHeBJuscPStG7BuOexpcrSQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t3dbb-0002Bq-NS; Wed, 23 Oct 2024 11:49:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73955] [PATCH v2 2/2] services: wireguard: Support lists of gexps for most fields. Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Wed, 23 Oct 2024 15:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73955 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73955@debbugs.gnu.org Cc: othacehe@gnu.org, Richard Sent , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 73955-submit@debbugs.gnu.org id=B73955.17296984998349 (code B ref 73955); Wed, 23 Oct 2024 15:49:03 +0000 Received: (at 73955) by debbugs.gnu.org; 23 Oct 2024 15:48:19 +0000 Received: from localhost ([127.0.0.1]:60461 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3das-0002Aa-Ru for submit@debbugs.gnu.org; Wed, 23 Oct 2024 11:48:19 -0400 Received: from mail-108-mta151.mxroute.com ([136.175.108.151]:43179) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3dar-0002AS-0T for 73955@debbugs.gnu.org; Wed, 23 Oct 2024 11:48:18 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta151.mxroute.com (ZoneMTA) with ESMTPSA id 192ba10085e0003e01.001 for <73955@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 23 Oct 2024 15:47:45 +0000 X-Zone-Loop: f4f2c2d9bda77eb1ccfd98b6096baba6bd3dd80a2a4b X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=TVOpfyTX3eiW7fUSYS2zQjtVjVZtSWCcWX0G9xBrehQ=; b=QFGdBZcegQryGhbXYFpiU0Mjbo LfLueNkRCBKUm4XhW8ipUsAkflvKgscIxmEhXYOdsWHoWCJlTCgt0qwQohRXp5V2PpOWf+6DkWvWK sHrbvNxzjzk0SNSTLenKRf9N3bIIso1AST8URyAbbwsxRWsjMZTEyVOClwJGTVeIbJnl0xkjmXvei VCA45INCN/BEhsXJPI4N4Dw6jrHxKu6U1enOrRuSfgRv4nJkWv3yxBdDGcziAiQ53ksKwziw7b1Z6 74ZBvspIoLwoCQBCUDIr63/NDadEMnHO3bRC8TLX3dT0czgXhs+A2zGpxI+YfFifjegb0TCM8deh4 cfMSfh6g==; From: Richard Sent Date: Wed, 23 Oct 2024 11:30:07 -0400 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 0.78 X-Spam-Score: 0.78 X-Migadu-Queue-Id: 6915B7DE48 X-TUID: SCHzAhTpNFUG 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. For example, the wg-quick(8) manual has an example on how to use password-store to retrieve a private key with a PreUp entry. This is now possible. * 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 | 31 +++++++++++++++++++++++++------ gnu/services/vpn.scm | 39 ++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5558bd7d44..0520b24c23 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -34430,13 +34430,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 @@ -34463,16 +34465,33 @@ 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. + +One example shown in the @code{wg-quick(8)} manual is retrieving a +private key using @code{password-store}. This can be achieved with the +following code: + +@lisp +(wireguard-configuration + ;; Retrieve the private key manually. + (private-key #f) + (pre-up (list #~(string-append "wg set %i private-key <(" + #$(file-append password-store "/bin/pass") + " WireGuard/private-keys/%i)")))) +@end lisp @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 diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index b62e0ac838..c1daba5dc1 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm @@ -12,6 +12,7 @@ ;;; Copyright © 2022 Cameron V Chaparro ;;; Copyright © 2022 Timo Wilken ;;; Copyright © 2023 Maxim Cournoyer +;;; Copyright © 2024 Richard Sent ;;; ;;; This file is part of GNU Guix. ;;; @@ -797,33 +798,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) "") - #$@(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