Skip to content
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: chore use consistent payload form #363565

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

hsjobeki
Copy link
Contributor

@hsjobeki hsjobeki commented Dec 9, 2024

Use attributeSet for functor.payload consistently. This reduces complexity and allows to move generic logic for payload handling out of the individual types.

types.separatedString
types.enum

Are the only ones that don't use attribute sets for their payload.

I'd like to introduce this convention. Maybe we should add a CI check.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@hsjobeki hsjobeki requested a review from infinisil December 9, 2024 13:10
@github-actions github-actions bot added 6.topic: module system About "NixOS" module system internals 6.topic: lib The Nixpkgs function library labels Dec 9, 2024
@nix-owners nix-owners bot requested a review from roberth December 9, 2024 13:12
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: changelog labels Dec 9, 2024
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at it together with @hsjobeki in a call, LGTM with the release notes!

@infinisil infinisil merged commit 062945b into NixOS:master Dec 9, 2024
20 of 21 checks passed
@PerchunPak
Copy link
Member

mergeEnums is a use-case that this PR broke:

https://github.com/catppuccin/nix/blob/a817009ebfd2cca7f70a77884e5098d0a8c83f8e/modules/lib/default.nix#L133-L137
https://github.com/catppuccin/nix/blob/a817009ebfd2cca7f70a77884e5098d0a8c83f8e/modules/home-manager/cursor.nix#L12

Fix is:

-mergeEnums = a: b: lib.types.enum (a.functor.binOp a.functor.payload b.functor.payload);
+mergeEnums = a: b: lib.types.enum (a.functor.binOp a.functor.payload b.functor.payload).values;

@infinisil
Copy link
Member

@PerchunPak Thanks for reaching out, we were thinking of that exact piece of code when discussing this PR! Since .payload is internal (for now), I don't recommend relying on it. Instead you can use this to merge types:

mergeEnums = a: b: a.typeMerge b.functor;

While .typeMerge and .functor are also somewhat internal, they can be expected to stay more stable.

PerchunPak added a commit to PerchunPak/catppuccin-nix that referenced this pull request Dec 10, 2024
@roberth
Copy link
Member

roberth commented Dec 11, 2024

Any reason not to add that to lib?

mergeTypes = a: b: a.typeMerge b.functor;

@infinisil
Copy link
Member

Oh yeah, good idea

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/breaking-changes-announcement-for-unstable/17574/72

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/breaking-changes-announcement-for-unstable/17574/73

@hsjobeki hsjobeki mentioned this pull request Dec 12, 2024
13 tasks
@hsjobeki
Copy link
Contributor Author

Any reason not to add that to lib?

mergeTypes = a: b: a.typeMerge b.functor;

Made a pr for that #364620

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/use-cases-of-option-type-internals/57317/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library 6.topic: module system About "NixOS" module system internals 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants