lib.types.attrNamesToTrue: unpublish temporarily

Thank you for making this change.
Unfortunately, and I take blame for this, this change to the module
system was not reviewed and approved by the module system maintainers.
I'm supportive of this change, but extending it on the staging-next
branch is not the right place.
This commit is also here to make sure that we don't run into conflicts
or other git trouble with the staging workflow.

Review:
It looks alright, but it didn't have tests yet, and it should be
considered in a broader context where the existence of this type
creates an incentive to be used in cases where the `<attr> = false;`
case is undesirable. I'd like to complement this with an type that
has `<attr> = {};` only.

My apologies for the lack of a timely and clear review. Often we
recommend to define the type outside the module system until
approved. This commit puts us back in that state.

attrNamesToTrue was introduced in 98652f9a901aac50c1d7780ea3507439803a3408
This commit is contained in:
Robert Hensing 2025-05-16 11:34:39 +02:00
parent 2f214a6041
commit 3dd811c4b9
5 changed files with 27 additions and 34 deletions

View File

@ -1456,12 +1456,6 @@ let
nestedTypes.finalType = finalType; nestedTypes.finalType = finalType;
}; };
# A list of attrnames is coerced into an attrset of bools by
# setting the values to true.
attrNamesToTrue = coercedTo (types.listOf types.str) (
enabledList: lib.genAttrs enabledList (_attrName: true)
) (types.attrsOf types.bool);
# Augment the given type with an additional type check function. # Augment the given type with an additional type check function.
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; }; addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };

View File

@ -135,29 +135,6 @@ merging is handled.
problems. problems.
::: :::
`types.attrNamesToTrue`
: Either a list of attribute names, or an attribute set of
booleans. A list will be coerced into an attribute set with those
names, whose values are set to `true`. This is useful when it is
convenient to be able to write definitions as a simple list, but
still need to be able to override and disable individual values.
::: {#ex-types-attrNamesToTrue .example}
### `types.attrNamesToTrue`
```
{
foo = [ "bar" ];
}
```
```
{
foo.bar = true;
}
```
:::
`types.pkgs` `types.pkgs`
: A type for the top level Nixpkgs package set. : A type for the top level Nixpkgs package set.

View File

@ -25,6 +25,12 @@ let
${concatStringsSep "\n" config.boot.kernelModules} ${concatStringsSep "\n" config.boot.kernelModules}
''; '';
# A list of attrnames is coerced into an attrset of bools by
# setting the values to true.
attrNamesToTrue = types.coercedTo (types.listOf types.str) (
enabledList: lib.genAttrs enabledList (_attrName: true)
) (types.attrsOf types.bool);
in in
{ {
@ -196,7 +202,7 @@ in
}; };
boot.kernelModules = mkOption { boot.kernelModules = mkOption {
type = types.attrNamesToTrue; type = attrNamesToTrue;
default = { }; default = { };
description = '' description = ''
The set of kernel modules to be loaded in the second stage of The set of kernel modules to be loaded in the second stage of
@ -211,7 +217,7 @@ in
}; };
boot.initrd.availableKernelModules = mkOption { boot.initrd.availableKernelModules = mkOption {
type = types.attrNamesToTrue; type = attrNamesToTrue;
default = { }; default = { };
example = [ example = [
"sata_nv" "sata_nv"
@ -238,7 +244,7 @@ in
}; };
boot.initrd.kernelModules = mkOption { boot.initrd.kernelModules = mkOption {
type = types.attrNamesToTrue; type = attrNamesToTrue;
default = { }; default = { };
description = '' description = ''
Set of modules that are always loaded by the initrd. Set of modules that are always loaded by the initrd.

View File

@ -7,6 +7,16 @@
with lib; with lib;
let
# A list of attrnames is coerced into an attrset of bools by
# setting the values to true.
attrNamesToTrue = types.coercedTo (types.listOf types.str) (
enabledList: lib.genAttrs enabledList (_attrName: true)
) (types.attrsOf types.bool);
in
{ {
###### interface ###### interface
@ -25,7 +35,7 @@ with lib;
}; };
boot.blacklistedKernelModules = mkOption { boot.blacklistedKernelModules = mkOption {
type = types.attrNamesToTrue; type = attrNamesToTrue;
default = { }; default = { };
example = [ example = [
"cirrusfb" "cirrusfb"

View File

@ -13,6 +13,12 @@ let
# https://wiki.archlinux.org/index.php/fstab#Filepath_spaces # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces
escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string; escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string;
# A list of attrnames is coerced into an attrset of bools by
# setting the values to true.
attrNamesToTrue = types.coercedTo (types.listOf types.str) (
enabledList: lib.genAttrs enabledList (_attrName: true)
) (types.attrsOf types.bool);
addCheckDesc = addCheckDesc =
desc: elemType: check: desc: elemType: check:
types.addCheck elemType check // { description = "${elemType.description} (with check: ${desc})"; }; types.addCheck elemType check // { description = "${elemType.description} (with check: ${desc})"; };
@ -326,7 +332,7 @@ in
zfs = lib.mkForce false; zfs = lib.mkForce false;
} }
''; '';
type = types.attrNamesToTrue; type = attrNamesToTrue;
description = '' description = ''
Names of supported filesystem types, or an attribute set of file system types Names of supported filesystem types, or an attribute set of file system types
and their state. The set form may be used together with `lib.mkForce` to and their state. The set form may be used together with `lib.mkForce` to