[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Return back original implementation for text-config serialization
From: |
Andrew Tropin |
Subject: |
Re: Return back original implementation for text-config serialization |
Date: |
Sun, 13 Feb 2022 17:09:37 +0300 |
On 2022-02-05 12:34, Maxime Devos wrote:
> Andrew Tropin schreef op wo 26-01-2022 om 11:36 [+0300]:
>> In addition to the problems I mentioned above:
>>
>> 1. Mixed usage of two configuration languages (nginx-conf and lisp).
>> 2. Having a string, which should be properly escaped (luckily for
>> this
>> example it's not a problem).
>
> Mixing two configuration languages can be avoided by supporting
> everything with records.
>
I suppose it will lead to a huge maintenance burden, but it's just a
guess.
>>
>> we also:
>>
>> 3. Have to implement our own templating engine (using format function
>> in this case) to share the values from guile with the config.
>
> This seems to be the same for this list based configuration system
> and record based configuraiton system; for the nginx example you gave,
> all these lists with parentheses need to turned into something with
> brackets that nginx understands anyway.
>
>> 4.1. Don't know where extra-content goes. (It goes to http section
>> not the
>> end of the file, so we have to start with "}" to get a correct
>> configuration).
>
> Can be solved by adding missing options to the Guix service definition
> (and documentation) when the need arises.
>
>> 4.2. Don't control where it must be placed. (Can be important in
>> other
>> use cases, which I can share if needed).
>
> Likewise.
>
>> 5. Have inconsistent implementation of extra-config, extra-content,
>> raw-lines
>> and other escape hatches (We need to learn it everytime we write a
>> new
>> service configuration).
>
> Likewise.
>
> Also, the mapping of upstream configuration files to lists in Guix
> seems far from obvious to me: in https://issues.guix.gnu.org/52698,
> how am I supposed to know that 'us,ru' must be a symbol, why isn't
> it a string?
It's quite obvious. ((layout us,ru)) will be translated to
`layout us,ru` and this is what expected by man 5 sway-input.
Strings and their purpose are covered below.
> If one of the strings for some property includes a special character
> from the configuration language (say, '$'), should it be escaped in
> Guix ((bindsym ... "[class=\"$100 dollars\"]" ...) or (bindsym
> ... "[class=\"\\$100 dollars\""]""))?
Not sure about this question. If this character have to be escaped in
the target configuration, "[class=\"\\$100 dollars\"]" will produce what
you need: [class="\$100 dollars"].
According to string serialization: In first iteration I made a soft
escape hatch (all strings are serialized to its values), it made it
possible to express this CRITERIA (man 5 sway) statement you menshioned
above.
I added a proper gexp support a little later, but the example with
string already was in use. Currently it should be done this way:
`((bindsym ... ,#~"[class=\"$100 dollars\"]" ...))
And probably strings must be serialized to quoted values now, if I
make home-sway v2 it will be done this way.
I didn't make a CRITERIA to be a part of a grammar because:
1. I needed a working prototype fast to move forward on Guix Home
itself.
2. I encountered a bug in guile compiler and already spend a lot of time
on home-sway service, after I finally localized it and it was fixed by
Andy. I decided to postpone further improvements of sway service for
later times.
> Why (bindsym ... "[class=\"foo\"]") instead of
> (bindsym ... (= class "foo"))?
This one is good. As you see I didn't made a CRITERIA a part of the
grammar, so there is no proper way to express it without escape hatch,
however home-sway v2 can be done slightly different, more on that in the
reply to lists and vectors question.
>
> Why (bindsym ... exec emacsclient ...) and not
> (bindsym ... exec (file-append emacs "/bin/emacsclient) ...)?
> How am I supposed to know whether emacs is in the path or not,
> and if it is, is this merely an implementation detail?
In most cases it should be
`((bindsym ... exec ,(file-append emacs "/bin/emacsclient") ...))
You are right.
>
> How would I know if it's (bindsym ... exec emacsclient -c --eval
> "'(eshell)'") or (bindsym ... "exec emacsclient -c --eval
> \"'(eshell)'\"")? Since the idea is to keep as close to the
> configuration language as possible, shouldn't it be the second?
exec is a part of configuration grammar and it should not be quoted.
Command itself doesn't have to be quoted too, but probably can be if you
want:
`((bindsym ... exec ,#~"'emacsclient -c --eval \"\\'(eshell)\\'\"'"))
>
> Why lists and not vectors?
This one is good as well, back in the day I was implmenting home-sway
service I didn't have much experience with guile vectors. I tried not
to be any fancy and used lists for both sequential and associative data
structures.
Vectors can be a good match, also it will be easier to make a CRITERIA
to be a part of a grammar and be used without escape hatch. In the
combination of proper string serialization it will look like:
--8<---------------cut here---------------start------------->8---
`#(#(bindsym $mod+o ((class . "foo")
(tiling)
(window_type . toolbar))
kill)
#(bindsym $mod+e exec ,(file-append emacs "/bin/emacsclient"))
,#~"# This is comment\n# Layout related settings:"
#(input
#(#(xkb_layout us,ru)
#(xkb_variant dvp,))))
--8<---------------cut here---------------end--------------->8---
and the resulting config will be:
--8<---------------cut here---------------start------------->8---
bindsym $mod+o [class="foo" tiling window_type=toolbar] kill
bindsym $mod+e exec
/gnu/store/2808l07ld4hzlmlslvbqjlqrprw7f1xz-emacs/bin/emacsclient
# This is comment
# Layout related settings:
input * {
xkb_layout us,ru
xkb_variant dvp,
}
--8<---------------cut here---------------end--------------->8---
Sharps are a little bit noisy, but such config is a little more complete
than original one, probably easier to parse, type check and serialize.
Also, I used vectors recently for serialization to a few different type
of configuration formats and quite satisfied with them.
Thank you very much for a fresh look, the thoughtful questions and
ideas! Only the knowledge I got thanks to this discussion is worth
starting this thread :)
--
Best regards,
Andrew Tropin
signature.asc
Description: PGP signature