unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 9295894f6e90ca94539d1d399881840dca0661d1 28927 bytes (raw)
name: emacs/guix-main.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
;;;
;;; 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/>.

;;; Commentary:

;; Information about packages and generations is passed to the elisp
;; side in the form of alists of parameters (such as ‘name’ or
;; ‘version’) and their values.  These alists are called "entries" in
;; this code.  So to distinguish, just "package" in the name of a
;; function means a guile object ("package" record) while
;; "package entry" means alist of package parameters and values (see
;; ‘%package-param-alist’).
;;
;; "Entry" is probably not the best name for such alists, because there
;; already exists "manifest-entry" which has nothing to do with the
;; "entry" described above.  Do not be confused.  "Manifest entries" are
;; shortened to "mentries" in this file.

;; ‘get-entries’ function is the “entry point” for the elisp side to get
;; information about packages and generations.

;; Since name/version pair is not necessarily unique, we use
;; `object-address' to identify a package (for ‘id’ parameter), if
;; possible.  However for the obsolete packages (that can be found in
;; installed manifest but not in a package directory), ‘id’ parameter is
;; still "name-version" string.  So ‘id’ package parameter in the code
;; below is either an object-address number or a full-name string.
;;
;; Important: as object addresses live only during guile session, elisp
;; part should take care about updating information after "Guix REPL" is
;; restarted (TODO!)
;;
;; ‘installed’ parameter of a package entry contains information about
;; installed outputs.  It is a list of "installed entries" (see
;; ‘%mentry-param-alist’).

;; To speed-up the process of getting information, the following
;; auxiliary variables are used:
;;
;; - `%packages' - VHash of "package address"/"package" pairs.
;;
;; - `%package-table' - Hash table of
;;   "name+version key"/"list of packages" pairs.

;;; Code:

(use-modules
 (ice-9 vlist)
 (ice-9 match)
 (srfi srfi-1)
 (srfi srfi-11)
 (srfi srfi-19)
 (srfi srfi-26)
 (guix)
 (guix packages)
 (guix profiles)
 (guix licenses)
 (guix utils)
 (guix ui)
 (guix scripts package)
 (gnu packages))

(define-syntax-rule (first-or-false lst)
  (and (not (null? lst))
       (first lst)))

(define full-name->name+version package-name->name+version)
(define (name+version->full-name name version)
  (string-append name "-" version))

(define* (make-package-specification name #:optional version output)
  (let ((full-name (if version
                       (name+version->full-name name version)
                       name)))
    (if output
        (string-append full-name ":" output)
        full-name)))

(define name+version->key cons)
(define key->name+version car+cdr)

(define %packages
  (fold-packages (lambda (pkg res)
                   (vhash-consq (object-address pkg) pkg res))
                 vlist-null))

(define %package-table
  (let ((table (make-hash-table (vlist-length %packages))))
    (vlist-for-each
     (lambda (elem)
       (match elem
         ((address . pkg)
          (let* ((key (name+version->key (package-name pkg)
                                         (package-version pkg)))
                 (ref (hash-ref table key)))
            (hash-set! table key
                       (if ref (cons pkg ref) (list pkg)))))))
     %packages)
    table))

(define (mentry->name+version+output mentry)
  (values
   (manifest-entry-name    mentry)
   (manifest-entry-version mentry)
   (manifest-entry-output  mentry)))

(define (mentries->hash-table mentries)
  "Return hash table of name keys and lists of matching MENTRIES."
  (let ((table (make-hash-table (length mentries))))
    (for-each (lambda (mentry)
                (let* ((key (manifest-entry-name mentry))
                       (ref (hash-ref table key)))
                  (hash-set! table key
                             (if ref (cons mentry ref) (list mentry)))))
              mentries)
    table))

(define (manifest=? m1 m2)
  (or (eq? m1 m2)
      (equal? m1 m2)))

(define manifest->hash-table
  (let ((current-manifest #f)
        (current-table #f))
    (lambda (manifest)
      "Return hash table of name keys and lists of matching MANIFEST entries."
      (unless (manifest=? manifest current-manifest)
        (set! current-manifest manifest)
        (set! current-table (mentries->hash-table
                             (manifest-entries manifest))))
      current-table)))

(define* (mentries-by-name manifest name #:optional version output)
  "Return list of MANIFEST entries matching NAME, VERSION and OUTPUT."
  (let ((mentries (or (hash-ref (manifest->hash-table manifest) name)
                      '())))
    (if (or version output)
        (filter (lambda (mentry)
                  (and (or (not version)
                           (equal? version (manifest-entry-version mentry)))
                       (or (not output)
                           (equal? output  (manifest-entry-output mentry)))))
                mentries)
        mentries)))

(define (mentry-by-output mentries output)
  (find (lambda (mentry)
          (string= output (manifest-entry-output mentry)))
        mentries))

(define (fold-manifest-by-name manifest proc init)
  "Fold over MANIFEST entries.
Call (PROC NAME VERSION MENTRIES RESULT), using INIT as the initial value
of RESULT.  MENTRIES is a list of manifest entries with NAME/VERSION."
  (hash-fold (lambda (name mentries res)
               (proc name (manifest-entry-version (car mentries))
                     mentries res))
             init
             (manifest->hash-table manifest)))

(define (list-maybe obj)
  (if (list? obj) obj (list obj)))

(define* (object-transformer param-alist #:optional (params '()))
  "Return function for transforming objects into alist of parameters/values.

PARAM-ALIST is alist of available parameters (symbols) and functions returning
values of these parameters.  Each function is applied to objects.

PARAMS is list of parameters from PARAM-ALIST that should be returned by a
resulting function.  If PARAMS is not specified or is an empty list, use all
available parameters.

Example:

  (let ((alist `((plus1 . ,1+) (minus1 . ,1-) (mul2 . ,(cut * 2 <>))))
        (number->alist (object-transformer alist '(plus1 mul2))))
    (number->alist 8))
  =>
  ((plus1 . 9) (mul2 . 16))
"
  (let ((alist (let ((use-all-params (null? params)))
                 (filter-map (match-lambda
                              ((param . fun)
                               (and (or use-all-params
                                        (memq param params))
                                    (cons param fun)))
                              (_ #f))
                             param-alist))))
    (lambda objects
      (map (match-lambda
            ((param . fun)
             (cons param (apply fun objects))))
           alist))))

(define %mentry-param-alist
  `((output       . ,manifest-entry-output)
    (path         . ,manifest-entry-item)
    (dependencies . ,manifest-entry-dependencies)))

(define mentry->alist
  (object-transformer %mentry-param-alist))

(define (package-inputs-names inputs)
  "Return list of full names of the packages from package INPUTS."
  (filter-map (match-lambda
               ((_ (? package? package))
                (package-full-name package))
               (_ #f))
              inputs))

(define (package-license-names package)
  "Return list of license names of the PACKAGE."
  (filter-map (lambda (license)
                (and (license? license)
                     (license-name license)))
              (list-maybe (package-license package))))

(define (package-unique? package)
  "Return #t if PACKAGE is a single package with such name/version."
  (null? (cdr (packages-by-name (package-name package)
                                (package-version package)))))

(define %package-param-alist
  `((id                . ,object-address)
    (package-id        . ,object-address)
    (name              . ,package-name)
    (version           . ,package-version)
    (license           . ,package-license-names)
    (synopsis          . ,package-synopsis)
    (description       . ,package-description)
    (home-url          . ,package-home-page)
    (outputs           . ,package-outputs)
    (non-unique        . ,(negate package-unique?))
    (inputs            . ,(lambda (pkg)
                            (package-inputs-names
                             (package-inputs pkg))))
    (native-inputs     . ,(lambda (pkg)
                            (package-inputs-names
                             (package-native-inputs pkg))))
    (propagated-inputs . ,(lambda (pkg)
                            (package-inputs-names
                             (package-propagated-inputs pkg))))
    (location          . ,(lambda (pkg)
                            (location->string (package-location pkg))))))

(define (package-param package param)
  "Return the value of a PACKAGE PARAM."
  (and=> (assq-ref %package-param-alist param)
         (cut <> package)))

\f
;;; Finding packages

(define (package-by-address address)
  (and=> (vhash-assq address %packages)
         cdr))

(define (packages-by-name+version name version)
  (or (hash-ref %package-table
                (name+version->key name version))
      '()))

(define (packages-by-full-name full-name)
  (call-with-values
      (lambda () (full-name->name+version full-name))
    packages-by-name+version))

(define (packages-by-id id)
  (if (integer? id)
      (let ((pkg (package-by-address id)))
        (if pkg (list pkg) '()))
      (packages-by-full-name id)))

(define (id->name+version id)
  (if (integer? id)
      (and=> (package-by-address id)
             (lambda (pkg)
               (values (package-name pkg)
                       (package-version pkg))))
      (full-name->name+version id)))

(define (package-by-id id)
  (first-or-false (packages-by-id id)))

(define (newest-package-by-id id)
  (and=> (id->name+version id)
         (lambda (name)
           (first-or-false (find-best-packages-by-name name #f)))))

(define (matching-packages predicate)
  (fold-packages (lambda (pkg res)
                   (if (predicate pkg)
                       (cons pkg res)
                       res))
                 '()))

(define (filter-packages-by-output packages output)
  (filter (lambda (package)
            (member output (package-outputs package)))
          packages))

(define* (packages-by-name name #:optional version output)
  "Return list of packages matching NAME, VERSION and OUTPUT."
  (let ((packages (if version
                      (packages-by-name+version name version)
                      (matching-packages
                       (lambda (pkg) (string=? name (package-name pkg)))))))
    (if output
        (filter-packages-by-output packages output)
        packages)))

(define (mentry->packages mentry)
  (call-with-values
      (lambda () (mentry->name+version+output mentry))
    packages-by-name))

(define (packages-by-regexp regexp match-params)
  "Return list of packages matching REGEXP string.
MATCH-PARAMS is a list of parameters that REGEXP can match."
  (define (package-match? package regexp)
    (any (lambda (param)
           (let ((val (package-param package param)))
             (and (string? val) (regexp-exec regexp val))))
         match-params))

  (let ((re (make-regexp regexp regexp/icase)))
    (matching-packages (cut package-match? <> re))))

(define (all-available-packages)
  "Return list of all available packages."
  (matching-packages (const #t)))

(define (newest-available-packages)
  "Return list of the newest available packages."
  (vhash-fold (lambda (name elem res)
                (match elem
                  ((_ newest pkgs ...)
                   (cons newest res))))
              '()
              (find-newest-available-packages)))

\f
;;; Making package/output patterns

(define (spec->package-pattern spec)
  (call-with-values
      (lambda () (full-name->name+version spec))
    list))

(define (spec->output-pattern spec)
  (call-with-values
      (lambda () (package-specification->name+version+output spec #f))
    list))

(define (id->package-pattern id)
  (if (integer? id)
      (package-by-address id)
      (spec->package-pattern id)))

(define (id->output-pattern id)
  ;; id should be "<package-address>:<output>" or "<name>-<version>:<output>"
  (let-values (((name version output)
                (package-specification->name+version+output id)))
    (if version
        (list name version output)
        (list (package-by-address (string->number name))
              output))))

(define (specs->package-patterns . specs)
  (map spec->package-pattern specs))

(define (specs->output-patterns . specs)
  (map spec->output-pattern specs))

(define (ids->package-patterns . ids)
  (map id->package-pattern ids))

(define (ids->output-patterns . ids)
  (map id->output-pattern ids))

(define (obsolete-package-patterns manifest)
  "Return list of package patterns for obsolete packages."
  (fold-manifest-by-name
   manifest
   (lambda (name version entries res)
     (let ((packages (packages-by-name name version)))
       (if (null? packages)
           (cons (list name version entries '()) res)
           res)))
   '()))

(define (obsolete-output-patterns manifest)
  "Return list of output patterns for obsolete packages."
  (fold (lambda (mentry res)
          (let ((packages (mentry->packages mentry)))
            (if (null? packages)
                (cons (list mentry '()) res)
                res)))
        '()
        (manifest-entries manifest)))

(define (manifest-package-patterns manifest)
  "Return list of package patterns for all MANIFEST entries."
  (fold-manifest-by-name manifest
                         (lambda (name version mentries res)
                           (cons (list name version mentries) res))
                         '()))

(define manifest-output-patterns manifest-entries)

\f
;;; Transforming package/output patterns into entries

(define (make-installed-alists mentries)
  (map mentry->alist mentries))

(define (make-package-entry palist malists)
  (cons (cons 'installed malists)
        palist))

(define (make-obsolete-package-entry name version mentries)
  `((id        . ,(name+version->full-name name version))
    (name      . ,name)
    (version   . ,version)
    (outputs   . ,(map manifest-entry-output mentries))
    (obsolete  . #t)
    (installed . ,(make-installed-alists mentries))))

(define* (make-output-entry palist package-address output
                            #:optional (malist '()) #:key installed?)
  (let ((base `((id        . ,(string-append
                               (number->string package-address)
                               ":" output))
                (output    . ,output)
                (installed . ,installed?))))
    (append base malist palist)))

(define* (make-obsolete-output-entry name version output
                                     #:optional (malist '()))
  (let ((base `((id         . ,(make-package-specification
                                name version output))
                (package-id . ,(name+version->full-name name version))
                (name       . ,name)
                (version    . ,version)
                (output     . ,output)
                (obsolete   . #t)
                (installed  . #t))))
    (append malist base)))

(define (package-pattern-transformer manifest params)
  "Return 'package-pattern->package-entries' function."
  (define package->alist
    (object-transformer %package-param-alist params))

  (define (->entries pattern)
    (match pattern
      ((? package? package)
       (list (make-package-entry
              (package->alist package)
              (make-installed-alists
               (mentries-by-name manifest
                                 (package-name package)
                                 (package-version package))))))
      ((name version)
       (->entries (list name version
                        (mentries-by-name manifest name version))))
      ((name version mentries)
       (->entries (list name version mentries
                        (packages-by-name name version))))
      ((name version mentries packages)
       (if (null? packages)
           (if (null? mentries)
               '()
               (list (make-obsolete-package-entry
                      name version mentries)))
           (let ((malists (make-installed-alists mentries)))
             (map (lambda (package)
                    (make-package-entry (package->alist package)
                                        malists))
                  packages))))))

  ->entries)

(define (output-pattern-transformer manifest params)
  "Return 'output-pattern->output-entries' function."
  (define package->alist
    (object-transformer (alist-delete 'id %package-param-alist)
                        params))

  (define mentry->alist
    (object-transformer (alist-delete 'output %mentry-param-alist)
                        params))

  (define* (entries-by-package package #:optional output
                               (mentries (mentries-by-name
                                          manifest
                                          (package-name package)
                                          (package-version package))))
    ;; Assuming that PACKAGE has this OUTPUT.
    (let ((palist  (package->alist package))
          (address (object-address package))
          (outputs (if output
                       (list output)
                       (package-outputs package))))
      (map (lambda (output)
             (let* ((mentry (mentry-by-output mentries output))
                    (malist (if mentry (mentry->alist mentry) '())))
               (make-output-entry palist address output malist
                                  #:installed? (->bool mentry))))
           outputs)))

  (define* (entries-by-mentry mentry #:optional
                              (packages (mentry->packages mentry)))
    (let-values (((name version output)
                  (mentry->name+version+output mentry)))
      (let ((malist (mentry->alist mentry)))
        (if (null? packages)
            (list (make-obsolete-output-entry
                   name version output malist))
            (map (lambda (package)
                   (make-output-entry
                    (package->alist package)
                    (object-address package)
                    output malist #:installed? #t))
                 packages)))))

  (define (->entries pattern)
    (match pattern
      ((? package? package)
       (entries-by-package package))
      (((? package? package) output)
       (entries-by-package package output))
      ((? manifest-entry? mentry)
       (entries-by-mentry mentry))
      (((? manifest-entry? mentry) packages)
       (entries-by-mentry mentry packages))
      ((name version output)
       (let ((packages (packages-by-name name version output))
             (mentries (mentries-by-name manifest name version output)))
         (if (null? mentries)
             (append-map (cut entries-by-package <> output mentries)
                         packages)
             (append-map (cut entries-by-mentry <> packages)
                         mentries))))))

  ->entries)

(define (entry-type-error entry-type)
  (error (format #f "Wrong entry-type '~a'" entry-type)))

(define (search-type-error entry-type search-type)
  (error (format #f "Wrong search type '~a' for entry-type '~a'"
                 search-type entry-type)))

(define %pattern-transformers
  `((package . ,package-pattern-transformer)
    (output  . ,output-pattern-transformer)))

(define (pattern-transformer entry-type)
  (assq-ref %pattern-transformers entry-type))

;; All functions from inner alists are called with (MANIFEST . SEARCH-VALS) as
;; arguments; see `get-package/output-entries'.
(define %patterns-makers
  (let* ((apply-to-rest        (lambda (fun)
                                 (lambda (_ . rest) (apply fun rest))))
         (apply-to-first       (lambda (fun)
                                 (lambda (first . _) (fun first))))
         (manifest-package-fun (apply-to-first manifest-package-patterns))
         (manifest-output-fun  (apply-to-first manifest-output-patterns))
         (regexp-fun           (lambda (_ regexp params . __)
                                 (packages-by-regexp regexp params)))
         (all-fun              (lambda _ (all-available-packages)))
         (newest-fun           (lambda _ (newest-available-packages))))
    `((package
       (id               . ,(apply-to-rest ids->package-patterns))
       (name             . ,(apply-to-rest specs->package-patterns))
       (installed        . ,manifest-package-fun)
       (generation       . ,manifest-package-fun)
       (obsolete         . ,(apply-to-first obsolete-package-patterns))
       (regexp           . ,regexp-fun)
       (all-available    . ,all-fun)
       (newest-available . ,newest-fun))
      (output
       (id               . ,(apply-to-rest ids->output-patterns))
       (name             . ,(apply-to-rest specs->output-patterns))
       (installed        . ,manifest-output-fun)
       (generation       . ,manifest-output-fun)
       (obsolete         . ,(apply-to-first obsolete-output-patterns))
       (regexp           . ,regexp-fun)
       (all-available    . ,all-fun)
       (newest-available . ,newest-fun)))))

(define (patterns-maker entry-type search-type)
  (or (and=> (assq-ref %patterns-makers entry-type)
             (cut assq-ref <> search-type))
      (search-type-error entry-type search-type)))

(define (get-package/output-entries profile params entry-type
                                    search-type search-vals)
  "Return list of package or output entries."
  (let* ((profile (if (eq? search-type 'generation)
                      (generation-file-name profile (car search-vals))
                      profile))
         (manifest (profile-manifest profile))
         (patterns (apply (patterns-maker entry-type search-type)
                          manifest search-vals))
         (->entries ((pattern-transformer entry-type) manifest params)))
    (append-map ->entries patterns)))

\f
;;; Generation entries

;;; XXX move to (guix profiles) ?
(define (profile-generations profile)
  "Return list of PROFILE generations."
  (let ((generations (generation-numbers profile)))
    (if (equal? generations '(0))
        '()
        generations)))

(define (generation-param-alist profile)
  "Return alist of generation parameters and functions for PROFILE."
  (list
   (cons 'id          identity)
   (cons 'number      identity)
   (cons 'prev-number (cut previous-generation-number profile <>))
   (cons 'path        (cut generation-file-name profile <>))
   (cons 'time        (lambda (gen)
                        (time-second (generation-time profile gen))))))

(define (matching-generations profile predicate)
  "Return list of PROFILE generations matching PREDICATE."
  (filter predicate (profile-generations profile)))

(define (last-generations profile number)
  "Return list of last NUMBER generations.
If NUMBER is 0 or less, return all generations."
  (let ((generations (profile-generations profile))
        (number (if (<= number 0) +inf.0 number)))
    (if (> (length generations) number)
        (list-head  (reverse generations) number)
        generations)))

(define (find-generations profile search-type search-vals)
  (case search-type
    ((id)
     (matching-generations profile (cut memq <> (car search-vals))))
    ((last)
     (last-generations profile (car search-vals)))
    ((all)
     (last-generations profile +inf.0))
    (else (search-type-error "generation" search-type))))

(define (get-generation-entries profile params search-type search-vals)
  "Return list of generation entries."
  (let ((generations (find-generations profile search-type search-vals))
        (->entry (object-transformer (generation-param-alist profile)
                                     params)))
    (map ->entry generations)))

\f
;;; Getting package/output/generation entries

(define (get-entries profile params entry-type search-type search-vals)
  (case entry-type
    ((package output)
     (get-package/output-entries profile params entry-type
                                 search-type search-vals))
    ((generation)
     (get-generation-entries profile params
                             search-type search-vals))
    (else (entry-type-error entry-type))))

\f
;;; Actions

(define* (package->manifest-entry* package #:optional output)
  (and package
       (begin
         (check-package-freshness package)
         (package->manifest-entry package output))))

(define* (make-install-manifest-entries id #:optional output)
  (package->manifest-entry* (package-by-id id) output))

(define* (make-upgrade-manifest-entries id #:optional output)
  (package->manifest-entry* (newest-package-by-id id) output))

(define* (make-manifest-pattern id #:optional output)
  "Make manifest pattern from a package ID and OUTPUT."
  (let-values (((name version)
                (id->name+version id)))
    (and name version
         (manifest-pattern
          (name name)
          (version version)
          (output output)))))

(define (convert-action-pattern pattern proc)
  "Convert action PATTERN into a list of objects returned by PROC.
PROC is called: (PROC ID) or (PROC ID OUTPUT)."
  (match pattern
    ((id . outputs)
     (if (null? outputs)
         (let ((obj (proc id)))
           (if obj (list obj) '()))
         (filter-map (cut proc id <>)
                     outputs)))
    (_ '())))

(define (convert-action-patterns patterns proc)
  (append-map (cut convert-action-pattern <> proc)
              patterns))

(define* (process-package-actions
          profile #:key (install '()) (upgrade '()) (remove '())
          (use-substitutes? #t) dry-run?)
  "Perform package actions.

INSTALL, UPGRADE, REMOVE are lists of 'package action patterns'.
Each pattern should have the following form:

  (ID . OUTPUTS)

ID is an object address or a full-name of a package.
OUTPUTS is a list of package outputs (may be an empty list)."
  (format #t "The process begins ...~%")
  (let* ((install (append
                   (convert-action-patterns
                    install make-install-manifest-entries)
                   (convert-action-patterns
                    upgrade make-upgrade-manifest-entries)))
         (remove (convert-action-patterns remove make-manifest-pattern))
         (transaction (manifest-transaction (install install)
                                            (remove remove)))
         (manifest (profile-manifest profile))
         (new-manifest (manifest-perform-transaction
                        manifest transaction)))
    (unless (and (null? install) (null? remove))
      (let* ((store (open-connection))
             (derivation (run-with-store
                          store (profile-derivation new-manifest)))
             (derivations (list derivation))
             (new-profile (derivation->output-path derivation)))
        (set-build-options store
                           #:use-substitutes? use-substitutes?)
        (manifest-show-transaction store manifest transaction
                                   #:dry-run? dry-run?)
        (show-what-to-build store derivations
                            #:use-substitutes? use-substitutes?
                            #:dry-run? dry-run?)
        (unless dry-run?
          (let ((name (generation-file-name
                       profile
                       (+ 1 (generation-number profile)))))
            (and (build-derivations store derivations)
                 (let* ((mentries (manifest-entries new-manifest))
                        (count    (length mentries)))
                   (switch-symlinks name new-profile)
                   (switch-symlinks profile name)
                   (format #t (N_ "~a package in profile~%"
                                  "~a packages in profile~%"
                                  count)
                           count)))))))))

debug log:

solving 9295894 ...
found 9295894 in https://yhetil.org/guix-devel/87sijodrl2.fsf@gmail.com/
found 1383d08 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 1383d088306bf44644566b6d54f4e000d4f4f6b4	emacs/guix-main.scm

applying [1/1] https://yhetil.org/guix-devel/87sijodrl2.fsf@gmail.com/
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 1383d08..9295894 100644

Checking patch emacs/guix-main.scm...
Applied patch emacs/guix-main.scm cleanly.

index at:
100644 9295894f6e90ca94539d1d399881840dca0661d1	emacs/guix-main.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).