Hello Ricardo! Ricardo Wurmus <rek...@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