From mboxrd@z Thu Jan 1 00:00:00 1970 From: Maxim Cournoyer Subject: Re: defining package variants automatically Date: Sat, 14 Sep 2019 22:34:19 +0900 Message-ID: <87blvn9f38.fsf@gmail.com> References: <87v9u3u3f6.fsf@elephly.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:38800) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i98C4-0006K0-On for help-guix@gnu.org; Sat, 14 Sep 2019 09:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i98C3-0006Qx-8W for help-guix@gnu.org; Sat, 14 Sep 2019 09:34:28 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:42311) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i98C3-0006QT-0c for help-guix@gnu.org; Sat, 14 Sep 2019 09:34:27 -0400 Received: by mail-pg1-x544.google.com with SMTP id z12so5237667pgp.9 for ; Sat, 14 Sep 2019 06:34:26 -0700 (PDT) In-Reply-To: <87v9u3u3f6.fsf@elephly.net> (Ricardo Wurmus's message of "Sun, 08 Sep 2019 00:50:21 +0200") List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+gcggh-help-guix=m.gmane.org@gnu.org Sender: "Help-Guix" To: Ricardo Wurmus Cc: help-guix@gnu.org Hello Ricardo! Ricardo Wurmus writes: > Hi Guix, > > I played a little with defining package variants automatically, but I > can=E2=80=99t get this to work. The idea of this module is to define a v= ariant > 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)))" ;;; (#) --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 #) In ice-9/boot-9.scm: 705:2 5 (call-with-prompt _ _ #) In ice-9/eval.scm: 619:8 4 (_ #(#(#))) In ice-9/command-line.scm: 181:18 3 (_ #) In unknown file: 2 (eval (let ((m (resolve-interface (quote (gnu packages emacs-c= ustom))))) (pk (module-ref m (quote emacs-magit-rekado)))) #) In ice-9/eval.scm: 155:9 1 (_ #(# #)) In unknown file: 0 (scm-error misc-error #f "~A ~S ~S ~S" ("No variable named" em= acs-magit-rekado in #) #f) ERROR: In procedure scm-error: No variable named emacs-magit-rekado in # --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