-
-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
modules: make apply
mergeable
#301472
base: master
Are you sure you want to change the base?
modules: make apply
mergeable
#301472
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/drv-parts-configure-packages-like-nixos-systems/23629/27 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/adding-more-control-over-overriding-default-module-definitions/4276/8 |
I don't think we should do this, because it makes more code dependent on the import order, which is too unpredictable and un-declarative, similar to what I've argued in the linked drv-parts thread. |
Most existing overlays and overrides are commutative. The order does not matter at all in most use cases. |
The use case would be to patch an existing package while not breaking other patches. In that case, the users would not depend on module application order. |
Could you elaborate in what use case the code would depend on the import order? |
Some examples in
|
I agree with Robert here. |
OK. I see your point. Unforunately given that @roberth you said "That doesn’t mean that we shouldn’t have it. In fact by having them, we have a good place to document why they are the way they are, and that they’re a last resort." |
That was in reference to types In |
Suppose I want to create a NixOS module that patches
I want |
It looks like you're recreating the traditional FHS problem of having only a single instance of a program, which has to satisfy all possible requirements simultaneously. If you're sure that's what you want, you could improve the Otherwise, I would recommend nix shells for projects, and independent java packages for each service that needs one. If you don't want explicit support for the things you're doing, and you would rather expose the |
The module is not necessarily a NixOS module. When it's a flake part or devenv module, the option could be a per project package, for example, languages.python.package. In that case, it's not a single instance of a program.
The build options are already available in
What does "have to" mean?
The |
How about having a 2-level merging system? First merge all the non- i.e.
This way, it becomes unambiguous which |
I was trying to illustrate why a composition of functions is not properly declarative, by showing workarounds. I don't think we need to go into much more detail here to see that the workarounds aren't great, but we could if you think we need to. Crucially, it's important for the module system to provide sound abstractions that behave predictably, as much as possible. Every time we introduce a feature that's not perfect, but helps a particular use case, it will be used in cases where it's not needed, leading to annoyances and bugs. This in turn damages the reputation of the module system, making it seem unreliable.
It gives a user-visible clue as to what might be going on. I think it's a bit early to ask for best practices; I think something might emerge. |
Laziness makes it so that the way things are evaluated is very flexible by default. We probably don't need to create "phases" like that at the module level, unless you really want to generate more actual options, in which case the overhead might double, or worst case something like exponential in the depth of submodule nestings. (In case both phases need to evaluate both phases of a submodule) Instead of building something extra into the module system, we can already do this in the cases where we need it: { config, ... }:
{
options = {
foo = mkOption {
type = <...>;
apply = config.fooModifiers;
};
fooModifiers = mkOption {
type = types.composedFunction; # Example, this type doesn't exist yet
};
};
} This way you can pick how you want the functions to be merged, and we don't need to complicate the module system or make it slower by even one conditional. |
My bad, I had misunderstood |
Description of changes
As discussed here and here, a restriction in module system in comparison to overlay is that we cannot visit previous value, nor transform it into a new one.
This PR aims to make
apply
mergeable, therefore modules can visit previous values by defining anapply
function.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.