From 0335d1a093dc3e2c577e2243a192775db23485ba Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Sun, 7 Apr 2024 21:28:11 +0200 Subject: [PATCH 1/6] common/gpu/intel: Make initrd - i915 an option --- common/gpu/intel/default.nix | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/common/gpu/intel/default.nix b/common/gpu/intel/default.nix index ed76057..b8ab823 100644 --- a/common/gpu/intel/default.nix +++ b/common/gpu/intel/default.nix @@ -1,15 +1,26 @@ { config, lib, pkgs, ... }: { - boot.initrd.kernelModules = [ "i915" ]; - - environment.variables = { - VDPAU_DRIVER = lib.mkIf config.hardware.opengl.enable (lib.mkDefault "va_gl"); + options.hardware.intelgpu.loadInInitrd = lib.mkEnableOption (lib.mdDoc + "loading `i195` kernelModule at stage 1. (Add `i915` to `boot.initrd.kernelModules`)" + ) // { + default = true; }; - hardware.opengl.extraPackages = with pkgs; [ - (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then vaapiIntel else intel-vaapi-driver) - libvdpau-va-gl - intel-media-driver + config = lib.mkMerge [ + (lib.mkIf config.hardware.intelgpu.loadInInitrd { + boot.initrd.kernelModules = [ "i915" ]; + }) + { + environment.variables = { + VDPAU_DRIVER = lib.mkIf config.hardware.opengl.enable (lib.mkDefault "va_gl"); + }; + + hardware.opengl.extraPackages = with pkgs; [ + (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then vaapiIntel else intel-vaapi-driver) + libvdpau-va-gl + intel-media-driver + ]; + } ]; } From f8e89e4e847d25f32c68adccf61e3ad42967847b Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Sun, 7 Apr 2024 21:31:18 +0200 Subject: [PATCH 2/6] framework: Add framework-laptop-kmod as default for NixOS >= 24.05 --- framework/13-inch/common/default.nix | 1 + framework/kmod.nix | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 framework/kmod.nix diff --git a/framework/13-inch/common/default.nix b/framework/13-inch/common/default.nix index c79061a..b7b961d 100644 --- a/framework/13-inch/common/default.nix +++ b/framework/13-inch/common/default.nix @@ -2,6 +2,7 @@ imports = [ ../../../common/pc/laptop ../../../common/pc/laptop/ssd + ../../kmod.nix ]; # Fix TRRS headphones missing a mic diff --git a/framework/kmod.nix b/framework/kmod.nix new file mode 100644 index 0000000..81ce37a --- /dev/null +++ b/framework/kmod.nix @@ -0,0 +1,17 @@ +{ config, lib, ... }: +{ + options.hardware.framework.enableKmod = lib.mkEnableOption (lib.mdDoc + "Enable the community created Framework kernel module that allows interacting with the embedded controller from sysfs." + ) // { + # Enable by default if on new enough version of NixOS + default = (lib.versionAtLeast (lib.versions.majorMinor lib.version) "24.05"); + }; + + config = lib.mkIf config.hardware.framework.enableKmod { + boot.extraModulePackages = with config.boot.kernelPackages; [ + framework-laptop-kmod + ]; + # https://github.com/DHowett/framework-laptop-kmod?tab=readme-ov-file#usage + boot.kernelModules = [ "cros_ec" "cros_ec_lpcs" ]; + }; +} From 8cde8633d4f93659856695189fa3ead28b7a839b Mon Sep 17 00:00:00 2001 From: Sebastian Sellmeier Date: Mon, 8 Apr 2024 09:53:42 +0200 Subject: [PATCH 3/6] framework/12th-gen-intel: Refactor module https://github.com/NixOS/nixos-hardware/pull/897 https://github.com/NixOS/nixos-hardware/pull/846 https://github.com/NixOS/nixos-hardware/issues/894 --- framework/13-inch/12th-gen-intel/default.nix | 100 ++++++++++--------- framework/13-inch/common/intel.nix | 12 ++- 2 files changed, 62 insertions(+), 50 deletions(-) diff --git a/framework/13-inch/12th-gen-intel/default.nix b/framework/13-inch/12th-gen-intel/default.nix index b16dc1d..e2fdcfd 100644 --- a/framework/13-inch/12th-gen-intel/default.nix +++ b/framework/13-inch/12th-gen-intel/default.nix @@ -1,52 +1,62 @@ -{ lib, pkgs, ... }: { +{ config, lib, pkgs, ... }: +{ imports = [ ../common ../common/intel.nix ]; - boot.kernelParams = [ - # 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" + config = lib.mkMerge [ + { + hardware.intelgpu.loadInInitrd = lib.versionOlder config.boot.kernelPackages.kernel.version "6.2"; + } + # https://community.frame.work/t/tracking-hard-freezing-on-fedora-36-with-the-new-12th-gen-system/20675/391 + (lib.mkIf (lib.versionOlder config.boot.kernelPackages.kernel.version "6.2") { + boot.kernelParams = [ + # Workaround iGPU hangs + # https://discourse.nixos.org/t/intel-12th-gen-igpu-freezes/21768/4 + "i915.enable_psr=1" + ]; + }) + (lib.mkIf (lib.versionOlder config.boot.kernelPackages.kernel.version "6.8") { + boot.blacklistedKernelModules = [ + # This enables the brightness and airplane mode keys to work + # https://community.frame.work/t/12th-gen-not-sending-xf86monbrightnessup-down/20605/11 + "hid-sensor-hub" + # This fixes controller crashes during sleep + # https://community.frame.work/t/tracking-fn-key-stops-working-on-popos-after-a-while/21208/32 + (lib.mkIf (config.hardware.framework.enableKmod == false) "cros_ec_lpcs") + ]; + + boot.kernelParams = [ + # For Power consumption + # https://kvark.github.io/linux/framework/2021/10/17/framework-nixos.html + # Update 04/2024: Combined with acpi_osi from framework-intel it increases the idle power-usage in my test (SebTM) + # (see: https://github.com/NixOS/nixos-hardware/pull/903#issuecomment-2068146658) + "mem_sleep_default=deep" + ]; + + # Further tweak to ensure the brightness and airplane mode keys work + # https://community.frame.work/t/responded-12th-gen-not-sending-xf86monbrightnessup-down/20605/67 + systemd.services.bind-keys-driver = { + description = "Bind brightness and airplane mode keys to their driver"; + wantedBy = [ "default.target" ]; + after = [ "network.target" ]; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + script = '' + ls -lad /sys/bus/i2c/devices/i2c-*:* /sys/bus/i2c/drivers/i2c_hid_acpi/i2c-*:* + if [ -e /sys/bus/i2c/devices/i2c-FRMW0001:00 -a ! -e /sys/bus/i2c/drivers/i2c_hid_acpi/i2c-FRMW0001:00 ]; then + echo fixing + echo i2c-FRMW0001:00 > /sys/bus/i2c/drivers/i2c_hid_acpi/bind + ls -lad /sys/bus/i2c/devices/i2c-*:* /sys/bus/i2c/drivers/i2c_hid_acpi/i2c-*:* + echo done + else + echo no fix needed + fi + ''; + }; + }) ]; - - boot.blacklistedKernelModules = [ - # This enables the brightness and airplane mode keys to work - # https://community.frame.work/t/12th-gen-not-sending-xf86monbrightnessup-down/20605/11 - "hid-sensor-hub" - # This fixes controller crashes during sleep - # https://community.frame.work/t/tracking-fn-key-stops-working-on-popos-after-a-while/21208/32 - "cros_ec_lpcs" - ]; - - # Further tweak to ensure the brightness and airplane mode keys work - # https://community.frame.work/t/responded-12th-gen-not-sending-xf86monbrightnessup-down/20605/67 - systemd.services.bind-keys-driver = { - description = "Bind brightness and airplane mode keys to their driver"; - wantedBy = [ "default.target" ]; - after = [ "network.target" ]; - serviceConfig = { - Type = "oneshot"; - User = "root"; - }; - script = '' - ls -lad /sys/bus/i2c/devices/i2c-*:* /sys/bus/i2c/drivers/i2c_hid_acpi/i2c-*:* - if [ -e /sys/bus/i2c/devices/i2c-FRMW0001:00 -a ! -e /sys/bus/i2c/drivers/i2c_hid_acpi/i2c-FRMW0001:00 ]; then - echo fixing - echo i2c-FRMW0001:00 > /sys/bus/i2c/drivers/i2c_hid_acpi/bind - ls -lad /sys/bus/i2c/devices/i2c-*:* /sys/bus/i2c/drivers/i2c_hid_acpi/i2c-*:* - echo done - else - echo no fix needed - fi - ''; - }; - - # Alder Lake CPUs benefit from kernel 5.18 for ThreadDirector - # https://www.tomshardware.com/news/intel-thread-director-coming-to-linux-5-18 - boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.18") (lib.mkDefault pkgs.linuxPackages_latest); - } diff --git a/framework/13-inch/common/intel.nix b/framework/13-inch/common/intel.nix index fb5c4ce..96bbec9 100644 --- a/framework/13-inch/common/intel.nix +++ b/framework/13-inch/common/intel.nix @@ -1,15 +1,17 @@ -{ lib, pkgs, ... }: { +{ config, lib, pkgs, ... }: { imports = [ ../../../common/cpu/intel ]; - boot.kernelParams = [ - # Fixes a regression in s2idle, making it more power efficient than deep sleep - "acpi_osi=\"!Windows 2020\"" + boot.kernelParams = [ # For Power consumption # https://community.frame.work/t/linux-battery-life-tuning/6665/156 "nvme.noacpi=1" - ]; + ] + # Fixes a regression in s2idle, making it more power efficient than deep sleep + # Update 04/2024: It appears that s2idle-regression got fixed in newer kernel-versions (SebTM) + # (see: https://github.com/NixOS/nixos-hardware/pull/903#discussion_r1556096657) + ++ lib.lists.optional (lib.versionOlder config.boot.kernelPackages.kernel.version "6.8") "acpi_osi=\"!Windows 2020\""; # Requires at least 5.16 for working wi-fi and bluetooth. # https://community.frame.work/t/using-the-ax210-with-linux-on-the-framework-laptop/1844/89 From 17ad09c30ce18c97c1d93bc500867ac0af6a930c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20W=C3=A5gberg?= Date: Fri, 12 Apr 2024 21:53:47 +0200 Subject: [PATCH 4/6] apple/t2: update to kernel 6.7.7 --- apple/t2/default.nix | 9 ------ .../t2/fix-keyboard-backlight-and-touchbar.sh | 28 ------------------- apple/t2/pkgs/linux-t2.nix | 13 +++++---- 3 files changed, 7 insertions(+), 43 deletions(-) delete mode 100755 apple/t2/fix-keyboard-backlight-and-touchbar.sh diff --git a/apple/t2/default.nix b/apple/t2/default.nix index 33658d6..cbdba9d 100644 --- a/apple/t2/default.nix +++ b/apple/t2/default.nix @@ -74,15 +74,6 @@ in # Make sure post-resume.service exists powerManagement.enable = true; - systemd.services.fix-keyboard-backlight-and-touchbar = { - path = [ pkgs.kmod ]; - serviceConfig.ExecStart = ''${pkgs.systemd}/bin/systemd-inhibit --what=sleep --why="fixing keyboard backlight and touchbar must finish before sleep" --mode=delay ${./fix-keyboard-backlight-and-touchbar.sh}''; - serviceConfig.Type = "oneshot"; - description = "reload touchbar driver and restart upower"; - wantedBy = [ "display-manager.service" "post-resume.target" ]; - after = [ "post-resume.target" ]; - }; - # Activation script to install apple-set-os-loader in order to unlock the iGPU system.activationScripts.appleSetOsLoader = lib.optionalString t2Cfg.enableAppleSetOsLoader '' if [[ -e /boot/efi/efi/boot/bootx64_original.efi ]]; then diff --git a/apple/t2/fix-keyboard-backlight-and-touchbar.sh b/apple/t2/fix-keyboard-backlight-and-touchbar.sh deleted file mode 100755 index c8c6a09..0000000 --- a/apple/t2/fix-keyboard-backlight-and-touchbar.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -set -eux - -unload () { - if modprobe -r "$1" 2>&1; - then echo ok - else echo fail - fi -} - -wait_unload() { - while sleep 1; do - output="$(unload "$1")" - case "$output" in - *is\ in\ use*) :;; - *ok*) return 0;; - *) echo "modprobe said: $output"; echo giving up; return 1; - esac - done -} - -wait_unload apple_touchbar -modprobe apple_touchbar - -# After suspend, the inode for the backlight device has changed. This service -# simply restarts upower to inform it of that change. -systemctl restart upower.service diff --git a/apple/t2/pkgs/linux-t2.nix b/apple/t2/pkgs/linux-t2.nix index 40371fe..1838fb9 100644 --- a/apple/t2/pkgs/linux-t2.nix +++ b/apple/t2/pkgs/linux-t2.nix @@ -5,11 +5,11 @@ let patchRepo = fetchFromGitHub { owner = "t2linux"; repo = "linux-t2-patches"; - rev = "46dd873d1d9d12b26916790045008a91a95d0c11"; - hash = "sha256-YGUGuzsAJFtZYjIW9d2XU4eGKNvMKCaWXqgqJn5TdeY="; + rev = "7cd298e227e95bac9a704ffc8f5ff5e89a1bf4d7"; + hash = "sha256-Oi3CwQl0IwdVc9w+pbmJjBnyqwLFhbqFwxs5o0mqtbE="; }; - version = "6.5"; + version = "6.7.7"; majorVersion = with lib; (elemAt (take 1 (splitVersion version)) 0); in buildLinux (args // { @@ -22,7 +22,7 @@ buildLinux (args // { src = runCommand "patched-source" {} '' cp -r ${fetchzip { url = "mirror://kernel/linux/kernel/v${majorVersion}.x/linux-${version}.tar.xz"; - hash = "sha256-qJmVSju69WcvDIbgrbtMyCi+OXUNTzNX2G+/0zwsPR4="; + hash = "sha256-j+Ufl6C1Mqjthk18GPt2e7j+i7viauOgNnVy9dJSgaM="; }} $out chmod -R u+w $out cd $out @@ -40,10 +40,11 @@ buildLinux (args // { BT_HCIBCM4377 = module; BT_HCIUART_BCM = yes; BT_HCIUART = module; - HID_APPLE_IBRIDGE = module; + HID_APPLETB_BL = module; + HID_APPLETB_KBD = module; HID_APPLE = module; + DRM_APPLETBDRM = module; HID_APPLE_MAGIC_BACKLIGHT = module; - HID_APPLE_TOUCHBAR = module; HID_SENSOR_ALS = module; SND_PCM = module; STAGING = yes; From 7e3a3f3170676043024055615da19b58614c4a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20W=C3=A5gberg?= Date: Fri, 12 Apr 2024 23:01:44 +0200 Subject: [PATCH 5/6] apple/t2: add tiny-dfr service --- apple/t2/default.nix | 21 +++++++++++++++- apple/t2/pkgs/tiny-dfr.nix | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 apple/t2/pkgs/tiny-dfr.nix diff --git a/apple/t2/default.nix b/apple/t2/default.nix index cbdba9d..abe9cac 100644 --- a/apple/t2/default.nix +++ b/apple/t2/default.nix @@ -24,6 +24,8 @@ let pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/"; + tiny-dfrPackage = pkgs.callPackage ./pkgs/tiny-dfr.nix { }; + apple-set-os-loader-installer = pkgs.stdenv.mkDerivation { name = "apple-set-os-loader-installer-1.0"; src = pkgs.fetchFromGitHub { @@ -60,9 +62,10 @@ in boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { }); boot.initrd.kernelModules = [ "apple-bce" ]; + services.udev.packages = [ audioFilesUdevRules tiny-dfrPackage ]; + # For audio boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; - services.udev.packages = [ audioFilesUdevRules ]; hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; @@ -71,6 +74,22 @@ in pipewire = pipewirePackage; }; + # For tiny-dfr + systemd.services.tiny-dfr = { + enable = true; + description = "Tiny Apple silicon touch bar daemon"; + after = [ "systemd-user-sessions.service" "getty@tty1.service" "plymouth-quit.service" "systemd-logind.service" ]; + bindsTo = [ "dev-tiny_dfr_display.device" "dev-tiny_dfr_backlight.device" ]; + startLimitIntervalSec = 30; + startLimitBurst = 2; + script = "${tiny-dfrPackage}/bin/tiny-dfr"; + restartTriggers = [ tiny-dfrPackage ]; + }; + + environment.etc."tiny-dfr/config.toml" = { + source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml"; + }; + # Make sure post-resume.service exists powerManagement.enable = true; diff --git a/apple/t2/pkgs/tiny-dfr.nix b/apple/t2/pkgs/tiny-dfr.nix new file mode 100644 index 0000000..ce4be0f --- /dev/null +++ b/apple/t2/pkgs/tiny-dfr.nix @@ -0,0 +1,51 @@ +{ pkgs, fetchFromGitHub, rustPlatform, ... }: + +let + repo = fetchFromGitHub { + owner = "kekrby"; + repo = "tiny-dfr"; + rev = "8a5d413cb1dbe2a25b77a9e7f3cb5b9c88ef3ffb"; + hash = "sha256-l4D7aePz/CYpkRorrvsgIYrvSzoZl59OGcFGJqqJftk="; + }; + +in +rustPlatform.buildRustPackage rec { + pname = "tiny-dfr"; + version = repo.rev; + + src = repo; + + cargoLock.lockFile = "${src}/Cargo.lock"; + + nativeBuildInputs = with pkgs; [ + pkg-config + ]; + + buildInputs = with pkgs; [ + udev + glib + pango + cairo + gdk-pixbuf + libxml2 + libinput + ]; + + postPatch = '' + substituteInPlace src/main.rs --replace "/usr/share/tiny-dfr/" "$out/share/tiny-dfr/" + ''; + + postInstall = '' + mkdir -p $out/etc $out/share + + cp -r etc/udev $out/etc/ + cp -r share/tiny-dfr $out/share/ + ''; + + meta = with pkgs.lib; { + description = "The most basic dynamic function row daemon possible"; + homepage = "https://github.com/kekrby/tiny-dfr"; + license = with licenses; [ asl20 bsd3 cc0 isc lgpl21Plus mit mpl20 unicode-dfs-2016 asl20 asl20-llvm mit unlicense ]; + maintainers = []; + }; +} From 1bcf716420ac6152edcd1277c743292da6b87529 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Fri, 26 Apr 2024 21:25:26 -0400 Subject: [PATCH 6/6] starfive visionfive2: use nixpkgs default u-boot version --- starfive/visionfive/v2/uboot.nix | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/starfive/visionfive/v2/uboot.nix b/starfive/visionfive/v2/uboot.nix index 9c0eb7a..ef92cce 100644 --- a/starfive/visionfive/v2/uboot.nix +++ b/starfive/visionfive/v2/uboot.nix @@ -1,29 +1,9 @@ -{ lib -, fetchFromGitHub -, buildUBoot -, buildPackages +{ buildUBoot , opensbi }: -buildUBoot rec { - version = "2024.01"; - - src = fetchFromGitHub { - owner = "u-boot"; - repo = "u-boot"; - rev = "refs/tags/v${version}"; - hash = "sha256-0Da7Czy9cpQ+D5EICc3/QSZhAdCBsmeMvBgykYhAQFw="; - }; - - # workaround for https://github.com/NixOS/nixpkgs/pull/146634 - # uboot: only apply raspberry pi patches to raspberry pi builds - patches = [ ]; - +buildUBoot { extraMakeFlags = [ - # workaround for https://github.com/NixOS/nixpkgs/pull/277997 - # buildUBoot: specify absolute path of dtc, fix building u-boot 2023.10+ - "DTC=${lib.getExe buildPackages.dtc}" - "OPENSBI=${opensbi}/share/opensbi/lp64/generic/firmware/fw_dynamic.bin" ];