From: Simon Streit <simon@netpanic.org>
To: help-guix@gnu.org
Subject: Help on writing config serialiser
Date: Mon, 24 Jan 2022 17:13:09 +0100 [thread overview]
Message-ID: <ygupmohglii.fsf@netpanic.org> (raw)
Hello!
I am trying to write a config serialiser for Samba's smb.conf. While
developing the service, I noticed that my current approach should be
done in while using a config serialiser. I modified the example that
is in the manual:
--8<---------------cut here---------------start------------->8---
(use-modules (gnu services)
(guix gexp)
(gnu services configuration)
(srfi srfi-26)
(srfi srfi-1))
;; Turn field names, which are Scheme symbols into strings
(define (uglify-field-name field-name)
(let ((str (symbol->string field-name)))
;; field? -> is-field
(if (string-suffix? "?" str)
(string-append "is-" (string-drop-right str 1))
str)))
(define (serialize-string field-name value)
#~(string-append #$(uglify-field-name field-name) " = " #$value "\n"))
(define (serialize-integer field-name value)
(serialize-string field-name (number->string value)))
(define (serialize-boolean field-name value)
(serialize-string field-name (if value "yes" "no")))
;;; [sections]
(define (serialize-section-name field-name value)
#~(string-append "\n[" #$value "]\n"))
(define (list-of-smb-conf-sections? lst) ;wrong type to apply?!?
(every smb-conf-section? lst))
(define (serialize-list-of-smb-conf-sections field-name value)
#~(string-append #$@(map (cut serialize-configuration <>
smb-conf-section-fields)
value)))
;;; [global]
(define (serialize-smb-conf configuration)
(mixed-text-file
"smb.conf"
#~(string-append ;; "[global]\n"
#$(serialize-configuration
configuration smb-conf-fields))))
(define-maybe integer)
(define-maybe string)
;;; section part
(define-configuration smb-conf-section
;; (package
;; (file-like samba)
;; "The @var{samba} package.")
(section-name
(string)
"Name of section that describes a shared resource, also known as
``share''. The section name is the name of the shared resource and
the parameters withing the section define the shares attributes."
serialize-section-name)
;; From here on all parameter options described in smb.conf(5)
;; should comes below. Currently this list is incomplete, needs
;; testing, and it would be nice to have a converter to easily
;; convert the parameters directly found in Samba's sources.
;; For instance, the manpage for smb.conf is automatically
;; generated. It should be possible to extract this from source,
;; and normalise it here.
(workgroup ;(G)
;; (string "WORKGROUP")
(maybe-string "WORKGROUP")
"This controls what workgroup your server will appear to be in when
queried by clients. Note that this parameter also controls the Domain
name used with the @code{security = domain} setting.
Default: @code{(\"WORKGROUP\")}
Example: @code{(\"MYGROUP\")}"))
;;; main part
(define-configuration smb-conf
(workgroup
(string "WORKGROUP")
"")
(sections
(list-of-smb-conf-sections '())
"List of sections are generated here."))
(define my-smb-conf
(smb-conf
;; (workgroup "GNU")
(sections
(list
(smb-conf-section
(section-name "global")
(workgroup "GNU")
)))
))
--8<---------------cut here---------------end--------------->8---
Unfortunately, this procedure fails with an error:
--8<---------------cut here---------------start------------->8---
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure every: Wrong type argument: #<syntax-transformer smb-conf-section?>
--8<---------------cut here---------------end--------------->8---
And this error is not clear to me yet. I've been stuck at comparing the
example with my version. I'd be happy to receive a bit of help.
Kind regards
Simon
next reply other threads:[~2022-01-24 16:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 16:13 Simon Streit [this message]
2022-01-28 13:13 ` Is the example about the serialiser in the manual correct? Was: Help on writing config serialiser Simon Streit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ygupmohglii.fsf@netpanic.org \
--to=simon@netpanic.org \
--cc=help-guix@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).