Hi,
I’m writing an external tool that does nix eval '.#nixosConfigurations.someconfig.config.some.options' --json under the hood. It does that to get some information about nix configurations in my flake. Now, I want to set an option that has the file and line in which that option was set as value. So similar how error messages display in what file and line an error happened. E.g. builtins.abort displays where it was called. The only difference is, that I want that information without exiting and failing the evaluation. Ideally, I’d like to assign it as value to a NixOS option, I defnied.
To give an example: what I’m looking for is <some mechanism> where I can do this:
# File: someconfig.nix (corresponds to the flake outputs.nixosConfigurations.someconfig)
{
some.options = {
currFileLine = <some mechanism>; # <--- where <some mechanism> would set currFileLine to `someconfig.nix:4`
anotherOption = "aValue";
yetAnotherOption = "anotherValue";
};
...
}
So that nix eval '.#nixosConfigurations.someconfig.config.some.options' --json results in the output:
{
"currentFile": "someconfig.nix:4", <--- store path of someconfig.nix would be okay here, too, of course
"anotherOption": "aValue",
"yetAnotherOption": "anotherValue"
}
Is that at all possible and if so how? Cloud there be something in _module that might have that info?