refactor(nixos): move cpu and gpu config to modules
This commit is contained in:
parent
5bef7c46a6
commit
d816825ac3
6 changed files with 89 additions and 64 deletions
|
@ -1,45 +0,0 @@
|
|||
{
|
||||
inputs,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
# Accept the license by default; needed for some packages.
|
||||
nixpkgs.config.nvidia.acceptLicense = true;
|
||||
nix.settings = {
|
||||
substituters = [ "https://cuda-maintainers.cachix.org" ];
|
||||
trusted-public-keys = [
|
||||
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
|
||||
];
|
||||
};
|
||||
services.xserver.videoDrivers = [ "nvidia" ];
|
||||
environment.variables = {
|
||||
GBM_BACKEND = "nvidia-drm";
|
||||
LIBVA_DRIVER_NAME = "nvidia";
|
||||
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
|
||||
};
|
||||
hardware = {
|
||||
enableRedistributableFirmware = true;
|
||||
nvidia-container-toolkit.enable = true;
|
||||
graphics = {
|
||||
enable = true;
|
||||
extraPackages = with pkgs; [
|
||||
nvidia-vaapi-driver # hardware acceleration
|
||||
];
|
||||
};
|
||||
nvidia = {
|
||||
modesetting.enable = true;
|
||||
open = false;
|
||||
nvidiaSettings = true;
|
||||
nvidiaPersistenced = true;
|
||||
package = config.boot.kernelPackages.nvidiaPackages.latest;
|
||||
};
|
||||
};
|
||||
boot.initrd.availableKernelModules = [
|
||||
"nvidia"
|
||||
"nvidia_modeset"
|
||||
"nvidia_uvm"
|
||||
"nvidia_drm"
|
||||
];
|
||||
}
|
|
@ -1,11 +1,8 @@
|
|||
{ lib, config, ... }:
|
||||
{
|
||||
imports = [
|
||||
../configs/filesystems/impermanence.nix
|
||||
../configs/services.nix
|
||||
];
|
||||
boot.kernelModules = [ "kvm-intel" ];
|
||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||
boot-config.bootloader = "systemd-boot";
|
||||
hardware-config.cpu = "intel";
|
||||
}
|
||||
|
|
|
@ -15,4 +15,5 @@
|
|||
nixosModules.enable = true;
|
||||
nix-config.enable = true;
|
||||
boot-config.enable = true;
|
||||
hardware-config.enable = true;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
{
|
||||
inputs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{ inputs, ... }:
|
||||
{
|
||||
imports = [
|
||||
../configs/filesystems/hw-nemesis.nix
|
||||
../configs/hardware/nvidia.nix
|
||||
../configs/hardware/powermanagement.nix
|
||||
inputs.nixos-hardware.nixosModules.gigabyte-b650
|
||||
];
|
||||
boot.kernelModules = [ "kvm-amd" ];
|
||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
||||
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||
boot-config.bootloader = "systemd-boot";
|
||||
hardware-config.cpu = "amd";
|
||||
hardware-config.gpu = "nvidia";
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
@ -10,8 +9,9 @@ let
|
|||
in
|
||||
{
|
||||
imports = [
|
||||
./nix-config.nix
|
||||
./boot.nix
|
||||
./hardware.nix
|
||||
./nix-config.nix
|
||||
];
|
||||
|
||||
options = {
|
||||
|
@ -20,7 +20,5 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages = with pkgs; [ micro ];
|
||||
};
|
||||
config = lib.mkIf cfg.enable { };
|
||||
}
|
||||
|
|
81
nixosModules/hardware.nix
Normal file
81
nixosModules/hardware.nix
Normal file
|
@ -0,0 +1,81 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
moduleName = "hardware-config";
|
||||
cfg = config."${moduleName}";
|
||||
in
|
||||
{
|
||||
options = {
|
||||
"${moduleName}" = {
|
||||
enable = lib.mkEnableOption "Enable ${moduleName}.";
|
||||
cpu = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
example = "amd";
|
||||
description = "What CPU is being used.";
|
||||
};
|
||||
gpu = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
example = "nvidia";
|
||||
description = "What GPU is being used.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf (cfg.cpu != "") {
|
||||
nixpkgs.hostPlatform = lib.mkIf (cfg.cpu == "amd" || cfg.cpu == "intel") "x86_64-linux";
|
||||
# CPU Settings
|
||||
boot.kernelModules =
|
||||
lib.optionals (cfg.cpu == "intel") [ "kvm-intel" ]
|
||||
++ lib.optionals (cfg.cpu == "amd") [ "kvm-amd" ];
|
||||
hardware.cpu =
|
||||
lib.mkIf (cfg.cpu == "intel") { intel.updateMicrocode = true; }
|
||||
// lib.mkIf (cfg.cpu == "amd") { amd.updateMicrocode = true; };
|
||||
})
|
||||
(lib.mkIf (cfg.gpu == "nvidia") {
|
||||
# Accept the license by default; needed for some packages.
|
||||
nixpkgs.config.nvidia.acceptLicense = true;
|
||||
nix.settings = {
|
||||
substituters = [ "https://cuda-maintainers.cachix.org" ];
|
||||
trusted-public-keys = [
|
||||
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
|
||||
];
|
||||
};
|
||||
services.xserver.videoDrivers = [ "nvidia" ];
|
||||
environment.variables = {
|
||||
GBM_BACKEND = "nvidia-drm";
|
||||
LIBVA_DRIVER_NAME = "nvidia";
|
||||
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
|
||||
};
|
||||
hardware = {
|
||||
enableRedistributableFirmware = true;
|
||||
nvidia-container-toolkit.enable = true;
|
||||
graphics = {
|
||||
enable = true;
|
||||
extraPackages = with pkgs; [
|
||||
nvidia-vaapi-driver # hardware acceleration
|
||||
];
|
||||
};
|
||||
nvidia = {
|
||||
modesetting.enable = true;
|
||||
open = false;
|
||||
nvidiaSettings = true;
|
||||
nvidiaPersistenced = true;
|
||||
package = config.boot.kernelPackages.nvidiaPackages.latest;
|
||||
};
|
||||
};
|
||||
boot.initrd.availableKernelModules = [
|
||||
"nvidia"
|
||||
"nvidia_modeset"
|
||||
"nvidia_uvm"
|
||||
"nvidia_drm"
|
||||
];
|
||||
})
|
||||
];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue