This is fine for small/scalar options but doesn’t really work for inspecting larger attrsets as it just prints one big single-line Nix expression. Passing --json and then piping to jq sometimes helps but:
Some values can’t be serialised as JSON at all (e.g. functions)
I think the Nix REPL would offer a way to work around this issue but it doesn’t actually seem to be usable (e.g. I can’t find a way to go through command history? Am I missing something there?)
Home Manager has an instantiate/option commands but they don’t work on Flake configurations.
The repl’s :p command can handle errors gracefully by printing an error for the problematic thunk and continuing:
nix-repl> :p { foo = builtins.abort "foo"; bar = 1; }
{
bar = 1;
foo = «error: evaluation aborted with the following error message: 'foo'»;
}
I find it’s most valuable to put together a repl environment with my config’s module args available in scope, then exploring config (or trying snippets of code to see if they do what I think they do).
Yeah, this is also something I’d wondered. You can’t evaluate the whole config, since there are options etc that fail the program if you evaluate them (like the ones I mentioned breaking --json).
It would be cool if you could print the subset of the configuration that actually got evaluated when you realise your config. I have no idea if this is possible.
To the REPL users… am I missing anything or does it not support command history?
No idea about standalone hm.
But nixos-option works for nixos configs, and it’s already on your system. It handles individual options and nested options too. It would of course work for hm as a nixos module as well.
It even tells you which files affected the final value.
Oh, it works on my other computer, seems just a normal readline prompt. So… yeah I guess I need to debug that.
Seems useful but as you implied, I think it only works for NixOS, so no good for standalone HM. (I use non-NixOS systems too. I suspect this is not a particularly common case. But I have a separate distro for my day job).