aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-08-27 15:38:59 +0200
committerLudovic Courtès <ludo@gnu.org>2018-09-02 16:43:10 +0200
commitfe634eaf93ba40862acdf62d7f197c6f19f0651c (patch)
tree1d0286c3c1610c328a2eb7b235744981ad9ec560 /guix
parent02fa1d251c9caeba39c7593e0b8ab52b60735b17 (diff)
downloadgnu-guix-fe634eaf93ba40862acdf62d7f197c6f19f0651c.tar
gnu-guix-fe634eaf93ba40862acdf62d7f197c6f19f0651c.tar.gz
Add (guix describe) and use it to initialize '%package-search-path'.
* guix/describe.scm: New file. * Makefile.am (MODULES): Add it. * gnu/packages.scm (%default-package-module-path): New variable. (%package-module-path): Honor 'package-path-entries'. * build-aux/update-NEWS.scm (main): Use %DEFAULT-PACKAGE-MODULE-PATH instead of (last (%package-module-path)).
Diffstat (limited to 'guix')
-rw-r--r--guix/describe.scm73
1 files changed, 73 insertions, 0 deletions
diff --git a/guix/describe.scm b/guix/describe.scm
new file mode 100644
index 0000000000..3122a762fe
--- /dev/null
+++ b/guix/describe.scm
@@ -0,0 +1,73 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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))))