1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (guix describe)
20 #:use-module (guix memoization)
21 #:use-module (guix profiles)
22 #:use-module (srfi srfi-1)
23 #:use-module (ice-9 match)
24 #:export (current-profile
25 current-profile-entries
26 package-path-entries))
30 ;;; This module provides supporting code to allow a Guix instance to find, at
31 ;;; run time, which profile it's in (profiles created by 'guix pull'). That
32 ;;; allows it to read meta-information about itself (e.g., repository URL and
33 ;;; commit ID) and to find other channels available in the same profile. It's
34 ;;; a bit like ELPA's pkg-info.el.
38 (define current-profile
40 "Return the profile (created by 'guix pull') the calling process lives in,
41 or #f if this is not applicable."
44 (and (string-suffix? "/bin/guix" program)
45 ;; Note: We want to do _lexical dot-dot resolution_. Using ".."
46 ;; for real would instead take us into the /gnu/store directory
47 ;; that ~/.config/guix/current/bin points to, whereas we want to
48 ;; obtain ~/.config/guix/current.
49 (let ((candidate (dirname (dirname program))))
50 (and (file-exists? (string-append candidate "/manifest"))
53 (define current-profile-entries
55 "Return the list of entries in the 'guix pull' profile the calling process
56 lives in, or #f if this is not applicable."
57 (match (current-profile)
60 (let ((manifest (profile-manifest profile)))
61 (manifest-entries manifest))))))
63 (define package-path-entries
65 "Return a list of package path entries to be added to the package search
66 path. These entries are taken from the 'guix pull' profile the calling
67 process lives in, when applicable."
68 ;; Filter out Guix itself.
69 (filter-map (lambda (entry)
70 (and (not (string=? (manifest-entry-name entry)
72 (string-append (manifest-entry-item entry)
74 (effective-version))))
75 (current-profile-entries))))