lib/modules: extract isDisabled from filterModules

Co-authored-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>

Changed files
+31 -22
lib
+31 -22
lib/modules.nix
···
else
m: m;
+
# isDisabled :: String -> [ { disabled, file } ] -> StructuredModule -> bool
+
#
+
# Figures out whether a `StructuredModule` is disabled.
+
isDisabled =
+
modulesPath: disabledList:
+
let
+
moduleKey =
+
file: m:
+
if isString m then
+
if substring 0 1 m == "/" then m else toString modulesPath + "/" + m
+
+
else if isConvertibleWithToString m then
+
if m ? key && m.key != toString m then
+
throw "Module `${file}` contains a disabledModules item that is an attribute set that can be converted to a string (${toString m}) but also has a `.key` attribute (${m.key}) with a different value. This makes it ambiguous which module should be disabled."
+
else
+
toString m
+
+
else if m ? key then
+
m.key
+
+
else if isAttrs m then
+
throw "Module `${file}` contains a disabledModules item that is an attribute set, presumably a module, that does not have a `key` attribute. This means that the module system doesn't have any means to identify the module that should be disabled. Make sure that you've put the correct value in disabledModules: a string path relative to modulesPath, a path value, or an attribute set with a `key` attribute."
+
else
+
throw "Each disabledModules item must be a path, string, or a attribute set with a key attribute, or a value supported by toString. However, one of the disabledModules items in `${toString file}` is none of that, but is of type ${typeOf m}.";
+
+
disabledKeys = concatMap ({ file, disabled }: map (moduleKey file) disabled) disabledList;
+
in
+
structuredModule: elem structuredModule.key disabledKeys;
+
/**
-
Collects all modules recursively into the form
+
Collects all modules recursively into a `[ StructuredModule ]` and a list of disabled modules:
{
disabled = [ <list of disabled modules> ];
···
modulesPath:
{ disabled, modules }:
let
-
moduleKey =
-
file: m:
-
if isString m then
-
if substring 0 1 m == "/" then m else toString modulesPath + "/" + m
-
-
else if isConvertibleWithToString m then
-
if m ? key && m.key != toString m then
-
throw "Module `${file}` contains a disabledModules item that is an attribute set that can be converted to a string (${toString m}) but also has a `.key` attribute (${m.key}) with a different value. This makes it ambiguous which module should be disabled."
-
else
-
toString m
-
-
else if m ? key then
-
m.key
-
-
else if isAttrs m then
-
throw "Module `${file}` contains a disabledModules item that is an attribute set, presumably a module, that does not have a `key` attribute. This means that the module system doesn't have any means to identify the module that should be disabled. Make sure that you've put the correct value in disabledModules: a string path relative to modulesPath, a path value, or an attribute set with a `key` attribute."
-
else
-
throw "Each disabledModules item must be a path, string, or a attribute set with a key attribute, or a value supported by toString. However, one of the disabledModules items in `${toString file}` is none of that, but is of type ${typeOf m}.";
-
-
disabledKeys = concatMap ({ file, disabled }: map (moduleKey file) disabled) disabled;
-
keyFilter = filter (attrs: !elem attrs.key disabledKeys);
+
keyFilter = filter (attrs: !isDisabled modulesPath disabled attrs);
in
map (attrs: attrs.module) (genericClosure {
startSet = keyFilter modules;