diff options
| -rw-r--r-- | doc/guix.texi | 4 | ||||
| -rw-r--r-- | gnu/services/vpn.scm | 36 |
2 files changed, 23 insertions, 17 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index f43cb539904..fa9a147bd0e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -34626,7 +34626,9 @@ an mcron time specification (@pxref{Guile Syntax,,,mcron}). | |||
| 34626 | 34626 | ||
| 34627 | @item @code{private-key} (default: @code{"/etc/wireguard/private.key"}) | 34627 | @item @code{private-key} (default: @code{"/etc/wireguard/private.key"}) |
| 34628 | The private key file for the interface. It is automatically generated | 34628 | The private key file for the interface. It is automatically generated |
| 34629 | if the file does not exist. | 34629 | if the file does not exist. If this field is @code{#f}, a private key |
| 34630 | is not automatically created and the path is not serialized to the | ||
| 34631 | configuration file. | ||
| 34630 | 34632 | ||
| 34631 | @item @code{peers} (default: @code{'()}) | 34633 | @item @code{peers} (default: @code{'()}) |
| 34632 | The authorized peers on this interface. This is a list of | 34634 | The authorized peers on this interface. This is a list of |
diff --git a/gnu/services/vpn.scm b/gnu/services/vpn.scm index 7fb4775757f..b62e0ac838e 100644 --- a/gnu/services/vpn.scm +++ b/gnu/services/vpn.scm | |||
| @@ -741,7 +741,7 @@ strongSwan."))) | |||
| 741 | (default '("10.0.0.1/32"))) | 741 | (default '("10.0.0.1/32"))) |
| 742 | (port wireguard-configuration-port ;integer | 742 | (port wireguard-configuration-port ;integer |
| 743 | (default 51820)) | 743 | (default 51820)) |
| 744 | (private-key wireguard-configuration-private-key ;string | 744 | (private-key wireguard-configuration-private-key ;maybe-string |
| 745 | (default "/etc/wireguard/private.key")) | 745 | (default "/etc/wireguard/private.key")) |
| 746 | (peers wireguard-configuration-peers ;list of <wiregard-peer> | 746 | (peers wireguard-configuration-peers ;list of <wiregard-peer> |
| 747 | (default '())) | 747 | (default '())) |
| @@ -805,9 +805,12 @@ strongSwan."))) | |||
| 805 | #$@(if (null? pre-up) | 805 | #$@(if (null? pre-up) |
| 806 | '() | 806 | '() |
| 807 | (list (format #f "~{PreUp = ~a~%~}" pre-up))) | 807 | (list (format #f "~{PreUp = ~a~%~}" pre-up))) |
| 808 | (format #f "PostUp = ~a set %i private-key ~a\ | 808 | (if #$private-key |
| 809 | ~{ peer ~a preshared-key ~a~}" #$(file-append wireguard "/bin/wg") | 809 | (format #f "PostUp = ~a set %i private-key ~a\ |
| 810 | #$private-key '#$peer-keys) | 810 | ~{ peer ~a preshared-key ~a~}" |
| 811 | #$(file-append wireguard "/bin/wg") | ||
| 812 | #$private-key '#$peer-keys) | ||
| 813 | "") | ||
| 811 | #$@(if (null? post-up) | 814 | #$@(if (null? post-up) |
| 812 | '() | 815 | '() |
| 813 | (list (format #f "~{PostUp = ~a~%~}" post-up))) | 816 | (list (format #f "~{PostUp = ~a~%~}" post-up))) |
| @@ -838,18 +841,19 @@ strongSwan."))) | |||
| 838 | (use-modules (guix build utils) | 841 | (use-modules (guix build utils) |
| 839 | (ice-9 popen) | 842 | (ice-9 popen) |
| 840 | (ice-9 rdelim)) | 843 | (ice-9 rdelim)) |
| 841 | (mkdir-p (dirname #$private-key)) | 844 | (when #$private-key |
| 842 | (unless (file-exists? #$private-key) | 845 | (mkdir-p (dirname #$private-key)) |
| 843 | (let* ((pipe | 846 | (unless (file-exists? #$private-key) |
| 844 | (open-input-pipe (string-append | 847 | (let* ((pipe |
| 845 | #$(file-append wireguard "/bin/wg") | 848 | (open-input-pipe (string-append |
| 846 | " genkey"))) | 849 | #$(file-append wireguard "/bin/wg") |
| 847 | (key (read-line pipe))) | 850 | " genkey"))) |
| 848 | (call-with-output-file #$private-key | 851 | (key (read-line pipe))) |
| 849 | (lambda (port) | 852 | (call-with-output-file #$private-key |
| 850 | (display key port))) | 853 | (lambda (port) |
| 851 | (chmod #$private-key #o400) | 854 | (display key port))) |
| 852 | (close-pipe pipe)))))) | 855 | (chmod #$private-key #o400) |
| 856 | (close-pipe pipe))))))) | ||
| 853 | 857 | ||
| 854 | ;;; XXX: Copied from (guix scripts pack), changing define to define*. | 858 | ;;; XXX: Copied from (guix scripts pack), changing define to define*. |
| 855 | (define-syntax-rule (define-with-source (variable args ...) body body* ...) | 859 | (define-syntax-rule (define-with-source (variable args ...) body body* ...) |
