aboutsummaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2022-10-20 10:49:05 +0200
committerMathieu Othacehe <othacehe@gnu.org>2022-10-20 13:07:46 +0200
commit7ee77dc6df625b974b8fc3a00b7144087b60a410 (patch)
treef9d95afd60c4b6683e0cd66add83958c65ca4741 /gnu
parent2a5c2a6184d65a1314fdf15bcfa5ddda5756ec18 (diff)
downloadguix-7ee77dc6df625b974b8fc3a00b7144087b60a410.tar.gz
guix-7ee77dc6df625b974b8fc3a00b7144087b60a410.zip
services: wireguard: Add more configuration fields.
* gnu/services/vpn.scm (<wireguard-configuration>)[pre-up, post-up, pre-down, post-down, table]: New fields. (wireguard-configuration-file): Take them into account. * doc/guix.texi (Wireguard): Update it.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/services/vpn.scm56
1 files changed, 54 insertions, 2 deletions
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 @@
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 @@ strongSwan.")))
(peers wireguard-configuration-peers ;list of <wiregard-peer>
(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 @@ AllowedIPs = ~a
"\n"))))
(match-record config <wireguard-configuration>
- (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 @@ AllowedIPs = ~a
(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)
"")