Commit | Line | Data |
---|---|---|
fe634eaf | 1 | ;;; GNU Guix --- Functional package management for GNU |
2cb658a9 | 2 | ;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org> |
fe634eaf LC |
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) | |
2cb658a9 LC |
22 | #:use-module (guix packages) |
23 | #:use-module ((guix utils) #:select (location-file)) | |
24 | #:use-module ((guix store) #:select (%store-prefix)) | |
fe634eaf LC |
25 | #:use-module (srfi srfi-1) |
26 | #:use-module (ice-9 match) | |
bd747018 LC |
27 | #:export (current-profile |
28 | current-profile-entries | |
2cb658a9 LC |
29 | package-path-entries |
30 | ||
31 | package-provenance)) | |
fe634eaf LC |
32 | |
33 | ;;; Commentary: | |
34 | ;;; | |
35 | ;;; This module provides supporting code to allow a Guix instance to find, at | |
36 | ;;; run time, which profile it's in (profiles created by 'guix pull'). That | |
37 | ;;; allows it to read meta-information about itself (e.g., repository URL and | |
38 | ;;; commit ID) and to find other channels available in the same profile. It's | |
39 | ;;; a bit like ELPA's pkg-info.el. | |
40 | ;;; | |
41 | ;;; Code: | |
42 | ||
43 | (define current-profile | |
44 | (mlambda () | |
45 | "Return the profile (created by 'guix pull') the calling process lives in, | |
46 | or #f if this is not applicable." | |
47 | (match (command-line) | |
48 | ((program . _) | |
49 | (and (string-suffix? "/bin/guix" program) | |
50 | ;; Note: We want to do _lexical dot-dot resolution_. Using ".." | |
51 | ;; for real would instead take us into the /gnu/store directory | |
52 | ;; that ~/.config/guix/current/bin points to, whereas we want to | |
53 | ;; obtain ~/.config/guix/current. | |
54 | (let ((candidate (dirname (dirname program)))) | |
55 | (and (file-exists? (string-append candidate "/manifest")) | |
56 | candidate))))))) | |
57 | ||
58 | (define current-profile-entries | |
59 | (mlambda () | |
60 | "Return the list of entries in the 'guix pull' profile the calling process | |
61 | lives in, or #f if this is not applicable." | |
62 | (match (current-profile) | |
63 | (#f '()) | |
64 | (profile | |
65 | (let ((manifest (profile-manifest profile))) | |
66 | (manifest-entries manifest)))))) | |
67 | ||
bfc9c339 | 68 | (define current-channel-entries |
fe634eaf | 69 | (mlambda () |
bfc9c339 LC |
70 | "Return manifest entries corresponding to extra channels--i.e., not the |
71 | 'guix' channel." | |
72 | (remove (lambda (entry) | |
73 | (string=? (manifest-entry-name entry) "guix")) | |
74 | (current-profile-entries)))) | |
75 | ||
76 | (define (package-path-entries) | |
77 | "Return two values: the list of package path entries to be added to the | |
78 | package search path, and the list to be added to %LOAD-COMPILED-PATH. These | |
79 | entries are taken from the 'guix pull' profile the calling process lives in, | |
80 | when applicable." | |
81 | ;; Filter out Guix itself. | |
82 | (unzip2 (map (lambda (entry) | |
83 | (list (string-append (manifest-entry-item entry) | |
fe634eaf | 84 | "/share/guile/site/" |
bfc9c339 LC |
85 | (effective-version)) |
86 | (string-append (manifest-entry-item entry) | |
87 | "/lib/guile/" (effective-version) | |
88 | "/site-ccache"))) | |
3f4f2ee4 | 89 | (current-channel-entries)))) |
2cb658a9 LC |
90 | |
91 | (define (package-provenance package) | |
92 | "Return the provenance of PACKAGE as an sexp for use as the 'provenance' | |
93 | property of manifest entries, or #f if it could not be determined." | |
94 | (define (entry-source entry) | |
95 | (match (assq 'source | |
96 | (manifest-entry-properties entry)) | |
97 | (('source value) value) | |
98 | (_ #f))) | |
99 | ||
100 | (match (and=> (package-location package) location-file) | |
101 | (#f #f) | |
102 | (file | |
103 | (let ((file (if (string-prefix? "/" file) | |
104 | file | |
105 | (search-path %load-path file)))) | |
106 | (and file | |
107 | (string-prefix? (%store-prefix) file) | |
108 | ||
109 | ;; Always store information about the 'guix' channel and | |
110 | ;; optionally about the specific channel FILE comes from. | |
111 | (or (let ((main (and=> (find (lambda (entry) | |
112 | (string=? "guix" | |
113 | (manifest-entry-name entry))) | |
114 | (current-profile-entries)) | |
115 | entry-source)) | |
116 | (extra (any (lambda (entry) | |
117 | (let ((item (manifest-entry-item entry))) | |
118 | (and (string-prefix? item file) | |
119 | (entry-source entry)))) | |
120 | (current-profile-entries)))) | |
121 | (and main | |
122 | `(,main | |
123 | ,@(if extra (list extra) '())))))))))) |