about summary refs log tree commit diff
path: root/modules/nixos-hardware/lenovo
diff options
context:
space:
mode:
Diffstat (limited to 'modules/nixos-hardware/lenovo')
-rw-r--r--modules/nixos-hardware/lenovo/ideapad/default.nix3
-rw-r--r--modules/nixos-hardware/lenovo/ideapad/z510/default.nix11
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/default.nix11
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/e470/default.nix19
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/e495/default.nix11
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/l13/default.nix10
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/l14/amd/default.nix23
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/l14/default.nix14
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/l14/intel/default.nix10
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/p53/default.nix10
l---------modules/nixos-hardware/lenovo/thinkpad/t141
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t14s/amd/default.nix11
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t14s/amd/gen1/default.nix8
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t14s/default.nix20
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t410/default.nix36
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t420/default.nix9
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t430/default.nix16
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t440p/default.nix16
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t440s/default.nix14
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t450s/default.nix9
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t460s/default.nix9
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t470s/default.nix9
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t480s/default.nix11
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t490/default.nix31
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t490/t490-profile-set.conf107
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/t495/default.nix16
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/tp-smapi.nix11
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1-extreme/default.nix8
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1-extreme/gen2/default.nix48
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/QHD/default.nix36
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/default.nix20
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/audio.nix15
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/default.nix7
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x1/default.nix6
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x13-yoga/default.nix13
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x140e/default.nix14
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x220/default.nix10
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x230/default.nix19
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x250/default.nix7
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x260/default.nix17
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x270/default.nix6
-rw-r--r--modules/nixos-hardware/lenovo/thinkpad/x280/default.nix12
42 files changed, 694 insertions, 0 deletions
diff --git a/modules/nixos-hardware/lenovo/ideapad/default.nix b/modules/nixos-hardware/lenovo/ideapad/default.nix
new file mode 100644
index 000000000000..d774ba3793af
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/ideapad/default.nix
@@ -0,0 +1,3 @@
+{
+  imports = [ ../../common/pc/laptop ];
+}
diff --git a/modules/nixos-hardware/lenovo/ideapad/z510/default.nix b/modules/nixos-hardware/lenovo/ideapad/z510/default.nix
new file mode 100644
index 000000000000..83f656806854
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/ideapad/z510/default.nix
@@ -0,0 +1,11 @@
+{ lib, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+  ];
+
+  # https://github.com/NixOS/nixpkgs/issues/18356
+  boot.blacklistedKernelModules = [ "nouveau" ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/default.nix b/modules/nixos-hardware/lenovo/thinkpad/default.nix
new file mode 100644
index 000000000000..99d4937e49c7
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/default.nix
@@ -0,0 +1,11 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [ ../../common/pc/laptop ];
+
+  hardware.trackpoint.enable = lib.mkDefault true;
+  hardware.trackpoint.emulateWheel = lib.mkDefault config.hardware.trackpoint.enable;
+
+  # Fingerprint reader: login and unlock with fingerprint (if you add one with `fprintd-enroll`)
+  # services.fprintd.enable = true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/e470/default.nix b/modules/nixos-hardware/lenovo/thinkpad/e470/default.nix
new file mode 100644
index 000000000000..c9bf8331b050
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/e470/default.nix
@@ -0,0 +1,19 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel/kaby-lake
+    ../../../common/gpu/nvidia.nix
+  ];
+
+  hardware.nvidia.prime = {
+    # Bus ID of the Intel GPU.
+    intelBusId = lib.mkDefault "PCI:0:2:0";
+
+    # Bus ID of the NVIDIA GPU.
+    nvidiaBusId = lib.mkDefault "PCI:1:0:0";
+  };
+
+  boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.6") pkgs.linuxPackages_latest;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/e495/default.nix b/modules/nixos-hardware/lenovo/thinkpad/e495/default.nix
new file mode 100644
index 000000000000..51ddb5cfd010
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/e495/default.nix
@@ -0,0 +1,11 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/amd
+  ];
+
+  # see https://github.com/NixOS/nixpkgs/issues/69289
+  boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.2") pkgs.linuxPackages_latest;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/l13/default.nix b/modules/nixos-hardware/lenovo/thinkpad/l13/default.nix
new file mode 100644
index 000000000000..3c09f5091ed8
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/l13/default.nix
@@ -0,0 +1,10 @@
+{ nixos, lib, pkgs, config, stdenv, ... }:
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+
+  services.throttled.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/l14/amd/default.nix b/modules/nixos-hardware/lenovo/thinkpad/l14/amd/default.nix
new file mode 100644
index 000000000000..c2d1534fd178
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/l14/amd/default.nix
@@ -0,0 +1,23 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../../common/cpu/amd
+  ];
+
+  boot.kernelParams = [
+    # With BIOS version 1.12 and the IOMMU enabled, the amdgpu driver
+    # either crashes or is not able to attach to the GPU depending on
+    # the kernel version. I've seen no issues with the IOMMU disabled.
+    #
+    # BIOS version 1.13 claims to fix IOMMU issues, but we leave the
+    # IOMMU off to avoid a sad experience for those people that drew
+    # the short straw when they bought their laptop.
+    "iommu=off"
+  ];
+
+  # As of writing this, Linux 5.8 is the oldest kernel that is still
+  # supported and has decent Renoir support.
+  boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.8") pkgs.linuxPackages_latest;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/l14/default.nix b/modules/nixos-hardware/lenovo/thinkpad/l14/default.nix
new file mode 100644
index 000000000000..e014b7d0fa68
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/l14/default.nix
@@ -0,0 +1,14 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  boot.kernelParams = [
+    # Force use of the thinkpad_acpi driver for backlight control.
+    # This allows the backlight save/load systemd service to work.
+    "acpi_backlight=native"
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/l14/intel/default.nix b/modules/nixos-hardware/lenovo/thinkpad/l14/intel/default.nix
new file mode 100644
index 000000000000..088289f37c19
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/l14/intel/default.nix
@@ -0,0 +1,10 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../../common/cpu/intel
+  ];
+
+  services.throttled.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/p53/default.nix b/modules/nixos-hardware/lenovo/thinkpad/p53/default.nix
new file mode 100644
index 000000000000..a499d5c2d51e
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/p53/default.nix
@@ -0,0 +1,10 @@
+{ nixos, pkgs, lib, config, stdenv, ... }:
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+
+  services.throttled.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t14 b/modules/nixos-hardware/lenovo/thinkpad/t14
new file mode 120000
index 000000000000..7be5dd832dad
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t14
@@ -0,0 +1 @@
+t14s/
\ No newline at end of file
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t14s/amd/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t14s/amd/default.nix
new file mode 100644
index 000000000000..2b860e847d65
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t14s/amd/default.nix
@@ -0,0 +1,11 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../../common/cpu/amd
+  ];
+
+  # For support of newer AMD GPUs, backlight and internal microphone
+  boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.8") pkgs.linuxPackages_latest;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t14s/amd/gen1/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t14s/amd/gen1/default.nix
new file mode 100644
index 000000000000..cb1ec7d81b76
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t14s/amd/gen1/default.nix
@@ -0,0 +1,8 @@
+
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t14s/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t14s/default.nix
new file mode 100644
index 000000000000..d783b21a8594
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t14s/default.nix
@@ -0,0 +1,20 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  # For suspending to RAM to work, set Config -> Power -> Sleep State to "Linux" in EFI.
+  # See https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_6)#Suspend_issues
+
+  # Fingerprint sensor requires a firmware-update to work.
+
+  # Force use of the thinkpad_acpi driver for backlight control.
+  # This allows the backlight save/load systemd service to work.
+  boot.kernelParams = [ "acpi_backlight=native" ];
+
+  # see https://github.com/NixOS/nixpkgs/issues/69289
+  boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.2") pkgs.linuxPackages_latest;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t410/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t410/default.nix
new file mode 100644
index 000000000000..c40801ffc0bc
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t410/default.nix
@@ -0,0 +1,36 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../tp-smapi.nix
+    ../../../common/cpu/intel
+  ];
+
+  boot = {
+    # TODO: this configuration seems to be very aggressive.
+    # Ask @peti if it's stable or not.
+    kernelParams = [
+      "drm.debug=0"
+      "drm.vblankoffdelay=1"
+      "i915.semaphores=1"
+      "i915.modeset=1"
+      "i915.use_mmio_flip=1"
+      "i915.powersave=1"
+      "i915.enable_ips=1"
+      "i915.disable_power_well=1"
+      "i915.enable_hangcheck=1"
+      "i915.enable_cmd_parser=1"
+      "i915.fastboot=0"
+      "i915.enable_ppgtt=1"
+      "i915.reset=0"
+      "i915.lvds_use_ssc=0"
+      "i915.enable_psr=0"
+      "vblank_mode=0"
+      "i915.i915_enable_rc6=1"
+    ];
+    blacklistedKernelModules = [
+      "sierra_net" "cdc_mbim" "cdc_ncm" "btusb"
+    ];
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t420/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t420/default.nix
new file mode 100644
index 000000000000..5d3efe831c96
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t420/default.nix
@@ -0,0 +1,9 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t430/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t430/default.nix
new file mode 100644
index 000000000000..bdad1be9878a
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t430/default.nix
@@ -0,0 +1,16 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  boot = {
+    kernelParams = [
+      # fixes brightness keys, see https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_T430s
+      "acpi_osi\='!Windows 2012'"
+    ];
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t440p/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t440p/default.nix
new file mode 100644
index 000000000000..4dd4085794fa
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t440p/default.nix
@@ -0,0 +1,16 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+  ];
+
+  boot = {
+    extraModprobeConfig = lib.mkDefault ''
+      options bbswitch use_acpi_to_detect_card_state=1
+    '';
+    # TODO: probably enable tcsd? Is this line necessary?
+    kernelModules = [ "tpm-rng" ];
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t440s/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t440s/default.nix
new file mode 100644
index 000000000000..c40ad90f9b3d
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t440s/default.nix
@@ -0,0 +1,14 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  boot = {
+    # TODO: probably enable tcsd? Is this line necessary?
+    kernelModules = [ "tpm-rng" ];
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t450s/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t450s/default.nix
new file mode 100644
index 000000000000..e62337171b9a
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t450s/default.nix
@@ -0,0 +1,9 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t460s/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t460s/default.nix
new file mode 100644
index 000000000000..e62337171b9a
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t460s/default.nix
@@ -0,0 +1,9 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t470s/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t470s/default.nix
new file mode 100644
index 000000000000..e62337171b9a
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t470s/default.nix
@@ -0,0 +1,9 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t480s/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t480s/default.nix
new file mode 100644
index 000000000000..1a14afa6b5e4
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t480s/default.nix
@@ -0,0 +1,11 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+
+  services.throttled.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t490/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t490/default.nix
new file mode 100644
index 000000000000..3578da66c73d
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t490/default.nix
@@ -0,0 +1,31 @@
+{ nixos, lib, pkgs, config, stdenv, ... }:
+{
+  imports = [
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../.
+  ];
+
+  services = {
+    # This fixes the pulseaudio profiles of the Thinkpad T490.
+    # The laptop contains a single audio card with 5 sub-devices. Default pulseaudio only offers a single sink
+    # which can only be switched between speaker/HDMI via a manual profile change.
+    # This configures a profile set for pulseaudio which offers multiple sinks corresponding to the
+    # speaker + 4 HDMI ports. This allows the user to play audio streams on the speaker and any of the 4 HDMI/USB-C
+    # ports at the same time.
+    udev.extraRules = let
+      t490ProfileSet = ./t490-profile-set.conf;
+    in ''
+    SUBSYSTEM!="sound", GOTO="pulseaudio_end"
+    ACTION!="change", GOTO="pulseaudio_end"
+    KERNEL!="card*", GOTO="pulseaudio_end"
+
+    # Lenovo T490
+    ATTRS{vendor}=="0x8086" ATTRS{device}=="0x9dc8" ATTRS{subsystem_vendor}=="0x17aa", ATTRS{subsystem_device}=="0x2279", ENV{PULSE_PROFILE_SET}="${t490ProfileSet}"
+
+    LABEL="pulseaudio_end"
+    '';
+    
+    throttled.enable = lib.mkDefault true;
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t490/t490-profile-set.conf b/modules/nixos-hardware/lenovo/thinkpad/t490/t490-profile-set.conf
new file mode 100644
index 000000000000..98f8f0318de1
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t490/t490-profile-set.conf
@@ -0,0 +1,107 @@
+[Profile speaker+hdmi-stereo]
+description = Speaker + HDMI Stereo
+output-mappings = analog-stereo hdmi-stereo hdmi-stereo-extra1 hdmi-stereo-extra2
+input-mappings = analog-stereo
+
+[Mapping analog-stereo]
+device-strings = front:%f
+channel-map = left,right
+paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2
+paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headphone-mic analog-input-headset-mic
+priority = 15
+
+[Mapping hdmi-stereo]
+description = Stereo (HDMI)
+device-strings = hdmi:%f
+paths-output = hdmi-output-0
+channel-map = left,right
+priority = 6
+direction = output
+
+[Mapping hdmi-stereo-extra1]
+description = Stereo (HDMI 2)
+device-strings = hdmi:%f,1
+paths-output = hdmi-output-1
+channel-map = left,right
+priority = 8
+direction = output
+
+[Mapping hdmi-stereo-extra2]
+description = Stereo (HDMI 3)
+device-strings = hdmi:%f,2
+paths-output = hdmi-output-2
+channel-map = left,right
+priority = 6
+direction = output
+
+[Profile speaker+hdmi-surround]
+description = Speaker + HDMI 5.1
+output-mappings = analog-stereo hdmi-surround hdmi-surround-extra1 hdmi-surround-extra2
+input-mappings = analog-stereo
+
+[Mapping analog-stereo]
+device-strings = front:%f
+channel-map = left,right
+paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2
+paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headphone-mic analog-input-headset-mic
+priority = 15
+
+[Mapping hdmi-surround]
+description = Digital Surround 5.1 (HDMI)
+device-strings = hdmi:%f
+paths-output = hdmi-output-0
+channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
+priority = 6
+direction = output
+
+[Mapping hdmi-surround-extra1]
+description = Digital Surround 5.1 (HDMI 2)
+device-strings = hdmi:%f,1
+paths-output = hdmi-output-1
+channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
+priority = 8
+direction = output
+
+[Mapping hdmi-surround-extra2]
+description = Digital Surround 5.1 (HDMI 3)
+device-strings = hdmi:%f,2
+paths-output = hdmi-output-2
+channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe
+priority = 6
+direction = output
+
+[Profile speaker+hdmi-surround71]
+description = Speaker + HDMI 7.1
+output-mappings = analog-stereo hdmi-surround71 hdmi-surround71-extra1 hdmi-surround71-extra2
+input-mappings = analog-stereo
+
+[Mapping analog-stereo]
+device-strings = front:%f
+channel-map = left,right
+paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2
+paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headphone-mic analog-input-headset-mic
+priority = 15
+
+[Mapping hdmi-surround71]
+description = Digital Surround 7.1 (HDMI)
+device-strings = hdmi:%f
+paths-output = hdmi-output-0
+channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
+priority = 6
+direction = output
+
+[Mapping hdmi-surround71-extra1]
+description = Digital Surround 7.1 (HDMI 2)
+device-strings = hdmi:%f,1
+paths-output = hdmi-output-1
+channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
+priority = 8
+direction = output
+
+[Mapping hdmi-surround71-extra2]
+description = Digital Surround 7.1 (HDMI 3)
+device-strings = hdmi:%f,2
+paths-output = hdmi-output-2
+channel-map = front-left,front-right,rear-left,rear-right,front-center,lfe,side-left,side-right
+priority = 6
+direction = output
diff --git a/modules/nixos-hardware/lenovo/thinkpad/t495/default.nix b/modules/nixos-hardware/lenovo/thinkpad/t495/default.nix
new file mode 100644
index 000000000000..64957e6e06c7
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/t495/default.nix
@@ -0,0 +1,16 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/amd
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  # Force use of the thinkpad_acpi driver for backlight control.
+  # This allows the backlight save/load systemd service to work.
+  boot.kernelParams = [ "acpi_backlight=native" ];
+
+  # see https://github.com/NixOS/nixpkgs/issues/69289
+  boot.kernelPackages = lib.mkIf (lib.versionOlder pkgs.linux.version "5.2") pkgs.linuxPackages_latest;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/tp-smapi.nix b/modules/nixos-hardware/lenovo/thinkpad/tp-smapi.nix
new file mode 100644
index 000000000000..451dd28ece03
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/tp-smapi.nix
@@ -0,0 +1,11 @@
+# tp_smapi works on ThinkPads made before 2013. See compat table:
+# https://www.thinkwiki.org/wiki/Tp_smapi#Model-specific_status
+
+{ config, ... }:
+
+{
+  boot = {
+    kernelModules = [ "tp_smapi" ];
+    extraModulePackages = with config.boot.kernelPackages; [ tp_smapi ];
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1-extreme/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x1-extreme/default.nix
new file mode 100644
index 000000000000..09a0ec1700a5
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1-extreme/default.nix
@@ -0,0 +1,8 @@
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../../../common/pc/laptop/ssd
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1-extreme/gen2/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x1-extreme/gen2/default.nix
new file mode 100644
index 000000000000..6b0ebbd5d1e3
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1-extreme/gen2/default.nix
@@ -0,0 +1,48 @@
+{ config, lib, ... }:
+
+with lib;
+
+{
+  imports = [
+    ../.
+  ];
+
+  # Fixes an issue with incorrect battery reporting. See
+  # https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Extreme_(Gen_2)#Invalid_Stats_Workaround
+  boot.initrd.availableKernelModules = [ "battery" ];
+
+  # New ThinkPads have a different TrackPoint manufacturer/name.
+  # See also https://certification.ubuntu.com/catalog/component/input/5313/input%3ATPPS/2ElanTrackPoint/
+  hardware.trackpoint.device = "TPPS/2 Elan TrackPoint";
+
+  # Since the HDMI port is connected to the NVIDIA card.
+  hardware.bumblebee.connectDisplay = true;
+
+  nixpkgs.overlays = [
+    (self: super: {
+      bumblebee = super.bumblebee.override {
+        extraNvidiaDeviceOptions = ''
+          Option "AllowEmptyInitialConfiguration"
+        '';
+      };
+    })
+  ];
+
+  services.xserver = mkMerge [
+    {
+      # Set the right DPI. xdpyinfo says the screen is 508×285 mm but
+      # it actually is 344×193 mm.
+      monitorSection = ''
+        DisplaySize 344 193
+      '';
+    }
+
+    # To support intel-virtual-output when using Bumblebee.
+    (mkIf config.hardware.bumblebee.enable {
+      deviceSection = ''Option "VirtualHeads" "1"'';
+      videoDrivers = [ "intel" ];
+    })
+  ];
+
+  services.throttled.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/QHD/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/QHD/default.nix
new file mode 100644
index 000000000000..0b8555fbfb08
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/QHD/default.nix
@@ -0,0 +1,36 @@
+# X1 6th generation with a QHD (2560x1440px) display
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+  ];
+
+  # Fix font sizes in X
+  services.xserver.dpi = 210;
+  fonts.fontconfig.dpi = 210;
+
+  # Fix sizes of GTK/GNOME ui elements
+  environment.variables = {
+    GDK_SCALE = lib.mkDefault "2";
+    GDK_DPI_SCALE= lib.mkDefault "0.5";
+  };
+  # Enable readable font on console. The example configuration that
+  # follows is taliored towards western languages. To see how to
+  # configure the font download the source tarball from
+  # http://terminus-font.sourceforge.net/ and read the README file on
+  # the root dir
+
+  # i18n = {
+  #   # this means ISO8859-1 or ISO8859-15 or Windows-1252 codepages
+  #   # (ter-1), 16x32 px (32), normal font weight (n)
+  #   consoleFont = "ter-132n";
+  #   consoleKeyMap = "us";
+  #   defaultLocale = "en_US.UTF-8";
+  #   consolePackages = [ pkgs.terminus_font ];
+  # };
+
+  # Early configure the console to make the font readable from the
+  # start
+  # boot.earlyVconsoleSetup = true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/default.nix
new file mode 100644
index 000000000000..00446b8c278b
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1/6th-gen/default.nix
@@ -0,0 +1,20 @@
+# A good source of information about how to fix the issues still
+# standing with kernel 4.6.11 is the following wiki page:
+# https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_6). The
+# TrackPoint and TouchPad issues there seem to have been fixed already.
+#
+# Enable the lower-power S3 suspend state by upgrading the BIOS to version >= 1.30,
+# then manually selecting Linux in the power management section.
+{ config, pkgs, lib, ... }:
+{
+  imports = [
+    ../.
+    ../../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  # New ThinkPads have a different TrackPoint manufacturer/name.
+  # See also https://certification.ubuntu.com/catalog/component/input/5313/input%3ATPPS/2ElanTrackPoint/
+  hardware.trackpoint.device = "TPPS/2 Elan TrackPoint";
+
+  services.throttled.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/audio.nix b/modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/audio.nix
new file mode 100644
index 000000000000..f6ecf58aa337
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/audio.nix
@@ -0,0 +1,15 @@
+{ lib, pkgs, ... }:
+{
+  # This can be removed when the default kernel is at least version 5.6
+  # https://github.com/NixOS/nixpkgs/pull/86168
+  boot.kernelPackages = lib.mkIf
+    (lib.versionOlder pkgs.linux.version "5.6")
+    (lib.mkDefault pkgs.linuxPackages_latest);
+
+  # This can be removed when PulseAudio is at least version 14
+  # https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_7)#Audio
+  hardware.pulseaudio.extraConfig = ''
+    load-module module-alsa-sink   device=hw:0,0 channels=4
+    load-module module-alsa-source device=hw:0,6 channels=4
+  '';
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/default.nix
new file mode 100644
index 000000000000..8349d05678a2
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1/7th-gen/default.nix
@@ -0,0 +1,7 @@
+{
+  imports = [
+    ../.
+    ../../../../common/pc/laptop/acpi_call.nix
+    ./audio.nix
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x1/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x1/default.nix
new file mode 100644
index 000000000000..870d9a857742
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x1/default.nix
@@ -0,0 +1,6 @@
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x13-yoga/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x13-yoga/default.nix
new file mode 100644
index 000000000000..2653910d44b4
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x13-yoga/default.nix
@@ -0,0 +1,13 @@
+{ config, lib, ... }: {
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../../../common/pc/laptop/ssd
+  ];
+
+  # automatic screen orientation
+  hardware.sensor.iio.enable = true;
+
+  services.xserver.wacom.enable = lib.mkDefault config.services.xserver.enable;
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x140e/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x140e/default.nix
new file mode 100644
index 000000000000..c03410e936e2
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x140e/default.nix
@@ -0,0 +1,14 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/amd
+  ];
+
+  boot.extraModprobeConfig = lib.mkDefault ''
+    options snd_hda_intel enable=0,1
+  '';
+
+  services.xserver.videoDrivers = [ "ati" ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x220/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x220/default.nix
new file mode 100644
index 000000000000..b28e27845b0b
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x220/default.nix
@@ -0,0 +1,10 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel/sandy-bridge
+    ../../../common/pc/laptop/hdd # TODO: reverse compat
+    ../tp-smapi.nix
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x230/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x230/default.nix
new file mode 100644
index 000000000000..58b09f4c5d5f
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x230/default.nix
@@ -0,0 +1,19 @@
+{ config, lib, pkgs, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  boot = {
+    kernelModules = [
+      "tpm-rng"
+    ];
+  };
+
+  services.xserver.deviceSection = lib.mkDefault ''
+    Option "TearFree" "true"
+  '';
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x250/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x250/default.nix
new file mode 100644
index 000000000000..55ae2096342e
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x250/default.nix
@@ -0,0 +1,7 @@
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x260/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x260/default.nix
new file mode 100644
index 000000000000..c11ef98f79e0
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x260/default.nix
@@ -0,0 +1,17 @@
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+  ];
+
+  boot.kernelParams = [
+    # https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X260#Thinkpad_X260
+    "i915.enable_psr=0"
+  ];
+
+  # https://wiki.archlinux.org/index.php/TLP#Btrfs
+  services.tlp.settings = {
+    SATA_LINKPWR_ON_BAT = "med_power_with_dipm";
+  };
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x270/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x270/default.nix
new file mode 100644
index 000000000000..870d9a857742
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x270/default.nix
@@ -0,0 +1,6 @@
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+  ];
+}
diff --git a/modules/nixos-hardware/lenovo/thinkpad/x280/default.nix b/modules/nixos-hardware/lenovo/thinkpad/x280/default.nix
new file mode 100644
index 000000000000..a9423e547321
--- /dev/null
+++ b/modules/nixos-hardware/lenovo/thinkpad/x280/default.nix
@@ -0,0 +1,12 @@
+{ config, pkgs, lib, ... }:
+
+{
+  imports = [
+    ../.
+    ../../../common/cpu/intel
+    ../../../common/pc/laptop/acpi_call.nix
+    ../../../common/pc/laptop/ssd/default.nix
+  ];
+
+  services.throttled.enable = lib.mkDefault true;
+}