-
-
Notifications
You must be signed in to change notification settings - Fork 15k
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
Introduce types.raw
#160489
Introduce types.raw
#160489
Conversation
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.
Not sure.
Is this the only use case?
@@ -138,7 +138,7 @@ rec { | |||
# support for that, in turn it's lazy in its values. This means e.g. | |||
# a `_module.args.pkgs = import (fetchTarball { ... }) {}` won't | |||
# start a download when `pkgs` wasn't evaluated. | |||
type = types.lazyAttrsOf types.unspecified; | |||
type = types.lazyAttrsOf types.raw; |
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 this is the right trade-off. It's already lazy and when you do access an attr value, like that of pkgs
, you'll force it anyway. Checking its type
attr before returning it is a cheap and one-time operation.
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.
OfBorg just finished. Allocations are down by 0.0002%
https://github.com/NixOS/nixpkgs/pull/160489/checks?check_run_id=5236802082
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.
So I don't think we should trade the ability to mkForce
in _module.args
for arguably no benefit.
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.
See #160489 (comment), mkForce
and co. still work on the spine
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 must have read too much into "raw".
The tests demonstrate it clearly.
Perhaps the docs can clarify that it's not entirely raw?
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 guess the confusion comes from #132448 where types.raw
originally worked like that, not doing any processing at all, but I changed that after discussing it with you :)
I think mentioning that in the docs is a good idea
type is recommended for options whose only value is defined | ||
by the same module as the option, because its structure is |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@roberth This type still works with let lib = import ./lib; in
lib.evalModules {
modules = [
{
options.foo = lib.mkOption {
type = lib.types.raw;
};
config.foo = lib.mkMerge [
(lib.mkIf false 10)
20
(lib.mkIf true (lib.mkForce 30))
];
}
];
}
The main use case for Other than We also need to deprecate |
This one seems valid. |
recommended for options whose only value is defined by the same module | ||
as the option, because its structure is known ahead-of time and doesn't | ||
need to be typechecked internally. Especially useful for values where | ||
type checking would be too expensive, or where type checking is handled | ||
in another way. |
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 think what's important is that
- it doesn't merge or check
- it does apply priorities
- it should be used if and only if merging and checking are not desirable
"Especially useful" and "recommended" are a bit too encouraging for something that should be applied with attention.
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.
Sounds good, I updated the docs
Fixes NixOS#53458, as types.raw doesn't allow setting multiple values
: A type which doesn't do any checking, merging or nested evaluation. It | ||
accepts a single arbitrary value that is not recursed into, making it | ||
useful for values coming from outside the module system, such as package | ||
sets or arbitrary data. Options of this type are still evaluated according | ||
to priorities and conditionals, so `mkForce`, `mkIf` and co. still work on | ||
the option value itself, but not for any value nested within it. This type | ||
should only be used when checking, merging and nested evaluation are not | ||
desirable. |
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.
@roberth Does this sound good?
As expected, this broke my config because I was adding my own stuff to Probably just a "me" problem not worth looking into as I couldn't reproduce that error on a minimal config. |
I'd like |
Yeah, I guess it's supposed to be a middle ground between |
As a general rule, The systemd logic can move into importable modules instead, after #156533 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-25/18003/1 |
Motivation for this change
types.raw
as a type that doesn't do any nested processing formkIf
,mkForce
, etc. on its values. This is useful when this processing would throw errors or where it would be too expensive (such as with package sets like nixpkgs).types.raw
for_module.args
's type. This finally fixes _module.args.name gets merged on assignment #53458This is split off from #132448. This is also motivated by wanting to deprecate
types.attrs
andtypes.unspecified
, for whichtypes.attrsOf types.raw
andtypes.raw
(ortypes.anything
) is an adequate general replacement.Things done