refactor: complete rewrite
This commit is contained in:
parent
19a4bbda3c
commit
8e81943cf9
399 changed files with 3396 additions and 8042 deletions
6
modules/nixos/hardware/common.nix
Normal file
6
modules/nixos/hardware/common.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
hardware = {
|
||||
enableRedistributableFirmware = true;
|
||||
enableAllFirmware = true;
|
||||
};
|
||||
}
|
||||
40
modules/nixos/hardware/cpu/amd.nix
Normal file
40
modules/nixos/hardware/cpu/amd.nix
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkMerge mkIf versionAtLeast versionOlder;
|
||||
inherit (config.ooknet.hardware) cpu;
|
||||
cfg = cpu.amd;
|
||||
kernelVersion = config.boot.kernelPackages.kernel.version;
|
||||
kernelVersionAtLeast = versionAtLeast kernelVersion;
|
||||
kernelVersionOlder = versionOlder kernelVersion;
|
||||
in {
|
||||
config = mkIf (cpu.type == "amd") {
|
||||
environment.systemPackages = [pkgs.amdctl];
|
||||
hardware.cpu.amd.updateMicrocode = true;
|
||||
boot = mkMerge [
|
||||
{
|
||||
kernelModules = [
|
||||
"amd-pstate"
|
||||
"amd-kvm" # virtulization
|
||||
"msr" # required for amdctl
|
||||
];
|
||||
}
|
||||
|
||||
(mkIf (cfg.pstate.enable && (kernelVersionAtLeast "5.27") && (kernelVersionOlder "6.1")) {
|
||||
kernelParams = ["initcall_blacklist-acpi_cpufreq_init"];
|
||||
kernelModules = ["amd-pstate"];
|
||||
})
|
||||
|
||||
(mkIf (cfg.pstate.enable && (kernelVersionAtLeast "6.1") && (kernelVersionOlder "6.3")) {
|
||||
kernelParams = ["amd_pstate=passive"];
|
||||
})
|
||||
|
||||
(mkIf (cfg.pstate.enable && (kernelVersionAtLeast "6.3")) {
|
||||
kernelParams = ["amd_pstate=active"];
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
6
modules/nixos/hardware/cpu/default.nix
Normal file
6
modules/nixos/hardware/cpu/default.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
./amd.nix
|
||||
./intel.nix
|
||||
];
|
||||
}
|
||||
18
modules/nixos/hardware/cpu/intel.nix
Normal file
18
modules/nixos/hardware/cpu/intel.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
inherit (config.ooknet.hardware) cpu;
|
||||
in {
|
||||
config = mkIf (cpu.type == "intel") {
|
||||
boot = {
|
||||
kernelModules = ["kvm-intel"];
|
||||
kernelParams = ["i915.fastboot=1" "enable_gvt=1"];
|
||||
};
|
||||
hardware.cpu.intel.updateMicrocode = true;
|
||||
environment.systemPackages = [pkgs.intel-gpu-tools];
|
||||
};
|
||||
}
|
||||
9
modules/nixos/hardware/default.nix
Normal file
9
modules/nixos/hardware/default.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
imports = [
|
||||
./cpu
|
||||
./gpu
|
||||
./features
|
||||
./common.nix
|
||||
./options.nix
|
||||
];
|
||||
}
|
||||
70
modules/nixos/hardware/features/audio.nix
Normal file
70
modules/nixos/hardware/features/audio.nix
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) elem;
|
||||
inherit (lib) mkIf;
|
||||
inherit (config.ooknet.hardware) features;
|
||||
in {
|
||||
# generic audio configuration
|
||||
config = mkIf (elem "audio" features) {
|
||||
hardware.pulseaudio.enable = false;
|
||||
services = {
|
||||
pipewire = {
|
||||
enable = true;
|
||||
audio.enable = true;
|
||||
alsa = {
|
||||
enable = true;
|
||||
support32Bit = true;
|
||||
};
|
||||
pulse.enable = true;
|
||||
jack.enable = true;
|
||||
wireplumber.enable = true;
|
||||
};
|
||||
|
||||
# realtime audio
|
||||
udev.extraRules = ''
|
||||
KERNEL=="cpu_dma_latency", GROUP="audio"
|
||||
KERNEL=="rtc0", GROUP="audio"
|
||||
KERNEL=="hpet", GROUP="audio"
|
||||
'';
|
||||
};
|
||||
|
||||
security = {
|
||||
rtkit.enable = true;
|
||||
pam.loginLimits = [
|
||||
{
|
||||
domain = "@audio";
|
||||
item = "nofile";
|
||||
type = "soft";
|
||||
value = "99999";
|
||||
}
|
||||
{
|
||||
domain = "@audio";
|
||||
item = "nofile";
|
||||
type = "hard";
|
||||
value = "99999";
|
||||
}
|
||||
{
|
||||
domain = "@audio";
|
||||
item = "rtprio";
|
||||
type = "-";
|
||||
value = "99";
|
||||
}
|
||||
{
|
||||
domain = "@audio";
|
||||
item = "memlock";
|
||||
type = "-";
|
||||
value = "unlimited";
|
||||
}
|
||||
{
|
||||
domain = "@audio";
|
||||
type = "-";
|
||||
item = "nice";
|
||||
value = -11;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
13
modules/nixos/hardware/features/backlight.nix
Normal file
13
modules/nixos/hardware/features/backlight.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (config.ooknet.hardware) features;
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) elem;
|
||||
in {
|
||||
config = mkIf (elem "backlight" features) {
|
||||
hardware.brillo.enable = true;
|
||||
};
|
||||
}
|
||||
44
modules/nixos/hardware/features/battery.nix
Normal file
44
modules/nixos/hardware/features/battery.nix
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) elem attrValues;
|
||||
inherit (config.ooknet.hardware) features;
|
||||
in {
|
||||
config = mkIf (elem "battery" features) {
|
||||
services = {
|
||||
# cpu power usage optimizer
|
||||
auto-cpufreq = {enable = true;};
|
||||
|
||||
# application interface for power management
|
||||
upower = {
|
||||
enable = true;
|
||||
percentageLow = 25;
|
||||
percentageCritical = 5;
|
||||
percentageAction = 3;
|
||||
criticalPowerAction = "Hibernate";
|
||||
};
|
||||
|
||||
# daemon for monitoring and controlling temperature
|
||||
thermald = {enable = true;};
|
||||
|
||||
# put this here because if we are enabling the battery modules
|
||||
# we are most likely using a laptop
|
||||
# lidSwitch defines the action to perform when the laptop lid is
|
||||
# closed
|
||||
logind = {lidSwitch = "suspend";};
|
||||
};
|
||||
boot = {
|
||||
kernelModules = ["acpi_call"];
|
||||
extraModulePackages = attrValues {
|
||||
inherit (config.boot.kernelPackages) acpi_call cpupower;
|
||||
};
|
||||
};
|
||||
environment.systemPackages = attrValues {
|
||||
inherit (pkgs) acpi powertop;
|
||||
};
|
||||
};
|
||||
}
|
||||
26
modules/nixos/hardware/features/bluetooth.nix
Normal file
26
modules/nixos/hardware/features/bluetooth.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
self,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) elem attrValues;
|
||||
inherit (config.ooknet.hardware) features;
|
||||
in {
|
||||
config = mkIf (elem "bluetooth" features) {
|
||||
hardware.bluetooth = {
|
||||
enable = true;
|
||||
package = pkgs.bluez5-experimental;
|
||||
};
|
||||
|
||||
environment.systemPackages = attrValues {
|
||||
#inherit (self.packages.${pkgs.system}) live-buds-cli;
|
||||
inherit (pkgs) bluetuith;
|
||||
};
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/issues/114222
|
||||
systemd.user.services.telephony_client.enable = false;
|
||||
};
|
||||
}
|
||||
11
modules/nixos/hardware/features/default.nix
Normal file
11
modules/nixos/hardware/features/default.nix
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
imports = [
|
||||
./video.nix
|
||||
./printing.nix
|
||||
./audio.nix
|
||||
./battery.nix
|
||||
./backlight.nix
|
||||
./ssd.nix
|
||||
# ./bluetooth.nix
|
||||
];
|
||||
}
|
||||
24
modules/nixos/hardware/features/printing.nix
Normal file
24
modules/nixos/hardware/features/printing.nix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) elem;
|
||||
inherit (config.ooknet.hardware) features;
|
||||
in {
|
||||
config = mkIf (elem "printing" features) {
|
||||
services = {
|
||||
printing = {
|
||||
enable = true;
|
||||
drivers = [pkgs.hplip];
|
||||
};
|
||||
avahi = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
nssmdns4 = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
23
modules/nixos/hardware/features/ssd.nix
Normal file
23
modules/nixos/hardware/features/ssd.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) elem;
|
||||
inherit (config.ooknet.hardware) features;
|
||||
in {
|
||||
config = mkIf (elem "ssd" features) {
|
||||
services.fstrim = {
|
||||
enable = true;
|
||||
};
|
||||
# only run fstrim while connected on AC
|
||||
systemd.services.fstrim = {
|
||||
unitConfig.ConditionACPower = true;
|
||||
serviceConfig = {
|
||||
Nice = 19;
|
||||
IOSchedulingClass = "idle";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
19
modules/nixos/hardware/features/video.nix
Normal file
19
modules/nixos/hardware/features/video.nix
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) elem;
|
||||
inherit (config.ooknet.hardware) features;
|
||||
in {
|
||||
config = mkIf (elem "video" features) {
|
||||
hardware = {
|
||||
graphics = {
|
||||
enable = true;
|
||||
enable32Bit = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
32
modules/nixos/hardware/gpu/amd.nix
Normal file
32
modules/nixos/hardware/gpu/amd.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (config.ooknet.hardware) gpu;
|
||||
inherit (lib) mkIf mkDefault;
|
||||
inherit (builtins) attrValues;
|
||||
in {
|
||||
config = mkIf (gpu.type == "amd") {
|
||||
hardware.graphics = {
|
||||
extraPackages = attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
vulkan-tools
|
||||
vulkan-loader
|
||||
vulkan-extension-layer
|
||||
vulkan-validation-layers
|
||||
mesa
|
||||
;
|
||||
};
|
||||
extraPackages32 = [pkgs.driversi686Linux.amdvlk];
|
||||
};
|
||||
boot = {
|
||||
initrd.kernelModules = ["amdgpu"];
|
||||
kernelModules = ["amdgpu"];
|
||||
};
|
||||
environment.systemPackages = [pkgs.nvtopPackages.amd];
|
||||
services.xserver.videoDrivers = mkDefault ["modesetting" "amdgpu"];
|
||||
};
|
||||
}
|
||||
7
modules/nixos/hardware/gpu/default.nix
Normal file
7
modules/nixos/hardware/gpu/default.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
imports = [
|
||||
./amd.nix
|
||||
./intel.nix
|
||||
./nvidia.nix
|
||||
];
|
||||
}
|
||||
39
modules/nixos/hardware/gpu/intel.nix
Normal file
39
modules/nixos/hardware/gpu/intel.nix
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (config.ooknet.hardware) gpu;
|
||||
inherit (lib) mkIf;
|
||||
inherit (builtins) attrValues;
|
||||
in {
|
||||
config = mkIf (gpu.type == "intel") {
|
||||
services.xserver.videoDrivers = ["modesetting"];
|
||||
hardware.graphics = {
|
||||
extraPackages = attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
vaapiIntel
|
||||
vaapiVdpau
|
||||
libvdpau-va-gl
|
||||
intel-compute-runtime
|
||||
intel-media-driver
|
||||
;
|
||||
};
|
||||
extraPackages32 = attrValues {
|
||||
inherit
|
||||
(pkgs.pkgsi686Linux)
|
||||
vaapiIntel
|
||||
vaapiVdpau
|
||||
libvdpau-va-gl
|
||||
intel-media-driver
|
||||
;
|
||||
};
|
||||
};
|
||||
boot.initrd.kernelModules = ["i915"];
|
||||
environment.variables = mkIf config.hardware.graphics.enable {
|
||||
VDPAU_DRIVER = "va_gl";
|
||||
};
|
||||
};
|
||||
}
|
||||
64
modules/nixos/hardware/gpu/nvidia.nix
Normal file
64
modules/nixos/hardware/gpu/nvidia.nix
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (config.ooknet.hardware) gpu;
|
||||
inherit (lib) mkIf mkDefault;
|
||||
inherit (builtins) attrValues;
|
||||
# production = config.boot.kernelPackages.nvidiaPackages.production;
|
||||
inherit (config.boot.kernelPackages.nvidiaPackages) beta;
|
||||
in {
|
||||
config = mkIf (gpu.type == "nvidia") {
|
||||
# need this even if using wayland
|
||||
services.xserver.videoDrivers = ["nvidia"];
|
||||
hardware = {
|
||||
nvidia = {
|
||||
open = false;
|
||||
package = beta;
|
||||
forceFullCompositionPipeline = true;
|
||||
nvidiaSettings = false;
|
||||
nvidiaPersistenced = true;
|
||||
modesetting.enable = true;
|
||||
powerManagement = {
|
||||
enable = mkDefault false;
|
||||
finegrained = mkDefault false;
|
||||
};
|
||||
};
|
||||
graphics = {
|
||||
extraPackages = [pkgs.nvidia-vaapi-driver];
|
||||
extraPackages32 = [pkgs.pkgsi686Linux.nvidia-vaapi-driver];
|
||||
};
|
||||
};
|
||||
environment.systemPackages = attrValues {
|
||||
inherit
|
||||
(pkgs)
|
||||
libva
|
||||
libva-utils
|
||||
vulkan-loader
|
||||
vulkan-validation-layers
|
||||
vulkan-tools
|
||||
vulkan-extension-layer
|
||||
mesa
|
||||
;
|
||||
inherit (pkgs.nvtopPackages) nvidia;
|
||||
};
|
||||
environment.sessionVariables = {
|
||||
LIBVA_DRIVER_NAME = "nvidia";
|
||||
NVD_BACKEND = "direct";
|
||||
};
|
||||
|
||||
# https://github.com/ventureoo/nvidia-tweaks
|
||||
services.udev.extraRules = ''
|
||||
ACTION=="bind", SUBSYSTEM=="pci", DRIVERS=="nvidia", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="auto"
|
||||
ACTION=="unbind", SUBSYSTEM=="pci", DRIVERS=="nvidia", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="on"
|
||||
'';
|
||||
boot.kernelParams = [
|
||||
"nvidia.NVreg_UsePageAttributeTable=1"
|
||||
"nvidia.NVreg_InitializeSystemMemoryAllocations=0"
|
||||
"nvidia.NVreg_EnableStreamMemOPs=1"
|
||||
"nvidia.NVreg_RegistryDwords=__REGISTRYDWORDS"
|
||||
];
|
||||
};
|
||||
}
|
||||
101
modules/nixos/hardware/options.nix
Normal file
101
modules/nixos/hardware/options.nix
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkOption mkEnableOption;
|
||||
inherit (lib.types) nullOr enum bool submodule listOf int str;
|
||||
inherit (config.ooknet) hardware;
|
||||
in {
|
||||
options.ooknet.hardware = {
|
||||
gpu = {
|
||||
type = mkOption {
|
||||
type = nullOr (enum ["intel" "amd" "nvidia"]);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
cpu = {
|
||||
type = mkOption {
|
||||
type = nullOr (enum ["intel" "amd"]);
|
||||
default = null;
|
||||
};
|
||||
amd.pstate.enable = mkEnableOption "";
|
||||
};
|
||||
|
||||
features = mkOption {
|
||||
type = listOf (enum [
|
||||
"audio"
|
||||
"video"
|
||||
"bluetooth"
|
||||
"backlight"
|
||||
"battery"
|
||||
"ssd"
|
||||
"printing"
|
||||
"fingerprint"
|
||||
]);
|
||||
default = ["ssd"];
|
||||
};
|
||||
|
||||
# monitor module inspired by misterio77
|
||||
# includes the addition of transform option
|
||||
monitors = mkOption {
|
||||
type = listOf (submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
example = "DP-1";
|
||||
};
|
||||
primary = mkOption {
|
||||
type = bool;
|
||||
default = false;
|
||||
};
|
||||
width = mkOption {
|
||||
type = int;
|
||||
example = 1920;
|
||||
};
|
||||
height = mkOption {
|
||||
type = int;
|
||||
example = 1080;
|
||||
};
|
||||
refreshRate = mkOption {
|
||||
type = int;
|
||||
default = 60;
|
||||
};
|
||||
x = mkOption {
|
||||
type = int;
|
||||
default = 0;
|
||||
};
|
||||
y = mkOption {
|
||||
type = int;
|
||||
default = 0;
|
||||
};
|
||||
transform = mkOption {
|
||||
type = int;
|
||||
default = 0;
|
||||
};
|
||||
enabled = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
};
|
||||
workspace = mkOption {
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
assertions = [
|
||||
{
|
||||
assertion =
|
||||
((lib.length hardware.monitors) != 0)
|
||||
-> ((lib.length (lib.filter (m: m.primary) hardware.monitors)) == 1);
|
||||
message = "At least 1 primary monitor is required";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue