gnu: cool-retro-term: Upgrade to 1.1.1.
[jackhill/guix/guix.git] / guix / describe.scm
CommitLineData
fe634eaf
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
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.
10;;;
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.
15;;;
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/>.
18
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)
bd747018
LC
24 #:export (current-profile
25 current-profile-entries
26 package-path-entries))
fe634eaf
LC
27
28;;; Commentary:
29;;;
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.
35;;;
36;;; Code:
37
38(define current-profile
39 (mlambda ()
40 "Return the profile (created by 'guix pull') the calling process lives in,
41or #f if this is not applicable."
42 (match (command-line)
43 ((program . _)
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"))
51 candidate)))))))
52
53(define current-profile-entries
54 (mlambda ()
55 "Return the list of entries in the 'guix pull' profile the calling process
56lives in, or #f if this is not applicable."
57 (match (current-profile)
58 (#f '())
59 (profile
60 (let ((manifest (profile-manifest profile)))
61 (manifest-entries manifest))))))
62
63(define package-path-entries
64 (mlambda ()
65 "Return a list of package path entries to be added to the package search
66path. These entries are taken from the 'guix pull' profile the calling
67process lives in, when applicable."
68 ;; Filter out Guix itself.
69 (filter-map (lambda (entry)
70 (and (not (string=? (manifest-entry-name entry)
71 "guix"))
72 (string-append (manifest-entry-item entry)
73 "/share/guile/site/"
74 (effective-version))))
75 (current-profile-entries))))