From 7ee77dc6df625b974b8fc3a00b7144087b60a410 Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Thu, 20 Oct 2022 10:49:05 +0200 Subject: services: wireguard: Add more configuration fields. * gnu/services/vpn.scm ()[pre-up, post-up, pre-down, post-down, table]: New fields. (wireguard-configuration-file): Take them into account. * doc/guix.texi (Wireguard): Update it. --- gnu/services/vpn.scm | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'gnu/services/vpn.scm') diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 82ff05b351..6f2821eccf 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm @@ -72,6 +72,11 @@ (define-module (gnu services vpn) wireguard-configuration-dns wireguard-configuration-private-key wireguard-configuration-peers + wireguard-configuration-pre-up + wireguard-configuration-post-up + wireguard-configuration-pre-down + wireguard-configuration-post-down + wireguard-configuration-table wireguard-service-type)) @@ -724,7 +729,17 @@ (define-record-type* (peers wireguard-configuration-peers ;list of (default '())) (dns wireguard-configuration-dns ;list of strings - (default #f))) + (default #f)) + (pre-up wireguard-configuration-pre-up ;list of strings + (default '())) + (post-up wireguard-configuration-post-up ;list of strings + (default '())) + (pre-down wireguard-configuration-pre-down ;list of strings + (default '())) + (post-down wireguard-configuration-post-down ;list of strings + (default '())) + (table wireguard-configuration-table ;string + (default "auto"))) (define (wireguard-configuration-file config) (define (peer->config peer) @@ -748,7 +763,8 @@ (define (peer->config peer) "\n")))) (match-record config - (wireguard interface addresses port private-key peers dns) + (wireguard interface addresses port private-key peers dns + pre-up post-up pre-down post-down table) (let* ((config-file (string-append interface ".conf")) (peers (map peer->config peers)) (config @@ -762,13 +778,49 @@ (define (peer->config peer) (let ((format (@ (ice-9 format) format))) (format port "[Interface] Address = ~a +~a +~a PostUp = ~a set %i private-key ~a ~a ~a +~a +~a +~a ~{~a~^~%~}" #$(string-join addresses ",") + #$(if table + (format #f "Table = ~a" table) + "") + #$(if (null? pre-up) + "" + (string-join + (map (lambda (command) + (format #f "PreUp = ~a" command)) + pre-up) + "\n")) #$(file-append wireguard "/bin/wg") #$private-key + #$(if (null? post-up) + "" + (string-join + (map (lambda (command) + (format #f "PostUp = ~a" command)) + post-up) + "\n")) + #$(if (null? pre-down) + "" + (string-join + (map (lambda (command) + (format #f "PreDown = ~a" command)) + pre-down) + "\n")) + #$(if (null? post-down) + "" + (string-join + (map (lambda (command) + (format #f "PostDown = ~a" command)) + post-down) + "\n")) #$(if port (format #f "ListenPort = ~a" port) "") -- cgit v1.2.3