mirror of
https://git.in.rschanz.org/ryan77627/guix-config.git
synced 2024-11-07 09:46:15 -05:00
34 lines
1.2 KiB
Scheme
34 lines
1.2 KiB
Scheme
|
(define-module (ryan-config utils)
|
||
|
#:use-module (gnu packages)
|
||
|
#:use-module (gnu services)
|
||
|
#:use-module (gnu home services)
|
||
|
#:use-module (gnu home services shepherd)
|
||
|
#:use-module (gnu packages freedesktop)
|
||
|
#:use-module (gnu services configuration)
|
||
|
#:use-module (guix gexp)
|
||
|
#:use-module (ice-9 regex)
|
||
|
#:use-module (ice-9 pretty-print)
|
||
|
#:use-module (ice-9 textual-ports)
|
||
|
|
||
|
#:export (gather-manifest-packages
|
||
|
apply-template-file))
|
||
|
|
||
|
(define (apply-template template-string value-alist)
|
||
|
(regexp-substitute/global #f
|
||
|
"\\$\\{([A-Za-z/\\-]+)\\}"
|
||
|
template-string
|
||
|
'pre
|
||
|
(lambda (m)
|
||
|
(let ((entry (assq (string->symbol (match:substring m 1))
|
||
|
value-alist)))
|
||
|
(if entry
|
||
|
(cdr entry)
|
||
|
"VALUE NOT FOUND")))
|
||
|
'post))
|
||
|
|
||
|
(define (apply-template-file file-path value-alist)
|
||
|
(call-with-input-file file-path
|
||
|
(lambda (port)
|
||
|
(apply-template (get-string-all port)
|
||
|
value-alist))))
|