-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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/types: Allow paths as submodule values #76861
Conversation
1b09f89
to
5b6cdb8
Compare
Can't we solve the problem by flipping the
We should lean towards simplification and document any required changes to user modules in the release notes. |
@roberth Tried that already, but unfortunately not as easy as that. Main problem is that If you have a decent implementation of |
Blocked on #76977 it seems. The builtin doesn't solve the other problem with path.check, which is adding intermediate cleanSourceWith sources to the store.
Can be done in the release notes. I don't expect it to be a big problem (famous last words?). |
Now that we could switch all |
Uses are probably few though, so it might not matter much |
This can be further remedied by backporting your |
For upcoming allowance of paths as submodules
5b6cdb8
to
b6e6d47
Compare
Previously when this function was called without a value coercible to a string it would throw an error instead of returning false. Now it does. As a result this now allows the use of a type like `either path attrs` without it erroring out when a definition is an attribute set. The warning about there not being a isPath primop was removed because this is not the case anymore, there is builtins.isPath. But also there always was `builtins.typeOf x == "path"` that could've been used instead. However the path type now stands for more than just path types, but absolute paths in general. (cherry picked from commit d7a109b) See #76861 (comment) for why this is cherry-picked
Removed the |
I'd say this is bad. Can't we already use |
@danbst It's for values, which occur more frequently than option/type declarations. (I think you mistyped?) |
It allows e.g. some-submodule = mkMerge [
./some-module.nix
(mkIf some-condition ./other-module.nix)
] instead of some-submodule = mkMerge [
{ imports = [ ./some-module.nix ]; }
(mkIf some-condition { imports = [ ./other-module.nix ]; })
] It's not that big of a benefit, but I don't think we should not allow that just because of a slight inconvenience with the |
Co-Authored-By: Robert Hensing <[email protected]>
6a0c941
to
9d4b59b
Compare
@infinisil I don't think it is possible to
However, if I remove |
@roberth this also adds an exception, when order of items in I can't build of top of my head a counterexample (when |
@danbst as much as I'd like
|
Oh yeah, what I showed above (the non-path version) doesn't work, it needs to be this (if you don't use some-submodule = mkMerge [
({ ... }: { imports = [ ./some-module.nix ]; })
(mkIf some-condition ({ ... }: { imports = [ ./other-module.nix ]; }))
] Compare that to the version when paths are allowed |
@infinisil still nope. I've cloned your branched and checked that paths don't work either:
And yes, if I remove |
Ah I didn't pay attention to the code, no that doesn't work because |
Here's a simple full example of what's now possible (Edit: Which is pretty much what the test case does)
{ config, lib, pkgs, ... }: {
options.some-submodule = lib.mkOption {
type = lib.types.submodule [];
};
config.some-submodule = ./some-module.nix;
}
{ lib, ... }: {
options.foo = lib.mkOption {
default = false;
};
} $ nix-instantiate --eval nixos --arg configuration ./config.nix -A config.some-submodule.foo
false |
@roberth okay, you are right. |
@roberth Good to merge? |
This more intuitively matches `types.either` and allows paths to be coerced to submodules again, which was inhibited by NixOS#76861
This more intuitively matches `types.either` and allows paths to be coerced to submodules again, which was inhibited by NixOS#76861 (cherry picked from commit 92b464d)
Until NixOS#76861 or so is merged (cherry picked from commit be3f887)
Without this, a big part of the lib tests aren't being done, which previously lead to e.g. NixOS/nixpkgs#76861 And this will also be useful for checked maintainers in NixOS/nixpkgs#82461
Motivation for this change
Because allowing paths as submodule values isn't always backwards compatible, that change from #75031 had to be reverted.
This restores that behavior but also fixes the backwards incompatibility in nixpkgs and adds a release note about it.
Ping @roberth @danbst @grahamc
Things done
lib/tests/modules.sh
successfully (again, the revert actually broke a test for this very thing in there)