From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id iKhOHNJ+GGPmfgAAbAwnHQ (envelope-from ) for ; Wed, 07 Sep 2022 13:21:54 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id cI1oHNJ+GGNFSAAA9RJhRA (envelope-from ) for ; Wed, 07 Sep 2022 13:21:54 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F3F44392D6 for ; Wed, 7 Sep 2022 13:21:53 +0200 (CEST) Received: from localhost ([::1]:58792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVt7w-000686-TO for larch@yhetil.org; Wed, 07 Sep 2022 07:21:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVt6j-00066x-Es for guix-devel@gnu.org; Wed, 07 Sep 2022 07:20:41 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:40613) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVt6f-0007Rb-Kl for guix-devel@gnu.org; Wed, 07 Sep 2022 07:20:36 -0400 Received: by mail-wr1-x432.google.com with SMTP id e16so589435wrx.7 for ; Wed, 07 Sep 2022 04:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date; bh=x5O8wsusiClS93/49qmxxTnLz5bh0kk2aX0CD0k5Qc4=; b=GrVgw3PYeFB3JI66DWQ9SPALqGTQj5LEbb8ev5brXH35S4XOU+eOkxP9UUKa20huwQ U3dHSR2CBiCeUWIdvoSz2NO49W8eLLKfsUK+FRNWsEZaSzOh9jd3LJoFPBA9Ahzu75aX wqAdDqZkmRcp7xVYQQeICtovzi5vxeoX9FcKc65rbQib+GyXw4POTm01IAfy5x0b5EB8 I2RpJHv6QXw+Ctp8YlH7WIxde/PfEDTF2zcnTHX9r8BMpzhWwHqmUpCO7Tu8z/ZgoRDQ 3QABd+t5pu/THCXtsDomKbhlEYNbEHgNBp94edMDMBDjT6AVf7Ly1PrkCo1WBDcw2D50 9Qgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date; bh=x5O8wsusiClS93/49qmxxTnLz5bh0kk2aX0CD0k5Qc4=; b=iCdWPF1SqobFiMOh5BgVLNaizvXnICf5mBvVnNto2mqQcaUQMQWBdu3N/7B2h47W2F OMqo9LJNLhKcG+7IIR6sqLym29AzxgpspIGM4QQYsvAgqFjH1DF7S/h9Iq6gUB6/DuEw KpX5XWbttuMwVzEtzyXaKneKKC8IzSZ4SVbMRiyQteBlzMdu/nfE5hKWm6Ktt6OXhgdN SshHkdawwOjO6vN18ENLV0eKFs+e1uqsWi57czoUlppczraVBVP4KTLM8fViEKqS1PTy Th4my1rp/7B8YyNe6xpaE3tmukZWh/Dt79kdU6qDc/yxhnVwJFFTa0wBNRk1091RNXU0 946Q== X-Gm-Message-State: ACgBeo0HFXWd1wzFDdfe+oPUT6kFzUq5Tt1lejRjX/Ggd6xYdVCXBD1+ sBfGr5nf6gPeMyZf60X4kPEmjLVNoLA= X-Google-Smtp-Source: AA6agR617Wx1P4ocD5oXh6Qa48JFa42HGBHbG/S+1axhjDjWJ2TYYcUV/wdSbzKSbfrfcpoJIWDYsw== X-Received: by 2002:a5d:68c6:0:b0:228:74b6:2b07 with SMTP id p6-20020a5d68c6000000b0022874b62b07mr1752094wrw.60.1662549629902; Wed, 07 Sep 2022 04:20:29 -0700 (PDT) Received: from lili ([2a01:e0a:59b:9120:65d2:2476:f637:db1e]) by smtp.gmail.com with ESMTPSA id l11-20020a05600c10cb00b003a5260b8392sm22090494wmd.23.2022.09.07.04.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 04:20:28 -0700 (PDT) From: zimoun To: Guix Devel Cc: Ricardo Wurmus Subject: How to write Guix extension? Date: Wed, 07 Sep 2022 13:20:24 +0200 Message-ID: <86o7vrzb0n.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=zimon.toutoune@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_BTC_ID=0.499, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1662549714; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=x5O8wsusiClS93/49qmxxTnLz5bh0kk2aX0CD0k5Qc4=; b=VMfBpEer8v9RYtnfggcgWhzZNoCpqAbfaUkp/M6Si7JgqXBohXaAWWVIrVebO3fJTTehoL MoTdYQbob9AAE2NXKvRowc3NRybFvypIRDylgJ7O+RfuJE8fUIIp7xphZ108Yi5r/XmLMc M2Bl2zrD5oQ64Z7Q7avrLNUKPDKbBnNg2BwYLY+zqw63NGrHwz7L9BkJZ37+tfVd2CMUjV ZEubQIDVz92XAkYCx63O9CzYguGkDTKQ7n+HSpgnK5oP8HMYk5vxgQVoWRPNkX40TYqTVY DizFvpHWY2Q9yxSMjBbnsAxNodJwtgituibxFVFQ3B1vO0pdeTlZodxpy8vByg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1662549714; a=rsa-sha256; cv=none; b=B9X80umJgssPDFzenqvVz9m5qj1oEmRElfuQ4kLbqw993pGTPQ3KcW+3ccLyH9XoaqPNR0 coNjvoglBlF3ZJDXYPdnW/gZ/WZfg3HtIIwtsVm5W2nCf66daYSkgKdvd/SQ4e5IikiF8e Wh+L2K2rKDB5xzjGUDGZbyG46t31LPDfHfs9TM3zLGgVV+7Iv23gnEypd5URfhi3C725FO WTR370BHOUy1dJ/ojHCIbZDj/Y+YOGI5aOldyiUt880ETSK5GDbadHgM8ZZ29tOkY3BJWa voqjugHaE4gxavFEU6FenzG46CUdnDA7UYyxHbyFBwG1zF65RtdfyLtDf2xqaw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GrVgw3PY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.77 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GrVgw3PY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: F3F44392D6 X-Spam-Score: -2.77 X-Migadu-Scanner: scn1.migadu.com X-TUID: qVYRz5/Wid+E --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Extension is a mechanism which allows to have more CLI subcommands. For example, see guix-modules or gwl; they extend Guix by providing the subcommands =E2=80=9Cguix module=E2=80=9D or =E2=80=9Cguix workflow=E2=80= =9D. Note that: - guix-modules uses guile-build-system and is one file. - gwl uses gnu-build-system and is multi-files I would like to have multi-files but without the =E2=80=9Ccomplexity=E2=80= =9D of gwl (transform .scm.in to .scm at build time, etc.). Let take an example. The structure is fixed and it looks like: --8<---------------cut here---------------start------------->8--- $ tree /tmp/example/ /tmp/example/ =E2=94=9C=E2=94=80=E2=94=80 guix =E2=94=82=C2=A0=C2=A0 =E2=94=94=E2=94=80=E2=94=80 extensions =E2=94=82=C2=A0=C2=A0 =E2=94=94=E2=94=80=E2=94=80 hello.scm =E2=94=94=E2=94=80=E2=94=80 my =E2=94=9C=E2=94=80=E2=94=80 module =E2=94=82=C2=A0=C2=A0 =E2=94=94=E2=94=80=E2=94=80 sub.scm =E2=94=94=E2=94=80=E2=94=80 top.scm 4 directories, 3 files --8<---------------cut here---------------end--------------->8--- Then setting GUIX_EXTENSIONS_PATH just works. --8<---------------cut here---------------start------------->8--- $ GUIX_EXTENSIONS_PATH=3D/tmp/example/guix/extensions guix help Usage: guix OPTION | COMMAND ARGS... [...] plumbing commands [...] hello hello world Report bugs to: bug-guix@gnu.org. GNU Guix home page: General help using Guix and GNU software: --8<---------------cut here---------------end--------------->8--- So far, so good! What is my issue? :-) Well, my issue is to correctly set the load path so that I can use the module defined under the folder my/. For instance, this =E2=80=99hello=E2=80=99 extension reads: --8<---------------cut here---------------start------------->8--- $ GUIX_EXTENSIONS_PATH=3D/tmp/example/guix/extensions guix hello hello path: "/tmp/example/my" load-path:=20 "/tmp/example/my" "/gnu/store/qdhi0a69908b0521gqzxdsf9a9bniqxi-guix-module-union/share/guil= e/site/3.0" "/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/share/guile/3.0" "/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/share/guile/3.0" "/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/share/guile/site= /3.0" "/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/share/guile/site" "/gnu/store/1jgcbdzx2ss6xv59w55g3kr3x4935dfb-guile-3.0.8/share/guile" "/home/simon/.guix-profile/share/guile/site/3.0" "/home/simon/.config/guix/profiles/emacs/emacs/share/guile/site/3.0" "/home/simon/.guix-profile/share/guile/site/3.0" "/home/simon/.config/guix/profiles/emacs/emacs/share/guile/site/3.0" "top": "/tmp/example/my/top.scm" "sub": #f "module/sub": "/tmp/example/my/module/sub.scm" --8<---------------cut here---------------end--------------->8--- which means that %load-path contains =E2=80=99my=E2=80=99 module and =E2=80= =99%search-load-path=E2=80=99 finds the relevant files. See plain script below. However, how do I use the exported procedure in these files my/top.scm and my/module/sub.scm? For instance, my/top.scm reads: --8<---------------cut here---------------start------------->8--- (define-module (my top) #:export (from-top)) (define (from-top) (let ((here (current-filename))) (format #t "top: ~s~%" (string-append (dirname here) here)))) --8<---------------cut here---------------end--------------->8--- but then I miss how to use =E2=80=99from-top=E2=80=99 inside =E2=80=99guix/extensions/hello.scm=E2=80=99. Obviously =E2=80=99#:use-modu= le (my top)=E2=80=99 cannot work because the load path is extended by the script itself. I have tried (apply (@ (my top) from-top)) or=20=20=20=20 (apply (@@ (my top) from-top)) without success. Well, I get: ERROR: In procedure %resolve-variable: How can I write a multi-files extension? Cheers, simon guix/extensions/hello.scm: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=hello.scm Content-Description: hello.scm (define-module (guix extensions hello) #:use-module ((guix scripts)) ;define-command, category, synopsis, etc. ;;#:use-module (my module world) #:export (guix-hello)) (define (my-path) (canonicalize-path (string-append (dirname (current-filename)) "/../../my"))) (define-command (guix-hello . args) (category plumbing) (synopsis "hello world") (begin (format #t "hello~%") (format #t "path: ~s~%" (my-path)) (add-to-load-path (my-path)) (format #t "load-path: ~%") (for-each (lambda (path) (format #t " ~s~%" path)) %load-path) (for-each (lambda (what) (format #t "~s: ~s~%" what (%search-load-path what))) (list "top" "sub" "module/sub")))) --=-=-= Content-Type: text/plain my/top.scm: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=top.scm Content-Description: top.scm (define-module (my top) #:export (from-top)) (define (from-top) (let ((here (current-filename))) (format #t "top: ~s~%" (string-append (dirname here) here)))) --=-=-=--