2018-09-03 15:03:33 +02:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2021-01-10 21:37:48 +01:00
|
|
|
|
;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
2018-11-21 14:45:08 +01:00
|
|
|
|
;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
|
2020-05-16 19:57:18 +02:00
|
|
|
|
;;; Copyright © 2020 Ekaitz Zarraga <ekaitz@elenq.tech>
|
2021-03-29 12:17:59 +02:00
|
|
|
|
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@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)
|
2019-04-28 15:05:41 +02:00
|
|
|
|
#:use-module ((guix config) #:select (%guix-version))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
#:use-module ((guix ui) #:hide (display-profile-content))
|
2020-02-11 12:17:33 +01:00
|
|
|
|
#:use-module ((guix utils) #:select (string-replace-substring))
|
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)
|
2022-04-09 00:29:24 +02:00
|
|
|
|
#:autoload (guix colors) (supports-hyperlinks? hyperlink)
|
2020-06-25 17:50:48 +02:00
|
|
|
|
#:autoload (guix openpgp) (openpgp-format-fingerprint)
|
2021-03-19 09:42:06 +01:00
|
|
|
|
#:autoload (json builder) (scm->json-string)
|
2018-09-03 15:03:33 +02:00
|
|
|
|
#:use-module (srfi srfi-1)
|
2020-06-25 17:50:48 +02:00
|
|
|
|
#:use-module (srfi srfi-26)
|
2018-09-03 15:03:33 +02:00
|
|
|
|
#:use-module (srfi srfi-37)
|
|
|
|
|
#:use-module (ice-9 match)
|
2020-06-25 23:33:22 +02:00
|
|
|
|
#:use-module (ice-9 format)
|
2018-09-03 15:03:33 +02:00
|
|
|
|
#:autoload (ice-9 pretty-print) (pretty-print)
|
2020-02-11 12:17:33 +01:00
|
|
|
|
#:use-module (web uri)
|
|
|
|
|
#:export (display-profile-content
|
|
|
|
|
channel-commit-hyperlink
|
|
|
|
|
|
|
|
|
|
guix-describe))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Command-line options.
|
|
|
|
|
;;;
|
2020-06-25 17:50:48 +02:00
|
|
|
|
(define %available-formats
|
|
|
|
|
'("human" "channels" "channels-sans-intro" "json" "recutils"))
|
2020-05-16 19:57:18 +02:00
|
|
|
|
|
|
|
|
|
(define (list-formats)
|
|
|
|
|
(display (G_ "The available formats are:\n"))
|
|
|
|
|
(newline)
|
|
|
|
|
(for-each (lambda (f)
|
|
|
|
|
(format #t " - ~a~%" f))
|
|
|
|
|
%available-formats))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
|
|
|
|
|
(define %options
|
|
|
|
|
;; Specifications of the command-line options.
|
|
|
|
|
(list (option '(#\f "format") #t #f
|
|
|
|
|
(lambda (opt name arg result)
|
2020-05-16 19:57:18 +02:00
|
|
|
|
(unless (member arg %available-formats)
|
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)))
|
2020-05-16 19:57:18 +02:00
|
|
|
|
(option '("list-formats") #f #f
|
|
|
|
|
(lambda (opt name arg result)
|
|
|
|
|
(list-formats)
|
|
|
|
|
(exit 0)))
|
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"))
|
2020-05-16 19:57:18 +02:00
|
|
|
|
(display (G_ "
|
|
|
|
|
--list-formats display available formats"))
|
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\"~%")
|
2019-03-18 09:50:10 +01:00
|
|
|
|
string))
|
|
|
|
|
(_
|
|
|
|
|
(warning (G_ "'GUIX_PACKAGE_PATH' is set but it is not captured~%")))))))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
|
2018-11-21 14:47:43 +01:00
|
|
|
|
(define (channel->json channel)
|
2020-06-25 17:50:48 +02:00
|
|
|
|
(scm->json-string
|
|
|
|
|
(let ((intro (channel-introduction channel)))
|
|
|
|
|
`((name . ,(channel-name channel))
|
|
|
|
|
(url . ,(channel-url channel))
|
|
|
|
|
(commit . ,(channel-commit channel))
|
|
|
|
|
,@(if intro
|
|
|
|
|
`((introduction
|
|
|
|
|
. ((commit . ,(channel-introduction-first-signed-commit
|
|
|
|
|
intro))
|
|
|
|
|
(signer . ,(openpgp-format-fingerprint
|
|
|
|
|
(channel-introduction-first-commit-signer
|
|
|
|
|
intro))))))
|
|
|
|
|
'())))))
|
2018-11-21 14:47:43 +01:00
|
|
|
|
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(define (channel->recutils channel port)
|
2020-06-25 17:50:48 +02:00
|
|
|
|
(define intro
|
|
|
|
|
(channel-introduction channel))
|
|
|
|
|
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(format port "name: ~a~%" (channel-name channel))
|
|
|
|
|
(format port "url: ~a~%" (channel-url channel))
|
2020-06-25 17:50:48 +02:00
|
|
|
|
(format port "commit: ~a~%" (channel-commit channel))
|
|
|
|
|
(when intro
|
|
|
|
|
(format port "introductioncommit: ~a~%"
|
|
|
|
|
(channel-introduction-first-signed-commit intro))
|
|
|
|
|
(format port "introductionsigner: ~a~%"
|
|
|
|
|
(openpgp-format-fingerprint
|
|
|
|
|
(channel-introduction-first-commit-signer intro)))))
|
2018-11-21 14:35:38 +01:00
|
|
|
|
|
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."
|
2022-08-08 17:37:12 +02:00
|
|
|
|
(let* ((program (car (command-line)))
|
|
|
|
|
(channel (repository->guix-channel (dirname program))))
|
|
|
|
|
(unless channel
|
|
|
|
|
(report-error (G_ "failed to determine origin~%"))
|
|
|
|
|
(display-hint (format #f (G_ "Perhaps this
|
2019-04-28 15:05:41 +02:00
|
|
|
|
@command{guix} command was not obtained with @command{guix pull}? Its version
|
|
|
|
|
string is ~a.~%")
|
2022-08-08 17:37:12 +02:00
|
|
|
|
%guix-version))
|
|
|
|
|
(exit 1))
|
|
|
|
|
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(match fmt
|
|
|
|
|
('human
|
|
|
|
|
(format #t (G_ "Git checkout:~%"))
|
2022-08-08 17:37:12 +02:00
|
|
|
|
(format #t (G_ " repository: ~a~%") (channel-url channel))
|
|
|
|
|
(format #t (G_ " branch: ~a~%") (channel-branch channel))
|
|
|
|
|
(format #t (G_ " commit: ~a~%") (channel-commit channel)))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
('channels
|
2022-08-08 17:37:12 +02:00
|
|
|
|
(pretty-print `(list ,(channel->code channel))))
|
2018-11-21 14:47:43 +01:00
|
|
|
|
('json
|
2022-08-08 17:37:12 +02:00
|
|
|
|
(display (channel->json channel))
|
2018-11-21 14:35:38 +01:00
|
|
|
|
(newline))
|
|
|
|
|
('recutils
|
2022-08-08 17:37:12 +02:00
|
|
|
|
(channel->recutils channel (current-output-port))))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(display-package-search-path fmt)))
|
|
|
|
|
|
2021-01-27 14:46:10 +01:00
|
|
|
|
(define* (display-profile-info profile fmt
|
|
|
|
|
#:optional
|
|
|
|
|
(channels (profile-channels profile)))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
"Display information about PROFILE, a profile as created by (guix channels),
|
2021-01-27 14:46:10 +01:00
|
|
|
|
in the format specified by FMT. PROFILE can be #f, in which case CHANNELS is
|
|
|
|
|
what matters."
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(define number
|
2021-01-27 14:46:10 +01:00
|
|
|
|
(and profile (generation-number profile)))
|
2018-11-21 14:45:08 +01:00
|
|
|
|
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(match fmt
|
|
|
|
|
('human
|
2021-01-27 14:46:10 +01:00
|
|
|
|
(display-profile-content profile number channels))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
('channels
|
2021-01-10 21:51:18 +01:00
|
|
|
|
(pretty-print `(list ,@(map channel->code channels))))
|
2020-06-25 17:50:48 +02:00
|
|
|
|
('channels-sans-intro
|
2021-01-10 21:51:18 +01:00
|
|
|
|
(pretty-print `(list ,@(map (cut channel->code <>
|
2020-06-25 17:50:48 +02:00
|
|
|
|
#:include-introduction? #f)
|
|
|
|
|
channels))))
|
2018-11-21 14:47:43 +01:00
|
|
|
|
('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))
|
|
|
|
|
|
2021-02-05 22:56:53 +01:00
|
|
|
|
(define (profile-generation-channels profile number)
|
|
|
|
|
"Return the list of channels for generation NUMBER of PROFILE."
|
|
|
|
|
(profile-channels (if (zero? number)
|
|
|
|
|
profile
|
|
|
|
|
(generation-file-name profile number))))
|
|
|
|
|
|
2021-01-27 14:46:10 +01:00
|
|
|
|
(define* (display-profile-content profile number
|
|
|
|
|
#:optional
|
2021-02-05 22:56:53 +01:00
|
|
|
|
(channels
|
|
|
|
|
(profile-generation-channels profile
|
|
|
|
|
number)))
|
2021-01-27 14:46:10 +01:00
|
|
|
|
"Display CHANNELS along with PROFILE info, generation NUMBER, in a
|
|
|
|
|
human-readable way and displaying details about the channel's source code.
|
|
|
|
|
PROFILE and NUMBER "
|
|
|
|
|
(when (and number profile)
|
|
|
|
|
(display-generation profile number))
|
2020-02-11 12:17:33 +01:00
|
|
|
|
|
2021-01-27 14:46:10 +01:00
|
|
|
|
(for-each (lambda (channel)
|
|
|
|
|
(format #t " ~a ~a~%"
|
|
|
|
|
(channel-name channel)
|
|
|
|
|
(string-take (channel-commit channel) 7))
|
|
|
|
|
(format #t (G_ " repository URL: ~a~%")
|
|
|
|
|
(channel-url channel))
|
|
|
|
|
(when (channel-branch channel)
|
|
|
|
|
(format #t (G_ " branch: ~a~%")
|
|
|
|
|
(channel-branch channel)))
|
|
|
|
|
(format #t (G_ " commit: ~a~%")
|
|
|
|
|
(if (supports-hyperlinks?)
|
|
|
|
|
(channel-commit-hyperlink channel)
|
|
|
|
|
(channel-commit channel))))
|
|
|
|
|
channels))
|
2020-02-11 12:17:33 +01:00
|
|
|
|
|
|
|
|
|
(define %vcs-web-views
|
|
|
|
|
;; Hard-coded list of host names and corresponding web view URL templates.
|
|
|
|
|
;; TODO: Allow '.guix-channel' files to specify a URL template.
|
|
|
|
|
(let ((labhub-url (lambda (repository-url commit)
|
|
|
|
|
(string-append
|
|
|
|
|
(if (string-suffix? ".git" repository-url)
|
|
|
|
|
(string-drop-right repository-url 4)
|
|
|
|
|
repository-url)
|
|
|
|
|
"/commit/" commit))))
|
|
|
|
|
`(("git.savannah.gnu.org"
|
|
|
|
|
,(lambda (repository-url commit)
|
|
|
|
|
(string-append (string-replace-substring repository-url
|
|
|
|
|
"/git/" "/cgit/")
|
|
|
|
|
"/commit/?id=" commit)))
|
|
|
|
|
("notabug.org" ,labhub-url)
|
|
|
|
|
("framagit.org" ,labhub-url)
|
|
|
|
|
("gitlab.com" ,labhub-url)
|
|
|
|
|
("gitlab.inria.fr" ,labhub-url)
|
|
|
|
|
("github.com" ,labhub-url))))
|
|
|
|
|
|
|
|
|
|
(define* (channel-commit-hyperlink channel
|
|
|
|
|
#:optional
|
2020-02-28 00:03:34 +01:00
|
|
|
|
(commit (channel-commit channel)))
|
2020-02-11 12:17:33 +01:00
|
|
|
|
"Return a hyperlink for COMMIT in CHANNEL, using COMMIT as the hyperlink's
|
2020-02-28 00:03:34 +01:00
|
|
|
|
text. The hyperlink links to a web view of COMMIT, when available."
|
2020-02-11 12:17:33 +01:00
|
|
|
|
(let* ((url (channel-url channel))
|
|
|
|
|
(uri (string->uri url))
|
|
|
|
|
(host (and uri (uri-host uri))))
|
|
|
|
|
(if host
|
|
|
|
|
(match (assoc host %vcs-web-views)
|
|
|
|
|
(#f
|
|
|
|
|
commit)
|
|
|
|
|
((_ template)
|
2020-02-28 00:03:34 +01:00
|
|
|
|
(hyperlink (template url commit) commit)))
|
2020-02-11 12:17:33 +01:00
|
|
|
|
commit)))
|
|
|
|
|
|
2018-09-03 15:03:33 +02:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Entry point.
|
|
|
|
|
;;;
|
|
|
|
|
|
2020-09-01 22:13:11 +02:00
|
|
|
|
(define-command (guix-describe . args)
|
|
|
|
|
(synopsis "describe the channel revisions currently used")
|
2021-03-29 12:17:59 +02:00
|
|
|
|
(let* ((opts (parse-command-line args %options (list %default-options)
|
|
|
|
|
#:build-options? #f
|
|
|
|
|
#:argument-handler cons))
|
2018-11-21 09:23:25 +01:00
|
|
|
|
(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
|
2021-01-27 14:46:10 +01:00
|
|
|
|
(match (current-channels)
|
|
|
|
|
(()
|
|
|
|
|
(display-checkout-info format))
|
|
|
|
|
(channels
|
|
|
|
|
(display-profile-info #f format channels))))
|
2018-09-03 15:03:33 +02:00
|
|
|
|
(profile
|
2021-05-09 17:22:24 +02:00
|
|
|
|
;; For the current profile, resort to 'current-channels', which has a
|
|
|
|
|
;; fallback to metadata from (guix config) in case PROFILE lacks it.
|
|
|
|
|
(let ((channels (if (and (current-profile)
|
|
|
|
|
(string=? profile (current-profile)))
|
|
|
|
|
(current-channels)
|
|
|
|
|
(profile-channels profile))))
|
|
|
|
|
(display-profile-info (canonicalize-profile profile)
|
|
|
|
|
format channels)))))))
|