Merge branch 'master' into visionfive2-uboot

This commit is contained in:
mergify[bot] 2024-04-27 06:39:07 +00:00 committed by GitHub
commit 27d49e2641
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 177 additions and 102 deletions

View File

@ -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,18 +74,25 @@ 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;
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

View File

@ -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

View File

@ -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;

View File

@ -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 = [];
};
}

View File

@ -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
];
}
];
}

View File

@ -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);
}

View File

@ -2,6 +2,7 @@
imports = [
../../../common/pc/laptop
../../../common/pc/laptop/ssd
../../kmod.nix
];
# Fix TRRS headphones missing a mic

View File

@ -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

17
framework/kmod.nix Normal file
View File

@ -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" ];
};
}