projects/guix·blob gnome-team · refs

149 lines · 5.0 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2015, 2016, 2017, 2019, 2020 Ludovic Courtès <[email protected]>
3;;; Copyright © 2015 Joshua S. Grant <[email protected]>
4;;; Copyright © 2017 Mathieu Othacehe <[email protected]>
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21;;; Commentary:
22;;;
23;;; This composite module re-exports core parts the (gnu …) public modules.
24;;;
25;;; Code:
26
27(define-module (gnu)
28 #:use-module (guix i18n)
29 #:use-module (guix diagnostics)
30 #:use-module (srfi srfi-34)
31 #:use-module (srfi srfi-35)
32 #:use-module (ice-9 match)
33 #:use-module (guix packages)
34 #:use-module (gnu packages)
35 #:use-module (gnu services)
36 #:export (use-package-modules
37 use-service-modules
38 use-system-modules))
39
40(eval-when (eval load compile)
41 (begin
42 (define %public-modules
43 '((gnu system)
44 (gnu system mapped-devices)
45 (gnu system file-systems)
46 (gnu bootloader)
47 (gnu bootloader grub)
48 (gnu system keyboard)
49 (gnu system pam)
50 (gnu system shadow) ; 'user-account'
51 (gnu system linux-initrd)
52 (gnu system nss)
53 (gnu services)
54 (gnu services base)
55 (gnu packages)
56 (gnu packages base)
57 (guix gexp))) ; so gexps can be used
58
59 (for-each (let ((i (module-public-interface (current-module))))
60 (lambda (m)
61 (module-use! i (resolve-interface m))))
62 %public-modules)))
63
64(define (%try-use-modules modules location make-hint)
65 "Attempt to load all of MODULES. Report errors as coming from LOCATION, a
66<location> record, and use MAKE-HINT to produce a fix hint."
67 (for-each (lambda (module)
68 (catch 'misc-error
69 (lambda ()
70 (process-use-modules `((,module))))
71 (lambda _
72 (raise
73 (apply
74 make-compound-condition
75 (formatted-message (G_ "module ~a not found")
76 module)
77 (condition
78 (&error-location (location location)))
79 (or (and=> (make-hint module) list)
80 '()))))))
81 modules))
82
83(define (package-module-hint module)
84 (define last-name
85 (match module
86 ((_ ... last)
87 (symbol->string last))))
88
89 (match (find-packages-by-name last-name)
90 (()
91 (condition
92 (&fix-hint
93 (hint (G_ "\
94You may use @command{guix package --show=foo | grep location} to search
95for the location of package @code{foo}.
96If you get the line @code{location: gnu/packages/bar.scm:174:2},
97add @code{bar} to the @code{use-package-modules} form.")))))
98 ((package _ ...)
99 (condition
100 (&fix-hint
101 (hint (format #f (G_ "\
102Try adding @code{(use-package-modules ~a)}.")
103 (basename (location-file (package-location package))
104 ".scm"))))))))
105
106(define (service-module-hint module)
107 (define last-name
108 (match module
109 ((_ ... last)
110 last)))
111
112 (match (lookup-service-types last-name)
113 (()
114 (condition
115 (&fix-hint
116 (hint (format #f (G_ "\
117You may use @command{guix system search ~a} to search for a service
118matching @code{~a}.
119If you get the line @code{location: gnu/services/foo.scm:188:2},
120add @code{foo} to the @code{use-service-modules} form.")
121 last-name last-name)))))
122 ((package _ ...)
123 (condition
124 (&fix-hint
125 (hint (format #f (G_ "\
126Try adding @code{(use-service-modules ~a)}.")
127 (basename (location-file (service-type-location package))
128 ".scm"))))))))
129
130(define-syntax-rule (try-use-modules hint modules ...)
131 (eval-when (expand load eval)
132 (%try-use-modules '(modules ...)
133 (source-properties->location
134 (current-source-location))
135 hint)))
136
137(define-syntax-rule (use-package-modules module ...)
138 (try-use-modules package-module-hint
139 (gnu packages module) ...))
140
141(define-syntax-rule (use-service-modules module ...)
142 (try-use-modules service-module-hint
143 (gnu services module) ...))
144
145(define-syntax-rule (use-system-modules module ...)
146 (try-use-modules (const #f) ;no hint
147 (gnu system module) ...))
148
149;;; gnu.scm ends here