From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id mGG1ALJEGWc6MgAAqHPOHw:P1 (envelope-from ) for ; Wed, 23 Oct 2024 18:47:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id mGG1ALJEGWc6MgAAqHPOHw (envelope-from ) for ; Wed, 23 Oct 2024 20:47:14 +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=e4SoOPJ5; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=NaXhLyVq; 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=1729709233; 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=ZIBmraVSuK3PEhnfd9hRXUckq3lc0Mmaaw8BnQDXMKyAldiXIdMl9ahSzvo7IOR3729xQ3 sHNILCoz8BY5Z0p0XKjaqN5hYCK1pvxg6J7QUTf5BfpgpwIt6t263CzfXQoJcsa4xwuTri LWTC0S+2rFfevALimdrz2reqIDOuitOEs/jE66DlLJRBbMg/QSX0mkQsRiUonBQryQ28mE LzY5LR+hIJNj0tqTi7OyW/NuDwXe6PNr8yJ4IfD1MDCSPRTSXPzrlwEtvgPpttBLjb1Jks eqEpOr04wiBwQ6AHbk4mCNu5FlRYlPI6eeUqA7XYMx7GoOXO9GGzKDofLsOQpw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1729709233; a=rsa-sha256; cv=none; b=tkD/f+ckVw+ZFuPzVyol3tmuVifXdBi2f2XGmLn18gjReGIMxwAoa0yZ9bIkSk1wxhrQug a0nYil03/FzlHm7imucykcd2A3nBJlIVo4RpICWjgg3G1MFy3yfabVIm+CEoNqqZWzENc/ 7UMnu5Eo6dx0xZl6BcWg4REzIR+uy7phSqK3APnMUxvn0tCn6zvlVnkUWKOPq1xbpIMIf6 qV8naY3UHAvpFl+Jkvs0neRKi9FSSRMJe7mZf+nPnb0w0rpkgPd53fvm4WtfBgKitXOkk1 kVeACG65BzUbBsV/buc+XUXlvHLIhofMC3esXBAis+dIFEg5qruPpwfFIGRUHQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=e4SoOPJ5; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=NaXhLyVq; 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 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 95DFB5D8B2 for ; Wed, 23 Oct 2024 20:47:13 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3gNV-0005wT-Pj; Wed, 23 Oct 2024 14:46:41 -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 1t3gNO-0005ut-Br for guix-patches@gnu.org; Wed, 23 Oct 2024 14:46:37 -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 1t3gNO-0002Jc-2E; Wed, 23 Oct 2024 14:46: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=e4SoOPJ5yHIiLejhEUR+KZfZ1KNE0eOpQqb16jh/PxfLT3y/5YM1GuXKTafJ5m3oBkzWzQL4kltQF9rtxcs6trW4LILLzhQdEEC5JYb2Le3KGaayljeJTED2RPiLMPKLT0i6xZWkvtA3ZaZHtwlHXcHkwdaMhc/xFolydtamjYtRmkAWH2qiAJF+n4VI6nx77nt3gSbjFG+lVbrk3WyOwQGvG4tqbb99y/E2kAsli44OgVeQlJC7eGpRPHTjZcWYIxalR89sQX7b3uuYx4Y8tJ7odcYjVnODTMZkBQoS7NjojkALTGDBIlhfDUyFy1XqFrWEMqVsOhb0UdIZ9KZ61A==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t3gNr-00025i-Gw; Wed, 23 Oct 2024 14:47:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73955] [PATCH v3 2/3] 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 18:47: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: 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.17297091957966 (code B ref 73955); Wed, 23 Oct 2024 18:47:03 +0000 Received: (at 73955) by debbugs.gnu.org; 23 Oct 2024 18:46:35 +0000 Received: from localhost ([127.0.0.1]:60805 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3gNO-00024N-G6 for submit@debbugs.gnu.org; Wed, 23 Oct 2024 14:46:35 -0400 Received: from mail-108-mta17.mxroute.com ([136.175.108.17]:36603) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3gNK-00023z-3O for 73955@debbugs.gnu.org; Wed, 23 Oct 2024 14:46:30 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta17.mxroute.com (ZoneMTA) with ESMTPSA id 192bab3269f0003e01.001 for <73955@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 23 Oct 2024 18:45:56 +0000 X-Zone-Loop: 42328fd5e92501493cfb2e59c110369711c1401c0438 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=NaXhLyVqE+4PQ97jh9qZ7moTb9 b9lfJUTG6fwESSeAPurklGguMCL/YJ3TGzBKAeoiZlVpeAcL+kGw1L2tUy/fme5TBsVrUOvdMpR/j WJCk2OABk7t+dUkVaitCBNj2zEDVo++QQOdrnC7Xm3HyMf1YAggMyX2oYOIwoFFk6ydKebTYMYM+N B11qe7WEUP+uG2Kg1/85knmP2+6qeb3gqPtaBJq2tFT9bQApj8r4cBR/OAgKsDF4iYVmkpqII/uTl n++K7ILTyXr3wGnYZ3qmmVkw/TztgxyuW7NApTjqkRBH+B7BrHYCO5oD+3olfiuNknDzJPjemDjvJ zHMwhGGw==; From: Richard Sent Date: Wed, 23 Oct 2024 14:20:58 -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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -2.47 X-Spam-Score: -2.47 X-Migadu-Queue-Id: 95DFB5D8B2 X-Migadu-Scanner: mx13.migadu.com X-TUID: krI4TPAyYI+j 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