Merge branch 'master' into microsoft/surface/kernel-6.6

This commit is contained in:
mexisme 2024-01-04 09:33:48 +13:00
commit 6e43a42577
62 changed files with 839 additions and 595 deletions

View file

@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v23
- uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Show nixpkgs version

View file

@ -70,7 +70,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md).
See code for all available configurations.
| Model | Path |
| ------------------------------------------------------------------- | -------------------------------------------------- |
| ---------------------------------------------------------------------- | ------------------------------------------------------- |
| [Acer Aspire 4810T](acer/aspire/4810t) | `<nixos-hardware/acer/aspire/4810t>` |
| [Airis N990](airis/n990) | `<nixos-hardware/airis/n990>` |
| [Apple MacBook Air 3,X](apple/macbook-air/3) | `<nixos-hardware/apple/macbook-air/3>` |
@ -100,6 +100,7 @@ See code for all available configurations.
| [Dell Latitude 3340](dell/latitude/3340) | `<nixos-hardware/dell/latitude/3340>` |
| [Dell Latitude 3480](dell/latitude/3480) | `<nixos-hardware/dell/latitude/3480>` |
| [Dell Latitude 5520](dell/latitude/5520) | `<nixos-hardware/dell/latitude/5520>` |
| [Dell Latitude 7390](dell/latitude/7390) | `<nixos-hardware/dell/latitude/7390>` |
| [Dell Latitude 7430](dell/latitude/7430) | `<nixos-hardware/dell/latitude/7430>` |
| [Dell Latitude 7490](dell/latitude/7490) | `<nixos-hardware/dell/latitude/7490>` |
| [Dell Poweredge R7515](dell/poweredge/r7515) | `<nixos-hardware/dell/poweredge/r7515>` |
@ -142,9 +143,11 @@ See code for all available configurations.
| [GPD P2 Max](gpd/p2-max) | `<nixos-hardware/gpd/p2-max>` |
| [GPD Pocket 3](gpd/pocket-3) | `<nixos-hardware/gpd/pocket-3>` |
| [GPD WIN 2](gpd/win-2) | `<nixos-hardware/gpd/win-2>` |
| [GPD WIN Max 2 2023](gpd/win-max-2/2023) | `<nixos-hardware/gpd/win-max-2/2023>` |
| [Google Pixelbook](google/pixelbook) | `<nixos-hardware/google/pixelbook>` |
| [HP Elitebook 2560p](hp/elitebook/2560p) | `<nixos-hardware/hp/elitebook/2560p>` |
| [HP Elitebook 845g7](hp/elitebook/845/g7) | `<nixos-hardware/hp/elitebook/845/g7>` |
| [HP Elitebook 845g8](hp/elitebook/845/g8) | `<nixos-hardware/hp/elitebook/845/g8>` |
| [HP Elitebook 845g9](hp/elitebook/845/g9) | `<nixos-hardware/hp/elitebook/845/g9>` |
| [HP Notebook 14-df0023](hp/notebook/14-df0023) | `<nixos-hardware/hp/notebook/14-df0023>` |
| [i.MX8QuadMax Multisensory Enablement Kit](nxp/imx8qm-mek/) | `<nixos-hardware/nxp/imx8qm-mek>` |
@ -152,11 +155,14 @@ See code for all available configurations.
| [Lenovo IdeaPad Gaming 3 15arh05](lenovo/ideapad/15arh05) | `<nixos-hardware/lenovo/ideapad/15arh05>` |
| [Lenovo IdeaPad Z510](lenovo/ideapad/z510) | `<nixos-hardware/lenovo/ideapad/z510>` |
| [Lenovo IdeaPad Slim 5](lenovo/ideapad/slim-5) | `<nixos-hardware/lenovo/ideapad/slim-5>` |
| [Lenovo IdeaPad S145 15api](lenovo/ideapad/s145-15api) | `<nixos-hardware/lenovo/ideapad/s145-15api>` |
| [Lenovo Legion 5 15arh05h](lenovo/legion/15arh05h) | `<nixos-hardware/lenovo/legion/15arh05h>` |
| [Lenovo Legion 7 Slim 15ach6](lenovo/legion/15ach6) | `<nixos-hardware/lenovo/legion/15ach6>` |
| [Lenovo Legion 5 Pro 16ach6h](lenovo/legion/16ach6h) | `<nixos-hardware/lenovo/legion/16ach6h>` |
| [Lenovo Legion 5 Pro 16ach6h (Hybrid)](lenovo/legion/16ach6h/hybrid) | `<nixos-hardware/lenovo/legion/16ach6h/hybrid>` |
| [Lenovo Legion 5 Pro 16ach6h (Nvidia)](lenovo/legion/16ach6h/nvidia) | `<nixos-hardware/lenovo/legion/16ach6h/nvidia>` |
| [Lenovo Legion 7 16achg6 (Hybrid)](lenovo/legion/16achg6/hybrid) | `<nixos-hardware/lenovo/legion/16achg6/hybrid>` |
| [Lenovo Legion 7 16achg6 (Nvidia)](lenovo/legion/16achg6/nvidia) | `<nixos-hardware/lenovo/legion/16achg6/nvidia>` |
| [Lenovo Legion 7i Pro 16irx8h (Intel)](lenovo/legion/16irx8h) | `<nixos-hardware/lenovo/legion/16irx8h>` |
| [Lenovo Legion Y530 15ICH](lenovo/legion/15ich) | `<nixos-hardware/lenovo/legion/15ich>` |
| [Lenovo ThinkPad E14 (AMD)](lenovo/thinkpad/e14/amd) | `<nixos-hardware/lenovo/thinkpad/e14/amd>` |
@ -209,6 +215,7 @@ See code for all available configurations.
| [Lenovo ThinkPad X1 Extreme Gen 4](lenovo/thinkpad/x1-extreme/gen4) | `<nixos-hardware/lenovo/thinkpad/x1-extreme/gen4>` |
| [Lenovo ThinkPad X1 Nano Gen 1](lenovo/thinkpad/x1-nano/gen1) | `<nixos-hardware/lenovo/thinkpad/x1-nano/gen1>` |
| [Lenovo ThinkPad X13 Yoga](lenovo/thinkpad/x13/yoga) | `<nixos-hardware/lenovo/thinkpad/x13/yoga>` |
| [Lenovo ThinkPad X13 Yoga (3th Gen)](lenovo/thinkpad/x13/yoga/3th-gen) | `<nixos-hardware/lenovo/thinkpad/x13/yoga/3th-gen>` |
| [Lenovo ThinkPad X13](lenovo/thinkpad/x13) | `<nixos-hardware/lenovo/thinkpad/x13>` |
| [Lenovo ThinkPad X140e](lenovo/thinkpad/x140e) | `<nixos-hardware/lenovo/thinkpad/x140e>` |
| [Lenovo ThinkPad X200s](lenovo/thinkpad/x200s) | `<nixos-hardware/lenovo/thinkpad/x200s>` |
@ -259,4 +266,5 @@ See code for all available configurations.
| [System76 Darter Pro 6](system76/darp6) | `<nixos-hardware/system76/darp6>` |
| [Toshiba Chromebook 2 `swanky`](toshiba/swanky) | `<nixos-hardware/toshiba/swanky>` |
| [Tuxedo InfinityBook v4](tuxedo/infinitybook/v4) | `<nixos-hardware/tuxedo/infinitybook/v4>` |
| [TUXEDO InfinityBook Pro 14 - Gen7](tuxedo/infinitybook/pro14/gen7) | `<nixos-hardware/tuxedo/infinitybook/pro14/gen7>` |
| [TUXEDO Pulse 15 - Gen2](tuxedo/pulse/15/gen2) | `<nixos-hardware/tuxedo/pulse/15/gen2>` |

View file

@ -1,4 +1,4 @@
{ config, lib, ... }:
{ lib, ... }:
{
imports = [ ../. ];

View file

@ -8,6 +8,12 @@ let
hash = "sha256-x7K0qa++P1e1vuCGxnsFxL1d9+nwMtZUJ6Kd9e27TFs=";
};
audioFilesUdevRules = pkgs.runCommand "audio-files-udev-rules" {} ''
mkdir -p $out/lib/udev/rules.d
cp ${audioFiles}/files/*.rules $out/lib/udev/rules.d
substituteInPlace $out/lib/udev/rules.d/*.rules --replace "/usr/bin/sed" "${pkgs.gnused}/bin/sed"
'';
overrideAudioFiles = package: pluginsPath:
package.overrideAttrs (new: old: {
preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ];
@ -18,7 +24,7 @@ let
pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/";
apple-set-os-loader-installer = pkgs.stdenv.mkDerivation rec {
apple-set-os-loader-installer = pkgs.stdenv.mkDerivation {
name = "apple-set-os-loader-installer-1.0";
src = pkgs.fetchFromGitHub {
owner = "Redecorating";
@ -51,15 +57,12 @@ in
config = {
# For keyboard and touchbar
boot.kernelPackages = with pkgs; recurseIntoAttrs (linuxPackagesFor (callPackage ./pkgs/linux-t2.nix { }));
boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { });
boot.initrd.kernelModules = [ "apple-bce" ];
# For audio
boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ];
services.udev.extraRules = builtins.readFile (pkgs.substitute {
src = "${audioFiles}/files/91-audio-custom.rules";
replacements = [ "--replace" "/usr/bin/sed" "${pkgs.gnused}/bin/sed" ];
});
services.udev.packages = [ audioFilesUdevRules ];
hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/";

View file

@ -1,4 +1,5 @@
{ lib, buildLinux, fetchFromGitHub, fetchurl, ... } @ args:
{ lib, buildLinux, fetchFromGitHub, fetchzip, runCommand
, ... } @ args:
let
patchRepo = fetchFromGitHub {
@ -18,10 +19,18 @@ buildLinux (args // {
# Snippet from nixpkgs
modDirVersion = with lib; "${concatStringsSep "." (take 3 (splitVersion "${version}.0"))}";
src = fetchurl {
src = runCommand "patched-source" {} ''
cp -r ${fetchzip {
url = "mirror://kernel/linux/kernel/v${majorVersion}.x/linux-${version}.tar.xz";
hash = "sha256-eldLvCCALqdrUsp/rwcmf3IEXoYbGJFcUnKpjCer+IQ=";
};
hash = "sha256-qJmVSju69WcvDIbgrbtMyCi+OXUNTzNX2G+/0zwsPR4=";
}} $out
chmod -R u+w $out
cd $out
while read -r patch; do
echo "Applying patch $patch";
patch -p1 < $patch;
done < <(find ${patchRepo} -type f -name "*.patch" | sort)
'';
structuredExtraConfig = with lib.kernel; {
APPLE_BCE = module;
@ -40,7 +49,5 @@ buildLinux (args // {
STAGING = yes;
};
kernelPatches = lib.attrsets.mapAttrsToList (file: type: { name = file; patch = "${patchRepo}/${file}"; })
(lib.attrsets.filterAttrs (file: type: type == "regular" && lib.strings.hasSuffix ".patch" file)
(builtins.readDir patchRepo));
kernelPatches = [];
} // (args.argsOverride or {}))

View file

@ -1,4 +1,4 @@
{ lib, pkgs, config, ... }:
{ lib, config, ... }:
{
imports = [ ./. ];

View file

@ -0,0 +1,8 @@
{ lib, ... }:
{
imports = [
../../../common/cpu/intel
../../../common/pc/laptop
];
}

View file

@ -1,5 +1,3 @@
{ lib, pkgs, ... }:
{
imports = [
../../../../common/cpu/intel

View file

@ -16,6 +16,12 @@
# Without this we get errors in dmesg on boot and hangs when shutting down.
boot.blacklistedKernelModules = [ "psmouse" ];
# enable finger print sensor.
# this has to be configured with `sudo fprintd-enroll <username>`.
services.fprintd.enable = true;
services.fprintd.tod.enable = true;
services.fprintd.tod.driver = pkgs.libfprint-2-tod1-goodix;
# Allows for updating firmware via `fwupdmgr`.
services.fwupd.enable = true;
}

View file

@ -1,4 +1,4 @@
{ lib, pkgs, ... }: {
{
imports = [
../../../common/cpu/intel
../../../common/pc/laptop

View file

@ -35,6 +35,7 @@
dell-latitude-3340 = import ./dell/latitude/3340;
dell-latitude-3480 = import ./dell/latitude/3480;
dell-latitude-5520 = import ./dell/latitude/5520;
dell-latitude-7390 = import ./dell/latitude/7390;
dell-latitude-7430 = import ./dell/latitude/7430;
dell-latitude-7490 = import ./dell/latitude/7490;
dell-poweredge-r7515 = import ./dell/poweredge/r7515;
@ -78,19 +79,25 @@
gpd-p2-max = import ./gpd/p2-max;
gpd-pocket-3 = import ./gpd/pocket-3;
gpd-win-2 = import ./gpd/win-2;
gpd-win-max-2-2023 = import ./gpd/win-max-2/2023;
hp-elitebook-2560p = import ./hp/elitebook/2560p;
hp-elitebook-845g7 = import ./hp/elitebook/845/g7;
hp-elitebook-845g8 = import ./hp/elitebook/845/g8;
hp-elitebook-845g9 = import ./hp/elitebook/845/g9;
hp-notebook-14-df0023 = import ./hp/notebook/14-df0023;
intel-nuc-8i7beh = import ./intel/nuc/8i7beh;
lenovo-ideapad-15arh05 = import ./lenovo/ideapad/15arh05;
lenovo-ideapad-z510 = import ./lenovo/ideapad/z510;
lenovo-ideapad-slim-5 = import ./lenovo/ideapad/slim-5;
lenovo-ideapad-s145-15api = import ./lenovo/ideapad/s145-15api;
lenovo-legion-15ach6 = import ./lenovo/legion/15ach6;
lenovo-legion-15arh05h = import ./lenovo/legion/15arh05h;
lenovo-legion-16ach6h = import ./lenovo/legion/16ach6h;
lenovo-legion-16ach6h-hybrid = import ./lenovo/legion/16ach6h/hybrid;
lenovo-legion-16ach6h-nvidia = import ./lenovo/legion/16ach6h/nvidia;
lenovo-legion-16achg6-hybrid = import ./lenovo/legion/16achg6/hybrid;
lenovo-legion-16achg6-nvidia = import ./lenovo/legion/16achg6/nvidia;
lenovo-legion-16aph8 = import ./lenovo/legion/16aph8;
lenovo-legion-16ithg6 = import ./lenovo/legion/16ithg6;
lenovo-legion-16irx8h = import ./lenovo/legion/16irx8h;
lenovo-legion-y530-15ich = import ./lenovo/legion/15ich;
@ -149,6 +156,7 @@
lenovo-thinkpad-x1-nano-gen1 = import ./lenovo/thinkpad/x1-nano/gen1;
lenovo-thinkpad-x13 = import ./lenovo/thinkpad/x13;
lenovo-thinkpad-x13-yoga = import ./lenovo/thinkpad/x13/yoga;
lenovo-thinkpad-x13-yoga-3th-gen = import ./lenovo/thinkpad/x13/yoga/3th-gen;
lenovo-thinkpad-x140e = import ./lenovo/thinkpad/x140e;
lenovo-thinkpad-x200s = import ./lenovo/thinkpad/x200s;
lenovo-thinkpad-x220 = import ./lenovo/thinkpad/x220;
@ -202,6 +210,7 @@
system76-darp6 = import ./system76/darp6;
toshiba-swanky = import ./toshiba/swanky;
tuxedo-infinitybook-v4 = import ./tuxedo/infinitybook/v4;
tuxedo-infinitybook-pro14-gen7 = import ./tuxedo/infinitybook/pro14/gen7;
tuxedo-pulse-15-gen2 = import ./tuxedo/pulse/15/gen2;
common-cpu-amd = import ./common/cpu/amd;

View file

@ -13,3 +13,43 @@ Then run
```sh
$ fwupdmgr update
```
## Getting the fingerprint sensor to work
The firmware on the fingerprint sensor needs a downgrade to make it work on Linux.
The process is documented [here](https://knowledgebase.frame.work/en_us/updating-fingerprint-reader-firmware-on-linux-for-13th-gen-and-amd-ryzen-7040-series-laptops-HJrvxv_za).
However on recent NixOS versions also fwupd can no longer update the firmware.
Using the following snippet allows to temporarly downgrade fwupd to an old-enough version:
```nix
{
services.fwupd.enable = true;
# we need fwupd 1.9.7 to downgrade the fingerprint sensor firmware
services.fwupd.package = (import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/bb2009ca185d97813e75736c2b8d1d8bb81bde05.tar.gz";
sha256 = "sha256:003qcrsq5g5lggfrpq31gcvj82lb065xvr7bpfa8ddsw8x4dnysk";
}) {
inherit (pkgs) system;
}).fwupd;
}
```
Afterwards the downgraded driver can be downloaded and installed like this:
```
wget https://github.com/FrameworkComputer/linux-docs/raw/main/goodix-moc-609c-v01000330.cab
sudo fwupdtool install --allow-reinstall --allow-older goodix-moc-609c-v01000330.cab
Loading… [ - ]/nix/store/1n2l5law9g3b77hcfyp50vrhhssbrj5g-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/f55npw04a2s6xmrbx4jw12xq16b3avb8-gvfs-1.52.1/lib/gio/modules/libgvfsdbus.so)
Failed to load module: /nix/store/f55npw04a2s6xmrbx4jw12xq16b3avb8-gvfs-1.52.1/lib/gio/modules/libgvfsdbus.so
Loading… [ ]12:16:46.348 FuHistory schema version 9 is unknown
Writing… [************************************* ]12:16:57.055 FuEngine failed to update-cleanup after failed update: failed to get device before update cleanup: failed to wait for detach replug: device d432baa2162a32c1554ef24bd8281953b9d07c11 did not come back
failed to write: failed to reply: transfer timed out
```
The error message above is harmless. After a reboot, I was able to enroll my fingerprint like this:
```
sudo fprintd-enroll $USER
```

View file

@ -1,10 +1,13 @@
{ lib, ... }: {
{ lib, config, ... }: {
imports = [
../../../common/cpu/amd
../../../common/cpu/amd/pstate.nix
../../../common/gpu/amd
];
# Workaround for SuspendThenHibernate: https://lore.kernel.org/linux-kernel/20231106162310.85711-1-mario.limonciello@amd.com/
boot.kernelParams = lib.optionals (lib.versionOlder config.boot.kernelPackages.kernel.version "6.8") ["rtc_cmos.use_acpi_alarm=1"] ;
# AMD has better battery life with PPD over TLP:
# https://community.frame.work/t/responded-amd-7040-sleep-states/38101/13
services.power-profiles-daemon.enable = lib.mkDefault true;

View file

@ -15,6 +15,9 @@
# https://community.frame.work/t/using-the-ax210-with-linux-on-the-framework-laptop/1844/89
boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.16") (lib.mkDefault pkgs.linuxPackages_latest);
# Module is not used for Framework EC but causes boot time error log.
boot.blacklistedKernelModules = [ "cros-usbpd-charger" ];
# Custom udev rules
services.udev.extraRules = ''
# Fix headphone noise when on powersave

View file

@ -1,5 +1,4 @@
{ lib
, pkgs
, ...
}:

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ...}:
{ config, lib, ...}:
{
imports = [
../../common/cpu/intel

View file

@ -0,0 +1,15 @@
{ config, lib, ...}:
with lib;
{
imports = [
./..
../../../common/cpu/amd
../../../common/cpu/amd/pstate.nix
../../../common/gpu/amd
];
# fix suspend problem: https://www.reddit.com/r/gpdwin/comments/16veksm/win_max_2_2023_linux_experience_suspend_problems/
services.udev.extraRules = ''
ACTION=="add" SUBSYSTEM=="pci" ATTR{vendor}=="0x1022" ATTR{device}=="0x14ee" ATTR{power/wakeup}="disabled"
'';
}

67
gpd/win-max-2/default.nix Normal file
View file

@ -0,0 +1,67 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.hardware.gpd.ppt;
in
{
imports = [
../../common/pc/laptop
../../common/pc/ssd
../../common/hidpi.nix
];
# Linux default PPT is 24-22-22, BIOS default PPT is 35-32-28. It can be controlled by ryzenadj.
# NOTICE: Whenever you can limit PPT to 15W by pressing Fn + Shift to enter quiet mode.
options.hardware.gpd.ppt = {
enable = mkEnableOption (mdDoc "Enable PPT control for device by ryzenadj.") // {
# Default increase PPT to the BIOS default when power adapter plugin to increase performance.
default = true;
};
adapter = {
fast-limit = mkOption {
description = "Fast PTT Limit(milliwatt) when power adapter plugin.";
default = 35000;
type = types.ints.unsigned;
};
slow-limit = mkOption {
description = "Slow PTT Limit(milliwatt) when power adapter plugin.";
default = 32000;
type = types.ints.unsigned;
};
stapm-limit = mkOption {
description = "Stapm PTT Limit(milliwatt) when power adapter plugin.";
default = 28000;
type = types.ints.unsigned;
};
};
battery = {
fast-limit = mkOption {
description = "Fast PTT Limit(milliwatt) when using battery.";
default = 24000;
type = types.ints.unsigned;
};
slow-limit = mkOption {
description = "Slow PTT Limit(milliwatt) when using battery.";
default = 22000;
type = types.ints.unsigned;
};
stapm-limit = mkOption {
description = "Stapm PTT Limit(milliwatt) when using battery.";
default = 22000;
type = types.ints.unsigned;
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.ryzenadj ];
services.udev.extraRules = ''
SUBSYSTEM=="power_supply", KERNEL=="ADP1", ATTR{online}=="1", RUN+="${pkgs.ryzenadj}/bin/ryzenadj --stapm-limit ${toString cfg.adapter.stapm-limit} --fast-limit ${toString cfg.adapter.fast-limit} --slow-limit ${toString cfg.adapter.slow-limit}"
SUBSYSTEM=="power_supply", KERNEL=="ADP1", ATTR{online}=="0", RUN+="${pkgs.ryzenadj}/bin/ryzenadj --stapm-limit ${toString cfg.battery.stapm-limit} --fast-limit ${toString cfg.battery.fast-limit} --slow-limit ${toString cfg.battery.slow-limit}"
'';
};
}

View file

@ -1,5 +1,3 @@
{ config, lib, ... }:
{
imports = [
../../common/cpu/intel/jasper-lake

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }:
{ pkgs, lib, ... }:
{
imports =

View file

@ -0,0 +1,25 @@
{ pkgs, lib, ... }:
{
imports =
[
../../../../common/cpu/amd
../../../../common/cpu/amd/pstate.nix
../../../../common/gpu/amd
../../../../common/pc/laptop
../../../../common/pc/laptop/acpi_call.nix
../../../../common/pc/laptop/ssd
];
hardware.enableRedistributableFirmware = lib.mkDefault true;
boot.kernelModules = [ "synaptics_usb" ];
boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "6.3") (lib.mkDefault pkgs.linuxPackages_latest);
# disable Scatter/Gather APU recently enabled by default,
# which results in white screen after display reconfiguration
boot.kernelParams = [ "amdgpu.sg_display=0" ];
services.xserver = {
videoDrivers = [ "amdgpu" ];
};
}

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }:
{ pkgs, lib, ... }:
{
imports =

View file

@ -0,0 +1,16 @@
{
imports = [
../../../common/cpu/amd
../../../common/gpu/amd
../../../common/gpu/amd/southern-islands
];
# Blacklist ideapad-laptop because it keeps resetting rfkill devices
boot.blacklistedKernelModules = [ "ideapad-laptop" ];
# For some reason we have to specify manually which model we want snd-hda-intel to use
# without it external microphone won't work
boot.extraModprobeConfig = ''
options snd-hda-intel model=alc255-acer,dell-headset-multi
'';
}

View file

@ -1,5 +1,3 @@
{ lib, ... }:
{
imports = [
../../../common/cpu/amd

View file

@ -1,7 +1,5 @@
{ lib, config, ... }:
let
inherit (config.boot) kernelPackages;
in {
{
imports = [
../../../common/cpu/amd
../../../common/gpu/amd

View file

@ -0,0 +1,23 @@
I personally use my laptop with an external display attached and haven't observed any issues so far.
From my experience, it's better to use gdm, as sddm seems to have a problem detecting the external monitor (more details available [here](https://github.com/sddm/sddm/issues/1558)). Of course it's not a blocker, as it is still possible to log in using sddm. I personally find it annoying that my main display remains idle.
## Setup at the time of testing
```
$ nix-info -m
- system: `"x86_64-linux"`
- host os: `Linux 6.1.62, NixOS, 23.05 (Stoat), 23.05.20231116.9fb1225`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.13.6`
- channels(beko): `"home-manager-23.05.tar.gz"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
```
```
$ lspci
...
01:00.0 VGA compatible controller: NVIDIA Corporation GA104M [GeForce RTX 3070 Mobile / Max-Q] (rev a1)
...
05:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne [Radeon Vega Series / Radeon Vega Mobile Series] (rev c5)
...
```

View file

@ -0,0 +1,28 @@
{ lib, ... }:
{
imports = [
../../../../common/cpu/amd
../../../../common/cpu/amd/pstate.nix
../../../../common/gpu/amd
../../../../common/gpu/nvidia/prime.nix
../../../../common/pc/laptop
../../../../common/pc/laptop/ssd
];
services.xserver.videoDrivers = [ "nvidia" ];
boot.initrd.kernelModules = [ "amdgpu" ];
hardware = {
nvidia = {
modesetting.enable = lib.mkDefault true;
powerManagement.enable = lib.mkDefault true;
open = lib.mkDefault false;
prime = {
amdgpuBusId = "PCI:5:0:0";
nvidiaBusId = "PCI:1:0:0";
};
};
};
}

View file

@ -0,0 +1,13 @@
{ ... }:
{
imports = [ ../hybrid ];
services.xserver.videoDrivers = [ "nvidia" ];
hardware = {
nvidia.prime.offload.enable = false;
amdgpu = {
amdvlk = false;
opencl = false;
};
};
}

View file

@ -0,0 +1,38 @@
I was unable to get the hybrid settings working well with lightdm or sddm, but Optimus Sync
mode seems to work the best for me.
I am running the Linux 6.6 LTS kernel with KDE + SDDM, and it seems to be working well.
## hardware-configuration.nix
I have the following customizations added for my nvidia drivers.
```
hardware.nvidia = {
nvidiaSettings = true;
package = config.boot.kernelPackages.nvidiaPackages.stable;
};
```
## Setup at the time of testing
### nix-info
```
$ nix-info -m
- system: `"x86_64-linux"`
- host os: `Linux 6.6.8, NixOS, 23.11 (Tapir), 23.11.20231231.32f6357`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.18.1`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
```
### lspci
```
$ lspci
...
01:00.0 VGA compatible controller: NVIDIA Corporation AD107M [GeForce RTX 4060 Max-Q / Mobile] (rev a1)
...
05:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Phoenix1 (rev c2)
...
```

View file

@ -0,0 +1,39 @@
{ lib, pkgs, ... }:
{
imports = [
../../../common/cpu/amd
../../../common/cpu/amd/pstate.nix
../../../common/gpu/amd
../../../common/gpu/nvidia
../../../common/pc/laptop
../../../common/pc/laptop/ssd
];
# Use latest LTS kernel for more Raphael fixes
boot = lib.mkMerge [
(lib.mkIf (lib.versionOlder pkgs.linux.version "6.6") {
kernelPackages = pkgs.linuxPackages_latest;
kernelParams = ["amdgpu.sg_display=0"];
})
];
hardware.nvidia = {
modesetting.enable = lib.mkDefault true;
powerManagement.enable = lib.mkDefault false;
powerManagement.finegrained = lib.mkDefault false;
open = lib.mkDefault false;
prime = {
sync.enable = lib.mkDefault true;
amdgpuBusId = "PCI:5:0:0";
nvidiaBusId = "PCI:1:0:0";
};
};
# Avoid issues with modesetting causing blank screen
services.xserver.videoDrivers = [ "nvidia" ];
# AMD has better battery life with PPD over TLP:
# https://community.frame.work/t/responded-amd-7040-sleep-states/38101/13
services.power-profiles-daemon.enable = lib.mkDefault true;
}

View file

@ -1,7 +1,6 @@
{
lib,
config,
pkgs,
...
}: {
imports = [

View file

@ -1,5 +1,3 @@
{ lib, ... }:
{
imports = [
../.

View file

@ -0,0 +1,8 @@
{ lib, ... }: {
imports = [
../.
];
# without throttled, our CPU (i5-1235u) did not boost beyond 1300MHz
services.throttled.enable = lib.mkDefault true;
}

View file

@ -1,5 +1,3 @@
{ pkgs, lib, ... }:
{
nixpkgs.overlays = [
(import ./overlay.nix)

View file

@ -10,7 +10,7 @@ in {
./surface-control
];
microsoft-surface.kernelVersion = mkDefault "6.6.2";
microsoft-surface.kernelVersion = mkDefault "6.6.8";
# Seems to be required to properly enable S0ix "Modern Standby":
boot.kernelParams = mkDefault [ "mem_sleep_default=deep" ];

View file

@ -1,13 +1,33 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkDefault mkEnableOption mkIf mkMerge;
inherit (lib) mkDefault mkEnableOption mkIf mkMerge mkOption types;
cfg = config.microsoft-surface.ipts;
in {
iptsConfFile = pkgs.writeTextFile {
name = "iptsd.conf";
text = lib.generators.toINI { } cfg.config;
};
in
{
options.microsoft-surface.ipts = {
enable = mkEnableOption "Enable IPTSd for Microsoft Surface";
config = mkOption {
type = types.attrs;
default = { };
description = ''
Values to wrote to iptsd.conf, first key is section, second key is property.
See the example config; https://github.com/linux-surface/iptsd/blob/v1.4.0/etc/iptsd.conf
'';
example = ''
DFT = {
ButtonMinMag = 1000;
};
'';
};
};
config = mkMerge [
@ -22,6 +42,7 @@ in {
script = "iptsd $(iptsd-find-hidraw)";
wantedBy = [ "multi-user.target" ];
};
environment.etc."iptsd/iptsd.conf".source = "${iptsConfFile}";
})
];
}

View file

@ -6,7 +6,6 @@ let
in {
imports = [
./linux-6.1.x
./linux-6.5.x
./linux-6.6.x
];

View file

@ -27,10 +27,10 @@ let
in {
options.microsoft-surface.kernelVersion = mkOption {
type = types.enum [ version ];
type = types.enum [ version majorVersion ];
};
config = mkIf (cfg.kernelVersion == version ) {
config = mkIf (cfg.kernelVersion == version || cfg.kernelVersion == majorVersion) {
boot = {
inherit kernelPackages;
};

View file

@ -1,38 +0,0 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkIf mkOption types;
inherit (pkgs) fetchurl;
inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage1 repos;
cfg = config.microsoft-surface;
version = "6.5.11";
extraMeta.branch = "6.5";
patchSrc = repos.linux-surface + "/patches/${extraMeta.branch}";
kernelPatches = pkgs.callPackage ./patches.nix {
inherit (lib) kernel;
inherit version patchSrc;
};
kernelPackages = linuxPackage1 {
inherit version extraMeta kernelPatches;
src = fetchurl {
url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz";
sha256 = "sha256-LuJK+SgrgJI7LaVrcKrX3y6O5OPwdkUuBbpmviBZtRk=";
};
};
in {
options.microsoft-surface.kernelVersion = mkOption {
type = types.enum [ version ];
};
config = mkIf (cfg.kernelVersion == version) {
boot = {
inherit kernelPackages;
};
};
}

View file

@ -1,143 +0,0 @@
{ lib,
kernel ? lib.kernel,
patchSrc,
version,
}:
[
{
name = "microsoft-surface-patches-linux-${version}";
patch = null;
structuredExtraConfig = with kernel; {
STREAMING_MEDIA = yes;
#
# Surface Aggregator Module
#
SURFACE_AGGREGATOR = module;
SURFACE_AGGREGATOR_ERROR_INJECTION = no;
SURFACE_AGGREGATOR_BUS = yes;
SURFACE_AGGREGATOR_CDEV = module;
SURFACE_AGGREGATOR_HUB = module;
SURFACE_AGGREGATOR_REGISTRY = module;
SURFACE_AGGREGATOR_TABLET_SWITCH = module;
SURFACE_ACPI_NOTIFY = module;
SURFACE_DTX = module;
SURFACE_PLATFORM_PROFILE = module;
SURFACE_HID = module;
SURFACE_KBD = module;
BATTERY_SURFACE = module;
CHARGER_SURFACE = module;
#
# Surface Hotplug
#
SURFACE_HOTPLUG = module;
#
# Intel Touch Host Controller
#
HID_ITHC = module;
#
# IPTS touchscreen
#
# This only enables the user interface for IPTS data.
# For the touchscreen to work, you need to install iptsd.
#
MISC_IPTS = module;
#
# Cameras: IPU3
#
VIDEO_DW9719 = module;
VIDEO_IPU3_IMGU = module;
VIDEO_IPU3_CIO2 = module;
CIO2_BRIDGE = yes;
INTEL_SKL_INT3472 = module;
REGULATOR_TPS68470 = module;
COMMON_CLK_TPS68470 = module;
COMMON_LEDS_TPS68470 = module;
#
# Cameras: Sensor drivers
#
VIDEO_OV5693 = module;
VIDEO_OV7251 = module;
VIDEO_OV8865 = module;
#
# ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7
#
APDS9960 = module;
#
# Other Drivers
#
INPUT_SOC_BUTTON_ARRAY = module;
SURFACE_3_POWER_OPREGION = module;
SURFACE_PRO3_BUTTON = module;
SURFACE_GPE = module;
SURFACE_BOOK1_DGPU_SWITCH = module;
};
}
{
name = "ms-surface/0001-surface3-oemb";
patch = patchSrc + "/0001-surface3-oemb.patch";
}
{
name = "ms-surface/0002-mwifiex";
patch = patchSrc + "/0002-mwifiex.patch";
}
{
name = "ms-surface/0003-ath10k";
patch = patchSrc + "/0003-ath10k.patch";
}
{
name = "ms-surface/0004-ipts";
patch = patchSrc + "/0004-ipts.patch";
}
{
name = "ms-surface/0005-ithc";
patch = patchSrc + "/0005-ithc.patch";
}
{
name = "ms-surface/0006-surface-sam";
patch = patchSrc + "/0006-surface-sam.patch";
}
{
name = "ms-surface/0007-surface-sam-over-hid";
patch = patchSrc + "/0007-surface-sam-over-hid.patch";
}
{
name = "ms-surface/0008-surface-button";
patch = patchSrc + "/0008-surface-button.patch";
}
{
name = "ms-surface/0009-surface-typecover";
patch = patchSrc + "/0009-surface-typecover.patch";
}
{
name = "ms-surface/0010-surface-shutdown";
patch = patchSrc + "/0010-surface-shutdown.patch";
}
{
name = "ms-surface/0011-surface-gpe";
patch = patchSrc + "/0011-surface-gpe.patch";
}
{
name = "ms-surface/0012-cameras";
patch = patchSrc + "/0012-cameras.patch";
}
{
name = "ms-surface/0013-amd-gpio";
patch = patchSrc + "/0013-amd-gpio.patch";
}
{
name = "ms-surface/0014-rtc";
patch = patchSrc + "/0014-rtc.patch";
}
]

View file

@ -7,14 +7,14 @@ let
cfg = config.microsoft-surface;
version = "6.6.2";
version = "6.6.8";
kernelPatches = surfacePatches {
inherit version;
patchFn = ./patches.nix;
};
kernelPackages = linuxPackage2 {
inherit version kernelPatches;
sha256 = "sha256-c9T2rY3WrCpB7VLCkoiYt8PyUZ7V29sRkgIJo2mZt34=";
sha256 = "sha256-UDbENOEeSzbY2j9ImFH3+CnPeF+n94h0aFN6nqRXJBY=";
};
in {

View file

@ -4,8 +4,8 @@
linux-surface = fetchFromGitHub {
owner = "linux-surface";
repo = "linux-surface";
rev = "a6eafcad32dc789ae92f42636b11e9aae6e7c879"; #b82e8acd3c015190423b114770b0e9fcc206dd2d";
hash = "sha256-GfxRzxFxDZoSZyEOzxr/Hz0IonbuwzkGaisKl3VYvlI="; #sha256-parp1F5fFzKkiM6ILK+ZolMdSwU1kLOOMvksSwE/zKA=";
rev = "arch-6.6.6-1";
hash = "sha256-0pP/A0XllR/iheIBEBwEApaXpyFYzsnGZ+wdm4w5Jjg=";
};
# This is the owner and repo for the pre-patched kernel from the "linux-surface" project:

View file

@ -1,4 +1,4 @@
{ lib, pkgs, ...}: {
{ lib, ...}: {
imports = [
../../common/cpu/amd
../../common/cpu/amd/pstate.nix

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ...}:
{ lib, pkgs, ...}:
{
hardware.deviceTree = {

View file

@ -1,4 +1,4 @@
{ pkgs, config, lib, ... }:
{ config, ... }:
{
imports = [

View file

@ -1,4 +1,4 @@
{ pkgs, lib, ... }:
{ lib, ... }:
{
boot.initrd.kernelModules = [
# PCIe/NVMe

View file

@ -1,4 +1,4 @@
{ callPackage, pkgsBuildHost, runCommand, writeText, writeShellApplication
{ callPackage, pkgsBuildHost, writeText, writeShellApplication
, stdenv, dtc, mtdutils, coreutils }:
let
uboot = callPackage ./uboot.nix { };

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, modulesPath, ... }:
{ config, pkgs, modulesPath, ... }:
let firmware = pkgs.callPackage ./firmware.nix { };
in {

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }:
{ config, lib, ... }:
lib.mkIf config.hardware.librem5.customInitrdModules {
boot.initrd = {
kernelModules = [

View file

@ -6,14 +6,14 @@
buildLinux (args
// rec {
defconfig = "librem5_defconfig";
version = "6.5.6-librem5";
version = "6.6.6-librem5";
modDirVersion = version;
src = fetchFromGitLab {
domain = "source.puri.sm";
owner = "Librem5";
repo = "linux";
rev = "pureos/6.5.6pureos1";
hash = "sha256-hOv0oy31mbC+43sI1n1oqKl7TtT/Ivj6UhiW4maumCg=";
rev = "pureos/6.6.6pureos1";
hash = "sha256-LJfY45yNYgFYLCGxb+WRMYBUHnY4HCI2rkflPeaeFe0=";
};
kernelPatches = [ ];
structuredExtraConfig = with lib.kernel; {

View file

@ -1,4 +1,4 @@
{ stdenv, gcc11Stdenv, buildUBoot, fetchurl, fetchFromGitLab, lib, flex, bison }:
{ stdenv, gcc11Stdenv, buildUBoot, fetchurl, fetchFromGitLab, lib, bison }:
let
firmware-imx = stdenv.mkDerivation (fa: {
pname = "firmware-imx";

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }:
{ config, lib, ... }:
lib.mkIf (config.hardware.librem5.wifiCard == "redpine") {
# Disable mainline rsi module
boot.blacklistedKernelModules = [

View file

@ -1,78 +1,26 @@
{ callPackage, pkgsBuildHost, runCommand, writeText, writeShellApplication
, stdenv, dtc, mtdutils, coreutils }:
let
uboot = callPackage ./uboot.nix { };
opensbi = callPackage ./opensbi.nix {
withPayload = "${uboot}/u-boot.bin";
withFDT = "${uboot}/starfive_visionfive2.dtb";
};
spl-tool = pkgsBuildHost.callPackage ./spl-tool.nix { };
its-file = writeText "visionfive2-uboot-fit-image.its" ''
/dts-v1/;
{ callPackage
, writeShellApplication
, stdenv
, mtdutils
}:
/ {
description = "U-boot-spl FIT image for JH7110 VisionFive2";
#address-cells = <2>;
images {
firmware {
description = "u-boot";
data = /incbin/("${opensbi}/share/opensbi/lp64/generic/firmware/fw_payload.bin");
type = "firmware";
arch = "riscv";
os = "u-boot";
load = <0x0 0x40000000>;
entry = <0x0 0x40000000>;
compression = "none";
};
};
configurations {
default = "config-1";
config-1 {
description = "U-boot-spl FIT config for JH7110 VisionFive2";
firmware = "firmware";
};
};
};
'';
in rec {
inherit opensbi uboot;
spl = stdenv.mkDerivation {
name = "starfive-visionfive2-spl";
depsBuildBuild = [ spl-tool ];
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/share/starfive-visionfive2/
ln -s ${uboot}/u-boot-spl.bin .
spl_tool -c -f ./u-boot-spl.bin
cp u-boot-spl.bin.normal.out $out/share/starfive-visionfive2/spl.bin
'';
};
uboot-fit-image = stdenv.mkDerivation {
name = "starfive-visionfive2-uboot-fit-image";
nativeBuildInputs = [ dtc ];
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/share/starfive-visionfive2/
${uboot}/mkimage -f ${its-file} -A riscv -O u-boot -T firmware $out/share/starfive-visionfive2/visionfive2_fw_payload.img
'';
};
rec {
opensbi = callPackage ./opensbi.nix { };
uboot = callPackage ./uboot.nix { inherit opensbi; };
updater-flash = writeShellApplication {
name = "visionfive2-firmware-update-flash";
runtimeInputs = [ mtdutils ];
text = ''
flashcp -v ${spl}/share/starfive-visionfive2/spl.bin /dev/mtd0
flashcp -v ${uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img /dev/mtd1
flashcp -v ${uboot}/u-boot-spl.bin.normal.out /dev/mtd0
flashcp -v ${uboot}/u-boot.itb /dev/mtd2
'';
};
updater-sd = writeShellApplication {
name = "visionfive2-firmware-update-sd";
runtimeInputs = [ ];
text = ''
dd if=${spl}/share/starfive-visionfive2/spl.bin of=/dev/mmcblk0p1 conv=fsync
dd if=${uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img of=/dev/mmcblk0p2 conv=fsync
dd if=${uboot}/u-boot-spl.bin.normal.out of=/dev/mmcblk0p1 conv=fsync
dd if=${uboot}/u-boot.itb of=/dev/mmcblk0p2 conv=fsync
'';
};
}

View file

@ -1,14 +1,13 @@
{ opensbi, withPayload, withFDT }:
{ opensbi }:
(opensbi.override {
inherit withPayload withFDT;
}).overrideAttrs (attrs: {
opensbi.overrideAttrs (attrs: {
makeFlags = attrs.makeFlags ++ [
# opensbi generic platform default FW_TEXT_START is 0x80000000
# For JH7110, need to specify the FW_TEXT_START to 0x40000000
# Otherwise, the fw_payload.bin downloading via jtag will not run.
# https://github.com/starfive-tech/VisionFive2/blob/7733673d27052dc5a48f1cb1d060279dfa3f0241/Makefile#L274
# Also matches u-boot documentation: https://docs.u-boot.org/en/latest/board/starfive/visionfive2.html
"FW_TEXT_START=0x40000000"
"FW_OPTIONS=0"
];
})

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, modulesPath, ... }:
{ config, pkgs, modulesPath, ... }:
let firmware = pkgs.callPackage ./firmware.nix { };
in {
@ -36,10 +36,10 @@ in {
EOF
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
dd conv=notrunc if=${firmware.spl}/share/starfive-visionfive2/spl.bin of=$img seek=$START count=$SECTORS
dd conv=notrunc if=${firmware.uboot}/u-boot-spl.bin.normal.out of=$img seek=$START count=$SECTORS
eval $(partx $img -o START,SECTORS --nr 2 --pairs)
dd conv=notrunc if=${firmware.uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img of=$img seek=$START count=$SECTORS
dd conv=notrunc if=${firmware.uboot}/u-boot.itb of=$img seek=$START count=$SECTORS
'';
populateRootCommands = ''

View file

@ -1,20 +1,36 @@
{ fetchFromGitHub, buildUBoot }:
{ lib
, fetchFromGitHub
, buildUBoot
, buildPackages
, opensbi
}:
buildUBoot rec {
version = "3.8.2";
version = "2024.01-rc5";
src = fetchFromGitHub {
owner = "starfive-tech";
owner = "u-boot";
repo = "u-boot";
rev = "refs/tags/VF2_v${version}";
hash = "sha256-M/ndil++spcJCYnpYLb+fuxqCi4H3BunXdHbl529ovM=";
rev = "refs/tags/v${version}";
hash = "sha256-QlwgvnSaXh39z9AM7HNF731lRiUkPbN3oQyioQNTYFA=";
};
# workaround for https://github.com/NixOS/nixpkgs/pull/146634
# uboot: only apply raspberry pi patches to raspberry pi builds
patches = [ ];
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"
];
defconfig = "starfive_visionfive2_defconfig";
filesToInstall = [
"u-boot.bin"
"arch/riscv/dts/starfive_visionfive2.dtb"
"spl/u-boot-spl.bin"
"tools/mkimage"
"spl/u-boot-spl.bin.normal.out"
"u-boot.itb"
];
}

View file

@ -1,7 +1,9 @@
{ profile }:
{ profile, pkgs }:
let
shim = { config, lib, pkgs, ... }: {
(pkgs.nixos [
profile
({ config, lib, ... }: {
nixpkgs.pkgs = pkgs;
boot.loader.systemd-boot.enable = !config.boot.loader.generic-extlinux-compatible.enable && !config.boot.loader.raspberryPi.enable;
# we forcefully disable grub here just for testing purposes, even though some profiles might still use grub in the end.
boot.loader.grub.enable = false;
@ -14,13 +16,6 @@ let
device = "/dev/disk/by-uuid/00000000-0000-0000-0000-000000000000";
fsType = "btrfs";
};
nixpkgs.config = {
allowBroken = true;
allowUnfree = true;
nvidia.acceptLicense = true;
};
};
in (import <nixpkgs/nixos> {
configuration.imports = [ profile shim ];
}).system
system.stateVersion = lib.version;
})
]).config.system.build.toplevel

64
tests/pyproject.toml Normal file
View file

@ -0,0 +1,64 @@
[tool.ruff]
line-length = 88
target-version = "py311"
select = ["ALL"]
ignore = [
# pydocstyle
"D",
# todo comments
"TD",
# fixmes
"FIX",
# Unused function argument
"ARG001",
# Shebang should contain `python`
"EXE003",
# Shebang should be at the beginning of the file
"EXE005",
# Missing type annotation for `self` in method
"ANN101",
# Dynamically typed expressions (typing.Any)
"ANN401",
# Trailing comma missing
"COM812",
# Unnecessary `dict` call (rewrite as a literal)
"C408",
# Boolean-typed positional argument in function definition
"FBT001",
# Logging statement uses f-string
"G004",
# disabled on ruff's recommendation as causes problems with the formatter
"ISC001",
# Use of `assert` detected
"S101",
# `subprocess` call: check for execution of untrusted input
"S603",
# Starting a process with a partial executable path
"S607",
# Boolean default positional argument in function definition
"FBT002",
# Too many statements
"PLR0915",
# Too many arguments in function definition
"PLR0913",
"PLR0912", # Too many branches
# $X is too complex
"C901",
"E501", # line too long
"T201", # `print` found
"PLR2004", # Magic value used in comparison
]
[tool.mypy]
python_version = "3.11"
warn_redundant_casts = true
disallow_untyped_calls = true
disallow_untyped_defs = true
no_implicit_optional = true
pretty = true

View file

@ -1,14 +1,16 @@
#!/usr/bin/env nix-shell
#!nix-shell --quiet -p nix -p python3 -i python
#!nix-shell --quiet -p nix-eval-jobs -p nix -p python3 -i python
import argparse
import json
import multiprocessing
import re
import subprocess
import sys
from functools import partial
import textwrap
from pathlib import Path
from typing import List, Tuple
from tempfile import TemporaryDirectory
from typing import IO
TEST_ROOT = Path(__file__).resolve().parent
ROOT = TEST_ROOT.parent
@ -17,53 +19,18 @@ GREEN = "\033[92m"
RED = "\033[91m"
RESET = "\033[0m"
re_nixos_hardware = re.compile(r"<nixos-hardware/([^>]+)>")
def parse_readme() -> List[str]:
def parse_readme() -> list[str]:
profiles = set()
with open(ROOT.joinpath("README.md")) as f:
with ROOT.joinpath("README.md").open() as f:
for line in f:
results = re.findall(r"<nixos-hardware/[^>]+>", line)
profiles.update(results)
if (m := re_nixos_hardware.search(line)) is not None:
profiles.add(m.group(1).strip())
return list(profiles)
def build_profile(
profile: str, verbose: bool
) -> Tuple[str, subprocess.CompletedProcess]:
# Hard-code this for now until we have enough other architectures to care about this.
system = "x86_64-linux"
if "raspberry-pi/2" in profile:
system = "armv7l-linux"
if "raspberry-pi/4" in profile:
system = "aarch64-linux"
cmd = [
"nix",
"build",
"--extra-experimental-features", "nix-command",
"-f",
"build-profile.nix",
"-I",
f"nixos-hardware={ROOT}",
"--show-trace",
"--system",
system,
"--arg",
"profile",
profile,
]
# uses import from derivation
if profile != "<nixos-hardware/toshiba/swanky>":
cmd += ["--dry-run"]
if verbose:
print(f"$ {' '.join(cmd)}")
res = subprocess.run(
cmd, cwd=TEST_ROOT, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
)
return (profile, res)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run hardware tests")
parser.add_argument(
@ -74,40 +41,98 @@ def parse_args() -> argparse.Namespace:
"If set to 1 it disable multi processing (suitable for debugging)",
)
parser.add_argument(
"--verbose", action="store_true", help="Print evaluation commands executed",
"--verbose",
action="store_true",
help="Print evaluation commands executed",
)
parser.add_argument("profiles", nargs="*")
return parser.parse_args()
def write_eval_test(f: IO[str], profiles: list[str]) -> None:
build_profile = TEST_ROOT.joinpath("build-profile.nix")
f.write(
textwrap.dedent(
f"""
let
purePkgs = system: import <nixpkgs> {{
config = {{
allowBroken = true;
allowUnfree = true;
nvidia.acceptLicense = true;
}};
overlays = [];
inherit system;
}};
pkgs.x86_64-linux = purePkgs "x86_64-linux";
pkgs.aarch64-linux = purePkgs "aarch64-linux";
buildProfile = import {build_profile};
in
"""
)
)
f.write("{\n")
for profile in profiles:
# does import-from-derivation
if profile == "toshiba/swanky":
continue
# uses custom nixpkgs config
if profile == "raspberry-pi/2":
continue
system = "x86_64-linux"
if "raspberry-pi/4" == profile:
system = "aarch64-linux"
f.write(
f' "{profile}" = buildProfile {{ profile = import {ROOT}/{profile}; pkgs = pkgs.{system}; }};\n'
)
f.write("}\n")
def run_eval_test(eval_test: Path, gcroot_dir: Path, jobs: int) -> list[str]:
failed_profiles = []
cmd = [
"nix-eval-jobs",
"--gc-roots-dir",
gcroot_dir,
"--max-memory-size",
"2048",
"--workers",
str(jobs),
str(eval_test),
]
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
text=True,
)
with proc as p:
assert p.stdout is not None
for line in p.stdout:
data = json.loads(line)
attr = data.get("attr")
if "error" in data:
failed_profiles.append(attr)
print(f"{RED}FAIL {attr}:{RESET}", file=sys.stderr)
print(f"{RED}{data['error']}{RESET}", file=sys.stderr)
else:
print(f"{GREEN}OK {attr}{RESET}")
return failed_profiles
def main() -> None:
args = parse_args()
if len(args.profiles) == 0:
profiles = parse_readme()
else:
profiles = args.profiles
profiles = parse_readme() if len(args.profiles) == 0 else args.profiles
failed_profiles = []
with TemporaryDirectory() as tmpdir:
eval_test = Path(tmpdir) / "eval-test.nix"
gcroot_dir = Path(tmpdir) / "gcroot"
with eval_test.open("w") as f:
write_eval_test(f, profiles)
failed_profiles = run_eval_test(eval_test, gcroot_dir, args.jobs)
def eval_finished(args: Tuple[str, subprocess.CompletedProcess]) -> None:
profile, res = args
if res.returncode == 0:
print(f"{GREEN}OK {profile}{RESET}")
else:
print(f"{RED}FAIL {profile}:{RESET}", file=sys.stderr)
if res.stdout != "":
print(f"{RED}{res.stdout.rstrip()}{RESET}", file=sys.stderr)
print(f"{RED}{res.stderr.rstrip()}{RESET}", file=sys.stderr)
failed_profiles.append(profile)
build = partial(build_profile, verbose=args.verbose)
if len(profiles) == 0 or args.jobs == 1:
for profile in profiles:
eval_finished(build(profile))
else:
pool = multiprocessing.Pool(processes=args.jobs)
for r in pool.imap(build, profiles):
eval_finished(r)
if len(failed_profiles) > 0:
print(f"\n{RED}The following {len(failed_profiles)} test(s) failed:{RESET}")
for profile in failed_profiles:

View file

@ -0,0 +1 @@
# [TUXEDO InfinityBook Pro 14 - Gen7](https://www.tuxedocomputers.com/de/TUXEDO-InfinityBook-Pro-14-Gen7.tuxedo)

View file

@ -0,0 +1,12 @@
{ lib, ... }:
{
imports = [
../../../../common/cpu/intel
../../../../common/pc/laptop
../../../../common/pc/ssd
];
# Cooling management
services.thermald.enable = lib.mkDefault true;
}