1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.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 channels)
23 #:use-module (guix git)
24 #:use-module (guix git-authenticate)
25 #:use-module ((guix openpgp)
26 #:select (openpgp-public-key-fingerprint
27 openpgp-format-fingerprint))
28 #:use-module (guix base16)
29 #:use-module (guix records)
30 #:use-module (guix gexp)
31 #:use-module (guix modules)
32 #:use-module (guix discovery)
33 #:use-module (guix monads)
34 #:use-module (guix profiles)
35 #:use-module (guix packages)
36 #:use-module (guix progress)
37 #:use-module (guix derivations)
38 #:use-module (guix combinators)
39 #:use-module (guix diagnostics)
40 #:use-module (guix sets)
41 #:use-module (guix store)
42 #:use-module (guix i18n)
43 #:use-module (srfi srfi-1)
44 #:use-module (srfi srfi-2)
45 #:use-module (srfi srfi-9)
46 #:use-module (srfi srfi-11)
47 #:use-module (srfi srfi-26)
48 #:use-module (srfi srfi-34)
49 #:use-module (srfi srfi-35)
50 #:autoload (guix self) (whole-package make-config.scm)
51 #:autoload (guix inferior) (gexp->derivation-in-inferior) ;FIXME: circular dep
52 #:autoload (guix quirks) (%quirks %patches applicable-patch? apply-patch)
53 #:use-module (ice-9 format)
54 #:use-module (ice-9 match)
55 #:use-module (ice-9 vlist)
56 #:use-module ((ice-9 rdelim) #:select (read-string))
57 #:use-module ((rnrs bytevectors) #:select (bytevector=?))
68 make-channel-introduction
69 channel-introduction-first-signed-commit
70 channel-introduction-first-commit-signer
72 openpgp-fingerprint->bytevector
79 channel-instance-channel
80 channel-instance-commit
81 channel-instance-checkout
84 latest-channel-instances
85 checkout->channel-instance
86 latest-channel-derivation
87 channel-instances->manifest
88 %channel-profile-hooks
89 channel-instances->derivation
90 ensure-forward-channel-update
95 channel-news-entry-commit
96 channel-news-entry-tag
97 channel-news-entry-title
98 channel-news-entry-body
100 channel-news-for-commit))
104 ;;; This module implements "channels." A channel is usually a source of
105 ;;; package definitions. There's a special channel, the 'guix' channel, that
106 ;;; provides all of Guix, including its commands and its documentation.
107 ;;; User-defined channels are expected to typically provide a bunch of .scm
108 ;;; files meant to be added to the '%package-search-path'.
110 ;;; This module provides tools to fetch and update channels from a Git
111 ;;; repository and to build them.
115 (define-record-type* <channel> channel make-channel
119 (branch channel-branch (default "master"))
120 (commit channel-commit (default #f))
121 (introduction channel-introduction (default #f))
122 (location channel-location
123 (default (current-source-location)) (innate)))
125 ;; Channel introductions. A "channel introduction" provides a commit/signer
126 ;; pair that specifies the first commit of the authentication process as well
127 ;; as its signer's fingerprint. Introductions are used to bootstrap trust in
129 (define-record-type <channel-introduction>
130 (%make-channel-introduction first-signed-commit first-commit-signer)
131 channel-introduction?
132 (first-signed-commit channel-introduction-first-signed-commit) ;hex string
133 (first-commit-signer channel-introduction-first-commit-signer)) ;bytevector
135 (define (make-channel-introduction commit signer)
136 "Return a new channel introduction: COMMIT is the introductory where
137 authentication starts, and SIGNER is the OpenPGP fingerprint (a bytevector) of
138 the signer of that commit."
139 (%make-channel-introduction commit signer))
141 (define (openpgp-fingerprint->bytevector str)
142 "Convert STR, an OpenPGP fingerprint (hexadecimal string with whitespace),
143 to the corresponding bytevector."
144 (base16-string->bytevector
145 (string-downcase (string-filter char-set:hex-digit str))))
147 (define-syntax openpgp-fingerprint
149 "Convert STR, an OpenPGP fingerprint (hexadecimal string with whitespace),
150 to the corresponding bytevector."
153 (string? (syntax->datum #'str))
154 (openpgp-fingerprint->bytevector (syntax->datum #'str)))
156 #'(openpgp-fingerprint->bytevector str)))))
158 (define %guix-channel-introduction
159 ;; Introduction of the official 'guix channel. The chosen commit is the
160 ;; first one that introduces '.guix-authorizations' on the 'staging'
161 ;; branch that was eventually merged in 'master'. Any branch starting
162 ;; before that commit cannot be merged or it will be rejected by 'guix pull'
164 (make-channel-introduction
165 "9edb3f66fd807b096b48283debdcddccfea34bad" ;2020-05-26
166 (openpgp-fingerprint ;mbakke
167 "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA")))
169 (define %default-channel-url
170 ;; URL of the default 'guix' channel.
171 "https://git.savannah.gnu.org/git/guix.git")
173 (define %default-channels
174 ;; Default list of channels.
178 (url %default-channel-url)
179 (introduction %guix-channel-introduction))))
181 (define (guix-channel? channel)
182 "Return true if CHANNEL is the 'guix' channel."
183 (eq? 'guix (channel-name channel)))
185 (define (ensure-default-introduction chan)
186 "If CHAN represents the \"official\" 'guix' channel and lacks an
187 introduction, add it."
188 (if (and (guix-channel? chan)
189 (not (channel-introduction chan))
190 (string=? (channel-url chan) %default-channel-url))
191 (channel (inherit chan)
192 (introduction %guix-channel-introduction))
195 (define-record-type <channel-instance>
196 (channel-instance channel commit checkout)
198 (channel channel-instance-channel)
199 (commit channel-instance-commit)
200 (checkout channel-instance-checkout))
202 (define-record-type <channel-metadata>
203 (channel-metadata directory dependencies news-file keyring-reference url)
205 (directory channel-metadata-directory) ;string with leading slash
206 (dependencies channel-metadata-dependencies) ;list of <channel>
207 (news-file channel-metadata-news-file) ;string | #f
208 (keyring-reference channel-metadata-keyring-reference) ;string
209 (url channel-metadata-url)) ;string | #f
211 (define %default-keyring-reference
212 ;; Default value of the 'keyring-reference' field.
215 (define (channel-reference channel)
216 "Return the \"reference\" for CHANNEL, an sexp suitable for
217 'latest-repository-commit'."
218 (match (channel-commit channel)
219 (#f `(branch . ,(channel-branch channel)))
220 (commit `(commit . ,(channel-commit channel)))))
222 (define sexp->channel-introduction
224 (('channel-introduction ('version 0)
225 ('commit commit) ('signer signer)
227 (make-channel-introduction commit (openpgp-fingerprint signer)))
230 (define (read-channel-metadata port)
231 "Read from PORT channel metadata in the format expected for the
232 '.guix-channel' file. Return a <channel-metadata> record, or raise an error
233 if valid metadata could not be read from PORT."
235 (('channel ('version 0) properties ...)
236 (let ((directory (and=> (assoc-ref properties 'directory) first))
237 (dependencies (or (assoc-ref properties 'dependencies) '()))
238 (news-file (and=> (assoc-ref properties 'news-file) first))
239 (url (and=> (assoc-ref properties 'url) first))
241 (or (and=> (assoc-ref properties 'keyring-reference) first)
242 %default-keyring-reference)))
244 (cond ((not directory) "/") ;directory
245 ((string-prefix? "/" directory) directory)
246 (else (string-append "/" directory)))
247 (map (lambda (item) ;dependencies
248 (let ((get (lambda* (key #:optional default)
249 (or (and=> (assoc-ref item key) first) default))))
250 (and-let* ((name (get 'name))
252 (branch (get 'branch "master")))
257 (commit (get 'commit))
258 (introduction (and=> (get 'introduction)
259 sexp->channel-introduction))))))
264 ((and ('channel ('version version) _ ...) sexp)
266 (&message (message "unsupported '.guix-channel' version"))
268 (location (source-properties->location
269 (source-properties sexp)))))))
272 (&message (message "invalid '.guix-channel' file"))
274 (location (source-properties->location
275 (source-properties sexp)))))))))
277 (define (read-channel-metadata-from-source source)
278 "Return a channel-metadata record read from channel's SOURCE/.guix-channel
279 description file, or return the default channel-metadata record if that file
283 (call-with-input-file (string-append source "/.guix-channel")
284 read-channel-metadata))
286 (if (= ENOENT (system-error-errno args))
287 (channel-metadata "/" '() #f %default-keyring-reference #f)
288 (apply throw args)))))
290 (define (channel-instance-metadata instance)
291 "Return a channel-metadata record read from the channel INSTANCE's
292 description file or its default value."
293 (read-channel-metadata-from-source (channel-instance-checkout instance)))
295 (define (channel-instance-dependencies instance)
296 "Return the list of channels that are declared as dependencies for the given
298 (channel-metadata-dependencies (channel-instance-metadata instance)))
300 (define (apply-patches checkout commit patches)
301 "Apply the matching PATCHES to CHECKOUT, modifying files in place. The
302 result is unspecified."
303 (let loop ((patches patches))
307 (when (applicable-patch? patch checkout commit)
308 (apply-patch patch checkout))
311 (define commit-short-id
312 (compose (cut string-take <> 7) oid->string commit-id))
314 (define* (authenticate-channel channel checkout commit
315 #:key (keyring-reference-prefix "origin/"))
316 "Authenticate the given COMMIT of CHANNEL, available at CHECKOUT, a
317 directory containing a CHANNEL checkout. Raise an error if authentication
320 (channel-introduction channel))
323 (string-append "channels/" (symbol->string (channel-name channel))))
325 (define keyring-reference
326 (channel-metadata-keyring-reference
327 (read-channel-metadata-from-source checkout)))
329 (define (make-reporter start-commit end-commit commits)
330 (format (current-error-port)
331 (G_ "Authenticating channel '~a', commits ~a to ~a (~h new \
333 (channel-name channel)
334 (commit-short-id start-commit)
335 (commit-short-id end-commit)
338 (progress-reporter/bar (length commits)))
340 ;; XXX: Too bad we need to re-open CHECKOUT.
341 (with-repository checkout repository
342 (authenticate-repository repository
344 (channel-introduction-first-signed-commit intro))
345 (channel-introduction-first-commit-signer intro)
346 #:end (string->oid commit)
348 (string-append keyring-reference-prefix
350 #:make-reporter make-reporter
351 #:cache-key cache-key)))
353 (define* (latest-channel-instance store channel
354 #:key (patches %patches)
358 ensure-forward-channel-update))
359 "Return the latest channel instance for CHANNEL. When STARTING-COMMIT is
360 true, call VALIDATE-PULL with CHANNEL, STARTING-COMMIT, the target commit, and
361 their relation. When AUTHENTICATE? is false, CHANNEL is not authenticated."
362 (define (dot-git? file stat)
363 (and (string=? (basename file) ".git")
364 (eq? 'directory (stat:type stat))))
366 (let-values (((channel)
367 (ensure-default-introduction channel))
368 ((checkout commit relation)
369 (update-cached-checkout (channel-url channel)
370 #:ref (channel-reference channel)
371 #:starting-commit starting-commit)))
373 (validate-pull channel starting-commit commit relation))
376 (if (channel-introduction channel)
377 (authenticate-channel channel checkout commit)
378 ;; TODO: Warn for all the channels once the authentication interface
380 (when (guix-channel? channel)
381 (raise (make-compound-condition
382 (formatted-message (G_ "channel '~a' lacks an \
383 introduction and cannot be authenticated~%")
384 (channel-name channel))
387 (hint (G_ "Add the missing introduction to your
388 channels file to address the issue. Alternatively, you can pass
389 @option{--disable-authentication}, at the risk of running unauthenticated and
390 thus potentially malicious code."))))))))
391 (warning (G_ "channel authentication disabled~%")))
393 (when (guix-channel? channel)
394 ;; Apply the relevant subset of PATCHES directly in CHECKOUT. This is
395 ;; safe to do because 'switch-to-ref' eventually does a hard reset.
396 (apply-patches checkout commit patches))
398 (let* ((name (url+commit->name (channel-url channel) commit))
399 (checkout (add-to-store store name #t "sha256" checkout
400 #:select? (negate dot-git?))))
401 (channel-instance channel commit checkout))))
403 (define (ensure-forward-channel-update channel start commit relation)
404 "Raise an error if RELATION is not 'ancestor, meaning that START is not an
405 ancestor of COMMIT, unless CHANNEL specifies a commit.
407 This procedure implements a channel update policy meant to be used as a
408 #:validate-pull argument."
413 (raise (make-compound-condition
417 aborting update of channel '~a' to commit ~a, which is not a descendant of ~a")
418 (channel-name channel)
421 ;; If the user asked for a specific commit, they might want
422 ;; that to happen nevertheless, so tell them about the
423 ;; relevant 'guix pull' option.
424 (if (channel-commit channel)
427 (hint (G_ "Use @option{--allow-downgrades} to force
431 (hint (G_ "This could indicate that the channel has
432 been tampered with and is trying to force a roll-back, preventing you from
433 getting the latest updates. If you think this is not the case, explicitly
434 allow non-forward updates."))))))))))
436 (define (channel-instance-primary-url instance)
437 "Return the primary URL advertised for INSTANCE, or #f if there is no such
439 (channel-metadata-url (channel-instance-metadata instance)))
441 (define* (latest-channel-instances store channels
443 (current-channels '())
446 ensure-forward-channel-update))
447 "Return a list of channel instances corresponding to the latest checkouts of
448 CHANNELS and the channels on which they depend.
450 When AUTHENTICATE? is true, authenticate the subset of CHANNELS that has a
451 \"channel introduction\".
453 CURRENT-CHANNELS is the list of currently used channels. It is compared
454 against the newly-fetched instances of CHANNELS, and VALIDATE-PULL is called
455 for each channel update and can choose to emit warnings or raise an error,
456 depending on the policy it implements."
457 ;; Only process channels that are unique, or that are more specific than a
458 ;; previous channel specification.
459 (define (ignore? channel others)
460 (member channel others
462 (and (eq? (channel-name a) (channel-name b))
463 (or (channel-commit b)
464 (not (or (channel-commit a)
465 (channel-commit b))))))))
467 (define (current-commit name)
468 ;; Return the current commit for channel NAME.
469 (any (lambda (channel)
470 (and (eq? (channel-name channel) name)
471 (channel-commit channel)))
474 (let loop ((channels channels)
475 (previous-channels '()))
476 ;; Accumulate a list of instances. A list of processed channels is also
477 ;; accumulated to decide on duplicate channel specifications.
478 (define-values (resulting-channels instances)
479 (fold2 (lambda (channel previous-channels instances)
480 (if (ignore? channel previous-channels)
481 (values previous-channels instances)
483 (format (current-error-port)
484 (G_ "Updating channel '~a' from Git repository at '~a'...~%")
485 (channel-name channel)
486 (channel-url channel))
487 (let* ((current (current-commit (channel-name channel)))
489 (latest-channel-instance store channel
497 ;; CHANNEL is authenticated so we can trust the
498 ;; primary URL advertised in its metadata and warn
499 ;; about possibly stale mirrors.
500 (let ((primary-url (channel-instance-primary-url
502 (unless (or (not primary-url)
503 (channel-commit channel)
504 (string=? primary-url (channel-url channel)))
505 (warning (G_ "pulled channel '~a' from a mirror \
506 of ~a, which might be stale~%")
507 (channel-name channel)
510 (let-values (((new-instances new-channels)
511 (loop (channel-instance-dependencies instance)
513 (values (append (cons channel new-channels)
515 (append (cons instance new-instances)
521 (let ((instance-name (compose channel-name channel-instance-channel)))
522 ;; Remove all earlier channel specifications if they are followed by a
523 ;; more specific one.
524 (values (delete-duplicates instances
526 (eq? (instance-name a) (instance-name b))))
527 resulting-channels))))
529 (define* (checkout->channel-instance checkout
531 (url checkout) (name 'guix))
532 "Return a channel instance for CHECKOUT, which is assumed to be a checkout
533 of COMMIT at URL. Use NAME as the channel name."
534 (let* ((commit (or commit (make-string 40 #\0)))
535 (channel (channel (name name)
538 (channel-instance channel commit checkout)))
540 (define %self-build-file
541 ;; The file containing code to build Guix. This serves the same purpose as
542 ;; a makefile, and, similarly, is intended to always keep this name.
543 "build-aux/build-self.scm")
545 (define %pull-version
546 ;; This is the version of the 'guix pull' protocol. It specifies what's
547 ;; expected from %SELF-BUILD-FILE. The initial version ("0") was when we'd
548 ;; place a set of compiled Guile modules in ~/.config/guix/latest.
551 (define (standard-module-derivation name source core dependencies)
552 "Return a derivation that builds with CORE, a Guix instance, the Scheme
553 modules in SOURCE and that depend on DEPENDENCIES, a list of lowerable
554 objects. The assumption is that SOURCE contains package modules to be added
555 to '%package-module-path'."
557 (let* ((metadata (read-channel-metadata-from-source source))
558 (directory (channel-metadata-directory metadata)))
561 ;; This is code that we'll run in CORE, a Guix instance, with its own
562 ;; modules and so on. That way, we make sure these modules are built for
563 ;; the right Guile version, with the right dependencies, and that they get
564 ;; to see the right (gnu packages …) modules.
565 (with-extensions dependencies
567 (use-modules (guix build compile)
572 (string-append #$output "/lib/guile/" (effective-version)
575 (string-append #$output "/share/guile/site/"
576 (effective-version)))
578 (let* ((subdir #$directory)
579 (source (string-append #$source subdir)))
580 (compile-files source go (find-files source "\\.scm$"))
581 (mkdir-p (dirname scm))
582 (symlink (string-append #$source subdir) scm))
586 (gexp->derivation-in-inferior name build core)))
588 (define* (guile-for-source source #:optional (quirks %quirks))
589 "Return the Guile package to use when building SOURCE or #f if the default
590 '%guile-for-build' should be good enough."
591 (let loop ((quirks quirks))
595 (((predicate . guile) rest ...)
596 (if (predicate source) (guile) (loop rest))))))
598 (define (call-with-guile guile thunk)
600 (values (parameterize ((%guile-for-build
602 (package-derivation store guile)
603 (%guile-for-build))))
604 (run-with-store store (thunk)))
607 (define-syntax-rule (with-guile guile exp ...)
608 "Set GUILE as the '%guile-for-build' parameter for the dynamic extent of
609 EXP, a series of monadic expressions."
610 (call-with-guile guile (lambda ()
611 (mbegin %store-monad exp ...))))
613 (define (with-trivial-build-handler mvalue)
614 "Run MVALUE, a monadic value, with a \"trivial\" build handler installed
615 that unconditionally resumes the continuation."
617 (with-build-handler (lambda (continue . _)
619 (values (run-with-store store mvalue)
622 (define* (build-from-source name source
623 #:key core verbose? commit
625 "Return a derivation to build Guix from SOURCE, using the self-build script
626 contained therein; use COMMIT as the version string. When CORE is true, build
627 package modules under SOURCE using CORE, an instance of Guix."
628 ;; Running the self-build script makes it easier to update the build
629 ;; procedure: the self-build script of the Guix-to-be-installed contains the
630 ;; right dependencies, build procedure, etc., which the Guix-in-use may not
633 (string-append source "/" %self-build-file))
635 (if (file-exists? script)
636 (let ((build (save-module-excursion
638 ;; Disable deprecation warnings; it's OK for SCRIPT to
639 ;; use deprecated APIs and the user doesn't have to know
641 (parameterize ((guix-warning-port
642 (%make-void-port "w")))
643 (primitive-load script)))))
644 (guile (guile-for-source source)))
645 ;; BUILD must be a monadic procedure of at least one argument: the
648 ;; Note: BUILD can return #f if it does not support %PULL-VERSION. In
649 ;; the future we'll fall back to a previous version of the protocol
650 ;; when that happens.
652 ;; BUILD is usually quite costly. Install a "trivial" build handler
653 ;; so we don't bounce an outer build-accumulator handler that could
654 ;; cause us to redo half of the BUILD computation several times just
655 ;; to realize it gives the same result.
656 (with-trivial-build-handler
657 (build source #:verbose? verbose? #:version commit
658 #:pull-version %pull-version))))
660 ;; Build a set of modules that extend Guix using the standard method.
661 (standard-module-derivation name source core dependencies)))
663 (define* (build-channel-instance instance
664 #:optional core (dependencies '()))
665 "Return, as a monadic value, the derivation for INSTANCE, a channel
666 instance. DEPENDENCIES is a list of extensions providing Guile modules that
667 INSTANCE depends on."
668 (build-from-source (symbol->string
669 (channel-name (channel-instance-channel instance)))
670 (channel-instance-checkout instance)
671 #:commit (channel-instance-commit instance)
673 #:dependencies dependencies))
675 (define (resolve-dependencies instances)
676 "Return a procedure that, given one of the elements of INSTANCES, returns
677 list of instances it depends on."
678 (define channel-instance-name
679 (compose channel-name channel-instance-channel))
681 (define table ;map a name to an instance
682 (fold (lambda (instance table)
683 (vhash-consq (channel-instance-name instance)
689 (fold (lambda (instance edges)
690 (fold (lambda (channel edges)
691 (let ((name (channel-name channel)))
692 (match (vhash-assq name table)
694 (vhash-consq instance target edges)))))
696 (channel-instance-dependencies instance)))
701 (vhash-foldq* cons '() instance edges)))
703 (define (channel-instance-derivations instances)
704 "Return the list of derivations to build INSTANCES, in the same order as
706 (define core-instance
707 ;; The 'guix' channel is treated specially: it's an implicit dependency of
708 ;; all the other channels.
709 (find (lambda (instance)
710 (guix-channel? (channel-instance-channel instance)))
714 (resolve-dependencies instances))
716 (define (instance->derivation instance)
717 (mlet %store-monad ((system (current-system)))
718 (mcached (if (eq? instance core-instance)
719 (build-channel-instance instance)
720 (mlet %store-monad ((core (instance->derivation core-instance))
721 (deps (mapm %store-monad instance->derivation
723 (build-channel-instance instance core deps)))
727 (unless core-instance
728 (let ((loc (and=> (any (compose channel-location channel-instance-channel)
730 source-properties->location)))
731 (raise (apply make-compound-condition
733 (&message (message "'guix' channel is lacking")))
735 (&fix-hint (hint (G_ "Make sure your list of channels
736 contains one channel named @code{guix} providing the core of Guix."))))
738 (list (condition (&error-location (location loc))))
741 (mapm %store-monad instance->derivation instances))
743 (define (whole-package-for-legacy name modules)
744 "Return a full-blown Guix package for MODULES, a derivation that builds Guix
745 modules in the old ~/.config/guix/latest style."
747 (resolve-interface '(gnu packages guile)))
749 (define modules+compiled
750 ;; Since MODULES contains both .scm and .go files at its root, re-bundle
751 ;; it so that it has share/guile/site and lib/guile, which is what
752 ;; 'whole-package' expects.
753 (computed-file (derivation-name modules)
754 (with-imported-modules '((guix build utils))
756 (use-modules (guix build utils))
761 (string-append #$output "/share/guile/site"))
763 (string-append #$output "/lib/guile/" version))
765 (mkdir-p share) (mkdir-p lib)
766 (symlink #$modules (string-append share "/" version))
767 (symlink #$modules (string-append lib "/site-ccache"))))))
769 (letrec-syntax ((list (syntax-rules (->)
772 ((_ (module -> variable) rest ...)
773 (cons (module-ref (resolve-interface
774 '(gnu packages module))
777 ((_ variable rest ...)
778 (cons (module-ref packages 'variable)
780 (whole-package name modules+compiled
782 ;; In the "old style", %SELF-BUILD-FILE would simply return a
783 ;; derivation that builds modules. We have to infer what the
784 ;; dependencies of these modules were.
785 (list guile-json-3 guile-git guile-bytestructures
786 (ssh -> guile-ssh) (tls -> gnutls)))))
788 (define (old-style-guix? drv)
789 "Return true if DRV corresponds to a ~/.config/guix/latest style of
791 ;; Here we rely on a gross historical fact: that derivations produced by the
792 ;; "old style" (before commit 8a0d9bc8a3f153159d9e239a151c0fa98f1e12d8,
793 ;; dated May 30, 2018) did not depend on "guix-command.drv".
794 (not (find (lambda (input)
795 (string=? "guix-command"
797 (derivation-input-derivation input))))
798 (derivation-inputs drv))))
800 (define (channel-instances->manifest instances)
801 "Return a profile manifest with entries for all of INSTANCES, a list of
803 (define (instance->entry instance drv)
804 (let* ((commit (channel-instance-commit instance))
805 (channel (channel-instance-channel instance))
806 (intro (channel-introduction channel)))
808 (name (symbol->string (channel-name channel)))
809 (version (string-take commit 7))
810 (item (if (guix-channel? channel)
811 (if (old-style-guix? drv)
812 (whole-package-for-legacy (string-append name "-" version)
817 `((source (repository
819 (url ,(channel-url channel))
820 (branch ,(channel-branch channel))
824 (channel-introduction
827 ,(channel-introduction-first-signed-commit
830 ,(openpgp-format-fingerprint
831 (channel-introduction-first-commit-signer
835 (mlet* %store-monad ((derivations (channel-instance-derivations instances))
836 (entries -> (map instance->entry instances derivations)))
837 (return (manifest entries))))
839 (define (package-cache-file manifest)
840 "Build a package cache file for the instance in MANIFEST. This is meant to
841 be used as a profile hook."
842 (let ((profile (profile (content manifest) (hooks '()))))
845 (use-modules (gnu packages))
847 (if (defined? 'generate-package-cache)
849 ;; Delegate package cache generation to the inferior.
850 (format (current-error-port)
851 "Generating package cache for '~a'...~%"
853 (generate-package-cache #$output))
856 (gexp->derivation-in-inferior "guix-package-cache" build
859 ;; If the Guix in PROFILE is too old and
860 ;; lacks 'guix repl', don't build the cache
861 ;; instead of failing.
864 #:properties '((type . profile-hook)
865 (hook . package-cache))
868 (define %channel-profile-hooks
869 ;; The default channel profile hooks.
870 (cons package-cache-file %default-profile-hooks))
872 (define (channel-instances->derivation instances)
873 "Return the derivation of the profile containing INSTANCES, a list of
875 (mlet %store-monad ((manifest (channel-instances->manifest instances)))
876 (profile-derivation manifest
877 #:hooks %channel-profile-hooks)))
879 (define latest-channel-instances*
880 (store-lift latest-channel-instances))
882 (define* (latest-channel-derivation #:optional (channels %default-channels)
884 (current-channels '())
886 ensure-forward-channel-update))
887 "Return as a monadic value the derivation that builds the profile for the
888 latest instances of CHANNELS. CURRENT-CHANNELS and VALIDATE-PULL are passed
889 to 'latest-channel-instances'."
890 (mlet %store-monad ((instances
891 (latest-channel-instances* channels
896 (channel-instances->derivation instances)))
898 (define (profile-channels profile)
899 "Return the list of channels corresponding to entries in PROFILE. If
900 PROFILE is not a profile created by 'guix pull', return the empty list."
901 (filter-map (lambda (entry)
902 (match (assq 'source (manifest-entry-properties entry))
903 (('source ('repository ('version 0)
908 (channel (name (string->symbol
909 (manifest-entry-name entry)))
913 (match (assq 'introduction rest)
915 (('introduction intro)
916 (sexp->channel-introduction intro))))))
918 ;; No channel information for this manifest entry.
919 ;; XXX: Pre-0.15.0 Guix did not provide that information,
920 ;; but there's not much we can do in that case.
923 ;; Show most recently installed packages last.
925 (manifest-entries (profile-manifest profile)))))
933 (define-record-type <channel-news>
934 (channel-news entries)
936 (entries channel-news-entries)) ;list of <channel-news-entry>
938 ;; News entry, associated with a specific commit of the channel.
939 (define-record-type <channel-news-entry>
940 (channel-news-entry commit tag title body)
942 (commit channel-news-entry-commit) ;hex string | #f
943 (tag channel-news-entry-tag) ;#f | string
944 (title channel-news-entry-title) ;list of language tag/string pairs
945 (body channel-news-entry-body)) ;list of language tag/string pairs
947 (define (sexp->channel-news-entry entry)
948 "Return the <channel-news-entry> record corresponding to ENTRY, an sexp."
949 (define (pair language message)
950 (cons (symbol->string language) message))
953 (('entry ((and (or 'commit 'tag) type) commit-or-tag)
954 ('title ((? symbol? title-tags) (? string? titles)) ...)
955 ('body ((? symbol? body-tags) (? string? bodies)) ...)
957 (channel-news-entry (and (eq? type 'commit) commit-or-tag)
958 (and (eq? type 'tag) commit-or-tag)
959 (map pair title-tags titles)
960 (map pair body-tags bodies)))
963 (&message (message "invalid channel news entry"))
965 (location (source-properties->location
966 (source-properties entry)))))))))
968 (define (read-channel-news port)
969 "Read a channel news feed from PORT and return it as a <channel-news>
971 (match (false-if-exception (read port))
972 (('channel-news ('version 0) entries ...)
973 (channel-news (map sexp->channel-news-entry entries)))
974 (('channel-news ('version version) _ ...)
975 ;; This is an unsupported version from the future. There's nothing wrong
976 ;; with that (the user may simply need to upgrade the 'guix' channel to
977 ;; be able to read it), so silently ignore it.
981 (&message (message "syntactically invalid channel news file")))))
984 (&message (message "invalid channel news file"))
986 (location (source-properties->location
987 (source-properties sexp)))))))))
989 (define (resolve-channel-news-entry-tag repository entry)
990 "If ENTRY has its 'commit' field set, return ENTRY. Otherwise, lookup
991 ENTRY's 'tag' in REPOSITORY and return ENTRY with its 'commit' field set to
992 the field its 'tag' refers to. A 'git-error' exception is raised if the tag
994 (if (channel-news-entry-commit entry)
996 (let* ((tag (channel-news-entry-tag entry))
997 (reference (string-append "refs/tags/" tag))
998 (oid (reference-name->oid repository reference)))
999 (channel-news-entry (oid->string oid) tag
1000 (channel-news-entry-title entry)
1001 (channel-news-entry-body entry)))))
1003 (define* (channel-news-for-commit channel new #:optional old)
1004 "Return a list of <channel-news-entry> for CHANNEL between commits OLD and
1005 NEW. When OLD is omitted or is #f, return all the news entries of CHANNEL."
1008 (let* ((checkout (update-cached-checkout (channel-url channel)
1009 #:ref `(commit . ,new)))
1010 (metadata (read-channel-metadata-from-source checkout))
1011 (news-file (channel-metadata-news-file metadata))
1012 (news-file (and news-file
1013 (string-append checkout "/" news-file))))
1014 (if (and news-file (file-exists? news-file))
1015 (with-repository checkout repository
1016 (let* ((news (call-with-input-file news-file
1018 (entries (map (lambda (entry)
1019 (resolve-channel-news-entry-tag repository
1021 (channel-news-entries news))))
1023 (let* ((new (commit-lookup repository (string->oid new)))
1024 (old (commit-lookup repository (string->oid old)))
1026 (map (compose oid->string commit-id)
1027 (commit-difference new old)))))
1028 (filter (lambda (entry)
1029 (set-contains? commits
1030 (channel-news-entry-commit entry)))
1034 (lambda (key error . rest)
1035 ;; If commit NEW or commit OLD cannot be found, then something must be
1036 ;; wrong (for example, the history of CHANNEL was rewritten and these
1037 ;; commits no longer exist upstream), so quietly return the empty list.
1038 (if (= GIT_ENOTFOUND (git-error-code error))
1040 (apply throw key error rest)))))
1042 ;;; Local Variables:
1043 ;;; eval: (put 'with-guile 'scheme-indent-function 1)