guixconfig/library.org

55 lines
1.6 KiB
Org Mode
Raw Normal View History

2023-12-01 13:22:33 +00:00
#+TITLE: Babel Library
2023-12-14 21:49:12 +00:00
#+PROPERTY: header-args:scheme :session *guile* :prologue "(use-modules (ice-9 pretty-print))"
2023-12-01 13:22:33 +00:00
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-12 09:57:23 +00:00
#+begin_src scheme :var use-call="use-modules" :var entries='() :var all-parens=0 :results output
(pretty-print
`(,(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.
2023-12-13 02:02:44 +00:00
#+NAME: list-sample
2023-12-12 09:57:23 +00:00
- Entry 1
- Entry 2
2023-12-01 13:22:33 +00:00
#+NAME: org-to-scheme-sym-list
2023-12-14 21:49:12 +00:00
#+begin_src scheme :var input=list-sample :results output
2023-12-12 09:57:23 +00:00
(pretty-print
2023-12-14 21:49:12 +00:00
`(list ,@(map string->symbol input)))
2023-12-01 13:22:33 +00:00
#+end_src
2023-12-14 21:49:12 +00:00
#+RESULTS: org-to-scheme-sym-list
: (list #{Entry 1}# #{Entry 2}#)
2023-12-01 13:22:33 +00:00
* Converting Tables
#+NAME: service-converter
2023-12-14 21:49:12 +00:00
#+begin_src scheme :var input='() :colnames yes :results output
2023-12-12 09:57:23 +00:00
(pretty-print
`(list
,@(map
(lambda (row)
(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)))))
input)))
2023-12-01 13:22:33 +00:00
#+end_src