Skip to content

lib/types: init defaultComposedFunctor for types.{attrsWith,listOf}#366015

Merged
infinisil merged 3 commits intoNixOS:masterfrom
hsjobeki:types/defaultComposed
Jan 6, 2025
Merged

lib/types: init defaultComposedFunctor for types.{attrsWith,listOf}#366015
infinisil merged 3 commits intoNixOS:masterfrom
hsjobeki:types/defaultComposed

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
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Dec 17, 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.

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
@ofborg ofborg bot added the 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. label Dec 19, 2024
@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
@github-actions github-actions bot removed the 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. label Jan 6, 2025
@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
23 of 27 checks passed
hsjobeki pushed a commit to infinisil/nixpkgs that referenced this pull request Feb 19, 2025
Otherwise nested types such as `attrsOf (attrsOf int)` won't have a
backwards compatible `type.nestedTypes.elemType.functor.wrapped`.

Follow-up work to NixOS#366015
github-actions bot pushed a commit to nix-community/nixpkgs.lib that referenced this pull request Feb 23, 2025
Otherwise nested types such as `attrsOf (attrsOf int)` won't have a
backwards compatible `type.nestedTypes.elemType.functor.wrapped`.

Follow-up work to NixOS/nixpkgs#366015
arcnmx pushed a commit to arcnmx/nixpkgs-lib that referenced this pull request Aug 29, 2025
Otherwise nested types such as `attrsOf (attrsOf int)` won't have a
backwards compatible `type.nestedTypes.elemType.functor.wrapped`.

Follow-up work to NixOS/nixpkgs#366015
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 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants