Hi Pierre, Pierre Neidhardt <m...@ambrevar.xyz> skribis:
> Ludovic Courtès <l...@gnu.org> 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’.