整理 system.kernel

This commit is contained in:
陈浩南 2023-09-02 15:25:05 +08:00
parent e1e88dfdba
commit e6969fb0c2
5 changed files with 92 additions and 102 deletions

View File

@ -124,11 +124,11 @@
}; };
march = "alderlake"; march = "alderlake";
gui.enable = true; gui.enable = true;
}; kernel =
kernel = {
{ patches = [ "cjktty" "preempt" ];
patches = [ "cjktty" "preempt" ]; modules.modprobeConfig = [ "options iwlmvm power_scheme=1" "options iwlwifi uapsd_disable=1" ];
modules.modprobeConfig = [ "options iwlmvm power_scheme=1" "options iwlwifi uapsd_disable=1" ]; };
}; };
hardware = hardware =
{ {
@ -255,6 +255,7 @@
network.enable = true; network.enable = true;
sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; };
}; };
kernel.patches = [ "preempt" ];
}; };
packages.packageSet = "server"; packages.packageSet = "server";
services = services =
@ -320,6 +321,7 @@
network.enable = true; network.enable = true;
sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; };
}; };
kernel.patches = [ "preempt" ];
}; };
packages.packageSet = "server"; packages.packageSet = "server";
services = services =
@ -364,6 +366,7 @@
network.enable = true; network.enable = true;
sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; };
}; };
kernel.patches = [ "preempt" ];
}; };
packages = packages =
{ {
@ -416,6 +419,7 @@
network.enable = true; network.enable = true;
sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; }; sshd = { enable = true; hostKeys = [ "/nix/persistent/etc/ssh/initrd_ssh_host_ed25519_key" ]; };
}; };
kernel.patches = [ "preempt" ];
}; };
packages.packageSet = "server"; packages.packageSet = "server";
services = services =
@ -473,11 +477,11 @@
substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ];
}; };
gui.enable = true; gui.enable = true;
}; kernel =
kernel = {
{ patches = [ "cjktty" "preempt" ];
patches = [ "cjktty" "preempt" ]; modules.modprobeConfig = [ "options iwlmvm power_scheme=1" "options iwlwifi uapsd_disable=1" ];
modules.modprobeConfig = [ "options iwlmvm power_scheme=1" "options iwlwifi uapsd_disable=1" ]; };
}; };
hardware = hardware =
{ {
@ -575,8 +579,8 @@
gui.enable = true; gui.enable = true;
grub.installDevice = "efi"; grub.installDevice = "efi";
nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ];
kernel.patches = [ "cjktty" "preempt" ];
}; };
kernel.patches = [ "cjktty" "preempt" ];
hardware = hardware =
{ {
cpus = [ "intel" ]; cpus = [ "intel" ];
@ -631,8 +635,8 @@
grub.installDevice = "efiRemovable"; grub.installDevice = "efiRemovable";
gui.enable = true; gui.enable = true;
nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ]; nix.substituters = [ "https://cache.nixos.org/" "https://nix-store.chn.moe" ];
kernel.patches = [ "cjktty" "preempt" ];
}; };
kernel.patches = [ "cjktty" "preempt" ];
hardware = hardware =
{ {
cpus = [ "intel" ]; cpus = [ "intel" ];

View File

@ -30,6 +30,6 @@ inputs:
deploy-rs = { inherit (prev) deploy-rs; inherit ((topInputs.deploy-rs.overlay final prev).deploy-rs) lib; }; deploy-rs = { inherit (prev) deploy-rs; inherit ((topInputs.deploy-rs.overlay final prev).deploy-rs) lib; };
}) })
];}) ];})
./kernel ./hardware ./packages ./system ./virtualization ./services ./bugs ./users ./hardware ./packages ./system ./virtualization ./services ./bugs ./users
]; ];
} }

View File

@ -1,89 +0,0 @@
inputs:
{
options.nixos.kernel = let inherit (inputs.lib) mkOption types; in
{
patches = mkOption { type = types.listOf (types.enum [ "cjktty" "preempt" ]); default = []; };
modules =
{
install = mkOption { type = types.listOf types.str; default = []; };
load = mkOption { type = types.listOf types.str; default = []; };
initrd = mkOption { type = types.listOf types.str; default = []; };
modprobeConfig = mkOption { type = types.listOf types.str; default = []; };
};
};
config = let inherit (inputs.lib) mkMerge mkIf; inherit (inputs.localLib) mkConditional; in mkMerge
[
# generic
{
boot =
{
kernelModules = [ "br_netfilter" ];
initrd.availableKernelModules =
[
"ahci" "ata_piix" "bfq" "failover" "net_failover" "nls_cp437" "nls_iso8859-1" "nvme" "sdhci_acpi" "sd_mod"
"sr_mod" "usbcore" "usbhid" "usbip-core" "usb-common" "usb_storage" "vhci-hcd" "virtio" "virtio_blk"
"virtio_net" "virtio_pci" "xhci_pci" "virtio_ring" "virtio_scsi" "cryptd" "crypto_simd" "libaes"
];
kernelParams = [ "delayacct" "acpi_osi=Linux" ];
kernelPackages = inputs.pkgs.linuxPackagesFor (inputs.pkgs.linuxPackages_xanmod.kernel.override rec
{
src = inputs.pkgs.fetchFromGitHub
{
owner = "xanmod";
repo = "linux";
rev = modDirVersion;
sha256 = "sha256-rvSQJb9MIOXkGEjHOPt3x+dqp1AysvQg7n5yYsg95fk=";
};
version = "6.4.12";
modDirVersion = "6.4.12-xanmod1";
});
};
}
# patches
{
boot.kernelPatches =
(
let
patches =
{
cjktty =
{
patch = inputs.pkgs.fetchurl
{
url = "https://raw.githubusercontent.com/zhmars/cjktty-patches/master/v6.x/cjktty-6.3.patch";
sha256 = "sha256-QnsWruzhtiZnqzTUXkPk9Hb19Iddr4VTWXyV4r+iLvE=";
};
extraStructuredConfig =
{ FONT_CJK_16x16 = inputs.lib.kernel.yes; FONT_CJK_32x32 = inputs.lib.kernel.yes; };
};
preempt =
{
patch = null;
extraStructuredConfig =
{
PREEMPT_VOLUNTARY = inputs.lib.mkForce inputs.lib.kernel.no;
PREEMPT = inputs.lib.mkForce inputs.lib.kernel.yes;
HZ_500 = inputs.lib.mkForce inputs.lib.kernel.no;
HZ_1000 = inputs.lib.mkForce inputs.lib.kernel.yes;
HZ = inputs.lib.mkForce (inputs.lib.kernel.freeform "1000");
};
};
};
in
builtins.map (name: { inherit name; } // patches.${name}) inputs.config.nixos.kernel.patches
);
}
# modules
{
boot =
{
extraModulePackages = inputs.config.nixos.kernel.modules.install;
kernelModules = inputs.config.nixos.kernel.modules.load;
initrd.availableKernelModules = inputs.config.nixos.kernel.modules.initrd;
extraModprobeConfig = builtins.concatStringsSep "\n" inputs.config.nixos.kernel.modules.modprobeConfig;
};
}
];
}
# modprobe --show-depends

View File

@ -6,6 +6,7 @@ inputs:
./fileSystems.nix ./fileSystems.nix
./grub.nix ./grub.nix
./initrd.nix ./initrd.nix
./kernel.nix
]; ];
options.nixos.system = let inherit (inputs.lib) mkOption types; in options.nixos.system = let inherit (inputs.lib) mkOption types; in
{ {

74
modules/system/kernel.nix Normal file
View File

@ -0,0 +1,74 @@
inputs:
{
options.nixos.system.kernel = let inherit (inputs.lib) mkOption types; in
{
patches = mkOption { type = types.listOf (types.enum [ "cjktty" "preempt" ]); default = []; };
modules =
{
install = mkOption { type = types.listOf types.str; default = []; };
load = mkOption { type = types.listOf types.str; default = []; };
initrd = mkOption { type = types.listOf types.str; default = []; };
modprobeConfig = mkOption { type = types.listOf types.str; default = []; };
};
};
config =
let
inherit (inputs.lib) mkMerge mkIf;
inherit (inputs.localLib) mkConditional;
inherit (inputs.config.nixos.system) kernel;
in { boot =
{
kernelModules = [ "br_netfilter" ] ++ kernel.modules.load;
# modprobe --show-depends
initrd.availableKernelModules =
[
"ahci" "ata_piix" "bfq" "failover" "net_failover" "nls_cp437" "nls_iso8859-1" "nvme" "sdhci_acpi" "sd_mod"
"sr_mod" "usbcore" "usbhid" "usbip-core" "usb-common" "usb_storage" "vhci-hcd" "virtio" "virtio_blk"
"virtio_net" "virtio_pci" "xhci_pci" "virtio_ring" "virtio_scsi" "cryptd" "crypto_simd" "libaes"
] ++ kernel.modules.initrd;
extraModulePackages = kernel.modules.install;
extraModprobeConfig = builtins.concatStringsSep "\n" kernel.modules.modprobeConfig;
kernelParams = [ "delayacct" "acpi_osi=Linux" ];
kernelPackages = inputs.pkgs.linuxPackagesFor (inputs.pkgs.linuxPackages_xanmod.kernel.override rec
{
src = inputs.pkgs.fetchFromGitHub
{
owner = "xanmod";
repo = "linux";
rev = modDirVersion;
sha256 = "sha256-rvSQJb9MIOXkGEjHOPt3x+dqp1AysvQg7n5yYsg95fk=";
};
version = "6.4.12";
modDirVersion = "6.4.12-xanmod1";
});
kernelPatches =
let
patches =
{
cjktty =
{
patch = inputs.pkgs.fetchurl
{
url = "https://raw.githubusercontent.com/zhmars/cjktty-patches/master/v6.x/cjktty-6.3.patch";
sha256 = "sha256-QnsWruzhtiZnqzTUXkPk9Hb19Iddr4VTWXyV4r+iLvE=";
};
extraStructuredConfig =
{ FONT_CJK_16x16 = inputs.lib.kernel.yes; FONT_CJK_32x32 = inputs.lib.kernel.yes; };
};
preempt =
{
patch = null;
extraStructuredConfig =
{
PREEMPT_VOLUNTARY = inputs.lib.mkForce inputs.lib.kernel.no;
PREEMPT = inputs.lib.mkForce inputs.lib.kernel.yes;
HZ_500 = inputs.lib.mkForce inputs.lib.kernel.no;
HZ_1000 = inputs.lib.mkForce inputs.lib.kernel.yes;
HZ = inputs.lib.mkForce (inputs.lib.kernel.freeform "1000");
};
};
};
in
builtins.map (name: { inherit name; } // patches.${name}) kernel.patches;
};};
}