modules/ryan-config/utils.scm

be3902a72477823bd5dc70301f4e48c84bc4d526 · 1.2 KB · 33 lines raw

1 (define-module (ryan-config utils)
2 #:use-module (gnu packages)
3 #:use-module (gnu services)
4 #:use-module (gnu home services)
5 #:use-module (gnu home services shepherd)
6 #:use-module (gnu packages freedesktop)
7 #:use-module (gnu services configuration)
8 #:use-module (guix gexp)
9 #:use-module (ice-9 regex)
10 #:use-module (ice-9 pretty-print)
11 #:use-module (ice-9 textual-ports)
12
13 #:export (gather-manifest-packages
14 apply-template-file))
15
16 (define (apply-template template-string value-alist)
17 (regexp-substitute/global #f
18 "\\$\\{([A-Za-z/\\-]+)\\}"
19 template-string
20 'pre
21 (lambda (m)
22 (let ((entry (assq (string->symbol (match:substring m 1))
23 value-alist)))
24 (if entry
25 (cdr entry)
26 "VALUE NOT FOUND")))
27 'post))
28
29 (define (apply-template-file file-path value-alist)
30 (call-with-input-file file-path
31 (lambda (port)
32 (apply-template (get-string-all port)
33 value-alist))))