Skip to content

Commit 71ad7ec

Browse files
nixos/kernel: Allow controlling modules with attrsets
1 parent c80f6a7 commit 71ad7ec

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

lib/types.nix

+5
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,11 @@ rec {
11621162
nestedTypes.finalType = finalType;
11631163
};
11641164

1165+
attrNamesToTrue = coercedTo
1166+
(types.listOf types.str)
1167+
(enabled: lib.listToAttrs (map (mod: lib.nameValuePair mod true) enabled))
1168+
(types.attrsOf types.bool);
1169+
11651170
# Augment the given type with an additional type check function.
11661171
addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };
11671172

nixos/modules/system/boot/kernel.nix

+26-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ let
88
inherit (config.boot.kernel) features randstructSeed;
99
inherit (config.boot.kernelPackages) kernel;
1010

11+
modulesTypeDesc = ''
12+
This can either be a list of modules, or an attrset. In an
13+
attrset, names that are set to `true` represent modules that will
14+
be included. Note that setting these names to `false` does not
15+
blacklist those modules. For that, use
16+
{option}`boot.blacklistedKernelModules`.
17+
'';
18+
1119
kernelModulesConf = pkgs.writeText "nixos.conf"
1220
''
1321
${concatStringsSep "\n" config.boot.kernelModules}
@@ -175,20 +183,23 @@ in
175183
};
176184

177185
boot.kernelModules = mkOption {
178-
type = types.listOf types.str;
179-
default = [];
186+
type = types.attrNamesToTrue;
187+
default = { };
180188
description = ''
181189
The set of kernel modules to be loaded in the second stage of
182190
the boot process. Note that modules that are needed to
183191
mount the root file system should be added to
184192
{option}`boot.initrd.availableKernelModules` or
185193
{option}`boot.initrd.kernelModules`.
194+
195+
${modulesTypeDesc}
186196
'';
197+
apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
187198
};
188199

189200
boot.initrd.availableKernelModules = mkOption {
190-
type = types.listOf types.str;
191-
default = [];
201+
type = types.attrNamesToTrue;
202+
default = { };
192203
example = [ "sata_nv" "ext3" ];
193204
description = ''
194205
The set of kernel modules in the initial ramdisk used during the
@@ -204,13 +215,21 @@ in
204215
modules for PCI devices are loaded when they match the PCI ID
205216
of a device in your system). To force a module to be loaded,
206217
include it in {option}`boot.initrd.kernelModules`.
218+
219+
${modulesTypeDesc}
207220
'';
221+
apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
208222
};
209223

210224
boot.initrd.kernelModules = mkOption {
211-
type = types.listOf types.str;
212-
default = [];
213-
description = "List of modules that are always loaded by the initrd.";
225+
type = types.attrNamesToTrue;
226+
default = { };
227+
description = ''
228+
Set of modules that are always loaded by the initrd.
229+
230+
${modulesTypeDesc}
231+
'';
232+
apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
214233
};
215234

216235
boot.initrd.includeDefaultModules = mkOption {

nixos/modules/system/boot/modprobe.nix

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ with lib;
2525
};
2626

2727
boot.blacklistedKernelModules = mkOption {
28-
type = types.listOf types.str;
29-
default = [ ];
28+
type = types.attrNamesToTrue;
29+
default = { };
3030
example = [
3131
"cirrusfb"
3232
"i2c_piix4"
3333
];
3434
description = ''
35-
List of names of kernel modules that should not be loaded
36-
automatically by the hardware probing code.
35+
Set of names of kernel modules that should not be loaded
36+
automatically by the hardware probing code. This can either be
37+
a list of modules or an attrset. In an attrset, names that are
38+
set to `true` represent modules that will be blacklisted.
3739
'';
40+
apply = mods: lib.attrNames (lib.filterAttrs (_: v: v) mods);
3841
};
3942

4043
boot.extraModprobeConfig = mkOption {

nixos/modules/tasks/filesystems.nix

+1-4
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,7 @@ in
273273
zfs = lib.mkForce false;
274274
}
275275
'';
276-
type = types.coercedTo
277-
(types.listOf types.str)
278-
(enabled: lib.listToAttrs (map (fs: lib.nameValuePair fs true) enabled))
279-
(types.attrsOf types.bool);
276+
type = types.attrNamesToTrue;
280277
description = ''
281278
Names of supported filesystem types, or an attribute set of file system types
282279
and their state. The set form may be used together with `lib.mkForce` to

0 commit comments

Comments
 (0)