utils: computed-substitution-with-inputs: Support directory substitution.

* modules/rosenthal/utils/file.scm (computed-substitution-with-inputs): Support
directory substitution.
Error when pattern not found.
This commit is contained in:
Hilton Chain 2025-09-12 14:33:50 +08:00
parent dff8c3d547
commit dfe569fdc0
No known key found for this signature in database
GPG Key ID: ACC66D09CA528292

View File

@ -16,11 +16,20 @@
(computed-file
name
#~(begin
(use-modules (guix build utils))
(use-modules (ice-9 match)
(guix build utils))
(copy-file #$file #$output)
(substitute* #$output
(("\\$\\$([^\\$]+)\\$\\$" _ path)
(search-path '#$inputs path)))))))
(let loop ((candidates '#$inputs))
(if (null? candidates)
(error "file '~a' not found" path)
(match candidates
((candidate . rest)
(let ((full-path (in-vicinity candidate path)))
(if (file-exists? full-path)
full-path
(loop rest)))))))))))))
(define (file-content file)
(call-with-input-file (canonicalize-path file) get-string-all))