From f90db4cb9e0ebc8ec767f088e324f54eef167b29 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 4 Jul 2022 23:24:35 -0400 Subject: [PATCH 01/10] add p50 and p51 --- README.md | 2 + lenovo/thinkpad/p50/default.nix | 100 +++++++++++++++++++++++++++++++ lenovo/thinkpad/p51/default.nix | 101 ++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 lenovo/thinkpad/p50/default.nix create mode 100644 lenovo/thinkpad/p51/default.nix diff --git a/README.md b/README.md index 462912f9..13005f23 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,8 @@ See code for all available configurations. | [Lenovo ThinkPad P1 Gen 3](lenovo/thinkpad/p1/3th-gen) | `` | | [Lenovo ThinkPad P14s AMD Gen 2](lenovo/thinkpad/p14s/amd/gen2) | `` | | [Lenovo ThinkPad P1](thinkpad/p1) | `` | +| [Lenovo ThinkPad P50](lenovo/thinkpad/p50) | `` | +| [Lenovo ThinkPad P51](lenovo/thinkpad/p51) | `` | | [Lenovo ThinkPad P53](lenovo/thinkpad/p53) | `` | | [Lenovo ThinkPad T14 AMD Gen 1](lenovo/thinkpad/t14/amd/gen1) | `` | | [Lenovo ThinkPad T14 AMD Gen 2](lenovo/thinkpad/t14/amd/gen2) | `` | diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix new file mode 100644 index 00000000..f9bdee9f --- /dev/null +++ b/lenovo/thinkpad/p50/default.nix @@ -0,0 +1,100 @@ +{ lib, ... }: +{ + imports = [ + ../../../common/gpu/nvidia.nix + ../../../common/cpu/intel + ../../../common/pc/laptop/acpi_call.nix + ../. + ]; + + hardware = { + nvidia = { + prime = { + intelBusId = "PCI:0:2:0"; + nvidiaBusId = "PCI:1:0:0"; + }; + }; + + # is this too much? It's convenient for Steam. + opengl = { + driSupport = lib.mkDefault true; + driSupport32Bit = lib.mkDefault true; + }; + }; + + # Sleep + # ----- + # + # The system will not resume from sleep properly while on battery power in + # either offload mode or sync mode. When it tries to resume, it gets to a + # state with a cursor in the top left hand side of the panel, the power LED + # goes from flashing to solid, and thereafter cannot be interacted with (even + # over SSH) and must be power cycled forcefully. Sometimes it doesn't even + # finish going to sleep before this behavior kicks in. + # + # When on AC, the machine either wakes up from sleep before being asked to + # (or maybe never gets to sleep state), or it goes into a sleep state and it + # appears consistently resume properly when it does. + # + # But the machine actually sleeps and resumes reliably when tlp is disabled + # fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be + # enough to allow it to work when tlp is active. I couldn't figure out a + # more granular way to get it working, despite trying to do a per-device + # binary search via powertop. + # + # My personal configuration to make this work looks like this: + # + # {config, lib, ...}: + # + # { + # services.tlp = { + # settings = { + # # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. + # DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; + # + # # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 + # # can't resume from sleep and P50 can't go to sleep. + # AHCI_RUNTIME_PM_ON_AC = "on"; + # AHCI_RUNTIME_PM_ON_BAT = "on"; + # + # # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep + # RUNTIME_PM_ON_AC = "on"; + # RUNTIME_PM_ON_BAT = "on"; + # }; + # }; + # } + # + # I'm thinking this is too aggressive to put into shared config, and folks may + # be concerned with the hit on battery life. + # + # throttled vs. thermald + # ----------------------- + # + # NB: the p53 profile currently uses throttled to prevent too-eager CPU + # throttling. I understand throttled to have been a workaround solution at + # the time the p53 profile was created (throttled's original name was + # "lenovo_fix"). thermald would have been preferred if it worked at the + # time. + # + # I read + # https://wiki.archlinux.org/title/Lenovo_ThinkPad_X1_Carbon_(Gen_6)#Power_management.2FThrottling_issues + # as saying that thermald is fixed under the circumstance that led to the + # development of throttled given version 5.12+ of the kernel combined + # with version 2.4.3+ of thermald. At the time of this writing, the + # stable NixOS kernel is 5.15 and 2.4.9 of thermald. + # + # In the meantime, I also ran the "s-tui" program which can stress test the + # system, while eyeing up the core temps and CPU frequency under three + # scenarios: under thermald, under throttled, and with neither. None of the + # scenarios seem to have massively improved fan behavior, core temps, or + # average CPU frequency than another. The highest core temp always seems to + # hover around 90 degrees C, the lowest CPU Ghz around 3.4 on a 3.8Ghz machine. + # + # I ended up choosing throttled because subjectively, the fans seem quieter + # when it's stressed and it allows the average temps to get a degree or two + # higher when running throttled than when running in the other two scenarios, + # but still substantially under critical temp. + + services.throttled.enable = lib.mkDefault true; + +} diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix new file mode 100644 index 00000000..9fa04196 --- /dev/null +++ b/lenovo/thinkpad/p51/default.nix @@ -0,0 +1,101 @@ +{ lib, ... }: +{ + imports = [ + ../../../common/gpu/nvidia.nix + ../../../common/cpu/intel + ../../../common/cpu/intel/kaby-lake + ../../../common/pc/laptop/acpi_call.nix + ../. + ]; + + hardware = { + nvidia = { + prime = { + intelBusId = "PCI:0:2:0"; + nvidiaBusId = "PCI:1:0:0"; + }; + }; + + # is this too much? It's convenient for Steam. + opengl = { + driSupport = lib.mkDefault true; + driSupport32Bit = lib.mkDefault true; + }; + }; + + # Sleep + # ----- + # + # The system will not resume from sleep properly while on battery power in + # either offload mode or sync mode. When it tries to resume, it gets to a + # state with a cursor in the top left hand side of the panel, the power LED + # goes from flashing to solid, and thereafter cannot be interacted with (even + # over SSH) and must be power cycled forcefully. Sometimes it doesn't even + # finish going to sleep before this behavior kicks in. + # + # When on AC, the machine either wakes up from sleep before being asked to + # (or maybe never gets to sleep state), or it goes into a sleep state and it + # appears consistently resume properly when it does. + # + # But the machine actually sleeps and resumes reliably when tlp is disabled + # fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be + # enough to allow it to work when tlp is active. I couldn't figure out a + # more granular way to get it working, despite trying to do a per-device + # binary search via powertop. + # + # My personal configuration to make sleep work looks like this: + # + # {config, lib, ...}: + # + # { + # services.tlp = { + # settings = { + # # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. + # DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; + # + # # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 + # # can't resume from sleep and P50 can't go to sleep. + # AHCI_RUNTIME_PM_ON_AC = "on"; + # AHCI_RUNTIME_PM_ON_BAT = "on"; + # + # # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep + # RUNTIME_PM_ON_AC = "on"; + # RUNTIME_PM_ON_BAT = "on"; + # }; + # }; + # } + # + # I'm thinking this is too aggressive to put into shared config, and folks may + # be concerned with the hit on battery life. + # + # throttled vs. thermald + # ----------------------- + # + # NB: the p53 profile currently uses throttled to prevent too-eager CPU + # throttling. I understand throttled to have been a workaround solution at + # the time the p53 profile was created (throttled's original name was + # "lenovo_fix"). thermald would have been preferred if it worked at the + # time. + # + # I read + # https://wiki.archlinux.org/title/Lenovo_ThinkPad_X1_Carbon_(Gen_6)#Power_management.2FThrottling_issues + # as saying that thermald is fixed under the circumstance that led to the + # development of throttled given version 5.12+ of the kernel combined + # with version 2.4.3+ of thermald. At the time of this writing, the + # stable NixOS kernel is 5.15 and 2.4.9 of thermald. + # + # In the meantime, I also ran the "s-tui" program which can stress test the + # system, while eyeing up the core temps and CPU frequency under three + # scenarios: under thermald, under throttled, and with neither. None of the + # scenarios seem to have massively improved fan behavior, core temps, or + # average CPU frequency than another. The highest core temp always seems to + # hover around 90 degrees C, the lowest CPU Ghz around 3.4 on a 3.8Ghz machine. + # + # I ended up choosing throttled because subjectively, the fans seem quieter + # when it's stressed and it allows the average temps to get a degree or two + # higher when running throttled than when running in the other two scenarios, + # but still substantially under critical temp. + + services.throttled.enable = lib.mkDefault true; + +} From ac75bbc47637e5e46fd7b8d1b153348f0d306b99 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 5 Jul 2022 17:45:16 -0400 Subject: [PATCH 02/10] transform sleep comment into optionally includable expression --- lenovo/thinkpad/p50/default.nix | 46 ++------------------------------- lenovo/thinkpad/p50/sleep.nix | 41 +++++++++++++++++++++++++++++ lenovo/thinkpad/p51/default.nix | 46 ++------------------------------- lenovo/thinkpad/p51/sleep.nix | 41 +++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 88 deletions(-) create mode 100644 lenovo/thinkpad/p50/sleep.nix create mode 100644 lenovo/thinkpad/p51/sleep.nix diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index f9bdee9f..f1f6038b 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -22,50 +22,8 @@ }; }; - # Sleep - # ----- - # - # The system will not resume from sleep properly while on battery power in - # either offload mode or sync mode. When it tries to resume, it gets to a - # state with a cursor in the top left hand side of the panel, the power LED - # goes from flashing to solid, and thereafter cannot be interacted with (even - # over SSH) and must be power cycled forcefully. Sometimes it doesn't even - # finish going to sleep before this behavior kicks in. - # - # When on AC, the machine either wakes up from sleep before being asked to - # (or maybe never gets to sleep state), or it goes into a sleep state and it - # appears consistently resume properly when it does. - # - # But the machine actually sleeps and resumes reliably when tlp is disabled - # fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be - # enough to allow it to work when tlp is active. I couldn't figure out a - # more granular way to get it working, despite trying to do a per-device - # binary search via powertop. - # - # My personal configuration to make this work looks like this: - # - # {config, lib, ...}: - # - # { - # services.tlp = { - # settings = { - # # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. - # DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; - # - # # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 - # # can't resume from sleep and P50 can't go to sleep. - # AHCI_RUNTIME_PM_ON_AC = "on"; - # AHCI_RUNTIME_PM_ON_BAT = "on"; - # - # # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep - # RUNTIME_PM_ON_AC = "on"; - # RUNTIME_PM_ON_BAT = "on"; - # }; - # }; - # } - # - # I'm thinking this is too aggressive to put into shared config, and folks may - # be concerned with the hit on battery life. + # See sleep.nix inside this directory for code that allows the system to + # sleep properly (out of the box, it will not) at the cost of battery life. # # throttled vs. thermald # ----------------------- diff --git a/lenovo/thinkpad/p50/sleep.nix b/lenovo/thinkpad/p50/sleep.nix new file mode 100644 index 00000000..fb2f6f80 --- /dev/null +++ b/lenovo/thinkpad/p50/sleep.nix @@ -0,0 +1,41 @@ +# Sleep +# ----- +# +# Without this configuration, the system will not resume from sleep properly +# while on battery power in either offload mode or sync mode. When it tries to +# resume, it gets to a state with a cursor in the top left hand side of the +# panel, the power LED goes from flashing to solid, and thereafter cannot be +# interacted with (even over SSH) and must be power cycled forcefully. +# Sometimes it doesn't even finish going to sleep before this behavior kicks +# in. +# +# When on AC, the machine either wakes up from sleep before being asked to +# (or maybe never gets to sleep state), or it goes into a sleep state and it +# appears consistently resume properly when it does. +# +# But the machine actually sleeps and resumes reliably when tlp is disabled +# fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be +# enough to allow it to work when tlp is active. This will negatively effect +# battery life. I couldn't figure out a more granular way to get it working, +# despite trying to do a per-device binary search via powertop. +# + +{config, lib, ...}: + +{ + services.tlp = { + settings = { + # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. + DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; + + # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 + # can't resume from sleep and P50 can't go to sleep. + AHCI_RUNTIME_PM_ON_AC = "on"; + AHCI_RUNTIME_PM_ON_BAT = "on"; + + # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep + RUNTIME_PM_ON_AC = "on"; + RUNTIME_PM_ON_BAT = "on"; + }; + }; +} diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index 9fa04196..01d3c650 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -23,50 +23,8 @@ }; }; - # Sleep - # ----- - # - # The system will not resume from sleep properly while on battery power in - # either offload mode or sync mode. When it tries to resume, it gets to a - # state with a cursor in the top left hand side of the panel, the power LED - # goes from flashing to solid, and thereafter cannot be interacted with (even - # over SSH) and must be power cycled forcefully. Sometimes it doesn't even - # finish going to sleep before this behavior kicks in. - # - # When on AC, the machine either wakes up from sleep before being asked to - # (or maybe never gets to sleep state), or it goes into a sleep state and it - # appears consistently resume properly when it does. - # - # But the machine actually sleeps and resumes reliably when tlp is disabled - # fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be - # enough to allow it to work when tlp is active. I couldn't figure out a - # more granular way to get it working, despite trying to do a per-device - # binary search via powertop. - # - # My personal configuration to make sleep work looks like this: - # - # {config, lib, ...}: - # - # { - # services.tlp = { - # settings = { - # # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. - # DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; - # - # # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 - # # can't resume from sleep and P50 can't go to sleep. - # AHCI_RUNTIME_PM_ON_AC = "on"; - # AHCI_RUNTIME_PM_ON_BAT = "on"; - # - # # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep - # RUNTIME_PM_ON_AC = "on"; - # RUNTIME_PM_ON_BAT = "on"; - # }; - # }; - # } - # - # I'm thinking this is too aggressive to put into shared config, and folks may - # be concerned with the hit on battery life. + # See sleep.nix inside this directory for code that allows the system to + # sleep properly (out of the box, it will not) at the cost of battery life. # # throttled vs. thermald # ----------------------- diff --git a/lenovo/thinkpad/p51/sleep.nix b/lenovo/thinkpad/p51/sleep.nix new file mode 100644 index 00000000..fb2f6f80 --- /dev/null +++ b/lenovo/thinkpad/p51/sleep.nix @@ -0,0 +1,41 @@ +# Sleep +# ----- +# +# Without this configuration, the system will not resume from sleep properly +# while on battery power in either offload mode or sync mode. When it tries to +# resume, it gets to a state with a cursor in the top left hand side of the +# panel, the power LED goes from flashing to solid, and thereafter cannot be +# interacted with (even over SSH) and must be power cycled forcefully. +# Sometimes it doesn't even finish going to sleep before this behavior kicks +# in. +# +# When on AC, the machine either wakes up from sleep before being asked to +# (or maybe never gets to sleep state), or it goes into a sleep state and it +# appears consistently resume properly when it does. +# +# But the machine actually sleeps and resumes reliably when tlp is disabled +# fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be +# enough to allow it to work when tlp is active. This will negatively effect +# battery life. I couldn't figure out a more granular way to get it working, +# despite trying to do a per-device binary search via powertop. +# + +{config, lib, ...}: + +{ + services.tlp = { + settings = { + # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. + DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; + + # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 + # can't resume from sleep and P50 can't go to sleep. + AHCI_RUNTIME_PM_ON_AC = "on"; + AHCI_RUNTIME_PM_ON_BAT = "on"; + + # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep + RUNTIME_PM_ON_AC = "on"; + RUNTIME_PM_ON_BAT = "on"; + }; + }; +} From 005e19d6f06b086f82c10a28ff6d9c2c036f4471 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 7 Jul 2022 09:31:42 -0400 Subject: [PATCH 03/10] required to make wireless work --- lenovo/thinkpad/p50/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index f1f6038b..dd8a3950 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -22,6 +22,9 @@ }; }; + # reqired to make wireless work + hardware.enableAllFirmware = true; + # See sleep.nix inside this directory for code that allows the system to # sleep properly (out of the box, it will not) at the cost of battery life. # From 22cdffc9253f3e37baf41468893fe604e735a8ad Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 7 Jul 2022 10:00:40 -0400 Subject: [PATCH 04/10] turns out hardware.enableAllFirmware is also required for p51 wireless --- lenovo/thinkpad/p51/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index 01d3c650..fd4d6f49 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -23,6 +23,9 @@ }; }; + # reqired to make wireless work + hardware.enableAllFirmware = true; + # See sleep.nix inside this directory for code that allows the system to # sleep properly (out of the box, it will not) at the cost of battery life. # From bd873a980740c1cbd9d2982ebd12067af3397b09 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 9 Jul 2022 04:36:30 -0400 Subject: [PATCH 05/10] cannot replicate sleep problem without external monitor or any usb device plugged in --- lenovo/thinkpad/p50/default.nix | 9 +++----- lenovo/thinkpad/p50/sleep.nix | 41 --------------------------------- lenovo/thinkpad/p51/default.nix | 5 +--- lenovo/thinkpad/p51/sleep.nix | 41 --------------------------------- 4 files changed, 4 insertions(+), 92 deletions(-) delete mode 100644 lenovo/thinkpad/p50/sleep.nix delete mode 100644 lenovo/thinkpad/p51/sleep.nix diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index dd8a3950..e9523fce 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, pkgs, ... }: { imports = [ ../../../common/gpu/nvidia.nix @@ -22,12 +22,9 @@ }; }; - # reqired to make wireless work + # required to make wireless work hardware.enableAllFirmware = true; - - # See sleep.nix inside this directory for code that allows the system to - # sleep properly (out of the box, it will not) at the cost of battery life. - # + # throttled vs. thermald # ----------------------- # diff --git a/lenovo/thinkpad/p50/sleep.nix b/lenovo/thinkpad/p50/sleep.nix deleted file mode 100644 index fb2f6f80..00000000 --- a/lenovo/thinkpad/p50/sleep.nix +++ /dev/null @@ -1,41 +0,0 @@ -# Sleep -# ----- -# -# Without this configuration, the system will not resume from sleep properly -# while on battery power in either offload mode or sync mode. When it tries to -# resume, it gets to a state with a cursor in the top left hand side of the -# panel, the power LED goes from flashing to solid, and thereafter cannot be -# interacted with (even over SSH) and must be power cycled forcefully. -# Sometimes it doesn't even finish going to sleep before this behavior kicks -# in. -# -# When on AC, the machine either wakes up from sleep before being asked to -# (or maybe never gets to sleep state), or it goes into a sleep state and it -# appears consistently resume properly when it does. -# -# But the machine actually sleeps and resumes reliably when tlp is disabled -# fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be -# enough to allow it to work when tlp is active. This will negatively effect -# battery life. I couldn't figure out a more granular way to get it working, -# despite trying to do a per-device binary search via powertop. -# - -{config, lib, ...}: - -{ - services.tlp = { - settings = { - # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. - DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; - - # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 - # can't resume from sleep and P50 can't go to sleep. - AHCI_RUNTIME_PM_ON_AC = "on"; - AHCI_RUNTIME_PM_ON_BAT = "on"; - - # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep - RUNTIME_PM_ON_AC = "on"; - RUNTIME_PM_ON_BAT = "on"; - }; - }; -} diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index fd4d6f49..e3fe36c4 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -23,12 +23,9 @@ }; }; - # reqired to make wireless work + # required to make wireless work hardware.enableAllFirmware = true; - # See sleep.nix inside this directory for code that allows the system to - # sleep properly (out of the box, it will not) at the cost of battery life. - # # throttled vs. thermald # ----------------------- # diff --git a/lenovo/thinkpad/p51/sleep.nix b/lenovo/thinkpad/p51/sleep.nix deleted file mode 100644 index fb2f6f80..00000000 --- a/lenovo/thinkpad/p51/sleep.nix +++ /dev/null @@ -1,41 +0,0 @@ -# Sleep -# ----- -# -# Without this configuration, the system will not resume from sleep properly -# while on battery power in either offload mode or sync mode. When it tries to -# resume, it gets to a state with a cursor in the top left hand side of the -# panel, the power LED goes from flashing to solid, and thereafter cannot be -# interacted with (even over SSH) and must be power cycled forcefully. -# Sometimes it doesn't even finish going to sleep before this behavior kicks -# in. -# -# When on AC, the machine either wakes up from sleep before being asked to -# (or maybe never gets to sleep state), or it goes into a sleep state and it -# appears consistently resume properly when it does. -# -# But the machine actually sleeps and resumes reliably when tlp is disabled -# fully or partially. Disabling RUNTIME_PM and AHCI_RUNTIME_PM appears to be -# enough to allow it to work when tlp is active. This will negatively effect -# battery life. I couldn't figure out a more granular way to get it working, -# despite trying to do a per-device binary search via powertop. -# - -{config, lib, ...}: - -{ - services.tlp = { - settings = { - # DISK_DEVICES must be specified for AHCI_RUNTIME_PM settings to work right. - DISK_DEVICES = "nvme0n1 nvme1n1 sda sdb"; - - # with AHCI_RUNTIME_PM_ON_AC/BAT set to defaults in battery mode, P51 - # can't resume from sleep and P50 can't go to sleep. - AHCI_RUNTIME_PM_ON_AC = "on"; - AHCI_RUNTIME_PM_ON_BAT = "on"; - - # with RUNTIME_PM_ON_BAT/AC set to defaults, P50/P51 can't go to sleep - RUNTIME_PM_ON_AC = "on"; - RUNTIME_PM_ON_BAT = "on"; - }; - }; -} From 47cb2be872750256d5749c9462baae8c69042783 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 10 Jul 2022 19:13:48 -0400 Subject: [PATCH 06/10] mkDefault consistency --- lenovo/thinkpad/p50/default.nix | 6 +++--- lenovo/thinkpad/p51/default.nix | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index e9523fce..4b249bf8 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -10,8 +10,8 @@ hardware = { nvidia = { prime = { - intelBusId = "PCI:0:2:0"; - nvidiaBusId = "PCI:1:0:0"; + intelBusId = lib.mkDefault "PCI:0:2:0"; + nvidiaBusId = lib.mkDefault "PCI:1:0:0"; }; }; @@ -23,7 +23,7 @@ }; # required to make wireless work - hardware.enableAllFirmware = true; + hardware.enableAllFirmware = lib.mkDefault true; # throttled vs. thermald # ----------------------- diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index e3fe36c4..0b3d16bb 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -11,8 +11,8 @@ hardware = { nvidia = { prime = { - intelBusId = "PCI:0:2:0"; - nvidiaBusId = "PCI:1:0:0"; + intelBusId = lib.mkDefault "PCI:0:2:0"; + nvidiaBusId = lib.mkDefault "PCI:1:0:0"; }; }; @@ -24,7 +24,7 @@ }; # required to make wireless work - hardware.enableAllFirmware = true; + hardware.enableAllFirmware = lib.mkDefault true; # throttled vs. thermald # ----------------------- From 20530b31ef90a9a9a28089251bfaf4f16b2894a2 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 11 Jul 2022 14:04:34 -0400 Subject: [PATCH 07/10] flake changes --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 06d488c9..9e35d0ff 100644 --- a/flake.nix +++ b/flake.nix @@ -66,6 +66,8 @@ lenovo-thinkpad-p1 = import ./lenovo/thinkpad/p1; lenovo-thinkpad-p1-gen3 = import ./lenovo/thinkpad/p1/3th-gen; lenovo-thinkpad-p14s-amd-gen2 = import ./lenovo/thinkpad/p14s/amd/gen2; + lenovo-thinkpad-p50 = import ./lenovo/thinkpad/p50; + lenovo-thinkpad-p51 = import ./lenovo/thinkpad/p51; lenovo-thinkpad-p53 = import ./lenovo/thinkpad/p53; lenovo-thinkpad-t14 = import ./lenovo/thinkpad/t14; lenovo-thinkpad-t14-amd-gen1 = import ./lenovo/thinkpad/t14/amd/gen1; From 6261a2842933491190fb2d20959513a252afb7af Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 12 Jul 2022 20:01:42 -0400 Subject: [PATCH 08/10] conditionally turn on power management and modesetting when we are in sync mode --- lenovo/thinkpad/p50/default.nix | 15 +++++++++++++-- lenovo/thinkpad/p51/default.nix | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index 4b249bf8..04f88cf2 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -1,5 +1,4 @@ -{ lib, pkgs, ... }: -{ +{ lib, config, ... }: { imports = [ ../../../common/gpu/nvidia.nix ../../../common/cpu/intel @@ -25,6 +24,18 @@ # required to make wireless work hardware.enableAllFirmware = lib.mkDefault true; + # fix suspend/resume screen corruption in sync mode + hardware.nvidia.powerManagement = + lib.mkIf config.hardware.nvidia.prime.sync.enable { + enable = lib.mkDefault true; + }; + + # fix screen tearing in sync mode + hardware.nvidia.modesetting = + lib.mkIf config.hardware.nvidia.prime.sync.enable { + enable = lib.mkDefault true; + }; + # throttled vs. thermald # ----------------------- # diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index 0b3d16bb..d3de7949 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -1,5 +1,4 @@ -{ lib, ... }: -{ +{ config, lib, ... }: { imports = [ ../../../common/gpu/nvidia.nix ../../../common/cpu/intel @@ -26,6 +25,18 @@ # required to make wireless work hardware.enableAllFirmware = lib.mkDefault true; + # fix suspend/resume screen corruption in sync mode + hardware.nvidia.powerManagement = + lib.mkIf config.hardware.nvidia.prime.sync.enable { + enable = lib.mkDefault true; + }; + + # fix screen tearing in sync mode + hardware.nvidia.modesetting = + lib.mkIf config.hardware.nvidia.prime.sync.enable { + enable = lib.mkDefault true; + }; + # throttled vs. thermald # ----------------------- # From a3f33268997e8cbbd11927abc60d21de0995b458 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 12 Jul 2022 23:01:26 -0400 Subject: [PATCH 09/10] add comment about normalizing dpi between sync and offload mode --- lenovo/thinkpad/p50/default.nix | 5 +++++ lenovo/thinkpad/p51/default.nix | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lenovo/thinkpad/p50/default.nix b/lenovo/thinkpad/p50/default.nix index 04f88cf2..48cf6054 100644 --- a/lenovo/thinkpad/p50/default.nix +++ b/lenovo/thinkpad/p50/default.nix @@ -36,6 +36,11 @@ enable = lib.mkDefault true; }; + # Make the DPI the same in sync mode as in offload mode (disabled because + # these thinkpads come with many kinds of screens, but this is valid for the + # 1920x1080 ones) + #services.xserver.dpi = 96; + # throttled vs. thermald # ----------------------- # diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index d3de7949..ff6cbdfd 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -37,6 +37,11 @@ enable = lib.mkDefault true; }; + # Make the DPI the same in sync mode as in offload mode (disabled because + # these thinkpads come with many kinds of screens, but this is valid for the + # 1920x1080 ones) + #services.xserver.dpi = 96; + # throttled vs. thermald # ----------------------- # From 6aafb9960b426b6031b413c55f420ddd38f8e047 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 13 Jul 2022 01:15:35 -0400 Subject: [PATCH 10/10] comment about silencing ACPI errors --- lenovo/thinkpad/p51/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lenovo/thinkpad/p51/default.nix b/lenovo/thinkpad/p51/default.nix index ff6cbdfd..5701c85c 100644 --- a/lenovo/thinkpad/p51/default.nix +++ b/lenovo/thinkpad/p51/default.nix @@ -42,6 +42,9 @@ # 1920x1080 ones) #services.xserver.dpi = 96; + # silence ACPI "errors" at boot shown before NixOS stage 1 output (default is 4) + #boot.consoleLogLevel = 3; + # throttled vs. thermald # ----------------------- #