diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ryan-config/utils.scm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/ryan-config/utils.scm b/modules/ryan-config/utils.scm new file mode 100644 index 0000000..e889e69 --- /dev/null +++ b/modules/ryan-config/utils.scm | |||
@@ -0,0 +1,33 @@ | |||
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)))) | ||