diff --git a/guix/gexp.scm b/guix/gexp.scm
index 732327751187246870d238ff2f257a0ae912560b..fa74e80cd60d1aaf06e4032cf1d4ea4fce7bda94 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -654,6 +654,28 @@ (define-record-type <lowered-gexp>
   (load-path           lowered-gexp-load-path)    ;list of store items
   (load-compiled-path  lowered-gexp-load-compiled-path)) ;list of store items
 
+(define* (imported+compiled-modules modules system
+                                    #:key (extensions '())
+                                    deprecation-warnings guile
+                                    (module-path %load-path))
+  "Return a pair where the first element is the imported MODULES and the
+second element is the derivation to compile them."
+  (mlet %store-monad ((modules  (if (pair? modules)
+                                    (imported-modules modules
+                                                      #:system system
+                                                      #:module-path module-path)
+                                    (return #f)))
+                      (compiled (if (pair? modules)
+                                    (compiled-modules modules
+                                                      #:system system
+                                                      #:module-path module-path
+                                                      #:extensions extensions
+                                                      #:guile guile
+                                                      #:deprecation-warnings
+                                                      deprecation-warnings)
+                                    (return #f))))
+    (return (cons modules compiled))))
+
 (define* (lower-gexp exp
                      #:key
                      (module-path %load-path)
@@ -719,20 +741,15 @@ (define (search-path modules extensions suffix)
                                        (lambda (obj)
                                          (lower-object obj system))
                                        extensions))
-                       (modules  (if (pair? %modules)
-                                     (imported-modules %modules
-                                                       #:system system
-                                                       #:module-path module-path)
-                                     (return #f)))
-                       (compiled (if (pair? %modules)
-                                     (compiled-modules %modules
-                                                       #:system system
-                                                       #:module-path module-path
-                                                       #:extensions extensions
-                                                       #:guile guile
-                                                       #:deprecation-warnings
-                                                       deprecation-warnings)
-                                     (return #f))))
+                       (modules+compiled (imported+compiled-modules
+                                          %modules system
+                                          #:extensions extensions
+                                          #:deprecation-warnings
+                                          deprecation-warnings
+                                          #:guile guile
+                                          #:module-path module-path))
+                       (modules ->  (car modules+compiled))
+                       (compiled -> (cdr modules+compiled)))
     (define load-path
       (search-path modules exts
                    (string-append "/share/guile/site/" effective-version)))