-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix/show-config: allow getting the value of a specific setting #7595
Conversation
Instead of needing to run `nix show-config --json | jq -r '."warn-dirty".value'` to view the value of `warn-dirty`, you can now run `nix show-config warn-dirty`.
ba6f8de
to
1fc74af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I actually had a talk just yesterday about the fact that it would be handy to have something like that :D
Can you add some tests for it? tests/config.sh
seems the right place for that
} | ||
|
||
Category category() override { return catUtility; } | ||
|
||
void run() override | ||
{ | ||
if (name) { | ||
if (json) { | ||
throw UsageError("'--json' is not supported when specifying a setting name"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we allow that? Both for consistency and because some settings are themselves a structured value (substituters
for example) so it's worth having them already parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I apparently didn't see the second half of the PR description 🤦♂️
Wouldn't it be enough to just print setting->second.toJSON()
in here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, SettingInfo
doesn't have toJSON()
... Which is why I left it unsupported 😅
Also, SettingInfo
is stringly-typed, so I'm not sure if we can easily get (useful) structured values out of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, if configRegistrations
was somehow exposed, maybe we could go through that, since that appears to have toJSON
with proper JSON types (that's how globalConfig.toJSON()
is implemented from what I can see).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derp, it is exposed, just under globalConfig
. Still, I did a bit of playing and it's real ugly, trying to get the proper toJSON
stuff. Basically need to be able to do the following:
- Iterate through all of the
Config
s inconfigRegistrations
- Gain access to
Config::_settings
(which isprivate
) so we can look up the setting by key there - Gain access to
AbstractSetting::toJSON()
(which isprotected
)
If there was a general-purpose "C++ value to appropriate JSON value" function somewhere, we could just call that, but I don't know if that exists (all the json files appears to be under libexpr).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need JSON support here, because you can always get a specific flag by doing nix show-config --json | jq .<name>.value
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might follow an issue. Whether or not this an important feature (and I readily believe the jq
way is good enough), it would be nice if our configuration infrastructure didn't get in the way of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to see json supported, but my attempt was a bit of a pain, and I was in over my head.
…-config <setting>`
Instead of needing to run
nix show-config --json | jq -r '."warn-dirty".value'
to view the value ofwarn-dirty
, you can now runnix show-config warn-dirty
.Fixes #7586.
I'm sure this isn't the most beautiful solution (and I couldn't figure out a good way to get JSON support for the single-option mode at this point in time), but it works!