1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-02 04:53:33 +02:00
home-manager/tests/lib/generators/tokdl.nix
h7x4 fce9dbfeb4
lib: add generator for KDL
Added a generator for the KDL document language.
This is in order for home-manager to natively generate
the new config format for zellij, as described in nix-community#3364.

There is not a one to one mapping between KDL and nix types,
but attrset translation is heavily based on KDLs JSON-IN-KDL microsyntax.
The exception here is the `_args` and `_props` arguments, which lets you
specify arguments and properties as described in the spec.

See more here:
- https://kdl.dev/
- https://github.com/kdl-org/kdl/blob/main/SPEC.md

The generator also conforms to the interface from the nixpkgs manual:
https://nixos.org/manual/nixpkgs/stable/#sec-generators

Co-authored-by: Gaetan Lepage <gaetan@glepage.com>
2023-03-10 16:48:10 +01:00

54 lines
965 B
Nix

{ config, lib, ... }:
{
home.file."result.txt".text = lib.hm.generators.toKDL { } {
a = 1;
b = "string";
c = ''
multiline string
with special characters:
\t \n \" "
'';
unsafeString = " \" \n ";
flatItems = [ 1 2 "asdf" true null ];
bigFlatItems = [
23847590283751
1.239
''
multiline " " "
string
''
null
];
nested = [ [ 1 2 ] [ true false ] [ ] [ null ] ];
extraAttrs = {
_args = [ 2 true ];
_props = {
arg1 = 1;
arg2 = false;
};
nested = {
a = 1;
b = null;
};
};
listInAttrsInList = {
list1 = [
{ a = 1; }
{ b = true; }
{
c = null;
d = [{ e = "asdfadfasdfasdf"; }];
}
];
list2 = [{ a = 8; }];
};
};
nmt.script = ''
assertFileContent \
home-files/result.txt \
${./tokdl-result.txt}
'';
}