about summary refs log tree commit diff
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2015-03-18 14:06:22 +0100
committeraszlig <aszlig@redmoonstudios.org>2015-03-18 14:11:42 +0100
commit95ff01f8965fd3b09953c75d16c4e2e7af38aa41 (patch)
tree9b3756971fbeb06c6d86f790383e0517271b4c27
parent7fc10424d9460046c18b5649e580cf308489501b (diff)
lib: Refactor kernel configuration into a module.
This means, we don't have that lib directory anymore and also we're not
doing text substitution on the kernel config but instead override the
original attributes.

However, this needs to be refactored even further, so we can use the
NixOS kernel system, which allows for certain modules to require
specific kernel features. That way we can automatically create a kernel
config from the list of required features and we only need to set a
specific base config instead of specifying the *full* kernel config.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
-rw-r--r--lib/default.nix17
-rw-r--r--machines/aszlig/dnyarri-kconf.nix2
-rw-r--r--machines/aszlig/dnyarri.nix119
-rw-r--r--machines/aszlig/mmrnmhrm.nix21
-rw-r--r--modules/module-list.nix1
-rw-r--r--modules/user/aszlig/system/kernel.nix53
6 files changed, 111 insertions, 102 deletions
diff --git a/lib/default.nix b/lib/default.nix
deleted file mode 100644
index 95f4f39f..00000000
--- a/lib/default.nix
+++ /dev/null
@@ -1,17 +0,0 @@
-with import <nixpkgs> {};
-
-with pkgs.lib;
-
-{
-  generateKConf = exprs: let
-    isNumber = c: elem c ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"];
-    mkValue = val:
-      if val == "" then "\"\""
-      else if val == "y" || val == "m" || val == "n" then val
-      else if all isNumber (stringToCharacters val) then val
-      else if substring 0 2 val == "0x" then val
-      else "\"${val}\"";
-    mkConfigLine = key: val: "${key}=${mkValue val}";
-    mkConf = cfg: concatStringsSep "\n" (mapAttrsToList mkConfigLine cfg);
-  in pkgs.writeText "generated.kconf" (mkConf exprs);
-}
diff --git a/machines/aszlig/dnyarri-kconf.nix b/machines/aszlig/dnyarri-kconf.nix
index 368c155f..7e176541 100644
--- a/machines/aszlig/dnyarri-kconf.nix
+++ b/machines/aszlig/dnyarri-kconf.nix
@@ -745,8 +745,6 @@
   "CONFIG_DEVTMPFS_MOUNT" = "y";
   "CONFIG_FW_LOADER" = "y";
   "CONFIG_FIRMWARE_IN_KERNEL" = "y";
-  "CONFIG_EXTRA_FIRMWARE" = "@extra_firmware@";
-  "CONFIG_EXTRA_FIRMWARE_DIR" = "@builtin_firmware@";
   "CONFIG_ALLOW_DEV_COREDUMP" = "y";
   "CONFIG_GENERIC_CPU_AUTOPROBE" = "y";
   "CONFIG_DMA_SHARED_BUFFER" = "y";
diff --git a/machines/aszlig/dnyarri.nix b/machines/aszlig/dnyarri.nix
index 89753820..9eb3a65e 100644
--- a/machines/aszlig/dnyarri.nix
+++ b/machines/aszlig/dnyarri.nix
@@ -1,18 +1,49 @@
-{ pkgs, ... }:
+{ pkgs, lib, ... }:
 
-with pkgs.lib;
-with import ../../lib;
+with lib;
 
 {
   vuizvui.user.aszlig.profiles.workstation.enable = true;
 
   nix.maxJobs = 8;
 
-  boot = let
-    patch51Name = "patch51.fw";
-    kernelParams = [ "snd-hda-intel.patch=${patch51Name}" ];
+  boot = {
+    kernelParams = [ "snd-hda-intel.patch=patch51.fw" ];
 
-    patch51 = pkgs.writeText patch51Name ''
+    initrd = {
+      mdadmConf = ''
+        ARRAY /dev/md0 metadata=1.2 UUID=f5e9de04:89efc509:4e184fcc:166b0b67
+        ARRAY /dev/md1 metadata=0.90 UUID=b85aa8be:cea0faf2:7abcbee8:eeae037b
+      '';
+      luks.devices = [
+        { name = "system_crypt";
+          device = "/dev/md1";
+          preLVM = true;
+        }
+      ];
+    };
+
+    loader.grub.devices = [
+      "/dev/disk/by-id/ata-ST31500541AS_5XW0AMNH"
+      "/dev/disk/by-id/ata-ST31500541AS_6XW0M217"
+    ];
+  };
+
+  nixpkgs.config.virtualbox.enableExtensionPack = true;
+
+  vuizvui.user.aszlig.system.kernel.enable = true;
+  vuizvui.user.aszlig.system.kernel.config = let
+    radeonFw = [
+      "radeon/R600_rlc.bin"
+      "radeon/R700_rlc.bin"
+      "radeon/RV710_uvd.bin"
+      "radeon/RV710_smc.bin"
+      "radeon/RV730_smc.bin"
+    ];
+
+    extraFw = radeonFw ++ [ "patch51.fw" ];
+
+    patch51 = pkgs.writeText "patch51.fw" ''
       [codec]
       0x10ec0889 0x80860033 2
 
@@ -36,69 +67,21 @@ with import ../../lib;
       auto
     '';
 
-    radeonFW = [
-      "radeon/R600_rlc.bin"
-      "radeon/R700_rlc.bin"
-      "radeon/RV710_uvd.bin"
-      "radeon/RV710_smc.bin"
-      "radeon/RV730_smc.bin"
-    ];
-
-    linuxVuizvui = pkgs.buildLinux {
-      inherit (pkgs.kernelSourceVuizvui) version src;
-
-      kernelPatches = singleton pkgs.vuizvuiKernelPatches.bfqsched;
-      configfile = pkgs.substituteAll {
-        name = "vuizvui-with-firmware.kconf";
-        src = generateKConf (import ./dnyarri-kconf.nix);
-
-        extra_firmware = concatStringsSep " " (radeonFW ++ [
-          "patch51.fw"
-        ]);
-
-        builtin_firmware = pkgs.stdenv.mkDerivation {
-          name = "builtin-firmware";
-          buildCommand = let
-            firmwareBasePath = "${pkgs.firmwareLinuxNonfree}/lib/firmware";
-          in ''
-            mkdir -p "$out/radeon"
-            ${concatMapStrings (x: ''
-              cp -Lv -t "$out/radeon" "${firmwareBasePath}/${x}";
-            '') radeonFW}
-
-            cp "${patch51}" "$out/${patch51Name}"
-          '';
-        };
-      };
-      allowImportFromDerivation = true; # XXX
-    };
-  in rec {
-    kernelPackages = let
-      kpkgs = pkgs.recurseIntoAttrs
-        (pkgs.linuxPackagesFor linuxVuizvui kernelPackages);
-      virtualbox = kpkgs.virtualbox.override {
-        enableExtensionPack = true;
-      };
-    in pkgs.recurseIntoAttrs (kpkgs // { inherit virtualbox; });
-    inherit kernelParams;
-
-    initrd = {
-      mdadmConf = ''
-        ARRAY /dev/md0 metadata=1.2 UUID=f5e9de04:89efc509:4e184fcc:166b0b67
-        ARRAY /dev/md1 metadata=0.90 UUID=b85aa8be:cea0faf2:7abcbee8:eeae037b
+  in import ./dnyarri-kconf.nix // {
+    CONFIG_EXTRA_FIRMWARE = concatStringsSep " " extraFw;
+    CONFIG_EXTRA_FIRMWARE_DIR = pkgs.stdenv.mkDerivation {
+      name = "builtin-firmware";
+      buildCommand = let
+        firmwareBasePath = "${pkgs.firmwareLinuxNonfree}/lib/firmware";
+      in ''
+        mkdir -p "$out/radeon"
+        ${concatMapStrings (x: ''
+          cp -Lv -t "$out/radeon" "${firmwareBasePath}/${x}"
+        '') radeonFw}
+
+        cp "${patch51}" "$out/patch51.fw"
       '';
-      luks.devices = [
-        { name = "system_crypt";
-          device = "/dev/md1";
-          preLVM = true;
-        }
-      ];
     };
-
-    loader.grub.devices = [
-      "/dev/disk/by-id/ata-ST31500541AS_5XW0AMNH"
-      "/dev/disk/by-id/ata-ST31500541AS_6XW0M217"
-    ];
   };
 
   networking.hostName = "dnyarri";
diff --git a/machines/aszlig/mmrnmhrm.nix b/machines/aszlig/mmrnmhrm.nix
index e46a723b..11ec69f6 100644
--- a/machines/aszlig/mmrnmhrm.nix
+++ b/machines/aszlig/mmrnmhrm.nix
@@ -1,31 +1,22 @@
-{ pkgs, ... }:
+{ pkgs, lib, ... }:
 
-with pkgs.lib;
-with import ../../lib;
+with lib;
 
 {
   vuizvui.user.aszlig.profiles.workstation.enable = true;
 
   nix.maxJobs = 2;
 
-  boot = let
-    linuxVuizvui = pkgs.buildLinux {
-      inherit (pkgs.kernelSourceVuizvui) version src;
-
-      kernelPatches = singleton pkgs.vuizvuiKernelPatches.bfqsched;
-      configfile = generateKConf (import ./mmrnmhrm-kconf.nix);
-      allowImportFromDerivation = true;
-    };
-  in rec {
-    kernelPackages = pkgs.recurseIntoAttrs
-      (pkgs.linuxPackagesFor linuxVuizvui kernelPackages);
-
+  boot = {
     loader.grub.devices = map (i: "/dev/disk/by-id/${i}") [
       "ata-WDC_WD10EZEX-00BN5A0_WD-WCC3F5756955"
       "ata-WDC_WD10EZEX-00BN5A0_WD-WCC3F5790537"
     ];
   };
 
+  vuizvui.user.aszlig.system.kernel.enable = true;
+  vuizvui.user.aszlig.system.kernel.config = import ./mmrnmhrm-kconf.nix;
+
   networking.hostName = "mmrnmhrm";
 
   fileSystems = {
diff --git a/modules/module-list.nix b/modules/module-list.nix
index dbcb08a7..2cc3235f 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -7,4 +7,5 @@
   ./user/aszlig/services/i3
   ./user/aszlig/services/slim
   ./user/aszlig/services/vlock
+  ./user/aszlig/system/kernel.nix
 ]
diff --git a/modules/user/aszlig/system/kernel.nix b/modules/user/aszlig/system/kernel.nix
new file mode 100644
index 00000000..4a7ba609
--- /dev/null
+++ b/modules/user/aszlig/system/kernel.nix
@@ -0,0 +1,53 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.vuizvui.user.aszlig.system.kernel;
+
+  generateKConf = exprs: let
+    isNumber = c: elem c ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"];
+    mkValue = val:
+      if val == "" then "\"\""
+      else if val == "y" || val == "m" || val == "n" then val
+      else if all isNumber (stringToCharacters val) then val
+      else if substring 0 2 val == "0x" then val
+      else "\"${val}\"";
+    mkConfigLine = key: val: "${key}=${mkValue val}";
+    mkConf = cfg: concatStringsSep "\n" (mapAttrsToList mkConfigLine cfg);
+  in pkgs.writeText "generated.kconf" (mkConf exprs + "\n");
+
+in {
+  options.vuizvui.user.aszlig.system.kernel = {
+    enable = mkEnableOption "aszlig's custom kernel";
+
+    config = mkOption {
+      type = types.attrsOf types.unspecified;
+      default = {};
+      description = ''
+        An attribute set of configuration options to use
+        for building a custom kernel.
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    boot = let
+      linuxVuizvui = pkgs.buildLinux {
+        inherit (pkgs.kernelSourceVuizvui) version src;
+
+        kernelPatches = singleton pkgs.vuizvuiKernelPatches.bfqsched;
+        configfile = generateKConf cfg.config;
+        allowImportFromDerivation = true;
+      };
+    in rec {
+      kernelPackages = pkgs.recurseIntoAttrs
+        (pkgs.linuxPackagesFor linuxVuizvui kernelPackages);
+
+      loader.grub.devices = map (i: "/dev/disk/by-id/${i}") [
+        "ata-WDC_WD10EZEX-00BN5A0_WD-WCC3F5756955"
+        "ata-WDC_WD10EZEX-00BN5A0_WD-WCC3F5790537"
+      ];
+    };
+  };
+}