| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 |
|
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 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) |
| 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))) |
| 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_ "\
|
| 94 | You may use @command{guix package --show=foo | grep location} to search
|
| 95 | for the location of package @code{foo}.
|
| 96 | If you get the line @code{location: gnu/packages/bar.scm:174:2},
|
| 97 | add @code{bar} to the @code{use-package-modules} form.")))))
|
| 98 | ((package _ ...)
|
| 99 | (condition
|
| 100 | (&fix-hint
|
| 101 | (hint (format #f (G_ "\
|
| 102 | Try 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_ "\
|
| 117 | You may use @command{guix system search ~a} to search for a service
|
| 118 | matching @code{~a}.
|
| 119 | If you get the line @code{location: gnu/services/foo.scm:188:2},
|
| 120 | add @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_ "\
|
| 126 | Try 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) |
| 147 | (gnu system module) ...))
|
| 148 |
|
| 149 | |