mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-11 17:39:37 +08:00
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>
This commit is contained in:
1
tests/lib/generators/default.nix
Normal file
1
tests/lib/generators/default.nix
Normal file
@@ -0,0 +1 @@
|
||||
{ generators-tokdl = ./tokdl.nix; }
|
||||
41
tests/lib/generators/tokdl-result.txt
Normal file
41
tests/lib/generators/tokdl-result.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
a 1
|
||||
b "string"
|
||||
bigFlatItems 23847590283751 1.239000 "multiline \" \" \"\nstring\n" null
|
||||
c "multiline string\nwith special characters:\n\t \n \\" \"\n"
|
||||
extraAttrs 2 true arg1=1 arg2=false {
|
||||
nested {
|
||||
a 1
|
||||
b null
|
||||
}
|
||||
}
|
||||
flatItems 1 2 "asdf" true null
|
||||
listInAttrsInList {
|
||||
list1 {
|
||||
- {
|
||||
a 1
|
||||
}
|
||||
- {
|
||||
b true
|
||||
}
|
||||
- {
|
||||
c null
|
||||
d {
|
||||
- {
|
||||
e "asdfadfasdfasdf"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
list2 {
|
||||
- {
|
||||
a 8
|
||||
}
|
||||
}
|
||||
}
|
||||
nested {
|
||||
- 1 2
|
||||
- true false
|
||||
-
|
||||
- null
|
||||
}
|
||||
unsafeString " \" \n "
|
||||
53
tests/lib/generators/tokdl.nix
Normal file
53
tests/lib/generators/tokdl.nix
Normal file
@@ -0,0 +1,53 @@
|
||||
{ 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}
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user