unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* sharing code between gexps in config.scm
@ 2019-07-08 12:42 Robert Vollmert
  2019-07-11 16:16 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Robert Vollmert @ 2019-07-08 12:42 UTC (permalink / raw)
  To: guix-devel

Hi,

I’m currently writing some slightly repetitive mcron jobs
in my config.scm that use gexps / program-file. I’m wondering
whether there’s a better way to share code between these than
writing a separate scheme file and importing that via
with-imported-modules?

That approach works, but it’s a bit painful because I can no
longer just “system reconfigure”, but need to deal with the
guile load path. Also I’d prefer to have config.scm self-contained.

It turns out to not be possible to use a config.scm-level function
via e.g. (#$funcname arg1 arg2) for what are probably good reasons.

Cheers
Robert

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

* Re: sharing code between gexps in config.scm
  2019-07-08 12:42 sharing code between gexps in config.scm Robert Vollmert
@ 2019-07-11 16:16 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2019-07-11 16:16 UTC (permalink / raw)
  To: Robert Vollmert; +Cc: guix-devel

Hi,

Robert Vollmert <rob@vllmrt.net> skribis:

> I’m currently writing some slightly repetitive mcron jobs
> in my config.scm that use gexps / program-file. I’m wondering
> whether there’s a better way to share code between these than
> writing a separate scheme file and importing that via
> with-imported-modules?
>
> That approach works, but it’s a bit painful because I can no
> longer just “system reconfigure”, but need to deal with the
> guile load path. Also I’d prefer to have config.scm self-contained.

Modules in general are a good way to group related functionality, I
think there’s no argument here.  :-)

So the question is really how one can avoid using multiple files, or at
least passing ‘-L’ to ‘guix system reconfigure’.

You could define your module directly in your config.scm:

  (define my-helpers
    #~(begin
        (define-module (helpers))
        …))

Such a module can then be used along these lines:

  (with-imported-modules `(((helpers) => ,my-helpers))
    #~(begin
        (use-modules (helpers))
        …))

It may not work well with mcron jobs though, because there’s no good
place (I think) where you could get that ‘use-modules’ form.

Well, with an example we may be able to find more appropriate solutions.

> It turns out to not be possible to use a config.scm-level function
> via e.g. (#$funcname arg1 arg2) for what are probably good reasons.

Remember that a gexp is a way to “stage” an expression for eventual
execution—e.g., when your system boots, when your mcron job fires, etc.

If ‘funcname’ exists as a function in memory when your config.scm
program is evaluated, it cannot be magically transferred to those other
stages.  Instead, you would need to make the _source code_ of ‘funcname’
available to those other stages.

HTH!

Ludo’.

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

end of thread, other threads:[~2019-07-11 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 12:42 sharing code between gexps in config.scm Robert Vollmert
2019-07-11 16:16 ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

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