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: init defaultComposedFunctor for types.{attrsWith,listOf} #366015

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

hsjobeki
Copy link
Contributor

@hsjobeki hsjobeki commented Dec 17, 2024

Overall i think all types.functor should deprecate functor.wrapped

This PR introduces a new defaultFunctor for composed types that makes the migration easy.

Additional thoughts:

types should be constructible via type payload maybe we want to spread the {type}With payload pattern ?
This design thought also went into the default functor:

Compare:

  • attrsWith
  • listWith (doesnt exist)
  • submoduleWith
  • deferredModuleWith
  • stringWith (doesnt exist)
  • ...

This only internally changes the following for now.

  • listOf requires overriding the type because there is no listWith yet.
  • attrsWith doesn't require any additional attribute overrides. (Only the custom binOp for merging)

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.

@github-actions github-actions bot added 6.topic: module system About "NixOS" module system internals 6.topic: lib The Nixpkgs function library labels Dec 17, 2024
@nix-owners nix-owners bot requested review from infinisil and roberth December 17, 2024 22:22
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.

Discussed this together in a meeting with @hsjobeki:

  • This should only be an internal refactoring, no new function should be exposed
  • The function can be specific to an elemType payload, e.g. elemTypeFunctor, which can then also implement the merge for elemType specifically
  • The deprecation message makes sense to have for types that currently use wrapped

In the future we could also imagine an interface like this for creating types with appropriate functors more easily:

submoduleWith = createAttrType {
  # Doesn't need to stay in sync with `submoduleWith` anymore
  # because the name is decoupled from the `lib.types` identifier
  name = "submodule";
  payloadSpec = {
    modules = {
      # No default, required argument
      binOp = a: b: a ++ b;
    };
    specialArgs = {
      default = {};
      binOp = unionOfDisjoint;
    }
    # ...
  };
  # Gets a functor/typeMerge based on the above spec
  create = { modules, specialArgs }: mkOptionType {
    description = "...";
    merge = "...";
    # ...
  };
};

@hsjobeki hsjobeki force-pushed the types/defaultComposed branch from 204bd60 to 3f80731 Compare December 18, 2024 16:14
@hsjobeki hsjobeki force-pushed the types/defaultComposed branch 2 times, most recently from 7679fed to 66be74f Compare January 6, 2025 14:22
@hsjobeki hsjobeki force-pushed the types/defaultComposed branch from 66be74f to 5978559 Compare January 6, 2025 14:25
@hsjobeki hsjobeki force-pushed the types/defaultComposed branch from 5978559 to 557e4fa Compare January 6, 2025 14:52
@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Jan 6, 2025
@hsjobeki hsjobeki force-pushed the types/defaultComposed branch from 557e4fa to 327883c Compare January 6, 2025 14:53
@hsjobeki hsjobeki force-pushed the types/defaultComposed branch from 327883c to 5782ef8 Compare January 6, 2025 15:01
@github-actions github-actions bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Jan 6, 2025
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.

Reviewed and updated together in a meeting with @hsjobeki, looking good now!

@infinisil infinisil merged commit 92b4730 into NixOS:master Jan 6, 2025
27 of 31 checks passed
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: 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.

2 participants