all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* defining package variants automatically
@ 2019-09-07 22:50 Ricardo Wurmus
  2019-09-14 13:34 ` Maxim Cournoyer
  2019-09-24 16:06 ` Ludovic Courtès
  0 siblings, 2 replies; 3+ messages in thread
From: Ricardo Wurmus @ 2019-09-07 22:50 UTC (permalink / raw)
  To: help-guix

Hi Guix,

I played a little with defining package variants automatically, but I
can’t get this to work.  The idea of this module is to define a variant
for every package using the emacs-build-system, such that it uses a
different Emacs variant during the build.

All of these packages should be exported as variables of the (gnu
packages emacs-custom) module.

Unfortunately, none of the dynamically defined variables are visible, so
none of the packages are accessible by Guix.  Is there something
obviously wrong here?

--8<---------------cut here---------------start------------->8---
(define-module (gnu packages emacs-custom)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages emacs)
  #:use-module (gnu packages emacs-xyz)
  #:use-module (guix build-system emacs))

(define my-custom-emacs emacs-no-x) ; just a test

(define package-with-my-emacs
  (package-mapping
   (lambda (pkg)
     (package
       (inherit pkg)
       (name (string-append (package-name pkg) "-rekado"))
       (arguments
        (substitute-keyword-arguments (package-arguments pkg)
          ((#:emacs _ '())
           my-custom-emacs)))))
   (lambda (pkg)
     (eq? emacs-build-system (package-build-system pkg)))))

(fold-packages (lambda (pkg result)
                 (let ((variable-name
                        (string->symbol (string-append (package-name pkg) "-rekado"))))
                   (module-define!
                    (resolve-module '(gnu packages emacs-custom))
                    variable-name
                    (package-with-my-emacs pkg))
                   (export variable-name))
                 result)
               '()
               #:select?
               (lambda (pkg)
                 (eq? emacs-build-system (package-build-system pkg))))
--8<---------------cut here---------------end--------------->8---

--
Ricardo

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

* Re: defining package variants automatically
  2019-09-07 22:50 defining package variants automatically Ricardo Wurmus
@ 2019-09-14 13:34 ` Maxim Cournoyer
  2019-09-24 16:06 ` Ludovic Courtès
  1 sibling, 0 replies; 3+ messages in thread
From: Maxim Cournoyer @ 2019-09-14 13:34 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: help-guix

Hello Ricardo!

Ricardo Wurmus <rekado@elephly.net> writes:

> Hi Guix,
>
> I played a little with defining package variants automatically, but I
> can’t get this to work.  The idea of this module is to define a variant
> for every package using the emacs-build-system, such that it uses a
> different Emacs variant during the build.
>
> All of these packages should be exported as variables of the (gnu
> packages emacs-custom) module.
>
> Unfortunately, none of the dynamically defined variables are visible, so
> none of the packages are accessible by Guix.  Is there something
> obviously wrong here?
>
> (define-module (gnu packages emacs-custom)
>   #:use-module (guix packages)
>   #:use-module (guix utils)
>   #:use-module (gnu packages)
>   #:use-module (gnu packages emacs)
>   #:use-module (gnu packages emacs-xyz)
>   #:use-module (guix build-system emacs))
>
> (define my-custom-emacs emacs-no-x) ; just a test
>
> (define package-with-my-emacs
>   (package-mapping
>    (lambda (pkg)
>      (package
>        (inherit pkg)
>        (name (string-append (package-name pkg) "-rekado"))
>        (arguments
>         (substitute-keyword-arguments (package-arguments pkg)
>           ((#:emacs _ '())
>            my-custom-emacs)))))
>    (lambda (pkg)
>      (eq? emacs-build-system (package-build-system pkg)))))
>
> (fold-packages (lambda (pkg result)
>                  (let ((variable-name
>                         (string->symbol (string-append (package-name pkg) "-rekado"))))
>                    (module-define!
>                     (resolve-module '(gnu packages emacs-custom))
>                     variable-name
>                     (package-with-my-emacs pkg))
>                    (export variable-name))
>                  result)
>                '()
>                #:select?
>                (lambda (pkg)
>                  (eq? emacs-build-system (package-build-system pkg))))
>
> --
> Ricardo

I took some time to study your script, and experimented here with the
slightly modified version below:

--8<---------------cut here---------------start------------->8---
(define-module (gnu packages emacs-custom)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages emacs)
  #:use-module (gnu packages emacs-xyz)
  #:use-module (guix build-system emacs))

(define my-custom-emacs emacs-no-x) ; just a test

(define package-with-my-emacs
  (package-mapping
   (lambda (pkg)
     (package
       (inherit pkg)
       (name (string-append (package-name pkg) "-rekado"))
       (arguments
        (substitute-keyword-arguments (package-arguments pkg)
          ((#:emacs _ '())
           my-custom-emacs)))))
   (lambda (pkg)
     (eq? emacs-build-system (package-build-system pkg)))))

(define custom-packages
  (fold-packages (lambda (pkg result)
		   (let ((variable-name
			  (string->symbol (string-append
					   (package-name pkg) "-rekado"))))
		     (module-define!
		      (resolve-module '(gnu packages emacs-custom))
		      variable-name
		      (package-with-my-emacs pkg))
		     (cons variable-name result)))
		 '()
		 #:select?
		 (lambda (pkg)
		   ;;(eq? emacs-build-system (package-build-system pkg))
		   (string-prefix? "emacs-magit" (package-name pkg)))))

(export custom-packages)
--8<---------------cut here---------------end--------------->8---

The mapped packages are really created, and bound to the module when
experimenting at the REPL, so that's that.

I don't have a solution yet, but I found something which may be allow
you to dig further: the dynamically exported symbols (custom packages)
are bound to the module but (even though exported) don't appear to be
part of the module *interface*.

For example, using `resolve-module' works:

--8<---------------cut here---------------start------------->8---
~/src/guix $  guile -L . -C . -c "(use-modules (gnu packages emacs-custom)) (let ((m (resolve-module '(gnu packages emacs-custom)))) (pk (module-ref m 'emacs-magit-rekado)))"
;;; (#<package emacs-magit-rekado@2.90.1-1.b4aec01 ./gnu/packages/emacs-custom.scm:14 4343370>)
--8<---------------cut here---------------end--------------->8---

But using `resolve-interface' (which corresponds to what is made visible to a
module *using* the emacs-custom modules ,e.g. Guix) fails like:

--8<---------------cut here---------------start------------->8---
~/src/guix $ guile -L . -C . -c "(use-modules (gnu packages emacs-custom)) (let ((m (resolve-interface '(gnu packages emacs-custom)))) (pk (module-ref m 'emacs-magit-rekado)))"
Backtrace:
           6 (apply-smob/1 #<catch-closure 7aa6e0>)
In ice-9/boot-9.scm:
    705:2  5 (call-with-prompt _ _ #<procedure default-prompt-handler (k proc)>)
In ice-9/eval.scm:
    619:8  4 (_ #(#(#<directory (guile-user) 88f140>)))
In ice-9/command-line.scm:
   181:18  3 (_ #<input: string 8ada80>)
In unknown file:
           2 (eval (let ((m (resolve-interface (quote (gnu packages emacs-custom))))) (pk (module-ref m (quote emacs-magit-rekado)))) #<directory (guile-user) 88f140>)
In ice-9/eval.scm:
    155:9  1 (_ #(#<directory (guile-user) 88f140> #<interface (gnu packages emacs-custom) 8cb140>))
In unknown file:
           0 (scm-error misc-error #f "~A ~S ~S ~S" ("No variable named" emacs-magit-rekado in #<interface (gnu packages emacs-custom) 8cb140>) #f)

ERROR: In procedure scm-error:
No variable named emacs-magit-rekado in #<interface (gnu packages emacs-custom) 8cb140>
--8<---------------cut here---------------end--------------->8---

I've read the 'Modules' section from the Guile Reference, but didn't
find an explanation.  The next place to look if you want to dig deeper
would be the implementation of the module system in
guile/module/ice-9/boot-9.scm.

Hopefully the above wall of text will provide some clue to your
debugging :-).

Maxim

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

* Re: defining package variants automatically
  2019-09-07 22:50 defining package variants automatically Ricardo Wurmus
  2019-09-14 13:34 ` Maxim Cournoyer
@ 2019-09-24 16:06 ` Ludovic Courtès
  1 sibling, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2019-09-24 16:06 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: help-guix

Ricardo Wurmus <rekado@elephly.net> skribis:

> (define-module (gnu packages emacs-custom)
>   #:use-module (guix packages)
>   #:use-module (guix utils)
>   #:use-module (gnu packages)
>   #:use-module (gnu packages emacs)
>   #:use-module (gnu packages emacs-xyz)
>   #:use-module (guix build-system emacs))
>
> (define my-custom-emacs emacs-no-x) ; just a test
>
> (define package-with-my-emacs
>   (package-mapping
>    (lambda (pkg)
>      (package
>        (inherit pkg)
>        (name (string-append (package-name pkg) "-rekado"))
>        (arguments
>         (substitute-keyword-arguments (package-arguments pkg)
>           ((#:emacs _ '())
>            my-custom-emacs)))))
>    (lambda (pkg)
>      (eq? emacs-build-system (package-build-system pkg)))))
>
> (fold-packages (lambda (pkg result)
>                  (let ((variable-name
>                         (string->symbol (string-append (package-name pkg) "-rekado"))))
>                    (module-define!
>                     (resolve-module '(gnu packages emacs-custom))

I suspect you’d need ‘resolve-interface’ here, or a call to
‘module-export!’.

But…  it’s evil!  :-)

Ludo’.

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

end of thread, other threads:[~2019-09-24 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-07 22:50 defining package variants automatically Ricardo Wurmus
2019-09-14 13:34 ` Maxim Cournoyer
2019-09-24 16:06 ` Ludovic Courtès

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.