profile-to-manifest.scm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;; Run with:
  2. ;; guile -s FILE ~/.guix-profile
  3. (use-modules (guix profiles)
  4. (gnu packages) ; fold-packages
  5. (guix packages) ; package structure
  6. (ice-9 match)
  7. (ice-9 pretty-print))
  8. (define (packages-by-name name)
  9. (fold-packages (lambda (package list)
  10. (if (string=? (package-name package) name)
  11. (cons package list)
  12. list))
  13. '()))
  14. (define (guix-manifest where)
  15. (sort (map (lambda (entry)
  16. (let* ((name (manifest-entry-name entry))
  17. (out (manifest-entry-output entry))
  18. (version (manifest-entry-version entry))
  19. (default-version (match (packages-by-name name)
  20. ((first-name . rest)
  21. (package-version
  22. first-name))
  23. (else #f))))
  24. (string-append name
  25. (if (and default-version
  26. (not (string= version default-version)))
  27. (format #f "@~a" version)
  28. "")
  29. (if (string= out "out")
  30. ""
  31. (format #f ":~a" out)))))
  32. (manifest-entries (profile-manifest where)))
  33. string<?))
  34. ;; Thanks to Ivan Vilata-i-Balaguer for this:
  35. (define (guix-commit)
  36. (let ((guix-manifest (profile-manifest (string-append (getenv "HOME") "/.config/guix/current"))))
  37. (match (assq 'source (manifest-entry-properties (car (manifest-entries guix-manifest))))
  38. (('source ('repository ('version 0) _ _
  39. ('commit commit) _ ...))
  40. commit)
  41. (_ #f))))
  42. (match (command-line)
  43. ((_ where)
  44. (format #t ";; commit: ~a\n" (guix-commit))
  45. (pretty-print
  46. `(specifications->manifest
  47. ',(guix-manifest where))))
  48. (_ (error "Please provide the path to a Guix profile.")))