unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Using gexps in wireguard-service-type postup
@ 2024-01-28  2:19 Richard Sent
  2024-01-28 12:51 ` Marek Paśnikowski
  2024-01-28 14:04 ` Clément Lassieur
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Sent @ 2024-01-28  2:19 UTC (permalink / raw)
  To: help-guix

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-28 23:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-28  2:19 Using gexps in wireguard-service-type postup Richard Sent
2024-01-28 12:51 ` 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

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).