From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#22629: [PATCH 2/3] Add (guix describe) and use it to initialize '%package-search-path'. Date: Tue, 28 Aug 2018 17:17:50 +0200 Message-ID: <20180828151751.4657-2-ludo@gnu.org> References: <87pny2iks2.fsf@gnu.org> <20180828151751.4657-1-ludo@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fug1J-0007Kl-0z for bug-guix@gnu.org; Tue, 28 Aug 2018 11:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuflm-0000yy-Rf for bug-guix@gnu.org; Tue, 28 Aug 2018 11:19:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:59030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fuflm-0000ys-LB for bug-guix@gnu.org; Tue, 28 Aug 2018 11:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fuflm-0000IO-DZ for bug-guix@gnu.org; Tue, 28 Aug 2018 11:19:02 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20180828151751.4657-1-ludo@gnu.org> List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: 22629@debbugs.gnu.org * guix/describe.scm: New file. * Makefile.am (MODULES): Add it. * gnu/packages.scm (%package-module-path): Honor 'package-path-entries'. --- Makefile.am | 1 + gnu/packages.scm | 22 ++++++++------ guix/describe.scm | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 guix/describe.scm diff --git a/Makefile.am b/Makefile.am index 324674a60..b6efd6d62 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,6 +86,7 @@ MODULES = \ guix/derivations.scm \ guix/grafts.scm \ guix/inferior.scm \ + guix/describe.scm \ guix/gnu-maintenance.scm \ guix/self.scm \ guix/upstream.scm \ diff --git a/gnu/packages.scm b/gnu/packages.scm index 7b954769e..e690d459f 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -30,6 +30,7 @@ #:select ((package-name->name+version . hyphen-separated-name->name+version))) #:autoload (guix profiles) (packages->manifest) + #:use-module (guix describe) #:use-module (ice-9 vlist) #:use-module (ice-9 match) #:use-module (srfi srfi-1) @@ -136,16 +137,21 @@ for system '~a'") ;; to narrow the search. (let* ((not-colon (char-set-complement (char-set #\:))) (environment (string-tokenize (or (getenv "GUIX_PACKAGE_PATH") "") - not-colon))) - ;; Automatically add items from $GUIX_PACKAGE_PATH to Guile's search path. - (for-each (lambda (directory) - (set! %load-path (cons directory %load-path)) - (set! %load-compiled-path - (cons directory %load-compiled-path))) - environment) + not-colon)) + (channels (package-path-entries))) + ;; Automatically add channels and items from $GUIX_PACKAGE_PATH to Guile's + ;; search path. For historical reasons, $GUIX_PACKAGE_PATH goes to the + ;; front; channels go to the back so that they don't override Guix' own + ;; modules. + (set! %load-path + (append environment %load-path channels)) + (set! %load-compiled-path + (append environment %load-compiled-path channels)) (make-parameter - (append environment `((,%distro-root-directory . "gnu/packages")))))) + (append environment + `((,%distro-root-directory . "gnu/packages")) + channels)))) (define %patch-path ;; Define it after '%package-module-path' so that '%load-path' contains user diff --git a/guix/describe.scm b/guix/describe.scm new file mode 100644 index 000000000..3122a762f --- /dev/null +++ b/guix/describe.scm @@ -0,0 +1,73 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2018 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix describe) + #:use-module (guix memoization) + #:use-module (guix profiles) + #:use-module (srfi srfi-1) + #:use-module (ice-9 match) + #:export (package-path-entries)) + +;;; Commentary: +;;; +;;; This module provides supporting code to allow a Guix instance to find, at +;;; run time, which profile it's in (profiles created by 'guix pull'). That +;;; allows it to read meta-information about itself (e.g., repository URL and +;;; commit ID) and to find other channels available in the same profile. It's +;;; a bit like ELPA's pkg-info.el. +;;; +;;; Code: + +(define current-profile + (mlambda () + "Return the profile (created by 'guix pull') the calling process lives in, +or #f if this is not applicable." + (match (command-line) + ((program . _) + (and (string-suffix? "/bin/guix" program) + ;; Note: We want to do _lexical dot-dot resolution_. Using ".." + ;; for real would instead take us into the /gnu/store directory + ;; that ~/.config/guix/current/bin points to, whereas we want to + ;; obtain ~/.config/guix/current. + (let ((candidate (dirname (dirname program)))) + (and (file-exists? (string-append candidate "/manifest")) + candidate))))))) + +(define current-profile-entries + (mlambda () + "Return the list of entries in the 'guix pull' profile the calling process +lives in, or #f if this is not applicable." + (match (current-profile) + (#f '()) + (profile + (let ((manifest (profile-manifest profile))) + (manifest-entries manifest)))))) + +(define package-path-entries + (mlambda () + "Return a list of package path entries to be added to the package search +path. These entries are taken from the 'guix pull' profile the calling +process lives in, when applicable." + ;; Filter out Guix itself. + (filter-map (lambda (entry) + (and (not (string=? (manifest-entry-name entry) + "guix")) + (string-append (manifest-entry-item entry) + "/share/guile/site/" + (effective-version)))) + (current-profile-entries)))) -- 2.18.0