unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Richard Sent <richard@freakingpenguin.com>
To: help-guix@gnu.org
Subject: (current-module) and gexp, fighting for pretty code
Date: Wed, 28 Feb 2024 14:57:54 -0500	[thread overview]
Message-ID: <87sf1cs6nx.fsf@freakingpenguin.com> (raw)

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.


                 reply	other threads:[~2024-02-28 19:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87sf1cs6nx.fsf@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).