From: Richard Sent <richard@freakingpenguin.com>
To: help-guix@gnu.org
Subject: Using gexps in wireguard-service-type postup
Date: Sat, 27 Jan 2024 21:19:54 -0500 [thread overview]
Message-ID: <93b89074d790b8554de4c10434fc6be2@freakingpenguin.com> (raw)
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
case).
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
(wireguard-configuration
...
(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
out.
I'd appreciate any help on this!
--
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.
next reply other threads:[~2024-01-28 2:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 2:19 Richard Sent [this message]
2024-01-28 12:51 ` Using gexps in wireguard-service-type postup Marek Paśnikowski
2024-01-28 14:04 ` Clément Lassieur
2024-01-28 18:36 ` Richard Sent
2024-01-28 22:59 ` Clément Lassieur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93b89074d790b8554de4c10434fc6be2@freakingpenguin.com \
--to=richard@freakingpenguin.com \
--cc=help-guix@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).