Enable specifying which kernel config options are needed for a given module

This commit is contained in:
Shea Levy 2012-08-01 21:50:43 -04:00
parent 5f57110e1f
commit 2a983acaff

@ -108,6 +108,24 @@ let kernel = config.boot.kernelPackages.kernel; in
apply = pkgs.aggregateModules;
};
system.requiredKernelConfig = mkOption {
default = [];
example = literalExample ''
with config.lib.kernelConfig; [
(isYes "MODULES")
(isEnabled "FB_CON_DECOR")
(isEnabled "BLK_DEV_INITRD")
]
'';
internal = true;
type = types.listOf types.attrs;
description = ''
This option allows modules to specify the kernel config options that
must be set (or unset) for the module to work. Please use the
lib.kernelConfig functions to build list elements.
'';
};
};
@ -173,6 +191,47 @@ let kernel = config.boot.kernelPackages.kernel; in
# The Linux kernel >= 2.6.27 provides firmware.
hardware.firmware = [ "${kernel}/lib/firmware" ];
};
lib.kernelConfig = {
isYes = option: {
assertion = config: config.isYes option;
message = "CONFIG_${option} is not yes!";
};
isNo = option: {
assertion = config: config.isNo option;
message = "CONFIG_${option} is not no!";
};
isModule = option: {
assertion = config: config.isModule option;
message = "CONFIG_${option} is not built as a module!";
};
### Usually you will just want to use these two
# True if yes or module
isEnabled = option: {
assertion = config: config.isEnabled option;
message = "CONFIG_${option} is not enabled!";
};
# True if no or omitted
isDisabled = option: {
assertion = config: config.isDisabled option;
message = "CONFIG_${option} is not disabled!";
};
};
# The config options that all modules can depend upon
system.requiredKernelConfig = with config.lib.kernelConfig; [
(isYes "MODULES")
(isYes "BLK_DEV_INITRD")
];
# nixpkgs kernels are assumed to have all required features
assertions = if config.boot.kernelPackages.kernel ? features then [] else
let cfg = config.boot.kernelPackages.kernel.config; in map (attrs:
{ assertion = attrs.assertion cfg; inherit (attrs) message; }
) config.system.requiredKernelConfig;
};
}