-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generators: new toKDL parser #4614
Conversation
Hello @cgahr! Thank you for looking into this. I strongly agree with you that the KDL parser is flawed and needs a complete rewrite. It probably shouldn't have been merged in the first place, and more work should have gone into ensuring a more complete one to one correspondence between the generator API and KDL. I'm currently working on a new set of generators for more obscure config languages in nixpkgs. Starting with libconfig at NixOS/nixpkgs#246115, I'm working my way through HOCON and KDL right now, using a very similar I think the KDL parser is much more needed in home-manager right now due to the broken state of the zellij module, but completing this also means potentially large duplicated efforts. If you'd like to join me, I'd be happy to work together on this! Feel free to DM me on matrix. If you decide you'd rather work on completing this here for now, I'll be happy to review and test the code. |
Thank you for your contribution! I marked this pull request as stale due to inactivity. Please read the relevant sections below before commenting. If you are the original author of the PR
If you are not the original author of the PR
|
Description
My idea for a new toKDL parser. The current one has significant problems since it is not possible to encode all possible KDls in nix (see #4613 #4612 #4485 #4465 #4160 #4054).
I propose this PR as a solution.
Idea
In its core, KDL is a language encoding not only data but also lists of sequential commands. By its nature, nix has problems encoding this.
In addition, the current implementation of
toKDL
was inspired by the rules for convertingkdl
tojson
. This, however, is the wrong direction: we want to convertnix -> json -> kdl
.As such, the current implementation cannot encode things like
Implementation
The idea is the following:
Incompatibilities
List of literals
All lists and sets are "exploded", i.e. each entry gets its own line:
before:
now:
In this case the previous behavior was intended to make writing the config easier but made the previous example impossible to express.
_args
and_props
_args
and_props
do not work anymore:Before:
Now:
This behavior can be readded. Afaik, it was only intended to be a workaround to handle nix limited capabilites. With this new parser, they are not needed anymore. We could consider properly depcrecating this behavior.
What's new
Converting
'
to"
The new parser heavily uses strings. To make to syntax easier I propose to convert
'
automatically to '"' if they are in thename
of a set or in a list:Now:
This is technically incompatible with the kdl specs since the following is a valid config:
This would be impossible to write as a nix with my proposed parser.
much more strings
With this parser much more strings would have to be used. Consider the following nix config for zellij:
In my opinion, this is much more readable compared to before (and of course it is now possible to encode things that were not possible before).
Checklist
For now the tests are failing, the original tests are falling to have a reference to how it used to be.
Change is backwards compatible.
Code formatted with
./format
.Code tested through
nix-shell --pure tests -A run.all
ornix develop --ignore-environment .#all
using Flakes.Test cases updated/added. See example.
Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module
Maintainer CC
@emilazy @foo-dogsquared @erikkrieg @h7x4 @rycee
What do you think?