1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
4 ;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
6 ;;; This file is part of GNU Guix.
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.
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.
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/>.
21 (define-module (guix scripts package)
22 #:use-module (guix ui)
23 #:use-module (guix store)
24 #:use-module (guix derivations)
25 #:use-module (guix packages)
26 #:use-module (guix utils)
27 #:use-module (guix config)
28 #:use-module ((guix build utils) #:select (directory-exists? mkdir-p))
29 #:use-module (ice-9 ftw)
30 #:use-module (ice-9 format)
31 #:use-module (ice-9 match)
32 #:use-module (ice-9 regex)
33 #:use-module (ice-9 vlist)
34 #:use-module (srfi srfi-1)
35 #:use-module (srfi srfi-11)
36 #:use-module (srfi srfi-26)
37 #:use-module (srfi srfi-34)
38 #:use-module (srfi srfi-37)
39 #:use-module (gnu packages)
40 #:use-module ((gnu packages base) #:select (guile-final))
41 #:use-module ((gnu packages bootstrap) #:select (%bootstrap-guile))
42 #:use-module (guix gnu-maintenance)
43 #:export (guix-package))
53 (define %user-environment-directory
54 (and=> (getenv "HOME")
55 (cut string-append <> "/.guix-profile")))
57 (define %profile-directory
58 (string-append (or (getenv "NIX_STATE_DIR") %state-directory) "/profiles/"
59 (or (and=> (getenv "USER")
60 (cut string-append "per-user/" <>))
63 (define %current-profile
64 ;; Call it `guix-profile', not `profile', to allow Guix profiles to
65 ;; coexist with Nix profiles.
66 (string-append %profile-directory "/guix-profile"))
68 (define (profile-manifest profile)
69 "Return the PROFILE's manifest."
70 (let ((manifest (string-append profile "/manifest")))
71 (if (file-exists? manifest)
72 (call-with-input-file manifest read)
73 '(manifest (version 1) (packages ())))))
75 (define (manifest-packages manifest)
76 "Return the packages listed in MANIFEST."
78 (('manifest ('version 0)
79 ('packages ((name version output path) ...)))
80 (zip name version output path
81 (make-list (length name) '())))
83 ;; Version 1 adds a list of propagated inputs to the
84 ;; name/version/output/path tuples.
85 (('manifest ('version 1)
86 ('packages (packages ...)))
90 (error "unsupported manifest format" manifest))))
92 (define (profile-regexp profile)
93 "Return a regular expression that matches PROFILE's name and number."
94 (make-regexp (string-append "^" (regexp-quote (basename profile))
97 (define (profile-numbers profile)
98 "Return the list of generation numbers of PROFILE, or '(0) if no
99 former profiles were found."
100 (define* (scandir name #:optional (select? (const #t))
101 (entry<? (@ (ice-9 i18n) string-locale<?)))
102 ;; XXX: Bug-fix version introduced in Guile v2.0.6-62-g139ce19.
103 (define (enter? dir stat result)
104 (and stat (string=? dir name)))
106 (define (visit basename result)
107 (if (select? basename)
108 (cons basename result)
111 (define (leaf name stat result)
113 (visit (basename name) result)))
115 (define (down name stat result)
118 (define (up name stat result)
121 (define (skip name stat result)
122 ;; All the sub-directories are skipped.
123 (visit (basename name) result))
125 (define (error name* stat errno result)
126 (if (string=? name name*) ; top-level NAME is unreadable
128 (visit (basename name*) result)))
130 (and=> (file-system-fold enter? leaf down up skip error #f name lstat)
132 (sort files entry<?))))
134 (match (scandir (dirname profile)
135 (cute regexp-exec (profile-regexp profile) <>))
136 (#f ; no profile directory
140 ((profiles ...) ; former profiles around
141 (map (compose string->number
142 (cut match:substring <> 1)
143 (cute regexp-exec (profile-regexp profile) <>))
146 (define (previous-profile-number profile number)
147 "Return the number of the generation before generation NUMBER of
148 PROFILE, or 0 if none exists. It could be NUMBER - 1, but it's not the
149 case when generations have been deleted (there are \"holes\")."
150 (fold (lambda (candidate highest)
151 (if (and (< candidate number) (> candidate highest))
155 (profile-numbers profile)))
157 (define (profile-derivation store packages)
158 "Return a derivation that builds a profile (a user environment) with
159 all of PACKAGES, a list of name/version/output/path/deps tuples."
161 ;; Turn any package object in PACKAGES into its output path.
163 ((name version output path (deps ...))
164 `(,name ,version ,output ,path
165 ,(map input->name+path deps))))
170 (use-modules (ice-9 pretty-print)
173 (setvbuf (current-output-port) _IOLBF)
174 (setvbuf (current-error-port) _IOLBF)
176 (let ((output (assoc-ref %outputs "out"))
177 (inputs (map cdr %build-inputs)))
178 (format #t "building user environment `~a' with ~a packages...~%"
179 output (length inputs))
180 (union-build output inputs)
181 (call-with-output-file (string-append output "/manifest")
183 (pretty-print '(manifest (version 1)
184 (packages ,packages*))
187 (define ensure-valid-input
188 ;; If a package object appears in the given input, turn it into a
191 ((name (? package? p) sub-drv ...)
192 `(,name ,(package-derivation (%store) p) ,@sub-drv))
196 (build-expression->derivation store "user-environment"
199 (append-map (match-lambda
200 ((name version output path deps)
202 ,@(map ensure-valid-input
205 #:modules '((guix build union))))
207 (define (profile-number profile)
208 "Return PROFILE's number or 0. An absolute file name must be used."
209 (or (and=> (false-if-exception (regexp-exec (profile-regexp profile)
210 (basename (readlink profile))))
211 (compose string->number (cut match:substring <> 1)))
214 (define (roll-back profile)
215 "Roll back to the previous generation of PROFILE."
216 (let* ((number (profile-number profile))
217 (previous-number (previous-profile-number profile number))
218 (previous-profile (format #f "~a-~a-link"
219 profile previous-number))
220 (manifest (string-append previous-profile "/manifest")))
222 (define (switch-link)
223 ;; Atomically switch PROFILE to the previous profile.
224 (format #t (_ "switching from generation ~a to ~a~%")
225 number previous-number)
226 (switch-symlinks profile previous-profile))
228 (cond ((not (file-exists? profile)) ; invalid profile
229 (leave (_ "profile `~a' does not exist~%")
231 ((zero? number) ; empty profile
232 (format (current-error-port)
233 (_ "nothing to do: already at the empty profile~%")))
234 ((or (zero? previous-number) ; going to emptiness
235 (not (file-exists? previous-profile)))
236 (let*-values (((drv-path drv)
237 (profile-derivation (%store) '()))
239 (derivation-output-path
240 (assoc-ref (derivation-outputs drv) "out"))))
241 (when (not (build-derivations (%store) (list drv-path)))
242 (leave (_ "failed to build the empty profile~%")))
244 (switch-symlinks previous-profile prof)
246 (else (switch-link))))) ; anything else
248 (define (find-packages-by-description rx)
249 "Search in SYNOPSIS and DESCRIPTION using RX. Return a list of
251 (define (same-location? p1 p2)
252 ;; Compare locations of two packages.
253 (equal? (package-location p1) (package-location p2)))
257 (fold-packages (lambda (package result)
259 (cut regexp-exec rx <>))
261 (if (or (and=> (package-synopsis package)
262 (compose matches? gettext))
263 (and=> (package-description package)
264 (compose matches? gettext)))
265 (cons package result)
269 (string<? (package-name p1)
273 (define (input->name+path input)
274 "Convert the name/package/sub-drv tuple INPUT to a name/store-path tuple."
275 (let loop ((input input))
277 ((name (? package? package))
278 (loop `(,name ,package "out")))
279 ((name (? package? package) sub-drv)
280 `(,name ,(package-output (%store) package sub-drv)))
284 (define %sigint-prompt
285 ;; The prompt to jump to upon SIGINT.
286 (make-prompt-tag "interruptible"))
288 (define (call-with-sigint-handler thunk handler)
289 "Call THUNK and return its value. Upon SIGINT, call HANDLER with the signal
290 number in the context of the continuation of the call to this function, and
291 return its return value."
292 (call-with-prompt %sigint-prompt
296 (sigaction SIGINT SIG_DFL)
297 (abort-to-prompt %sigint-prompt signum)))
301 (cut sigaction SIGINT SIG_DFL)))
305 (define-syntax-rule (waiting exp fmt rest ...)
306 "Display the given message while EXP is being evaluated."
307 (let* ((message (format #f fmt rest ...))
308 (blank (make-string (string-length message) #\space)))
309 (display message (current-error-port))
310 (force-output (current-error-port))
311 (call-with-sigint-handler
318 (display #\cr (current-error-port))
319 (display blank (current-error-port))
320 (display #\cr (current-error-port))
321 (force-output (current-error-port)))))
323 (format (current-error-port) " interrupted by signal ~a~%" SIGINT)
326 (define (check-package-freshness package)
327 "Check whether PACKAGE has a newer version available upstream, and report
329 ;; TODO: Automatically inject the upstream version when desired.
333 (when (false-if-exception (gnu-package? package))
334 (let ((name (package-name package))
335 (full-name (package-full-name package)))
336 (match (waiting (latest-release name)
337 (_ "looking for the latest release of GNU ~a...") name)
338 ((latest-version . _)
339 (when (version>? latest-version full-name)
340 (format (current-error-port)
341 (_ "~a: note: using ~a \
342 but ~a is available upstream~%")
343 (location->string (package-location package))
344 full-name latest-version)))
347 ;; Silently ignore networking errors rather than preventing
350 ((getaddrinfo-error ftp-error) #f)
351 (else (apply throw key args))))))
353 (define* (search-path-environment-variables packages profile
354 #:optional (getenv getenv))
355 "Return environment variable definitions that may be needed for the use of
356 PACKAGES in PROFILE. Use GETENV to determine the current settings and report
357 only settings not already effective."
359 ;; Prefer ~/.guix-profile to the real profile directory name.
360 (let ((profile (if (and %user-environment-directory
362 (string=? (readlink %user-environment-directory)
364 %user-environment-directory
367 ;; The search path info is not stored in the manifest. Thus, we infer the
368 ;; search paths from same-named packages found in the distro.
370 (define package-in-manifest->package
372 ((name version _ ...)
373 (match (append (find-packages-by-name name version)
374 (find-packages-by-name name))
378 (define search-path-definition
380 (($ <search-path-specification> variable directories separator)
381 (let ((values (or (and=> (getenv variable)
382 (cut string-tokenize* <> separator))
384 (directories (filter file-exists?
385 (map (cut string-append profile
388 (if (every (cut member <> values) directories)
390 (format #f "export ~a=\"~a\""
392 (string-join directories separator)))))))
394 (let* ((packages (filter-map package-in-manifest->package packages))
395 (search-paths (delete-duplicates
396 (append-map package-native-search-paths
398 (filter-map search-path-definition search-paths))))
400 (define (display-search-paths packages profile)
401 "Display the search path environment variables that may need to be set for
402 PACKAGES, in the context of PROFILE."
403 (let ((settings (search-path-environment-variables packages profile)))
404 (unless (null? settings)
405 (format #t (_ "The following environment variable definitions may be needed:~%"))
406 (format #t "~{ ~a~%~}" settings))))
410 ;;; Command-line options.
413 (define %default-options
414 ;; Alist of default option values.
415 `((profile . ,%current-profile)
416 (max-silent-time . 3600)
417 (substitutes? . #t)))
420 (display (_ "Usage: guix package [OPTION]... PACKAGES...
421 Install, remove, or upgrade PACKAGES in a single transaction.\n"))
423 -i, --install=PACKAGE install PACKAGE"))
425 -e, --install-from-expression=EXP
426 install the package EXP evaluates to"))
428 -r, --remove=PACKAGE remove PACKAGE"))
430 -u, --upgrade[=REGEXP] upgrade all the installed packages matching REGEXP"))
432 --roll-back roll back to the previous generation"))
434 --search-paths display needed environment variable definitions"))
437 -p, --profile=PROFILE use PROFILE instead of the user's default profile"))
439 -n, --dry-run show what would be done without actually doing it"))
441 --fallback fall back to building when the substituter fails"))
443 --no-substitutes build instead of resorting to pre-built substitutes"))
445 --max-silent-time=SECONDS
446 mark the build as failed after SECONDS of silence"))
448 --bootstrap use the bootstrap Guile to build the profile"))
450 --verbose produce verbose output"))
453 -s, --search=REGEXP search in synopsis and description using REGEXP"))
455 -I, --list-installed[=REGEXP]
456 list installed packages matching REGEXP"))
458 -A, --list-available[=REGEXP]
459 list available packages matching REGEXP"))
462 -h, --help display this help and exit"))
464 -V, --version display version information and exit"))
466 (show-bug-report-information))
469 ;; Specification of the command-line options.
470 (list (option '(#\h "help") #f #f
474 (option '(#\V "version") #f #f
476 (show-version-and-exit "guix package")))
478 (option '(#\i "install") #t #f
479 (lambda (opt name arg result)
480 (alist-cons 'install arg result)))
481 (option '(#\e "install-from-expression") #t #f
482 (lambda (opt name arg result)
483 (alist-cons 'install (read/eval-package-expression arg)
485 (option '(#\r "remove") #t #f
486 (lambda (opt name arg result)
487 (alist-cons 'remove arg result)))
488 (option '(#\u "upgrade") #f #t
489 (lambda (opt name arg result)
490 (alist-cons 'upgrade arg result)))
491 (option '("roll-back") #f #f
492 (lambda (opt name arg result)
493 (alist-cons 'roll-back? #t result)))
494 (option '("search-paths") #f #f
495 (lambda (opt name arg result)
496 (cons `(query search-paths) result)))
497 (option '(#\p "profile") #t #f
498 (lambda (opt name arg result)
499 (alist-cons 'profile arg
500 (alist-delete 'profile result))))
501 (option '(#\n "dry-run") #f #f
502 (lambda (opt name arg result)
503 (alist-cons 'dry-run? #t result)))
504 (option '("fallback") #f #f
505 (lambda (opt name arg result)
506 (alist-cons 'fallback? #t
507 (alist-delete 'fallback? result))))
508 (option '("no-substitutes") #f #f
509 (lambda (opt name arg result)
510 (alist-cons 'substitutes? #f
511 (alist-delete 'substitutes? result))))
512 (option '("max-silent-time") #t #f
513 (lambda (opt name arg result)
514 (alist-cons 'max-silent-time (string->number* arg)
516 (option '("bootstrap") #f #f
517 (lambda (opt name arg result)
518 (alist-cons 'bootstrap? #t result)))
519 (option '("verbose") #f #f
520 (lambda (opt name arg result)
521 (alist-cons 'verbose? #t result)))
522 (option '(#\s "search") #t #f
523 (lambda (opt name arg result)
524 (cons `(query search ,(or arg ""))
526 (option '(#\I "list-installed") #f #t
527 (lambda (opt name arg result)
528 (cons `(query list-installed ,(or arg ""))
530 (option '(#\A "list-available") #f #t
531 (lambda (opt name arg result)
532 (cons `(query list-available ,(or arg ""))
540 (define (guix-package . args)
541 (define (parse-options)
542 ;; Return the alist of option values.
543 (args-fold* args %options
544 (lambda (opt name arg result)
545 (leave (_ "~A: unrecognized option~%") name))
547 (leave (_ "~A: extraneous argument~%") arg))
550 (define (guile-missing?)
551 ;; Return #t if %GUILE-FOR-BUILD is not available yet.
552 (let ((out (derivation-path->output-path (%guile-for-build))))
553 (not (valid-path? (%store) out))))
555 (define newest-available-packages
556 (memoize find-newest-available-packages))
558 (define (find-best-packages-by-name name version)
560 (find-packages-by-name name version)
561 (match (vhash-assoc name (newest-available-packages))
562 ((_ version pkgs ...) pkgs)
565 (define* (find-package name #:optional (output "out"))
566 ;; Find the package NAME; NAME may contain a version number and a
567 ;; sub-derivation name. If the version number is not present,
568 ;; return the preferred newest version. If the sub-derivation name is not
569 ;; present, use OUTPUT.
570 (define request name)
572 (define (ensure-output p sub-drv)
573 (if (member sub-drv (package-outputs p))
575 (leave (_ "package `~a' lacks output `~a'~%")
576 (package-full-name p)
579 (let*-values (((name sub-drv)
580 (match (string-rindex name #\:)
581 (#f (values name output))
582 (colon (values (substring name 0 colon)
583 (substring name (+ 1 colon))))))
585 (package-name->name+version name)))
586 (match (find-best-packages-by-name name version)
588 (list name (package-version p) sub-drv (ensure-output p sub-drv)
589 (package-transitive-propagated-inputs p)))
591 (warning (_ "ambiguous package specification `~a'~%")
593 (warning (_ "choosing ~a from ~a~%")
594 (package-full-name p)
595 (location->string (package-location p)))
596 (list name (package-version p) sub-drv (ensure-output p sub-drv)
597 (package-transitive-propagated-inputs p)))
599 (leave (_ "~a: package not found~%") request)))))
601 (define (upgradeable? name current-version current-path)
602 ;; Return #t if there's a version of package NAME newer than
603 ;; CURRENT-VERSION, or if the newest available version is equal to
604 ;; CURRENT-VERSION but would have an output path different than
606 (match (vhash-assoc name (newest-available-packages))
607 ((_ candidate-version pkg . rest)
608 (case (version-compare candidate-version current-version)
611 ((=) (let ((candidate-path (derivation-path->output-path
612 (package-derivation (%store) pkg))))
613 (not (string=? current-path candidate-path))))))
616 (define (ensure-default-profile)
617 ;; Ensure the default profile symlink and directory exist and are
621 (format (current-error-port)
622 (_ "Try \"info '(guix) Invoking guix package'\" for \
623 more information.~%"))
626 ;; Create ~/.guix-profile if it doesn't exist yet.
627 (when (and %user-environment-directory
629 (not (false-if-exception
630 (lstat %user-environment-directory))))
631 (symlink %current-profile %user-environment-directory))
633 (let ((s (stat %profile-directory #f)))
634 ;; Attempt to create /…/profiles/per-user/$USER if needed.
635 (unless (and s (eq? 'directory (stat:type s)))
638 (mkdir-p %profile-directory))
640 ;; Often, we cannot create %PROFILE-DIRECTORY because its
641 ;; parent directory is root-owned and we're running
643 (format (current-error-port)
644 (_ "error: while creating directory `~a': ~a~%")
646 (strerror (system-error-errno args)))
647 (format (current-error-port)
648 (_ "Please create the `~a' directory, with you as the owner.~%")
652 ;; Bail out if it's not owned by the user.
653 (unless (or (not s) (= (stat:uid s) (getuid)))
654 (format (current-error-port)
655 (_ "error: directory `~a' is not owned by you~%")
657 (format (current-error-port)
658 (_ "Please change the owner of `~a' to user ~s.~%")
659 %profile-directory (or (getenv "USER") (getuid)))
662 (define (process-actions opts)
663 ;; Process any install/remove/upgrade action from OPTS.
665 (define dry-run? (assoc-ref opts 'dry-run?))
666 (define verbose? (assoc-ref opts 'verbose?))
667 (define profile (assoc-ref opts 'profile))
669 (define (canonicalize-deps deps)
670 ;; Remove duplicate entries from DEPS, a list of propagated inputs,
671 ;; where each input is a name/path tuple.
672 (define (same? d1 d2)
681 (and (string=? out1 out2)
685 (delete-duplicates deps same?))
687 (define (package->tuple p)
688 ;; Convert package P to a tuple.
689 ;; When given a package via `-e', install the first of its
691 (let* ((out (car (package-outputs p)))
692 (path (package-output (%store) p out))
693 (deps (package-transitive-propagated-inputs p)))
698 ,(canonicalize-deps deps))))
700 (define (show-what-to-remove/install remove install dry-run?)
701 ;; Tell the user what's going to happen in high-level terms.
702 ;; TODO: Report upgrades more clearly.
704 (((name version _ path _) ..1)
705 (let ((len (length name))
706 (remove (map (cut format #f " ~a-~a\t~a" <> <> <>)
709 (format (current-error-port)
710 (N_ "The following package would be removed:~% ~{~a~%~}~%"
711 "The following packages would be removed:~% ~{~a~%~}~%"
714 (format (current-error-port)
715 (N_ "The following package will be removed:~% ~{~a~%~}~%"
716 "The following packages will be removed:~% ~{~a~%~}~%"
721 (((name version output path _) ..1)
722 (let ((len (length name))
723 (install (map (cut format #f " ~a-~a\t~a\t~a" <> <> <> <>)
724 name version output path)))
726 (format (current-error-port)
727 (N_ "The following package would be installed:~%~{~a~%~}~%"
728 "The following packages would be installed:~%~{~a~%~}~%"
731 (format (current-error-port)
732 (N_ "The following package will be installed:~%~{~a~%~}~%"
733 "The following packages will be installed:~%~{~a~%~}~%"
738 ;; First roll back if asked to.
739 (if (and (assoc-ref opts 'roll-back?) (not dry-run?))
742 (process-actions (alist-delete 'roll-back? opts)))
743 (let* ((installed (manifest-packages (profile-manifest profile)))
744 (upgrade-regexps (filter-map (match-lambda
746 (make-regexp (or regexp "")))
749 (upgrade (if (null? upgrade-regexps)
751 (let ((newest (find-newest-available-packages)))
752 (filter-map (match-lambda
753 ((name version output path _)
754 (and (any (cut regexp-exec <> name)
756 (upgradeable? name version path)
763 (filter-map (match-lambda
764 (('install . (? package? p))
766 (('install . (? store-path?))
768 (('install . package)
769 (find-package package))
772 (drv (filter-map (match-lambda
773 ((name version sub-drv
776 (check-package-freshness package)
777 (package-derivation (%store) package))
781 (filter-map (match-lambda
782 (('install . (? package? p))
784 (('install . (? store-path? path))
785 (let-values (((name version)
786 (package-name->name+version
787 (store-path-package-name
789 `(,name ,version #f ,path ())))
792 (map (lambda (tuple drv)
794 ((name version sub-drv _ (deps ...))
796 (derivation-path->output-path
798 `(,name ,version ,sub-drv ,output-path
799 ,(canonicalize-deps deps))))))
801 (remove (filter-map (match-lambda
806 (remove* (filter-map (cut assoc <> installed) remove))
807 (packages (append install*
808 (fold (lambda (package result)
811 (alist-delete name result))))
812 (fold alist-delete installed remove)
815 (when (equal? profile %current-profile)
816 (ensure-default-profile))
818 (show-what-to-remove/install remove* install* dry-run?)
819 (show-what-to-build (%store) drv
820 #:use-substitutes? (assoc-ref opts 'substitutes?)
824 (and (build-derivations (%store) drv)
825 (let* ((prof-drv (profile-derivation (%store) packages))
826 (prof (derivation-path->output-path prof-drv))
827 (old-drv (profile-derivation
828 (%store) (manifest-packages
829 (profile-manifest profile))))
830 (old-prof (derivation-path->output-path old-drv))
831 (number (profile-number profile))
833 ;; Always use NUMBER + 1 for the new profile,
834 ;; possibly overwriting a "previous future
836 (name (format #f "~a-~a-link"
837 profile (+ 1 number))))
838 (if (string=? old-prof prof)
839 (when (or (pair? install) (pair? remove))
840 (format (current-error-port)
841 (_ "nothing to be done~%")))
842 (and (parameterize ((current-build-output-port
843 ;; Output something when Guile
844 ;; needs to be built.
845 (if (or verbose? (guile-missing?))
847 (%make-void-port "w"))))
848 (build-derivations (%store) (list prof-drv)))
849 (let ((count (length packages)))
850 (switch-symlinks name prof)
851 (switch-symlinks profile name)
852 (format #t (N_ "~a package in profile~%"
853 "~a packages in profile~%"
856 (display-search-paths packages
859 (define (process-query opts)
860 ;; Process any query specified by OPTS. Return #t when a query was
861 ;; actually processed, #f otherwise.
862 (let ((profile (assoc-ref opts 'profile)))
863 (match (assoc-ref opts 'query)
864 (('list-installed regexp)
865 (let* ((regexp (and regexp (make-regexp regexp)))
866 (manifest (profile-manifest profile))
867 (installed (manifest-packages manifest)))
868 (for-each (match-lambda
869 ((name version output path _)
870 (when (or (not regexp)
871 (regexp-exec regexp name))
872 (format #t "~a\t~a\t~a\t~a~%"
873 name (or version "?") output path))))
877 (('list-available regexp)
878 (let* ((regexp (and regexp (make-regexp regexp)))
879 (available (fold-packages
881 (let ((n (package-name p)))
883 (if (regexp-exec regexp n)
888 (for-each (lambda (p)
889 (format #t "~a\t~a\t~a\t~a~%"
892 (string-join (package-outputs p) ",")
893 (location->string (package-location p))))
896 (string<? (package-name p1)
897 (package-name p2)))))
901 (let ((regexp (make-regexp regexp regexp/icase)))
902 (for-each (cute package->recutils <> (current-output-port))
903 (find-packages-by-description regexp))
907 (let* ((manifest (profile-manifest profile))
908 (packages (manifest-packages manifest))
909 (settings (search-path-environment-variables packages
912 (format #t "~{~a~%~}" settings)
917 (let ((opts (parse-options)))
918 (or (process-query opts)
920 (parameterize ((%store (open-connection)))
921 (set-build-options (%store)
922 #:fallback? (assoc-ref opts 'fallback?)
924 (assoc-ref opts 'substitutes?)
926 (assoc-ref opts 'max-silent-time))
928 (parameterize ((%guile-for-build
929 (package-derivation (%store)
930 (if (assoc-ref opts 'bootstrap?)
933 (process-actions opts)))))))