NixOS Option Inspection

I’m constantly learning new gestures and workflows; all I can do is try to document them :melting_face:

9 Likes

Would be nice if there is a way to map these source hashes to flake names or if flakes named the source path after the flake.

How do I know which has represents which flake? It’s still kind of user unfriendly

Interesting idea; everthing is just the hash name… hmm.

FYI nixos-option is getting a rewrite with flake support, might consider contributing there if you have ideas.

6 Likes

I doubt that definitionsWithLocations is only 2 years old, given that this feature was present in the first iteration of nixos-option (the bash + sed + nix script) and that it used to be included in the manual a very long time ago.

For the problem of quickly debugging with multiple mergeable definitions, you might be able to fallback on creating an additional option declaration, which would be merged with the previous option declaration, and let you declare the option as being read-only, i-e force having a single definition:

{lib, ...}: {
  options = {
    a.value = lib.mkOption {
      readOnly = true;
    };
  };
}

Another problem related to option introspection is, where are options used. At the moment the only way to figure this out is this (most likely outdated) option-usage.nix script, which will evaluate a configuration once, then re-evaluate each of the options replacing them one by one with a throw and catch the failures to compute a graph of usage, i-e O(n²). Until Nix / nixos-option gets reflexivity or partial evaluation, there is no better way to solve this issue.

Another worth mentioning project:

5 Likes

I would try the readOnly or conflict option but I found this lacking:

  1. It only prints a single conflict definition
  2. I wanted to know who set a value and if it’s mergeable this is even harder

Thanks for the advice nontheless.

Wow so instead of going backwards, option-usage helps you figure it forward with fixed-point iteration replacing with throws? Cool.

Yea I’ve used this also; pretty good tool.

Language servers teach your editor how to ‘goto definition’ via nix repl. AFAIK in nixd you can “goto declaration” to nixos/home-manager options.

录屏2024-07-31 09.38.54

“goto definition”, likely can be easily implemented in the same way but not done yet.

1 Like

The interesting is that there can be multiple definitions.
Never seen that in a language before especially with merged values.

You’d need a popup to show which to choose :melting_face:

As per my understanding LSP protocol actually allows the server sending multiple locations, that would be simple and vscode indeed shows you a list of locations.

2 Likes