unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* (current-module) and gexp, fighting for pretty code
@ 2024-02-28 19:57 Richard Sent
  0 siblings, 0 replies; only message in thread
From: Richard Sent @ 2024-02-28 19:57 UTC (permalink / raw)
  To: help-guix

Hi Guix!

I have a setup where my operating system configurations are hosted in a
custom channel in dedicated modules, and I'm trying to get
unattended-upgrade-service working "cleanly" with it.

At present, I have an operating system that looks like

--8<---------------cut here---------------start------------->8---
(define-module (rsent machines droplets droplet-rampart)
  ;; ...
  #:export (droplet-rampart-system))

(define droplet-rampart-system
  (operating-system
   (inherit base-system)
   (services
    (cons*
     ;; ...
     (service unattended-upgrade-service-type
              (unattended-upgrade-configuration
               ;; ...
               (operating-system-expression
                ;; This way the operating-system itself will update,
                ;; not just imports
                #~(@ (rsent machines droplets droplet-rampart)
                droplet-rampart-system))))
     (operating-system-user-services base-system)))))
--8<---------------cut here---------------end--------------->8---

I'm trying to rewrite operating-system-expression to remove the
duplicate list of symbols, i.e. '(rsent machines droplets droplet-rampart).

I found that

--8<---------------cut here---------------start------------->8---
(operating-system-expression
 #~(module-variable #$(module-name (current-module))
    'droplet-rampart-system))
--8<---------------cut here---------------end--------------->8---

/nearly/ works, but (current-module) refers to (guile-user), not (rsent
...), in the generated unattended-upgrades.scm file.

I did find if I wrote

--8<---------------cut here---------------start------------->8---
(define module (current-module))
;; ...
#~(module-variable #$(module-name module) 'droplet-rampart-system)
--8<---------------cut here---------------end--------------->8---

The correct module name is used. However, this feels inelegant and I'd
rather just deal with the (admittedly very minor) module name
duplication.

Presumably the references ungexp captures are "module independent", for
lack of a better phrase, and are evaluated after we already left the
module. Ergo, capturing a reference to the current module /function/ is
meaningless, since the function will evaluate outside the scope of the
module I want to capture.

Is there a way I can have the best of both worlds? No module name
duplication and no extra variable creation? Some preexisting magical
variable I can capture that refers to the module I am currently in?

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-28 19:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 19:57 (current-module) and gexp, fighting for pretty code Richard Sent

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