From 0c5f176147e15b2e402deeedc20870d4a57747f2 Mon Sep 17 00:00:00 2001 From: Bryan Gardiner Date: Sun, 23 Aug 2020 16:42:07 -0700 Subject: [PATCH 1/4] Add support for System76 hardware, specifically the Darter Pro 6. This relies on new `system76`, `system76-acpi`, and `system76-io` packages in `linuxPackages` in Nixpkgs. --- CODEOWNERS | 1 + README.md | 4 ++++ flake.nix | 2 ++ system76/darp6/default.nix | 27 +++++++++++++++++++++++++++ system76/default.nix | 22 ++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 system76/darp6/default.nix create mode 100644 system76/default.nix diff --git a/CODEOWNERS b/CODEOWNERS index 4f2bb2cc..1bbf05e4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -5,3 +5,4 @@ lenovo/thinkpad/x230 @makefu @yegortimoshenko lenovo/thinkpad/x250 @Mic92 pcengines/apu @yegortimoshenko purism/librem/13v3 @yegortimoshenko +system76/darp6 @khumba diff --git a/README.md b/README.md index 4d23e8d1..0af8c290 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ See code for all available configurations. | [Purism Librem 15v3][] | `` | | Supermicro A1SRi-2758F | `` | | Supermicro X10SLL-F | `` | +| [System76 (generic)][] | `` | +| [System76 Darter Pro 6][] | `` | | [Toshiba Chromebook 2 `swanky`][] | `` | | [Tuxedo InfinityBook v4][] | `` | @@ -151,6 +153,8 @@ See code for all available configurations. [Microsoft Surface Pro 3]: microsoft/surface-pro/3 [Raspberry Pi 2]: raspberry-pi/2 [Samsung Series 9 NP900X3C]: samsung/np900x3c +[System76 (generic)]: system76 +[System76 Darter Pro 6]: system76/darp6 [Purism Librem 13v3]: purism/librem/13v3 [Purism Librem 15v5]: purism/librem/15v5 [Toshiba Chromebook 2 `swanky`]: toshiba/swanky diff --git a/flake.nix b/flake.nix index 43fb6fcc..31d61c43 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,8 @@ pcengines-apu = import ./pcengines/apu; raspberry-pi-2 = import ./raspberry-pi/2; samsung-np900x3c = import ./samsung/np900x3c; + system76 = import ./system76; + system76-darp6 = import ./system76/darp6; purism-librem-13v3 = import ./purism/librem/13v3; purism-librem-15v3 = import ./purism/librem/15v3; supermicro-a1sri-2758f = import ./supermicro/a1sri-2758f; diff --git a/system76/darp6/default.nix b/system76/darp6/default.nix new file mode 100644 index 00000000..545523d5 --- /dev/null +++ b/system76/darp6/default.nix @@ -0,0 +1,27 @@ +# Hardware profile for the Darter Pro 6 laptop by System76. +# +# https://system76.com/laptops/darter + +{ config, ... }: +let + # darp6 needs system76-acpi-dkms, not system76-dkms: + # + # [1] https://github.com/pop-os/system76-dkms/issues/39 + # jackpot51> system76-acpi-dkms is the correct driver to use on the darp6 + # + # system76-io-dkms also appears to be loaded on darp6 with Pop!_OS, and + # system76-dkms does not, and in fact refuses to load. + packages = with config.boot.kernelPackages; [ system76-acpi system76-io ]; +in +{ + imports = [ + ../../common/pc/laptop + ../../common/pc/laptop/ssd + ]; + + boot.extraModulePackages = packages; + + # system76_acpi automatically loads on darp6, but system76_io does not. + # Explicitly list all modules to be loaded, for consistency. + boot.kernelModules = map (drv: drv.moduleName) packages; +} diff --git a/system76/default.nix b/system76/default.nix new file mode 100644 index 00000000..64b10322 --- /dev/null +++ b/system76/default.nix @@ -0,0 +1,22 @@ +# Implementation of support for general System76 hardware. +# +# https://system76.com/ + +{ config, ... }: +let + # Try loading all system76 modules. The ones not relevant to specific + # hardware won't be loaded. + packages = with config.boot.kernelPackages; [ system76 system76-acpi system76-io ]; +in +{ + imports = [ ../common/pc ]; + + # This seems to be required for system76-driver. + boot.kernelParams = [ "ec_sys.write_support=1" ]; + + boot.extraModulePackages = packages; + + # Explicitly attempt to load all available system76 modules. Some do + # (system76-acpi), some don't (system76-io). + boot.kernelModules = map (drv: drv.moduleName) packages; +} From 602f9d86c630d0daaaf6371fa77b2a04cca86626 Mon Sep 17 00:00:00 2001 From: Bryan Gardiner Date: Sat, 12 Sep 2020 22:33:04 -0700 Subject: [PATCH 2/4] Add options for applying the darp6 headset fixup. --- system76/darp6/default.nix | 86 +++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/system76/darp6/default.nix b/system76/darp6/default.nix index 545523d5..552c5e95 100644 --- a/system76/darp6/default.nix +++ b/system76/darp6/default.nix @@ -2,8 +2,20 @@ # # https://system76.com/laptops/darter -{ config, ... }: +{ config, lib, options, pkgs, ... }: let + cfg = config.hardware.system76.darp6; + + # Allow silencing the warning about these options if either is defined. + soundSettingsDefined = + options.hardware.system76.darp6.soundVendorId.isDefined || + options.hardware.system76.darp6.soundSubsystemId.isDefined; + + # We neeed both options non-null to be able to apply the headset fixup though. + soundSettingsAvailable = + soundSettingsDefined && + (cfg.soundVendorId != null && cfg.soundSubsystemId != null); + # darp6 needs system76-acpi-dkms, not system76-dkms: # # [1] https://github.com/pop-os/system76-dkms/issues/39 @@ -19,9 +31,73 @@ in ../../common/pc/laptop/ssd ]; - boot.extraModulePackages = packages; + options.hardware.system76.darp6 = { + soundVendorId = lib.mkOption { + type = with lib.types; nullOr (strMatching "0x[0-9a-f]{8}"); + description = '' + The vendor ID of the sound card PCI device, for applying the headset fixup. + This should be set to the value of the following file on your Darter Pro: + /sys/class/sound/hwC0D0/vendor_id + If this option has the default null value, then the headset fixup will + not be applied. + ''; + }; + soundSubsystemId = lib.mkOption { + type = with lib.types; nullOr (strMatching "0x[0-9a-f]{8}"); + description = '' + The subsystem ID of the sound card PCI device, for applying the headset fixup. + This should be set to the value of the following file on your Darter Pro: + /sys/class/sound/hwC0D0/subsystem_id + If this option has the default null value, then the headset fixup will + not be applied. + ''; + }; + }; - # system76_acpi automatically loads on darp6, but system76_io does not. - # Explicitly list all modules to be loaded, for consistency. - boot.kernelModules = map (drv: drv.moduleName) packages; + config = lib.mkMerge [ + { + boot.extraModulePackages = packages; + + # system76_acpi automatically loads on darp6, but system76_io does not. + # Explicitly list all modules to be loaded, for consistency. + boot.kernelModules = map (drv: drv.moduleName) packages; + + warnings = lib.optional (!soundSettingsDefined) '' + For full Darter Pro support, set the options: + - hardware.system76.darp76.soundVendorId + - hardware.system76.darp76.soundSubsystemId + You can copy these values directly from: + - /sys/class/sound/hwC0D0/vendor_id + - /sys/class/sound/hwC0D0/subsystem_id + The headset audio fixup will not be applied without these values. + Set these options to null to silence this warning. + ''; + } + + # Apply the headset fixup patch from system76-driver, if the necessary + # options have been provided. + # + # See occurrences of "darp" in: + # https://github.com/pop-os/system76-driver/blob/master/system76driver/actions.py + # https://github.com/pop-os/system76-driver/blob/master/system76driver/products.py + (lib.mkIf soundSettingsAvailable { + boot.extraModprobeConfig = '' + options snd-hda-intel model=headset-mode-no-hp-mic patch=system76-audio-patch + ''; + + hardware.firmware = [ + (pkgs.writeTextFile { + name = "system76-audio-patch"; + destination = "/lib/firmware/system76-audio-patch"; + text = '' + [codec] + ${cfg.soundVendorId} ${cfg.soundSubsystemId} 0 + + [pincfg] + 0x1a 0x01a1913c + ''; + }) + ]; + }) + ]; } From d86324ba69da76cb9ceb87000172ebb896947a03 Mon Sep 17 00:00:00 2001 From: Bryan Gardiner Date: Sat, 10 Oct 2020 19:33:59 -0700 Subject: [PATCH 3/4] system76: Update configs to use the module from Nixpkgs. --- system76/darp6/default.nix | 24 +++++++++--------------- system76/default.nix | 13 ++----------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/system76/darp6/default.nix b/system76/darp6/default.nix index 552c5e95..3f93993e 100644 --- a/system76/darp6/default.nix +++ b/system76/darp6/default.nix @@ -1,6 +1,14 @@ # Hardware profile for the Darter Pro 6 laptop by System76. # # https://system76.com/laptops/darter +# +# Regarding kernel modules, darp6 needs system76-acpi-dkms, not system76-dkms: +# +# [1] https://github.com/pop-os/system76-dkms/issues/39 +# jackpot51> system76-acpi-dkms is the correct driver to use on the darp6 +# +# system76-io-dkms also appears to be loaded on darp6 with Pop!_OS, and +# system76-dkms does not, and in fact refuses to load. { config, lib, options, pkgs, ... }: let @@ -15,18 +23,10 @@ let soundSettingsAvailable = soundSettingsDefined && (cfg.soundVendorId != null && cfg.soundSubsystemId != null); - - # darp6 needs system76-acpi-dkms, not system76-dkms: - # - # [1] https://github.com/pop-os/system76-dkms/issues/39 - # jackpot51> system76-acpi-dkms is the correct driver to use on the darp6 - # - # system76-io-dkms also appears to be loaded on darp6 with Pop!_OS, and - # system76-dkms does not, and in fact refuses to load. - packages = with config.boot.kernelPackages; [ system76-acpi system76-io ]; in { imports = [ + ../. ../../common/pc/laptop ../../common/pc/laptop/ssd ]; @@ -56,12 +56,6 @@ in config = lib.mkMerge [ { - boot.extraModulePackages = packages; - - # system76_acpi automatically loads on darp6, but system76_io does not. - # Explicitly list all modules to be loaded, for consistency. - boot.kernelModules = map (drv: drv.moduleName) packages; - warnings = lib.optional (!soundSettingsDefined) '' For full Darter Pro support, set the options: - hardware.system76.darp76.soundVendorId diff --git a/system76/default.nix b/system76/default.nix index 64b10322..e09a9897 100644 --- a/system76/default.nix +++ b/system76/default.nix @@ -2,21 +2,12 @@ # # https://system76.com/ -{ config, ... }: -let - # Try loading all system76 modules. The ones not relevant to specific - # hardware won't be loaded. - packages = with config.boot.kernelPackages; [ system76 system76-acpi system76-io ]; -in +{ config, lib, ... }: { imports = [ ../common/pc ]; # This seems to be required for system76-driver. boot.kernelParams = [ "ec_sys.write_support=1" ]; - boot.extraModulePackages = packages; - - # Explicitly attempt to load all available system76 modules. Some do - # (system76-acpi), some don't (system76-io). - boot.kernelModules = map (drv: drv.moduleName) packages; + hardware.system76.enableAll = lib.mkDefault true; } From fdc0812787828fd4a373f9c4c80cbb8d862b3f22 Mon Sep 17 00:00:00 2001 From: Bryan Gardiner Date: Mon, 12 Oct 2020 18:06:11 -0700 Subject: [PATCH 4/4] system76: Remove kernel param ec_sys.write_support=1. I don't think we need this in the generic configuration. There is a call to `modprobe ec_sys.write_support=1` in system76-driver, only for the airplane mode daemon (which only applies to certain models, not including darp6), and the driver executes the modprobe call anyhow. Also the kernel's documentation for the parameter says: write_support:Dangerous, reboot and removal of battery may be needed. (bool) So let's only enable this where it's required. --- system76/default.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/system76/default.nix b/system76/default.nix index e09a9897..8a881c04 100644 --- a/system76/default.nix +++ b/system76/default.nix @@ -6,8 +6,5 @@ { imports = [ ../common/pc ]; - # This seems to be required for system76-driver. - boot.kernelParams = [ "ec_sys.write_support=1" ]; - hardware.system76.enableAll = lib.mkDefault true; }