[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using gexps in wireguard-service-type postup

From: Richard Sent
Subject: Using gexps in wireguard-service-type postup
Date: Sat, 27 Jan 2024 21:19:54 -0500

Hi all,

I'm trying to create a wireguard service, but I've encountered an issue
that I'm pretty sure I can only resolve using gexps and am having
trouble with the syntax (or if it's even possible to use them in this

I want to fetch my private key from password-store when running the
service, and a PostUp command seems the best way of implementing
that. Using the wg-quick manual as a base, I get a naive solution like:

--8<---------------cut here---------------start------------->8---
(define* (get-secret-command key #:optional (user (sudo-user)))
  "Returns the shell command needed to read KEY from USER."
  (string-append "sudo -u " user " pass ls " key))

(service wireguard-service-type
     (post-up (list
               ;; Returns "wg set wg-nickleslan private-key <(sudo pass
               ;; ls wireguard-nickleslan-private-key-key)"
               (string-append "wg set " interface " private-key <("
(get-secret-command wireguard-nickleslan-private-key-key) ")") (string-append "wg set " interface " peer " wireguard-nickleslan-public-key
                              " preshared-key <("
(get-secret-command wireguard-nickleslan-preshared-key-key) ")")))))
--8<---------------cut here---------------end--------------->8---

Running `sudo herd start wireguard-wg-nickleslan` and checking
`/var/log/messages` shows an pretty unambiguous error, `error: sudo
not found`.

Presumably I need to use the full /gnu/store/...-sudo/bin/sudo path,
which (I think) can be done using gexps and (file-append sudo
"/bin/sudo"). However, I'm not quite sure how to go about it, in part
since I'm moving all the responsibility for key->secret collection to
(get-secret-command), which seems to make things harder.

I /think/ I need to
a) modify (get-secret-command) to return a gexp
b) replace sudo and pass with ungexp'd file-append calls. #$(file-append ...)
c) gexp the (string-append) calls in post-up
d) ungexp the (get-secret-command) calls

This exact process causes a string representation of the gexp to be
printed to the postup command in wg-nicklesbread.conf, e.g. `PostUp =
#<gexp .......>`.

I'm /guessing/ this is because post-up is assumed to be a string and not
a gexp, although I can see there is some ungexp-splicing going on so
maybe not? (In gnu/services/vpn.scm:wireguard-configuration-file) I only
really have a vague understanding of gexps in isolation so this is
starting to get a bit over my head. It really feels like there should be
a solution here, but I can't quite parse the vpn.scm code to figure it

I'd appreciate any help on this!

Take it easy,
Richard Sent
Making my computer weirder one commit at a time.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]