I split my config into modules, but I want to be able to get the resulting config into 1 big file and manipulate it. For example I’d like to see what the config would look like if instead of nested attribute sets it was written in this way:
...
option1.x.y = "a";
option1.x.z = "b";
...
That’s going to be hard for many reasons, e.g. there’s a lot more to configuration that you’ve set. Most of the standard NixOS modules (and there’s way over 1.5k of them) only take whatever options they understand and set other options in place. E.g. I doubt you’ve ever set
systemd.units."nix-daemon.socket".name
and yet I’m pretty sure it’s set in your full configuration.
Other reason is that, because nix is lazy, there’s a lot of items that are defined by default but never used. Some of them might even be plain incomplete. E.g. I have a config item services.pleroma.enable
that’s set to false. Even though, the default value for services.pleroma.configs
is still set, but trying to reference it results in an error.
So is the only option parsing the nix file with something like tree-sitter, figuring out which options are imported for some output, and then doing a merge of everything into 1 big string?
You can call lib.evalModules
yourself and get the .config
attribute out of it. Though if your module has dependencies, you’ll have to make sure to include all those modules as well.
Getting the .config
attribute out of your full config is probably not feasible, though, unless you have lots of RAM and time to spend.
EDIT: and also handle the sources of infrec.