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
lib/modules: Add function to create option alias that respects priority #53397
lib/modules: Add function to create option alias that respects priority #53397
Conversation
…he priority This commit adds a function `mkAliasOptionModuleWithPriority`. This function will make an alias to an existing option and copy over the priority. This functionality is needed for PRs like NixOS#53041. In that case `nixos-generate-config` added an option to `hardware-configuration.nix` with `mkDefault`. That option was then changed and an alias created for the old name. The end user should be able to set the non-alias option in their `configuration.nix` and have everything work correctly. Without this function, the priority for the option won't be copied over correctly and the end-user will get a message saying they have the same option set to two different values.
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.
Thanks! For some reasons I thought this was the case but this might be a really long time ago...
A minor change and making the test cases more robust and this should be good for landing.
withPriority = true; | ||
}; | ||
|
||
doRename = { from, to, visible, warn, use, withPriority ? false }: |
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.
Once this issue is fixed. Open a follow-up issue / PR to evaluate the impact of switching this flag to true
and replacing mkAliasAndWrapDefinitions
with the one you are adding.
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.
Will do.
@nbp Thanks for the review and the good suggestions. I have fixed the things you've pointed out. This PR should be ready for a final review and hopefully merging. |
Hey @nbp, any chance getting this merged? |
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.
Sorry for the delay and thanks for the patches. These are great changes!
…lias. This commit changes the `mkAliasOptionModule` function to make sure that the priority for the aliased option is propagated to the non-aliased option. This also affects the `mkRenamedOptionModule` function in a similar fashion. This also removes the `mkAliasOptionModuleWithPriority` function, since its functionality is now subsumed by `mkAliasOptionModule`. This change was recommended by @nbp: #53397 (comment)
Motivation for this change
This commit adds a function
mkAliasOptionModuleWithPriority
. This function will make an alias to an existing option and copy over the priority. (This is in contrast tomkAliasOptionModule
which does not copy over the priority.)This functionality is needed for PRs like #53041 (specifically #53041 (comment)).
Here's the use-case:
There exists an option
powerManagement.cpuFreqGovernor
. On some systems, this is set inhardware-configuration.nix
bynixos-generate-config
:Note how it gets a low priority. The end-user (or other modules) should be able to easily override it.
In #53041, I wanted to add options to set the CPU max and min frequency:
I thought it was silly to have the options called both
powerManagement.cpuFreqGovernor
andpowerManagement.cpufreq.max
, so I renamedpowerManagement.cpuFreqGovernor
topowerManagement.cpufreq.governor
. This is fine, but it will break for people that are usinghardware-configuration.nix
generated with an older version ofnixos-generate-config
(since in their config it is calledpowerManagement.cpuFreqGovernor
).In order to accommodate those people, I added the alias
powerManagement.cpuFreqGovernor
topowerManagement.cpufreq.governor
:This should let people use their older
hardware-configuration.nix
with thepowerManagement.cpuFreqGovernor
option.However, there is one edge case this doesn't work for.
Imagine that the user has
powerManagement.cpuFreqGovernor
set inhardware-configuration.nix
:The user then tries to set
powerManagement.cpufreq.governor
to something else inconfiguration.nix
:This actually will fail. The user will get an error that
powerManagement.cpufreq.governor
is defined two places (which is true, but the definition inhardware-configuration.nix
should have low priority).What's going on here? Well, the
mkAliasOptionModule
function doesn't actually copy over the priority of the alias option to the normal option. So to the nix module system, it really does look likepowerManagement.cpufreq.governor
is being set two different places.This PR adds a function
mkAliasOptionModuleWithPriority
that does correctly(?) copy over the priority from the alias option to the normal option.Tests have also been added to make sure this is working correctly.
Pinging @infinisil since he helped a lot with #53041. Also pinging @edolstra @nbp since they seem to be code-owners of the stuff in
lib/
.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)