I would like to create my dotfiles in a declarative way. Unfortunately I can’t find the right solution for me. I know that there are several modules for home managers (e.g. Alacritty), which are intended for this. But I would need something “general”. Here as an example for Home-Manager, how I imagine it:
Depends on your definition of “working”, I guess. I commonly used this to add comments to JSON files if the parser didn’t allow them, but yeah, it’s not ideal.
If you only need the text in the first few lines, you could do it like this:
BTW, the reason this is so annoyingly complicated with yaml is that the yaml formatter actually uses builtins.toJSON first, and then runs the tool json2yaml in a command line environment, so the result must be a file in the nix store, not just a string. If there were a builtins.toYAML, it would be as simple as:
xdg.configFile."alacritty/new_alacritty.json".source =
''
--- Leading comment
'' + builtins.toYAML {
colors = {
normal = {
black = "0x2e3436";
"#test" = "test123";
};
};
};
error:
… while evaluating the attribute 'activationPackage'
at /nix/store/pxj5ql0c5597pjz35vyz16hizljm7jk7-home-manager/home-manager/modules/default.nix:54:3:
53|
54| activationPackage = module.config.home.activationPackage;
| ^
55|
… while evaluating a branch condition
at /nix/store/7vg7bb78m45bp0lx0hrlbx1l5m71n1s6-nixpkgs/nixpkgs/lib/lists.nix:57:9:
56| fold' = n:
57| if n == len
| ^
58| then nul
(stack trace truncated; use '--show-trace' to show the full trace)
error: syntax error, unexpected '}', expecting ')'
at /home/xxx/.config/home-manager/alacritty.nix:31:1:
30|
31| }
| ^
32|
~ » home-manager switch 1
error:
… while evaluating the attribute 'activationPackage'
at /nix/store/pxj5ql0c5597pjz35vyz16hizljm7jk7-home-manager/home-manager/modules/default.nix:54:3:
53|
54| activationPackage = module.config.home.activationPackage;
| ^
55|
… while evaluating a branch condition
at /nix/store/7vg7bb78m45bp0lx0hrlbx1l5m71n1s6-nixpkgs/nixpkgs/lib/lists.nix:57:9:
56| fold' = n:
57| if n == len
| ^
58| then nul
(stack trace truncated; use '--show-trace' to show the full trace)
error: syntax error, unexpected '}', expecting ';'
at /home/xxx/.config/home-manager/alacritty.nix:31:1:
30|
31| }
| ^
32|
Ok wow I also forgot the final semicolon I updated it again, but this time I actually tested it inside the repl, and it worked fine. If you get the same error again, please post the part of your file where you’ve pasted my code, including a few lines before and a few lines after it.