From 3dd811c4b9f7963a66a6cb17b4dbac5a7ce68a26 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 16 May 2025 11:34:39 +0200 Subject: [PATCH] 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 ` = false;` case is undesirable. I'd like to complement this with an type that has ` = {};` 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 --- lib/types.nix | 6 ----- .../development/option-types.section.md | 23 ------------------- nixos/modules/system/boot/kernel.nix | 12 +++++++--- nixos/modules/system/boot/modprobe.nix | 12 +++++++++- nixos/modules/tasks/filesystems.nix | 8 ++++++- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 73d59309e91b..715da842ac01 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -1456,12 +1456,6 @@ let 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. addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; }; diff --git a/nixos/doc/manual/development/option-types.section.md b/nixos/doc/manual/development/option-types.section.md index 8539da71a214..c0add330b72e 100644 --- a/nixos/doc/manual/development/option-types.section.md +++ b/nixos/doc/manual/development/option-types.section.md @@ -135,29 +135,6 @@ merging is handled. 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` : A type for the top level Nixpkgs package set. diff --git a/nixos/modules/system/boot/kernel.nix b/nixos/modules/system/boot/kernel.nix index 1d8f65ad28d3..c5a2f5933b48 100644 --- a/nixos/modules/system/boot/kernel.nix +++ b/nixos/modules/system/boot/kernel.nix @@ -25,6 +25,12 @@ let ${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 { @@ -196,7 +202,7 @@ in }; boot.kernelModules = mkOption { - type = types.attrNamesToTrue; + type = attrNamesToTrue; default = { }; description = '' The set of kernel modules to be loaded in the second stage of @@ -211,7 +217,7 @@ in }; boot.initrd.availableKernelModules = mkOption { - type = types.attrNamesToTrue; + type = attrNamesToTrue; default = { }; example = [ "sata_nv" @@ -238,7 +244,7 @@ in }; boot.initrd.kernelModules = mkOption { - type = types.attrNamesToTrue; + type = attrNamesToTrue; default = { }; description = '' Set of modules that are always loaded by the initrd. diff --git a/nixos/modules/system/boot/modprobe.nix b/nixos/modules/system/boot/modprobe.nix index b38e78c3222a..18c34f547c85 100644 --- a/nixos/modules/system/boot/modprobe.nix +++ b/nixos/modules/system/boot/modprobe.nix @@ -7,6 +7,16 @@ 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 @@ -25,7 +35,7 @@ with lib; }; boot.blacklistedKernelModules = mkOption { - type = types.attrNamesToTrue; + type = attrNamesToTrue; default = { }; example = [ "cirrusfb" diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index b28a902a7c54..c9588f65b506 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -13,6 +13,12 @@ let # https://wiki.archlinux.org/index.php/fstab#Filepath_spaces 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 = desc: elemType: check: types.addCheck elemType check // { description = "${elemType.description} (with check: ${desc})"; }; @@ -326,7 +332,7 @@ in zfs = lib.mkForce false; } ''; - type = types.attrNamesToTrue; + type = attrNamesToTrue; description = '' 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