From f60c37c6c064b28395f6c5339ccfedb9a43919c1 Mon Sep 17 00:00:00 2001 From: Einherjar Date: Sat, 18 Nov 2023 12:20:31 -0600 Subject: [PATCH] feat: support for Framework 13 AMD (#92) --- README.md | 1 + .../laptop-minimal/hardware-configuration.nix | 14 ++--- hosts/laptop/hardware-configuration.nix | 52 +++++++++++++++---- hosts/laptop/wayland/default.nix | 18 +++---- hosts/system.nix | 5 +- modules/hardware/amd.nix | 36 +++++++++++++ modules/hardware/default.nix | 3 +- modules/hardware/intel.nix | 40 ++++++++++++-- 8 files changed, 137 insertions(+), 32 deletions(-) create mode 100644 modules/hardware/amd.nix diff --git a/README.md b/README.md index f4a9728..d3aaa8e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Read more about this in the [NixOs Paranoid Guide](https://xeiaso.net/blog/paran ## Features +- [XanMod Kernel](https://xanmod.org/) - [`Hyprland`](https://github.com/hyprwm/Hyprland) Wayland window manager: - [`Waybar`](https://github.com/Alexays/Waybar) status bar. diff --git a/hosts/laptop-minimal/hardware-configuration.nix b/hosts/laptop-minimal/hardware-configuration.nix index 2d94ed0..0bf7cb9 100644 --- a/hosts/laptop-minimal/hardware-configuration.nix +++ b/hosts/laptop-minimal/hardware-configuration.nix @@ -6,11 +6,13 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = - [ "xhci_pci" "nvme" "usbhid" "usb_storage" "sd_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; + boot.initrd.availableKernelModules = [ + "xhci_pci" + "nvme" + "usbhid" + "usb_storage" + "sd_mod" + ]; fileSystems."/" = { device = "none"; @@ -39,6 +41,4 @@ # networking.interfaces.wlp0s20f3.useDHCP = lib.mkDefault true; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; - hardware.cpu.intel.updateMicrocode = - lib.mkDefault config.hardware.enableRedistributableFirmware; } diff --git a/hosts/laptop/hardware-configuration.nix b/hosts/laptop/hardware-configuration.nix index aa14622..fd6d651 100644 --- a/hosts/laptop/hardware-configuration.nix +++ b/hosts/laptop/hardware-configuration.nix @@ -6,11 +6,6 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = - [ "xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; fileSystems."/" = { device = "none"; @@ -23,9 +18,6 @@ fsType = "btrfs"; }; - boot.initrd.luks.devices."encryptedroot".device = - "/dev/disk/by-uuid/44795d11-d166-49d7-89e9-62a9945e05f3"; - fileSystems."/boot" = { device = "/dev/disk/by-uuid/5835-50BF"; fsType = "vfat"; @@ -48,6 +40,46 @@ nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; - hardware.cpu.intel.updateMicrocode = - lib.mkDefault config.hardware.enableRedistributableFirmware; + + # Enable AMD/Intel microcode + hardware.enableRedistributableFirmware = true; + + # Fix WiFi speeds + hardware.wirelessRegulatoryDatabase = true; + + # Needed for desktop environments to detect/manage display brightness + hardware.sensor.iio.enable = lib.mkDefault true; + + boot = { + initrd = { + luks.devices."encryptedroot".device = + "/dev/disk/by-uuid/44795d11-d166-49d7-89e9-62a9945e05f3"; + availableKernelModules = [ + "xhci_pci" + "thunderbolt" + "nvme" + "usb_storage" + "sd_mod" + ]; + }; + + # Fix TRRS headphones missing a mic + # https://community.frame.work/t/headset-microphone-on-linux/12387/3 + # + # This is temporary until a kernel patch is submitted + extraModprobeConfig = '' + options snd-hda-intel model=dell-headset-multi + ''; + }; + + services = { + auto-cpufreq.enable = true; + thermald.enable = true; + fprintd.enable = lib.mkDefault true; + # Custom udev rules + udev.extraRules = '' + # Ethernet expansion card support + ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0bda", ATTR{idProduct}=="8156", ATTR{power/autosuspend}="20" + ''; + }; } diff --git a/hosts/laptop/wayland/default.nix b/hosts/laptop/wayland/default.nix index 468542b..983ad7f 100644 --- a/hosts/laptop/wayland/default.nix +++ b/hosts/laptop/wayland/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, user, inputs, ... }: +{ config, pkgs, lib, user, inputs, ... }: let user = "einherjar"; @@ -47,7 +47,7 @@ in }; boot = { supportedFilesystems = [ "ntfs" ]; - kernelPackages = pkgs.linuxPackages_latest; + kernelPackages = pkgs.linuxPackages_xanmod_latest; loader = { systemd-boot = { enable = true; @@ -60,14 +60,12 @@ in }; timeout = 3; }; - kernelParams = [ - "quiet" - "splash" - # framework specific ones - "mem_sleep_default=deep" # better battery life - "nvme.noacpi=1" # better battery life for NVME - "usbcore.quirks=0bda:8156:k" # framework ethernet port not responding after sleep - ]; + + # Fix WiFi speeds + extraModprobeConfig = '' + options cfg80211 ieee80211_regdom="US" + ''; + blacklistedKernelModules = [ # Bluetooth # "btusb" diff --git a/hosts/system.nix b/hosts/system.nix index 96ae1ca..be9cc99 100644 --- a/hosts/system.nix +++ b/hosts/system.nix @@ -43,7 +43,10 @@ }; openssh = { enable = false; }; fstrim.enable = true; - fwupd.enable = true; + fwupd = { + enable = true; + extraRemotes = [ "lvfs-testing" ]; + }; tor.enable = true; }; diff --git a/modules/hardware/amd.nix b/modules/hardware/amd.nix new file mode 100644 index 0000000..a6e6daf --- /dev/null +++ b/modules/hardware/amd.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +{ + boot = { + kernelParams = [ + "quiet" + "splash" + + # framework specific ones + # https://www.kernel.org/doc/html/latest/admin-guide/pm/amd-pstate.html#active-mode + # note: if you're using 6.1, use "passive" + "amd_pstate=active" + ]; + # https://git.exozy.me/a/zenpower3 + extraModulePackages = with config.boot.kernelPackages; [ zenpower ]; + }; + services = { + # AMD has better battery life with PPD over TLP: + # https://community.frame.work/t/responded-amd-7040-sleep-states/38101/13 + power-profiles-daemon.enable = lib.mkDefault true; + }; + hardware = { + cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + opengl = { + enable = true; + extraPackages = with pkgs; [ + rocm-opencl-icd + amdvlk + ]; + }; + pulseaudio.support32Bit = true; + }; + environment = { + systemPackages = with pkgs; [ glxinfo ]; + }; +} diff --git a/modules/hardware/default.nix b/modules/hardware/default.nix index f4ab718..0426ebf 100644 --- a/modules/hardware/default.nix +++ b/modules/hardware/default.nix @@ -1,4 +1,5 @@ [ - ./intel.nix + # ./intel.nix + ./amd.nix ./bluetooth.nix ] diff --git a/modules/hardware/intel.nix b/modules/hardware/intel.nix index fedf8d0..b24f9c3 100644 --- a/modules/hardware/intel.nix +++ b/modules/hardware/intel.nix @@ -1,6 +1,29 @@ { config, lib, pkgs, ... }: { + boot = { + kernelModules = [ "kvm-intel" ]; + kernelParams = [ + "quiet" + "splash" + + # framework specific ones + # Fixes a regression in s2idle, making it more power efficient than deep sleep + "acpi_osi=\"!Windows 2020\"" + # For Power consumption + # https://kvark.github.io/linux/framework/2021/10/17/framework-nixos.html + "mem_sleep_default=deep" + # Workaround iGPU hangs + # https://discourse.nixos.org/t/intel-12th-gen-igpu-freezes/21768/4 + "i915.enable_psr=1" + # better battery life for NVME + "nvme.noacpi=1" + ]; + + # This enables the brightness and airplane mode keys to work + # https://community.frame.work/t/12th-gen-not-sending-xf86monbrightnessup-down/20605/11 + blacklistedKernelModules = [ "hid-sensor-hub" ]; + }; services = { tlp = { enable = true; @@ -53,10 +76,16 @@ PLATFORM_PROFILE_ON_BAT = "low-power"; }; }; - auto-cpufreq.enable = true; - thermald.enable = true; + + # Custom udev rules + udev.extraRules = '' + # Fix headphone noise when on powersave + # https://community.frame.work/t/headphone-jack-intermittent-noise/5246/55 + SUBSYSTEM=="pci", ATTR{vendor}=="0x8086", ATTR{device}=="0xa0e0", ATTR{power/control}="on" + ''; }; hardware = { + cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; opengl = { enable = true; extraPackages = with pkgs; [ @@ -68,9 +97,14 @@ ]; }; pulseaudio.support32Bit = true; + + # Mis-detected by nixos-generate-config + # https://github.com/NixOS/nixpkgs/issues/171093 + # https://wiki.archlinux.org/title/Framework_Laptop#Changing_the_brightness_of_the_monitor_does_not_work + acpilight.enable = lib.mkDefault true; }; environment = { - systemPackages = with pkgs; [ libva libva-utils glxinfo ]; + systemPackages = with pkgs; [ libva libva-utils glxinfo fw-ectool ]; variables = { LIBVA_DRIVER_NAME = "iHD"; }; }; }