summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Pastor Pérez <sergio.pastorperez@outlook.es>2025-01-18 21:45:21 +0100
committerHilton Chain <hako@ultrarare.space>2025-01-20 23:52:23 +0800
commitc29a9af656befb05fc75674133db9e0d37ffbac0 (patch)
treed1cabd9b95aa0cf49bffad7040659988da506a6d
parenta11ff2a65a6b9e0e9f2edd0930a1b7efbed7a5aa (diff)
nonguix: Add with-transformation.
* nonguix/utils.scm (with-transformation): New procedure. Signed-off-by: Hilton Chain <hako@ultrarare.space>
-rw-r--r--nonguix/utils.scm47
1 files changed, 46 insertions, 1 deletions
diff --git a/nonguix/utils.scm b/nonguix/utils.scm
index 6703f4a..4deb597 100644
--- a/nonguix/utils.scm
+++ b/nonguix/utils.scm
@@ -4,11 +4,14 @@
4 4
5(define-module (nonguix utils) 5(define-module (nonguix utils)
6 #:use-module (srfi srfi-26) 6 #:use-module (srfi srfi-26)
7 #:use-module (srfi srfi-43)
7 #:use-module (ice-9 match) 8 #:use-module (ice-9 match)
8 #:use-module (ice-9 textual-ports) 9 #:use-module (ice-9 textual-ports)
9 #:use-module (ice-9 popen) 10 #:use-module (ice-9 popen)
10 #:use-module (guix utils) 11 #:use-module (guix utils)
11 #:use-module (guix packages)) 12 #:use-module (guix packages)
13 #:use-module (gnu services)
14 #:export (with-transformation))
12 15
13(define-public (to32 package64) 16(define-public (to32 package64)
14 "Build package for i686-linux. 17 "Build package for i686-linux.
@@ -22,3 +25,45 @@ Only x86_64-linux and i686-linux are supported.
22 (arguments `(#:system "i686-linux" 25 (arguments `(#:system "i686-linux"
23 ,@(package-arguments package64))))) 26 ,@(package-arguments package64)))))
24 (_ package64))) 27 (_ package64)))
28
29;; For concerns and direction of improvement, see this thread:
30;; https://lists.gnu.org/archive/html/guix-devel/2024-06/msg00275.html
31(define* (with-transformation proc obj #:optional (pred package?))
32 "Recursing into child elements, apply PROC to every element of OBJ that
33matches PRED."
34 (match obj
35 ((? pred)
36 (proc obj))
37 ((? procedure?)
38 (lambda args
39 (apply values
40 (map (cut with-transformation proc <> pred)
41 (call-with-values
42 (lambda ()
43 (apply obj args))
44 list)))))
45 ((a . b)
46 (cons (with-transformation proc a pred)
47 (with-transformation proc b pred)))
48 ((_ ...)
49 (map (cut with-transformation proc <> pred)
50 obj))
51 (#(_ ...)
52 (vector-map (lambda (vec elt)
53 (with-transformation proc elt pred))
54 obj))
55 ;; `<service-type>' and `<origin>' record types are expected to not be
56 ;; modified. Altering them causes very difficult to debug run-time errors.
57 ((or (? service-type?)
58 (? origin?))
59 obj)
60 ((? record?)
61 (let* ((record-type (record-type-descriptor obj))
62 (record-fields (record-type-fields record-type)))
63 (apply (record-constructor record-type)
64 (map (lambda (field)
65 (let* ((accessor (record-accessor record-type field))
66 (obj (accessor obj)))
67 (with-transformation proc obj pred)))
68 record-fields))))
69 (_ obj)))