From 4b1850bad3c8cba93ffb12041da1a530cbe03c6d Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Wed, 23 Sep 2020 06:44:40 -0400 Subject: [PATCH] Add system76 NixOS module --- nixos/modules/hardware/system-76.nix | 56 ++++++++++++++++++++++++++++ nixos/modules/module-list.nix | 1 + 2 files changed, 57 insertions(+) create mode 100644 nixos/modules/hardware/system-76.nix diff --git a/nixos/modules/hardware/system-76.nix b/nixos/modules/hardware/system-76.nix new file mode 100644 index 0000000000000..48eb63f4f22de --- /dev/null +++ b/nixos/modules/hardware/system-76.nix @@ -0,0 +1,56 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkOption mkEnableOption types mkIf mkMerge optional versionOlder; + cfg = config.hardware.system76; + + kpkgs = config.boot.kernelPackages; + modules = [ "system76" "system76-io" ] ++ (optional (versionOlder kpkgs.kernel.version "5.5") "system76-acpi"); + modulePackages = map (m: kpkgs.${m}) modules; + moduleConfig = mkIf cfg.kernel-modules.enable { + boot.extraModulePackages = modulePackages; + + boot.kernelModules = modules; + + services.udev.packages = modulePackages; + }; + + firmware-pkg = pkgs.system76-firmware; + firmwareConfig = mkIf cfg.firmware-daemon.enable { + services.dbus.packages = [ firmware-pkg ]; + + systemd.services.system76-firmware-daemon = { + description = "The System76 Firmware Daemon"; + + serviceConfig = { + ExecStart = "${firmware-pkg}/bin/system76-firmware-daemon"; + + Restart = "on-failure"; + }; + + wantedBy = [ "multi-user.target" ]; + }; + }; +in { + options = { + hardware.system76 = { + enableAll = mkEnableOption "all recommended configuration for system76 systems"; + + firmware-daemon.enable = mkOption { + default = cfg.enableAll; + example = true; + description = "Whether to enable the system76 firmware daemon"; + type = types.bool; + }; + + kernel-modules.enable = mkOption { + default = cfg.enableAll; + example = true; + description = "Whether to make the system76 out-of-tree kernel modules available"; + type = types.bool; + }; + }; + }; + + config = mkMerge [ moduleConfig firmwareConfig ]; +} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index e7e5fbb4f3f27..96529424e8f12 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -60,6 +60,7 @@ ./hardware/printers.nix ./hardware/raid/hpsa.nix ./hardware/steam-hardware.nix + ./hardware/system-76.nix ./hardware/tuxedo-keyboard.nix ./hardware/usb-wwan.nix ./hardware/onlykey.nix