summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiliana Marie Prikler <liliana.prikler@gmail.com>2022-05-26 11:01:02 +0200
committerGuix Patches Tester <>2022-05-26 10:23:30 +0100
commit8454d5f5713a6a8774612d8156af828f76d134f5 (patch)
tree6df498d73b3d2e9f1a1bfc7f0c481b829a96f05d
parent07101ac33fc0596a0ad4b7a59a12f4dbd5c0cd58 (diff)
downloadguix-patches-8454d5f5713a6a8774612d8156af828f76d134f5.tar
guix-patches-8454d5f5713a6a8774612d8156af828f76d134f5.tar.gz
guix: Add syntactic sugar for profile generation.series-12477
* guix/profiles.scm (%profile, package-compatibility-helper): New variables. (profile): Implement in terms of package-compatibility-helper.
-rw-r--r--guix/profiles.scm23
-rw-r--r--tests/profiles.scm16
2 files changed, 38 insertions, 1 deletions
diff --git a/guix/profiles.scm b/guix/profiles.scm
index bf50c00a1e..fbc343c456 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -1974,7 +1974,7 @@ are cross-built for TARGET."
(manifest-entries manifest))))))))
;; Declarative profile.
-(define-record-type* <profile> profile make-profile
+(define-record-type* <profile> %profile make-profile
profile?
(name profile-name (default "profile")) ;string
(content profile-content) ;<manifest>
@@ -1987,6 +1987,27 @@ are cross-built for TARGET."
(relative-symlinks? profile-relative-symlinks? ;Boolean
(default #f)))
+(define-syntax package-compatibility-helper
+ (syntax-rules (packages manifest)
+ ((_ () (fields ...))
+ (%profile fields ...))
+ ((_ ((packages exp) rest ...) (others ...))
+ (package-compatibility-helper
+ (rest ...)
+ (others ... (content (packages->manifest
+ (delete-duplicates exp eq?))))))
+ ((_ ((manifest exp) rest ...) (others ...))
+ (package-compatibility-helper
+ (rest ...)
+ (others ... (content exp))))
+ ((_ (field rest ...) (others ...))
+ (package-compatibility-helper (rest ...) (others ... field)))))
+
+(define-syntax-rule (profile fields ...)
+ "Build a <profile> record, automatically converting 'packages' or 'manifest '
+field specifications to 'content'."
+ (package-compatibility-helper (fields ...) ()))
+
(define-gexp-compiler (profile-compiler (profile <profile>) system target)
"Compile PROFILE to a derivation."
(match profile
diff --git a/tests/profiles.scm b/tests/profiles.scm
index d59d75985f..970a34b6cc 100644
--- a/tests/profiles.scm
+++ b/tests/profiles.scm
@@ -272,6 +272,22 @@
(manifest-pattern (name name))))
'("gcc" "binutils" "glibc" "coreutils" "grep" "sed"))))
+(test-assert "profile syntax sugar"
+ (let ((p1 (dummy-package "p1"))
+ (p2 (dummy-package "p2")))
+ (define (profile=? . profiles)
+ (define (manifest=? . manifests)
+ ;; Since we're using the same packages, we could also compare via eq?
+ (apply list= manifest-entry=? (map manifest-entries manifests)))
+ (apply manifest=? (map profile-content profiles)))
+
+ (profile=?
+ (profile (content (manifest
+ (map package->manifest-entry (list p1 p2)))))
+ (profile (content (packages->manifest (list p1 p2))))
+ (profile (manifest (packages->manifest (list p1 p2))))
+ (profile (packages (list p1 p2))))))
+
(test-assertm "profile-derivation"
(mlet* %store-monad
((entry -> (package->manifest-entry %bootstrap-guile))