2018-09-03 15:03:33 +02:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
|
2018-11-21 14:45:08 +01:00
|
|
|
|
;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
|
2018-09-03 15:03:33 +02:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (guix scripts describe)
|
|
|
|
|
#:use-module ((guix ui) #:hide (display-profile-content))
|
2018-11-21 14:45:08 +01:00
|
|
|
|
#:use-module (guix channels)
|
2018-09-03 15:03:33 +02:00
|
|
|
|
#:use-module (guix scripts)
|
|
|
|
|
#:use-module (guix describe)
|
|
|
|
|
#:use-module (guix profiles)
|
|
|
|
|
#:use-module ((guix scripts pull) #:select (display-profile-content))
|
|
|
|
|
#:use-module (git)
|
2018-11-21 14:47:43 +01:00
|
|
|
|
#:use-module (json)
|
2018-09-03 15:03:33 +02:00
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-37)
|
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:autoload (ice-9 pretty-print) (pretty-print)
|
|
|
|
|
#:export (guix-describe))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Command-line options.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define %options
|
|
|
|
|
;; Specifications of the command-line options.
|
|
|
|
|
(list (option '(#\f "format") #t #f
|
|
|
|
|
(lambda (opt name arg result)
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(unless (member arg '("human" "channels" "json" "recutils"))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(leave (G_ "~a: unsupported output format~%") arg))
|
2018-11-20 23:19:54 +01:00
|
|
|
|
(alist-cons 'format (string->symbol arg) result)))
|
2018-11-21 09:23:25 +01:00
|
|
|
|
(option '(#\p "profile") #t #f
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(alist-cons 'profile (canonicalize-profile arg)
|
|
|
|
|
result)))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(option '(#\h "help") #f #f
|
|
|
|
|
(lambda args
|
|
|
|
|
(show-help)
|
|
|
|
|
(exit 0)))
|
|
|
|
|
(option '(#\V "version") #f #f
|
|
|
|
|
(lambda args
|
|
|
|
|
(show-version-and-exit "guix describe")))))
|
|
|
|
|
|
|
|
|
|
(define %default-options
|
|
|
|
|
;; Alist of default option values.
|
|
|
|
|
'((format . human)))
|
|
|
|
|
|
|
|
|
|
(define (show-help)
|
|
|
|
|
(display (G_ "Usage: guix describe [OPTION]...
|
|
|
|
|
Display information about the channels currently in use.\n"))
|
|
|
|
|
(display (G_ "
|
|
|
|
|
-f, --format=FORMAT display information in the given FORMAT"))
|
2018-11-21 09:23:25 +01:00
|
|
|
|
(display (G_ "
|
|
|
|
|
-p, --profile=PROFILE display information about PROFILE"))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(newline)
|
|
|
|
|
(display (G_ "
|
|
|
|
|
-h, --help display this help and exit"))
|
|
|
|
|
(display (G_ "
|
|
|
|
|
-V, --version display version information and exit"))
|
|
|
|
|
(newline)
|
|
|
|
|
(show-bug-report-information))
|
|
|
|
|
|
|
|
|
|
(define (display-package-search-path fmt)
|
|
|
|
|
"Display GUIX_PACKAGE_PATH, if it is set, according to FMT."
|
|
|
|
|
(match (getenv "GUIX_PACKAGE_PATH")
|
|
|
|
|
(#f #t)
|
|
|
|
|
(string
|
|
|
|
|
(match fmt
|
|
|
|
|
('human
|
|
|
|
|
(format #t "~%GUIX_PACKAGE_PATH=\"~a\"~%" string))
|
|
|
|
|
('channels
|
|
|
|
|
(format #t (G_ "~%;; warning: GUIX_PACKAGE_PATH=\"~a\"~%")
|
|
|
|
|
string))))))
|
|
|
|
|
|
2018-11-21 14:45:08 +01:00
|
|
|
|
(define (channel->sexp channel)
|
|
|
|
|
`(channel
|
|
|
|
|
(name ,(channel-name channel))
|
|
|
|
|
(url ,(channel-url channel))
|
|
|
|
|
(commit ,(channel-commit channel))))
|
|
|
|
|
|
2018-11-21 14:47:43 +01:00
|
|
|
|
(define (channel->json channel)
|
|
|
|
|
(scm->json-string `((name . ,(channel-name channel))
|
|
|
|
|
(url . ,(channel-url channel))
|
|
|
|
|
(commit . ,(channel-commit channel)))))
|
|
|
|
|
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(define (channel->recutils channel port)
|
|
|
|
|
(format port "name: ~a~%" (channel-name channel))
|
|
|
|
|
(format port "url: ~a~%" (channel-url channel))
|
|
|
|
|
(format port "commit: ~a~%" (channel-commit channel)))
|
|
|
|
|
|
2018-11-21 15:21:22 +01:00
|
|
|
|
(define (display-checkout-info fmt)
|
2018-09-03 15:03:33 +02:00
|
|
|
|
"Display information about the current checkout according to FMT, a symbol
|
|
|
|
|
denoting the requested format. Exit if the current directory does not lie
|
|
|
|
|
within a Git checkout."
|
2018-11-21 15:21:22 +01:00
|
|
|
|
(let* ((program (car (command-line)))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(directory (catch 'git-error
|
|
|
|
|
(lambda ()
|
|
|
|
|
(repository-discover (dirname program)))
|
|
|
|
|
(lambda (key err)
|
|
|
|
|
(leave (G_ "failed to determine origin~%")))))
|
|
|
|
|
(repository (repository-open directory))
|
|
|
|
|
(head (repository-head repository))
|
|
|
|
|
(commit (oid->string (reference-target head))))
|
|
|
|
|
(match fmt
|
|
|
|
|
('human
|
|
|
|
|
(format #t (G_ "Git checkout:~%"))
|
|
|
|
|
(format #t (G_ " repository: ~a~%") (dirname directory))
|
|
|
|
|
(format #t (G_ " branch: ~a~%") (reference-shorthand head))
|
|
|
|
|
(format #t (G_ " commit: ~a~%") commit))
|
|
|
|
|
('channels
|
2018-11-21 14:45:08 +01:00
|
|
|
|
(pretty-print `(list ,(channel->sexp (channel (name 'guix)
|
|
|
|
|
(url (dirname directory))
|
2018-11-21 14:47:43 +01:00
|
|
|
|
(commit commit))))))
|
|
|
|
|
('json
|
|
|
|
|
(display (channel->json (channel (name 'guix)
|
|
|
|
|
(url (dirname directory))
|
|
|
|
|
(commit commit))))
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(newline))
|
|
|
|
|
('recutils
|
|
|
|
|
(channel->recutils (channel (name 'guix)
|
|
|
|
|
(url (dirname directory))
|
|
|
|
|
(commit commit))
|
|
|
|
|
(current-output-port))))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(display-package-search-path fmt)))
|
|
|
|
|
|
|
|
|
|
(define (display-profile-info profile fmt)
|
|
|
|
|
"Display information about PROFILE, a profile as created by (guix channels),
|
|
|
|
|
in the format specified by FMT."
|
|
|
|
|
(define number
|
2018-09-07 14:19:42 +02:00
|
|
|
|
(generation-number profile))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
|
2018-11-21 14:45:08 +01:00
|
|
|
|
(define channels
|
|
|
|
|
(map (lambda (entry)
|
|
|
|
|
(match (assq 'source (manifest-entry-properties entry))
|
|
|
|
|
(('source ('repository ('version 0)
|
|
|
|
|
('url url)
|
|
|
|
|
('branch branch)
|
|
|
|
|
('commit commit)
|
|
|
|
|
_ ...))
|
|
|
|
|
(channel (name (string->symbol (manifest-entry-name entry)))
|
|
|
|
|
(url url)
|
|
|
|
|
(commit commit)))
|
|
|
|
|
|
|
|
|
|
;; Pre-0.15.0 Guix does not provide that information,
|
|
|
|
|
;; so there's not much we can do in that case.
|
|
|
|
|
(_ (channel (name 'guix)
|
|
|
|
|
(url "?")
|
|
|
|
|
(commit "?")))))
|
|
|
|
|
|
|
|
|
|
;; Show most recently installed packages last.
|
|
|
|
|
(reverse
|
|
|
|
|
(manifest-entries
|
|
|
|
|
(profile-manifest
|
|
|
|
|
(if (zero? number)
|
|
|
|
|
profile
|
|
|
|
|
(generation-file-name profile number)))))))
|
|
|
|
|
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(match fmt
|
|
|
|
|
('human
|
|
|
|
|
(display-profile-content profile number))
|
|
|
|
|
('channels
|
2018-11-21 14:47:43 +01:00
|
|
|
|
(pretty-print `(list ,@(map channel->sexp channels))))
|
|
|
|
|
('json
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(format #t "[~a]~%" (string-join (map channel->json channels) ",")))
|
|
|
|
|
('recutils
|
|
|
|
|
(format #t "~{~a~%~}"
|
|
|
|
|
(map (lambda (channel)
|
|
|
|
|
(with-output-to-string
|
|
|
|
|
(lambda ()
|
|
|
|
|
(channel->recutils channel (current-output-port)))))
|
|
|
|
|
channels))))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(display-package-search-path fmt))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Entry point.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(define (guix-describe . args)
|
2018-11-21 09:23:25 +01:00
|
|
|
|
(let* ((opts (args-fold* args %options
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(leave (G_ "~A: unrecognized option~%")
|
|
|
|
|
name))
|
|
|
|
|
cons
|
|
|
|
|
%default-options))
|
|
|
|
|
(format (assq-ref opts 'format))
|
|
|
|
|
(profile (or (assq-ref opts 'profile) (current-profile))))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(with-error-handling
|
2018-11-21 09:23:25 +01:00
|
|
|
|
(match profile
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(#f
|
|
|
|
|
(display-checkout-info format))
|
|
|
|
|
(profile
|
2018-10-14 21:25:46 +02:00
|
|
|
|
(display-profile-info (canonicalize-profile profile) format))))))
|