Commit | Line | Data |
---|---|---|
c9384945 | 1 | ;;; GNU Guix --- Functional package management for GNU |
db1e2522 | 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org> |
fbb02045 | 3 | ;;; Copyright © 2015 Joshua S. Grant <jgrant@parenthetical.io> |
b09a8da4 | 4 | ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> |
c9384945 LC |
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 | ||
fbb02045 | 21 | (define-module (gnu) |
c5a4a92f LC |
22 | #:use-module (guix i18n) |
23 | #:use-module (guix utils) | |
24 | #:use-module (srfi srfi-34) | |
25 | #:use-module (srfi srfi-35) | |
26 | #:use-module (ice-9 match) | |
27 | #:use-module (guix packages) | |
28 | #:use-module (gnu packages) | |
29 | #:use-module (gnu services) | |
fbb02045 JG |
30 | #:export (use-package-modules |
31 | use-service-modules | |
32 | use-system-modules)) | |
c9384945 LC |
33 | |
34 | ;;; Commentary: | |
35 | ;;; | |
36 | ;;; This composite module re-exports core parts the (gnu …) public modules. | |
37 | ;;; | |
38 | ;;; Code: | |
39 | ||
40 | (eval-when (eval load compile) | |
41 | (begin | |
42 | (define %public-modules | |
43 | '((gnu system) | |
060d62a7 | 44 | (gnu system mapped-devices) |
c9384945 | 45 | (gnu system file-systems) |
b09a8da4 MO |
46 | (gnu bootloader) |
47 | (gnu bootloader grub) | |
db1e2522 | 48 | (gnu system keyboard) |
6e828634 | 49 | (gnu system pam) |
c9384945 LC |
50 | (gnu system shadow) ; 'user-account' |
51 | (gnu system linux-initrd) | |
996ed739 | 52 | (gnu system nss) |
c9384945 LC |
53 | (gnu services) |
54 | (gnu services base) | |
55 | (gnu packages) | |
bde7eb8f LC |
56 | (gnu packages base) |
57 | (guix gexp))) ; so gexps can be used | |
c9384945 LC |
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 | ||
c5a4a92f LC |
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 | (define (location->string loc) | |
68 | (match loc | |
69 | (#f "") | |
70 | (($ <location> file line column) | |
71 | (format #f "~a:~a:~a: " file line column)))) | |
72 | ||
73 | (for-each (lambda (module) | |
74 | (catch 'misc-error | |
75 | (lambda () | |
76 | (process-use-modules `((,module)))) | |
77 | (lambda _ | |
78 | (raise | |
79 | (apply | |
80 | make-compound-condition | |
81 | (condition | |
82 | (&message | |
83 | (message (format #f (G_ "module ~a not found") | |
84 | module)))) | |
85 | (condition | |
86 | (&error-location (location location))) | |
87 | (or (and=> (make-hint module) list) | |
88 | '())))))) | |
89 | modules)) | |
90 | ||
91 | (define (package-module-hint module) | |
92 | (define last-name | |
93 | (match module | |
94 | ((_ ... last) | |
95 | (symbol->string last)))) | |
96 | ||
97 | (match (find-packages-by-name last-name) | |
98 | (() | |
99 | (condition | |
100 | (&fix-hint | |
101 | (hint (G_ "\ | |
102 | You may use @command{guix package --show=foo | grep location} to search | |
103 | for the location of package @code{foo}. | |
104 | If you get the line @code{location: gnu/packages/bar.scm:174:2}, | |
105 | add @code{bar} to the @code{use-package-modules} form."))))) | |
106 | ((package _ ...) | |
107 | (condition | |
108 | (&fix-hint | |
109 | (hint (format #f (G_ "\ | |
110 | Try adding @code{(use-package-modules ~a)}.") | |
111 | (basename (location-file (package-location package)) | |
112 | ".scm")))))))) | |
113 | ||
114 | (define (service-module-hint module) | |
115 | (define last-name | |
116 | (match module | |
117 | ((_ ... last) | |
118 | last))) | |
119 | ||
120 | (match (lookup-service-types last-name) | |
121 | (() | |
122 | (condition | |
123 | (&fix-hint | |
124 | (hint (format #f (G_ "\ | |
125 | You may use @command{guix system search ~a} to search for a service | |
126 | matching @code{~a}. | |
127 | If you get the line @code{location: gnu/services/foo.scm:188:2}, | |
128 | add @code{foo} to the @code{use-service-modules} form.") | |
129 | last-name last-name))))) | |
130 | ((package _ ...) | |
131 | (condition | |
132 | (&fix-hint | |
133 | (hint (format #f (G_ "\ | |
134 | Try adding @code{(use-service-modules ~a)}.") | |
135 | (basename (location-file (service-type-location package)) | |
136 | ".scm")))))))) | |
137 | ||
138 | (define-syntax-rule (try-use-modules hint modules ...) | |
139 | (eval-when (expand load eval) | |
140 | (%try-use-modules '(modules ...) | |
141 | (source-properties->location | |
142 | (current-source-location)) | |
143 | hint))) | |
144 | ||
fbb02045 | 145 | (define-syntax-rule (use-package-modules module ...) |
c5a4a92f LC |
146 | (try-use-modules package-module-hint |
147 | (gnu packages module) ...)) | |
fbb02045 JG |
148 | |
149 | (define-syntax-rule (use-service-modules module ...) | |
c5a4a92f LC |
150 | (try-use-modules service-module-hint |
151 | (gnu services module) ...)) | |
fbb02045 JG |
152 | |
153 | (define-syntax-rule (use-system-modules module ...) | |
c5a4a92f LC |
154 | (try-use-modules (const #f) ;no hint |
155 | (gnu system module) ...)) | |
fbb02045 | 156 | |
c9384945 | 157 | ;;; gnu.scm ends here |