guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Store channel specification in profile


From: Ludovic Courtès
Subject: Re: Store channel specification in profile
Date: Mon, 24 Feb 2020 17:16:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hi Pierre,

Pierre Neidhardt <address@hidden> skribis:

> Ludovic Courtès <address@hidden> writes:

[...]

>> What we lack is the ability to obtain a “manifest.scm” kind of file
>> (code) that users can pick as a starting point in their migration
>> towards declarative deployment.
>
> You mean a script like the following?
>
> ;; Run with:
> ;;     guile -s FILE ~/.guix-profile
>
> (use-modules (guix profiles)
>              (gnu packages)             ; fold-packages
>              (guix packages)            ; package structure
>              (ice-9 match)
>              (ice-9 pretty-print))
>
>
> (define (packages-by-name name)
>   (fold-packages (lambda (package list)
>                    (if (string=? (package-name package) name)
>                        (cons package list)
>                        list))
>                  '()))
>
> (define (guix-manifest where)
>   (sort (map (lambda (entry)
>                (let* ((name (manifest-entry-name entry))
>                       (out (manifest-entry-output entry))
>                       (version (manifest-entry-version entry))
>                       (default-version (match (packages-by-name name)
>                                          ((first-name . rest)
>                                           (package-version
>                                            first-name))
>                                          (else #f))))
>                  (string-append name
>                                 (if (and default-version
>                                          (not (string= version 
> default-version)))
>                                     (format #f "@~a" version)
>                                     "")
>                                 (if (string= out "out")
>                                     ""
>                                     (format #f ":~a" out)))))
>              (manifest-entries (profile-manifest where)))
>         string<?))

Yes!  That alone would already be a useful tool to migrate from the
“imperative” style to the declarative style.  I’m sure it’d be good
enough 90% of the time.

(Note: we should remove the ‘sort’ call here as the order of packages in
the manifest is significant when there are file collisions.)

How does that sound?  Would you like to integrate something like this,
maybe ‘guix package --export’ or something?

> ;; Thanks to Ivan Vilata-i-Balaguer for this:
> (define (guix-commit)
>   (let ((guix-manifest (profile-manifest (string-append (getenv "HOME") 
> "/.config/guix/current"))))
>     (match (assq 'source (manifest-entry-properties (car (manifest-entries 
> guix-manifest))))
>       (('source ('repository ('version 0) _ _
>                              ('commit commit) _ ...))
>        commit)
>       (_ #f))))
>
> (match (command-line)
>   ((_ where)
>    (format #t ";; commit: ~a\n" (guix-commit))
>    (pretty-print
>     `(specifications->manifest
>       ',(guix-manifest where))))

Emitting channel info as comments like this, and/or a warning when
there’s a conflict (packages coming from different commits of the same
channel) could be done as a second step.

Thanks,
Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]