guix-dotfiles/modules/ryan-config/utils.scm

34 lines
1.2 KiB
Scheme
Raw Normal View History

2024-01-18 23:43:59 +00:00
(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))))