From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:35329) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmK69-0007ir-K7 for guix-patches@gnu.org; Sat, 13 Jul 2019 11:38:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmK66-0008FG-U2 for guix-patches@gnu.org; Sat, 13 Jul 2019 11:38:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:34376) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hmK66-0008F9-P5 for guix-patches@gnu.org; Sat, 13 Jul 2019 11:38:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hmK66-0002Yp-Lr for guix-patches@gnu.org; Sat, 13 Jul 2019 11:38:02 -0400 Subject: [bug#36563] [PATCH] guix: Add directory to channel. Resent-Message-ID: From: Jan Nieuwenhuizen References: <878st7dn7b.fsf@gnu.org> <87lfx29qjq.fsf@gnu.org> Date: Sat, 13 Jul 2019 17:37:07 +0200 In-Reply-To: <87lfx29qjq.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sat, 13 Jul 2019 12:28:41 +0200") Message-ID: <87ef2ukkt8.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 36563@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: Hi! > That makes a lot of sense to me. > > I think that, instead of letting the user specify the right directory in > ~/.config/guix/channels.scm, it should be the channel author that > specifies the sub-directory. > > There=E2=80=99s already support for a =E2=80=98.guix-channel=E2=80=99 fil= e so this is where this > =E2=80=98directory=E2=80=99 thing could be added (actually there=E2=80=99= s a FIXME in > channels.scm about this particular use case :-)). > > WDYT? Yes, I agree that this should be the first option to support. Attached is a second attempt: I removed the FIXME and moved `directory' to channel-metadata. A downside could be that this could make a channel user dependent on upstream to provide this `.guix-channel' file; probably best to worry about that when the need arises :) Greetings, janneke --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-channels-Add-optional-directory-to-channel-metadata.patch Content-Transfer-Encoding: quoted-printable >From 5d78a7eab391ea93c044d85736706b333c2dfee8 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 13 Jul 2019 16:31:50 +0200 Subject: [PATCH] channels: Add optional directory to channel metadata. * guix/channels.scm (): Add directory slot. Update users. (read-channel-metadata-from-source): New function. (standard-module-derivation): Use it. * doc/guix.texi (Package Modules in a Subdirectory): New subsection. --- doc/guix.texi | 23 ++++++++++++ guix/channels.scm | 93 ++++++++++++++++++++++++++--------------------- 2 files changed, 75 insertions(+), 41 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5a8ad7ebda..8bc00a5350 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -3921,6 +3921,29 @@ For the sake of reliability and maintainability, you= should avoid dependencies on channels that you don't control, and you should aim to keep the number = of dependencies to a minimum. =20 +@cindex subdirectory, channels +@subsection Package Modules in a Subdirectory + +A developer may include a @file{guix} subdirectory in their upstream source +that contains additional or modified Guix package descriptions. Typically, +their toplevel @file{guix.scm} then uses those package definitions: + +@lisp +(define %source-dir (dirname (current-filename))) +(add-to-load-path (string-append %source-dir "/guix")) +(use-modules @dots{}) +@dots{} +@end lisp + +By adding a meta-data file @file{.guix-channel} that specifies the +subdirectory that contains the Guix package descriptions it can be used +directly as a channel: + +@lisp +(channel + (directory "guix")) +@end lisp + @subsection Replicating Guix =20 @cindex pinning, channels diff --git a/guix/channels.scm b/guix/channels.scm index e6bb9b891b..614639f091 100644 --- a/guix/channels.scm +++ b/guix/channels.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2018, 2019 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2018 Ricardo Wurmus +;;; Copyright =C2=A9 2019 Jan (janneke) Nieuwenhuizen ;;; ;;; This file is part of GNU Guix. ;;; @@ -107,9 +108,10 @@ (checkout channel-instance-checkout)) =20 (define-record-type - (channel-metadata version dependencies) + (channel-metadata version directory dependencies) channel-metadata? (version channel-metadata-version) + (directory channel-metadata-directory) (dependencies channel-metadata-dependencies)) =20 (define (channel-reference channel) @@ -119,18 +121,18 @@ (#f `(branch . ,(channel-branch channel))) (commit `(commit . ,(channel-commit channel))))) =20 -(define (read-channel-metadata instance) - "Return a channel-metadata record read from the channel INSTANCE's -description file, or return #F if the channel instance does not include the -file." - (let* ((source (channel-instance-checkout instance)) - (meta-file (string-append source "/.guix-channel"))) +(define (read-channel-metadata-from-source source) + "Return a channel-metadata record read from channel's SOURCE/.guix-chann= el +description file, or return #F if SOURCE/.guix-channel does not exist." + (let ((meta-file (string-append source "/.guix-channel"))) (and (file-exists? meta-file) - (and-let* ((raw (call-with-input-file meta-file read)) - (version (and=3D> (assoc-ref raw 'version) first)) - (dependencies (or (assoc-ref raw 'dependencies) '()))) + (let* ((raw (call-with-input-file meta-file read)) + (version (and=3D> (assoc-ref raw 'version) first)) + (directory (and=3D> (assoc-ref raw 'directory) first)) + (dependencies (or (assoc-ref raw 'dependencies) '()))) (channel-metadata version + directory (map (lambda (item) (let ((get (lambda* (key #:optional default) (or (and=3D> (assoc-ref item key) first) d= efault)))) @@ -144,12 +146,18 @@ file." (commit (get 'commit)))))) dependencies)))))) =20 +(define (read-channel-metadata instance) + "Return a channel-metadata record read from the channel INSTANCE's +description file, or return #F if the channel instance does not include the +file." + (read-channel-metadata-from-source (channel-instance-checkout instance))) + (define (channel-instance-dependencies instance) "Return the list of channels that are declared as dependencies for the g= iven channel INSTANCE." (match (read-channel-metadata instance) (#f '()) - (($ version dependencies) + (($ version directory dependencies) dependencies))) =20 (define* (latest-channel-instances store channels #:optional (previous-cha= nnels '())) @@ -230,36 +238,39 @@ of COMMIT at URL. Use NAME as the channel name." modules in SOURCE and that depend on DEPENDENCIES, a list of lowerable objects. The assumption is that SOURCE contains package modules to be add= ed to '%package-module-path'." - ;; FIXME: We should load, say SOURCE/.guix-channel.scm, which would allow - ;; channel publishers to specify things such as the sub-directory where = .scm - ;; files live, files to exclude from the channel, preferred substitute U= RLs, - ;; etc. - - (define build - ;; This is code that we'll run in CORE, a Guix instance, with its own - ;; modules and so on. That way, we make sure these modules are built = for - ;; the right Guile version, with the right dependencies, and that they= get - ;; to see the right (gnu packages =E2=80=A6) modules. - (with-extensions dependencies - #~(begin - (use-modules (guix build compile) - (guix build utils) - (srfi srfi-26)) - - (define go - (string-append #$output "/lib/guile/" (effective-version) - "/site-ccache")) - (define scm - (string-append #$output "/share/guile/site/" - (effective-version))) - - (compile-files #$source go - (find-files #$source "\\.scm$")) - (mkdir-p (dirname scm)) - (symlink #$source scm) - scm))) - - (gexp->derivation-in-inferior name build core)) + + (let* ((metadata (read-channel-metadata-from-source source)) + (directory (and=3D> metadata channel-metadata-directory))) + + (define build + ;; This is code that we'll run in CORE, a Guix instance, with its own + ;; modules and so on. That way, we make sure these modules are buil= t for + ;; the right Guile version, with the right dependencies, and that th= ey get + ;; to see the right (gnu packages =E2=80=A6) modules. + (with-extensions dependencies + #~(begin + (use-modules (guix build compile) + (guix build utils) + (srfi srfi-26)) + + (define go + (string-append #$output "/lib/guile/" (effective-version) + "/site-ccache")) + (define scm + (string-append #$output "/share/guile/site/" + (effective-version))) + + (let* ((subdir (if #$directory + (string-append "/" #$directory) + "")) + (dir (string-append #$source subdir))) + (compile-files dir go (find-files dir "\\.scm$")) + (mkdir-p (dirname scm)) + (symlink (string-append #$source subdir) scm)) + + scm))) + + (gexp->derivation-in-inferior name build core))) =20 (define* (build-from-source name source #:key core verbose? commit --=20 2.21.0 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.com --=-=-=--