diff --git a/guix/packages.scm b/guix/packages.scm index c94a651f27..7d5c8198ac 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -26,6 +26,7 @@ #:use-module (guix store) #:use-module (guix monads) #:use-module (guix gexp) + #:use-module (guix modules) #:use-module (guix base32) #:use-module (guix grafts) #:use-module (guix derivations) @@ -749,6 +750,64 @@ recursively." '())) (package-transitive-propagated-inputs package)))) +(define (package-run-time-search-paths package) + "Return a file that contains a list of search path specifications +corresponding to the run-time references of PACKAGE." + (define search-paths + (map (lambda (package) + (cons (package-full-name package "-") + (map search-path-specification->sexp + (package-native-search-paths package)))) + (package-closure (list package)))) + + (define build + (with-imported-modules (source-module-closure + '((guix build utils) + (guix search-paths) + (guix build store-copy))) + #~(begin + (use-modules (guix build utils) + (guix build store-copy) + (guix search-paths) + (srfi srfi-1) + (ice-9 match) + (ice-9 pretty-print)) + + (define search-paths + ;; Map items like "coreutils-8.20" to their search path specs. + (map (match-lambda + ((item . paths) + (cons item (map sexp->search-path-specification paths)))) + '#$search-paths)) + + (define (store-item-search-paths item) + "Return the search paths that apply to ITEM, a store item." + (or (any (match-lambda + ((entry . paths) + (and (string-suffix? entry item) + paths))) + search-paths) + '())) + + (let* ((references (map store-info-item + (call-with-input-file "graph" + read-reference-graph))) + (paths (delete-duplicates + (append-map store-item-search-paths + references)))) + (call-with-output-file #$output + (lambda (port) + (pretty-print (map search-path-specification->sexp + paths) + port))))))) + + (computed-file (string-append (package-full-name package "-") + "-search-paths") + build + #:options + `(#:references-graphs (("graph" ,package)) + #:properties '((type . search-paths))))) + (define (transitive-input-references alist inputs) "Return a list of (assoc-ref ALIST