-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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: init mergeTypes #364620
base: master
Are you sure you want to change the base?
lib.types: init mergeTypes #364620
Conversation
@infinisil What do you think about this function? It abstracts the need to use attributes of a type which i think is good. Because it decouples them and allows changes without breaking. |
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 I like it!
lib/types.nix
Outdated
Merges two option types together. | ||
|
||
:::{.note} | ||
Uses the merge function of the first type, to merge it with the second type. |
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.
This seems like an implementation detail
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.
Uses the merge function of the first type, to merge it with the second type. | |
Uses the type merge function of the first type, to merge it with the second type. |
This is relevant for solving the "expression problem". Interactions between extensions don't have a natural home. This says that interactions are the responsibility of the first type. Concretely: if the types can be merged, you can only fix it if you control the first.
If you have to deal with a partially applied mergeTypes
, you are subject to the provided type's merging support, with no way to extend its merging behavior.
If you control the first argument, you can add as much merge support as you like.
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 had similar thoughts as roberth. If you want to change some of the merge behavior its important to know that merging is not commutative. In most cases it might be, but thats only true when both types are the same anyways.
lib/types.nix
Outdated
- The merged option type. | ||
- `null` if the types can't be 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.
I'm a bit worried that this API isn't very future proof, because null
doesn't allow for better error messages. How about we change it to return a string instead, for now just always "Cannot merge types"
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.
How about a set { error = "..."; }
representing the empty type? Since a "type" is also an attribute set internally this means it is somewhat homomorphic. You can check for the success by checking result ? error
.
We could extend that set in the future to contain more error related information
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 made this an attribute set { error = ... ; }
for now.
I think this is the best compromise that is extensible in the future.
Error case alternatives:
- string:
Some Error
: Not extensible in the future. (Cannot hold other attributes) - null:
null
: Leaks an implementation detail. Cannot hold any helpful information about the actual problem. Throw "error"
: Downstream projects cannot handle error cases. (downstream wrapping withTryEval
not a good idea either, since the error is not made accessible)
0421581
to
3d16d71
Compare
Expose a utility for merging types together manually
Related: #363565
Sometimes downstream projects want to extend an enum and it is quite complicated to understand which attributes of a type are meant to be internal.
catppuccin/nix#400
This PR help to reduce downstream reliance on type attributes by adding this function as abstraction.
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.