guix-devel
[Top][All Lists]
Advanced

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

Shepherd config file and GEXP semantics


From: Attila Lendvai
Subject: Shepherd config file and GEXP semantics
Date: Sun, 30 Jan 2022 19:53:00 +0000

dear list,

i'm having a hard time with a service's start GEXP. my service is using a 
utility module, but when anything is referenced from its toplevel, i get a 
variable unbound error.

to the best of my knowledge everything is fine with WITH-IMPORTED-MODULES and 
whatnot. i have digged down into the store to verify the service's generated 
.scm file.

in fact, if i cut down that file to the relevant parts, then i can even run it 
using guile -s foo.scm, and it does what i expect.

strangely enough, it also works as i expect it when i run the same code not 
through a `guix pull` and `guix system reconfigure` on a Guix System, but 
rather though:

$(./pre-inst-env guix system --no-graphic vm /path/to/swarm.scm)

but now, back to why it probably behaves differently in shepherd: it loads its 
config file using LOAD-IN-USER-MODULE, which does the following dance:

(define (load-in-user-module file)
  (let ((user-module (make-user-module)))
    (save-module-excursion
     (lambda ()
       (set-current-module user-module)
       (primitive-load file)))))

the service's start procedure is captured and stored as a closure, which is 
only called *after* the SAVE-MODULE-EXCURSION has been passed.

am i right in assuming that:

1) the global value DEFINE'd on the toplevel of my utility module ends up in 
this unnamed USER-MODULE's env, and that

2) when the start closure is called, it looks for the global variables in a 
different global current-module (i probably lack the lingo here), which doesn't 
have the bindings of my util module, and that's why i get the unbound variable 
error at service start?

if these assumptions are right, then what is the right way to deal with this? 
is this something to be fixed in shepherd? as demonstrated by the attached 
file, there's at least one way to make it work.

to verify this, i have copied some bits from shepherd's code, and attached it 
in an x.scm file. it exhibits the behavior that an escaping closure doesn't see 
the variable bindings. but when i eval the closure, then it does work as 
expected.

you won't be able to run the attached file as-is, but i have added the outputs 
of the two runs at its end.

any thoughts?

--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“A slave is one who waits for someone to come and free him.”
        — Ezra Pound (1885–1972)

Attachment: x.scm
Description: Text Data


reply via email to

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