summary refs log tree commit diff
path: root/modules/system/boot/kernel.nix
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2012-08-01 21:50:43 -0400
committerShea Levy <shea@shealevy.com>2012-08-01 21:50:43 -0400
commit2a983acaffd9382302ebc3a36a2649f9b2f53a6c (patch)
tree773fecc5935776236ea932fbbbb6994eb37f9051 /modules/system/boot/kernel.nix
parent5f57110e1f977bf0a2e11b4f0ee92244de53d331 (diff)
downloadnixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.tar
nixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.tar.gz
nixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.tar.bz2
nixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.tar.lz
nixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.tar.xz
nixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.tar.zst
nixpkgs-2a983acaffd9382302ebc3a36a2649f9b2f53a6c.zip
Enable specifying which kernel config options are needed for a given module
Diffstat (limited to 'modules/system/boot/kernel.nix')
-rw-r--r--modules/system/boot/kernel.nix61
1 files changed, 60 insertions, 1 deletions
diff --git a/modules/system/boot/kernel.nix b/modules/system/boot/kernel.nix
index 1b247a65890..5bb47969835 100644
--- a/modules/system/boot/kernel.nix
+++ b/modules/system/boot/kernel.nix
@@ -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;
+
+  };
 }