From e092725c05625f1b6c5705177b3f080471611e85 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 7 Nov 2017 11:46:34 +0100 Subject: [PATCH] Catch use-modules errors in configuration. * gnu.scm (use-package-modules, use-service-modules, use-system-modules): Catch use-modules errors and show a small explanation about it. --- gnu.scm | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/gnu.scm b/gnu.scm index 913ce6160..1ae5f2d1d 100644 --- a/gnu.scm +++ b/gnu.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès ;;; Copyright © 2015 Joshua S. Grant ;;; Copyright © 2017 Mathieu Othacehe +;;; Copyright © 2017 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -52,13 +53,48 @@ (module-use! i (resolve-interface m)))) %public-modules))) +(define (import-error type module syntax) + (define package-hint + (string-append + "Hint: You may use `guix package --show=foo | grep location` to search\n" + "Hint: for foo's location.\n" + "Hint: If you get the line \"location: gnu/packages/bar.scm:174:2\",\n" + "Hint: you want to add bar in use-package-modules.")) + (define service-hint + (string-append + "Hint: You may use `guix system search foo` to search for foo's location.\n" + "Hint: If you get the line \"location: gnu/services/bar.scm:188:2\",\n" + "Hint: you want to add bar in use-service-modules.")) + (error (string-append + type " module \"" module "\" does not exist.\n" + "Check the \"" syntax "\" line in your configuration.\n" + (if (equal? type "Package") + package-hint + (if (equal? type "Service") + service-hint + ""))))) + (define-syntax-rule (use-package-modules module ...) - (use-modules (gnu packages module) ...)) + (begin + (catch #t (lambda () (use-modules (gnu packages module))) + (lambda _ + (import-error "Package" (symbol->string 'module) "use-package-modules"))) + ...)) (define-syntax-rule (use-service-modules module ...) - (use-modules (gnu services module) ...)) + (begin + (catch #t (lambda () (use-modules (gnu services module))) + (lambda _ + (import-error "Service" (symbol->string 'module) "use-service-modules"))) + ...)) + (define-syntax-rule (use-system-modules module ...) - (use-modules (gnu system module) ...)) + (begin + (catch #t (lambda () (use-modules (gnu system module))) + (lambda _ + (import-error "System" (symbol->string 'module) "use-system-modules"))) + ...)) + ;;; gnu.scm ends here -- 2.13.6