guixconfig/library.org

46 lines
1.4 KiB
Org Mode
Raw Normal View History

2023-12-01 14:30:07 +00:00
# -*- geiser-scheme-implementation: guile -*-
2023-12-01 13:22:33 +00:00
#+TITLE: Babel Library
This library contains code blocks to be used by other files in this repository.
* Converting Lists
Converting org lists into guix ~use-~ calls.
#+NAME: list-to-use
2023-12-01 14:30:07 +00:00
#+begin_src scheme :var use-call="use-modules" :var entries='() :var all-parens=0 :results code pp
`(,(string->symbol use-call)
,@(map (lambda (x)
(let ((splits (string-split x #\ )))
(if (and (= (length splits) 1)
(= 0 all-parens))
(string->symbol (car splits))
(map (lambda (y) (string->symbol y))
splits))))
entries))
2023-12-01 13:22:33 +00:00
#+end_src
Converting Org lists into Scheme symbol lists.
#+NAME: org-to-scheme-sym-list
2023-12-01 14:30:07 +00:00
#+begin_src scheme :var input='() :results code pp
2023-12-01 13:22:33 +00:00
`(list
2023-12-01 14:30:07 +00:00
,@(map (lambda (x) (string->symbol x)) input))
2023-12-01 13:22:33 +00:00
#+end_src
* Converting Tables
#+NAME: service-converter
2023-12-01 14:30:07 +00:00
#+begin_src scheme :var input='() :colnames yes :results code pp
2023-12-01 13:22:33 +00:00
`(list
2023-12-01 14:30:07 +00:00
,@(map
2023-12-01 13:22:33 +00:00
(lambda (row)
2023-12-01 14:30:07 +00:00
(let ((service-name (car row))
(configuration (cadr row)))
`(service ,(string->symbol (string-append service-name "-service-type"))
(,(string->symbol (string-append service-name "-configuration"))
,@(call-with-input-string configuration
read)))))
2023-12-01 13:22:33 +00:00
input))
#+end_src