Skip to content

Commit

Permalink
[feat]: nixosModules (system/boot)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxyhn committed Jan 6, 2024
1 parent 83c1ebf commit 208b2a8
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 88 deletions.
60 changes: 37 additions & 23 deletions hosts/yuki/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,36 @@ in {
};
};
};
};

boot = {
kernelModules = ["acpi_call"];
extraModulePackages = with config.boot.kernelPackages; [acpi_call];
initrd.kernelModules = ["ideapad_laptop"];
kernelPackages = pkgs.linuxPackages_latest;
kernelParams = [
"quiet"
"splash"
"iommu=pt"
"i8042.direct"
"i8042.dumbkbd"
"i915.enable_psr=0"
];
loader = {
efi.canTouchEfiVariables = true;
grub = {
system = {
boot = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
configurationLimit = 3;
gfxmodeEfi = "1920x1080";
kernelModules = ["acpi_call"];
extraModulePackages = with config.boot.kernelPackages; [acpi_call];
initrdKernelModules = ["ideapad_laptop"];
kernelPackages = pkgs.linuxPackages_latest;

kernelParams = [
"quiet"
"splash"
"iommu=pt"
"i8042.direct"
"i8042.dumbkbd"
"i915.enable_psr=0"
];

loader = {
canTouchEfiVariables = true;

grub = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
configurationLimit = 3;
gfxmodeEfi = "1920x1080";
};
};
};
};
};
Expand Down Expand Up @@ -94,7 +100,15 @@ in {
};
};

networking.hostName = "yuki";
networking = {
hostName = "yuki";
extraHosts = builtins.readFile (
builtins.fetchurl {
url = "https://raw.githubusercontent.com/bebasid/bebasid/master/releases/hosts";
sha256 = "18a1q92jg5558hviw3wxp9z6k9zpmr6k5kk1mzfiwm6pnyrg8bp5";
}
);
};

services = {
fstrim.enable = true;
Expand Down
2 changes: 2 additions & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ in {
}

self.nixosModules.hardware
self.nixosModules.system
../settings.nix
./theme
];
};

flake.nixosModules = {
hardware = import ./hardware;
system = import ./system;
};
}
23 changes: 11 additions & 12 deletions modules/hardware/gpu/intel.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
...
}: let
cfg = config.modules.hardware.gpu.intel;
in
with lib; {
options.modules.hardware.gpu.intel = {
enable = mkEnableOption "Intel GPU support";
};
in {
options.modules.hardware.gpu.intel = {
enable = lib.mkEnableOption "Intel GPU support";
};

config = mkIf cfg.enable {
boot.initrd.kernelModules = ["i915"];
config = lib.mkIf cfg.enable {
boot.initrd.kernelModules = ["i915"];

hardware.opengl = {
extraPackages = with pkgs; [intel-media-driver intel-ocl];
extraPackages32 = with pkgs.pkgsi686Linux; [intel-media-driver];
};
hardware.opengl = {
extraPackages = with pkgs; [intel-media-driver intel-ocl];
extraPackages32 = with pkgs.pkgsi686Linux; [intel-media-driver];
};
}
};
}
105 changes: 52 additions & 53 deletions modules/hardware/gpu/nvidia.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,68 @@
...
}: let
cfg = config.modules.hardware.gpu.nvidia;
in
with lib; {
options.modules.hardware.gpu.nvidia = {
enable = mkEnableOption "NVIDIA GPU support";
in {
options.modules.hardware.gpu.nvidia = {
enable = lib.mkEnableOption "NVIDIA GPU support";

optimus = {
enable = mkEnableOption "NVIDIA Optimus support";
optimus = {
enable = lib.mkEnableOption "NVIDIA Optimus support";

intelBusId = mkOption {
type = types.str;
default = "PCI:0:2:0";
description = "Bus ID for the Intel GPU in Optimus setup.";
};
intelBusId = lib.mkOption {
type = lib.types.str;
default = "PCI:0:2:0";
description = "Bus ID for the Intel GPU in Optimus setup.";
};

nvidiaBusId = mkOption {
type = types.str;
default = "PCI:1:0:0";
description = "Bus ID for the NVIDIA GPU in Optimus setup.";
};
nvidiaBusId = lib.mkOption {
type = lib.types.str;
default = "PCI:1:0:0";
description = "Bus ID for the NVIDIA GPU in Optimus setup.";
};
};
};

config = mkIf cfg.enable {
boot = {
blacklistedKernelModules = ["nouveau"];
initrd.kernelModules = [
"nvidia"
"nvidia_modeset"
"nvidia_uvm"
"nvidia_drm"
];
};
config = lib.mkIf cfg.enable {
boot = {
blacklistedKernelModules = ["nouveau"];
initrd.kernelModules = [
"nvidia"
"nvidia_modeset"
"nvidia_uvm"
"nvidia_drm"
];
};

environment.variables = {
NVD_BACKEND = "direct";
MOZ_DISABLE_RDD_SANDBOX = "1";
};
environment.variables = {
NVD_BACKEND = "direct";
MOZ_DISABLE_RDD_SANDBOX = "1";
};

hardware.nvidia = {
open = mkDefault false;
package = mkDefault config.boot.kernelPackages.nvidiaPackages.beta;
modesetting.enable = mkDefault true;
powerManagement.enable = mkDefault true;
hardware.nvidia = {
open = lib.mkDefault false;
package = lib.mkDefault config.boot.kernelPackages.nvidiaPackages.beta;
modesetting.enable = lib.mkDefault true;
powerManagement.enable = lib.mkDefault true;

prime = {
offload = {
enable = cfg.optimus.enable;
enableOffloadCmd = mkIf config.hardware.nvidia.prime.offload.enable true;
};
intelBusId = cfg.optimus.intelBusId;
nvidiaBusId = cfg.optimus.nvidiaBusId;
prime = {
offload = {
enable = cfg.optimus.enable;
enableOffloadCmd = lib.mkIf config.hardware.nvidia.prime.offload.enable true;
};
intelBusId = cfg.optimus.intelBusId;
nvidiaBusId = cfg.optimus.nvidiaBusId;
};
};

hardware.opengl = {
extraPackages = with pkgs; [
libvdpau-va-gl
vaapiVdpau
nvidia-vaapi-driver
];
extraPackages32 = with pkgs.pkgsi686Linux; [libvdpau-va-gl vaapiVdpau];
};

services.xserver.videoDrivers = mkDefault ["nvidia"];
hardware.opengl = {
extraPackages = with pkgs; [
libvdpau-va-gl
vaapiVdpau
nvidia-vaapi-driver
];
extraPackages32 = with pkgs.pkgsi686Linux; [libvdpau-va-gl vaapiVdpau];
};
}

services.xserver.videoDrivers = lib.mkDefault ["nvidia"];
};
}
73 changes: 73 additions & 0 deletions modules/system/boot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
config,
lib,
pkgs,
...
}: let
cfg = config.modules.system.boot;
in {
options.modules.system.boot = {
enable = lib.mkEnableOption "Custom boot configuration";

kernelModules = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "List of kernel modules to load at boot";
};

extraModulePackages = lib.mkOption {
type = lib.types.listOf lib.types.package;
description = "Extra kernel module packages";
};

initrdKernelModules = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "List of kernel modules for the initial ramdisk";
};

kernelPackages = lib.mkOption {
type = lib.types.raw;
description = "Kernel packages";
};

kernelParams = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "List of kernel parameters";
};

loader = {
canTouchEfiVariables = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether the boot loader can modify EFI variables";
};

grub = lib.mkOption {
type = lib.types.nullOr lib.types.attrs;
default = null;
description = "GRUB bootloader configuration";
};

systemdBoot = lib.mkOption {
type = lib.types.nullOr lib.types.attrs;
default = null;
description = "systemd-boot bootloader configuration";
};
};
};

config = lib.mkIf cfg.enable {
boot = {
kernelModules = cfg.kernelModules;
extraModulePackages = cfg.extraModulePackages;
initrd.kernelModules = cfg.initrdKernelModules;
kernelPackages = cfg.kernelPackages;
kernelParams = cfg.kernelParams;

loader = {
efi.canTouchEfiVariables = cfg.loader.canTouchEfiVariables;
grub = lib.optionalAttrs (cfg.loader.grub != null) cfg.loader.grub;
systemd-boot = lib.optionalAttrs (cfg.loader.systemdBoot != null) cfg.loader.systemdBoot;
};
};
};
}
5 changes: 5 additions & 0 deletions modules/system/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
imports = [
./boot.nix
];
}

0 comments on commit 208b2a8

Please sign in to comment.