From 4a177d2122eeeaf9d7771b378e68eec2e67896bf Mon Sep 17 00:00:00 2001 From: ooks-io Date: Mon, 8 Apr 2024 17:30:42 +1200 Subject: [PATCH] refactor(hardware): major refactor of hardware modules --- system/hosts/ookst480s/default.nix | 32 +++++++++------ system/modules/default.nix | 1 - system/modules/hardware/backlight/default.nix | 16 -------- system/modules/hardware/bluetooth/default.nix | 29 -------------- system/modules/hardware/default.nix | 5 ++- .../hardware/features/backlight/default.nix | 13 ++++++ .../features/battery}/default.nix | 11 ++--- .../hardware/features/bluetooth/default.nix | 24 +++++++++++ system/modules/hardware/features/default.nix | 19 +++++++++ system/modules/hardware/gpu/amd/default.nix | 12 +++--- system/modules/hardware/gpu/intel/default.nix | 2 +- .../modules/hardware/gpu/nvidia/default.nix | 2 +- system/modules/laptop/default.nix | 6 --- system/profiles/amd/default.nix | 29 -------------- system/profiles/base/default.nix | 14 ++----- system/profiles/default.nix | 12 ------ system/profiles/laptop/default.nix | 19 --------- system/profiles/nvidia/default.nix | 40 ------------------- 18 files changed, 95 insertions(+), 191 deletions(-) delete mode 100644 system/modules/hardware/backlight/default.nix delete mode 100644 system/modules/hardware/bluetooth/default.nix create mode 100644 system/modules/hardware/features/backlight/default.nix rename system/modules/{laptop/power => hardware/features/battery}/default.nix (88%) create mode 100644 system/modules/hardware/features/bluetooth/default.nix create mode 100644 system/modules/hardware/features/default.nix delete mode 100644 system/modules/laptop/default.nix delete mode 100644 system/profiles/amd/default.nix delete mode 100644 system/profiles/laptop/default.nix delete mode 100644 system/profiles/nvidia/default.nix diff --git a/system/hosts/ookst480s/default.nix b/system/hosts/ookst480s/default.nix index b5ed252..29c8632 100644 --- a/system/hosts/ookst480s/default.nix +++ b/system/hosts/ookst480s/default.nix @@ -7,21 +7,27 @@ ../../profiles ]; - activeProfiles = ["base" "laptop"]; + activeProfiles = ["base"]; - systemModules.user = { - ooks.enable = true; - shell.fish.enable = true; - }; - - systemModules.laptop.power = { - powersave = { - minFreq = 800; - maxFreq = 1800; + systemModules = { + user = { + ooks.enable = true; + shell.fish.enable = true; }; - performance = { - minFreq = 1800; - maxFreq = 3600; + hardware = { + cpu.type = "intel"; + gpu.type = "intel"; + features = [ "bluetooth" "backlight" "battery" ]; + battery = { + powersave = { + minFreq = 800; + maxFreq = 1800; + }; + performance = { + minFreq = 1800; + maxFreq = 3600; + }; + }; }; }; diff --git a/system/modules/default.nix b/system/modules/default.nix index 6a028d8..b8a6c41 100644 --- a/system/modules/default.nix +++ b/system/modules/default.nix @@ -4,7 +4,6 @@ imports = [ ./hardware ./bootloader - ./laptop ./nix ./programs ./user diff --git a/system/modules/hardware/backlight/default.nix b/system/modules/hardware/backlight/default.nix deleted file mode 100644 index 9a0d0f4..0000000 --- a/system/modules/hardware/backlight/default.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ lib, config, ... }: - -let - cfg = config.systemModules.hardware.backlight; - inherit (lib) mkIf mkEnableOption; -in - -{ - options.systemModules.hardware.backlight = { - enable = mkEnableOption "Enable backlight module"; - }; - - config = mkIf cfg.enable { - hardware.brillo.enable = true; - }; -} diff --git a/system/modules/hardware/bluetooth/default.nix b/system/modules/hardware/bluetooth/default.nix deleted file mode 100644 index 0c68b3b..0000000 --- a/system/modules/hardware/bluetooth/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.systemModules.hardware.bluetooth; - inherit (lib) mkIf mkEnableOption; -in - -{ - options.systemModules.hardware.bluetooth = { - enable = mkEnableOption "Enable bluetooth module"; - }; - - config = mkIf cfg.enable { - - hardware.bluetooth = { - enable = true; - package = pkgs.bluez5-experimental; - }; - - environment.systemPackages = with pkgs; [ - galaxy-buds-client - live-buds-cli - bluetuith - ]; - - # https://github.com/NixOS/nixpkgs/issues/114222 - systemd.user.services.telephony_client.enable = false; - }; -} diff --git a/system/modules/hardware/default.nix b/system/modules/hardware/default.nix index cd9c0cf..7b40e27 100644 --- a/system/modules/hardware/default.nix +++ b/system/modules/hardware/default.nix @@ -1,7 +1,8 @@ { imports = [ - ./bluetooth - ./backlight + ./cpu + ./gpu + ./features ./ssd ]; } diff --git a/system/modules/hardware/features/backlight/default.nix b/system/modules/hardware/features/backlight/default.nix new file mode 100644 index 0000000..6f17b87 --- /dev/null +++ b/system/modules/hardware/features/backlight/default.nix @@ -0,0 +1,13 @@ +{ lib, config, ... }: + +let + features = config.systemModules.hardware.features; + inherit (lib) mkIf; + inherit (builtins) elem; +in + +{ + config = mkIf (elem "backlight" features) { + hardware.brillo.enable = true; + }; +} diff --git a/system/modules/laptop/power/default.nix b/system/modules/hardware/features/battery/default.nix similarity index 88% rename from system/modules/laptop/power/default.nix rename to system/modules/hardware/features/battery/default.nix index e785dee..f13ac4e 100644 --- a/system/modules/laptop/power/default.nix +++ b/system/modules/hardware/features/battery/default.nix @@ -2,14 +2,15 @@ { lib, config, pkgs, ... }: let - cfg = config.systemModules.laptop.power; - inherit (lib) mkIf mkDefault mkEnableOption mkOption types; + features = config.systemModules.hardware.features; + cfg = config.systemModules.hardware.battery; + inherit (lib) mkIf mkDefault mkOption types; + inherit (builtins) elem; MHz = x: x * 1000; in { - options.systemModules.laptop.power = { - enable = mkEnableOption "Enable laptop power module"; + options.systemModules.hardware.battery = { powersave = { minFreq = mkOption { type = types.int; @@ -36,7 +37,7 @@ in }; }; - config = mkIf cfg.enable { + config = mkIf (elem "battery" features) { boot = { kernelModules = ["acpi_call"]; extraModulePackages = with config.boot.kernelPackages; [ diff --git a/system/modules/hardware/features/bluetooth/default.nix b/system/modules/hardware/features/bluetooth/default.nix new file mode 100644 index 0000000..bae0d1e --- /dev/null +++ b/system/modules/hardware/features/bluetooth/default.nix @@ -0,0 +1,24 @@ +{ config, lib, pkgs, ... }: + +let + features = config.systemModules.hardware.features; + inherit (lib) mkIf; + inherit (builtins) elem; +in + +{ + config = mkIf (elem "bluetooth" features) { + hardware.bluetooth = { + enable = true; + package = pkgs.bluez5-experimental; + }; + + environment.systemPackages = with pkgs; [ + live-buds-cli + bluetuith + ]; + + # https://github.com/NixOS/nixpkgs/issues/114222 + systemd.user.services.telephony_client.enable = false; + }; +} diff --git a/system/modules/hardware/features/default.nix b/system/modules/hardware/features/default.nix new file mode 100644 index 0000000..206737b --- /dev/null +++ b/system/modules/hardware/features/default.nix @@ -0,0 +1,19 @@ +{ lib, config, ... }: + +let + inherit (lib) types mkOption; +in + +{ + imports = [ + ./bluetooth + ./backlight + ./battery + ]; + + options.systemModules.hardware.features = mkOption { + type = with types; listOf (enum ["bluetooth" "backlight" "battery"]); + default = []; + description = "What extra hardware feature system modules to use"; + }; +} diff --git a/system/modules/hardware/gpu/amd/default.nix b/system/modules/hardware/gpu/amd/default.nix index a9e641b..d0b1b57 100644 --- a/system/modules/hardware/gpu/amd/default.nix +++ b/system/modules/hardware/gpu/amd/default.nix @@ -18,12 +18,12 @@ in mesa ]; extraPackages32 = [ pkgs.driversi686Linux.amdvlk ]; - boot = { - initrd.kernelModules = ["amdgpu"]; - kernelModules = ["amdgpu"]; - }; - environment.systemPackages = [ pkgs.nvtopPackages.amd ]; - services.xserver.videoDrivers = mkDefault ["modesetting" "amdgpu"]; }; + boot = { + initrd.kernelModules = ["amdgpu"]; + kernelModules = ["amdgpu"]; + }; + environment.systemPackages = [ pkgs.nvtopPackages.amd ]; + services.xserver.videoDrivers = mkDefault ["modesetting" "amdgpu"]; }; } diff --git a/system/modules/hardware/gpu/intel/default.nix b/system/modules/hardware/gpu/intel/default.nix index e532170..afcdb12 100644 --- a/system/modules/hardware/gpu/intel/default.nix +++ b/system/modules/hardware/gpu/intel/default.nix @@ -5,7 +5,7 @@ let inherit (lib) mkIf; inherit (builtins) elem; - vaapiIntel = pkgs.vaapiIntel.override {enableHypbridCodec = true;}; + # vaapiIntel = pkgs.vaapiIntel.override {enableHybridCodec = true;}; in { diff --git a/system/modules/hardware/gpu/nvidia/default.nix b/system/modules/hardware/gpu/nvidia/default.nix index fe0ff6d..167515a 100644 --- a/system/modules/hardware/gpu/nvidia/default.nix +++ b/system/modules/hardware/gpu/nvidia/default.nix @@ -19,7 +19,7 @@ in nvidiaSettings = false; nvidiaPersistenced = true; modesetting.enable = true; - powermanagement = { + powerManagement = { enable = mkDefault true; finegrained = mkDefault false; }; diff --git a/system/modules/laptop/default.nix b/system/modules/laptop/default.nix deleted file mode 100644 index 021d3fd..0000000 --- a/system/modules/laptop/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./power - # ./touchpad - ]; -} diff --git a/system/profiles/amd/default.nix b/system/profiles/amd/default.nix deleted file mode 100644 index 77a32f7..0000000 --- a/system/profiles/amd/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ lib, config, pkgs, ... }: - -let - cfg = config.systemProfile.amd; -in - -{ - config = lib.mkIf cfg.enable { - - hardware.opengl = { - extraPackages = with pkgs; [ - vulkan-tools - vulkan-loader - vulkan-extension-layer - vulkan-validation-layer - amdvlk - mesa - ]; - extraPackages32 = [ pkgs.driversi686Linux.amdvlk ]; - }; - - boot = { - initrd.kernelModules = ["amdgpu"]; - kernelModules = ["amdgpu"]; - }; - - environment.systemPackages = [ pkgs.nvtopPackages.amd ]; - }; -} diff --git a/system/profiles/base/default.nix b/system/profiles/base/default.nix index 93c3dd6..8cee7cb 100644 --- a/system/profiles/base/default.nix +++ b/system/profiles/base/default.nix @@ -1,6 +1,7 @@ { inputs, outputs, lib, config, pkgs, ... }: let + isx86Linux = pkgs: with pkgs.stdenv; hostPlatform.isLinux && hostPlatform.isx86; cfg = config.systemProfile.base; in @@ -51,17 +52,8 @@ in enableAllFirmware = true; opengl = { enable = true; - extraPackages = with pkgs; [ - intel-media-driver - vaapiIntel - vaapiVdpau - libvdpau-va-gl - libva-utils - ]; - extraPackages32 = with pkgs.pkgsi686Linux; [ - vaapiVdpau - libvdpau-va-gl - ]; + driSupport = true; + driSupport32Bit = isx86Linux pkgs; }; }; system.stateVersion = lib.mkDefault "23.11"; diff --git a/system/profiles/default.nix b/system/profiles/default.nix index ed2187f..5139526 100644 --- a/system/profiles/default.nix +++ b/system/profiles/default.nix @@ -9,11 +9,8 @@ in { imports = [ ./base - ./nvidia ./gaming - ./laptop ./mediaServer - ./amd ]; options = { @@ -29,15 +26,6 @@ in gaming = { enable = lib.mkEnableOption "Enable the gaming profile"; }; - laptop = { - enable = lib.mkEnableOption "Enable the laptop profile"; - }; - nvidia = { - enable = lib.mkEnableOption "Enable the nvidia profile"; - }; - amd = { - enable = lib.mkEnableOption "Enable the amd profile"; - }; mediaServer = { enable = lib.mkEnableOption "Enable the mediaServer profile"; }; diff --git a/system/profiles/laptop/default.nix b/system/profiles/laptop/default.nix deleted file mode 100644 index 12f5e90..0000000 --- a/system/profiles/laptop/default.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.systemProfile.laptop; -in -{ - imports = [ - ../../modules - ]; - - config = lib.mkIf cfg.enable { - systemModules = { - hardware = { - bluetooth.enable = true; - backlight.enable = true; - }; - laptop.power.enable = true; - }; - }; -} diff --git a/system/profiles/nvidia/default.nix b/system/profiles/nvidia/default.nix deleted file mode 100644 index b8d18ee..0000000 --- a/system/profiles/nvidia/default.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ lib, config, pkgs, ... }: - -let - cfg = config.systemProfile.nvidia; - production = config.boot.kernelPackages.nvidiaPackages.production; - beta = config.boot.kernelPackages.nvidiaPackages.beta; -in - -{ - config = lib.mkIf cfg.enable { - hardware.nvidia = { - open = true; - package = production; - modesetting.enable = true; - nvidiaSettings = true; - powerManagement.enable = true; - }; - hardware.opengl.extraPackages = with pkgs; [ nvidia-vaapi-driver ]; - hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [ nvidia-vaapi-driver ]; - services.xserver.videoDrivers = [ "nvidia" ]; - environment.sessionVariables = { - LIBVA_DRIVER_NAME = "nvidia"; - NVD_BACKEND = "direct"; - }; - environment.systemPackages = with pkgs; [ - nvtopPackages.nvidia - mesa - - libva - libva-utils - - vulkan-loader - vulkan-validation-layers - vulkan-tools - vulkan-extension-layer - ]; - }; - - -}