1 { config, lib, options, pkgs, ... }:
4 inherit (lib) literalExpression mkOption mkEnableOption types mkIf mkMerge optional versionOlder;
5 cfg = config.hardware.system76;
6 opt = options.hardware.system76;
8 kpkgs = config.boot.kernelPackages;
9 modules = [ "system76" "system76-io" ] ++ (optional (versionOlder kpkgs.kernel.version "5.5") "system76-acpi");
10 modulePackages = map (m: kpkgs.${m}) modules;
11 moduleConfig = mkIf cfg.kernel-modules.enable {
12 boot.extraModulePackages = modulePackages;
14 boot.kernelModules = modules;
16 services.udev.packages = modulePackages;
19 firmware-pkg = pkgs.system76-firmware;
20 firmwareConfig = mkIf cfg.firmware-daemon.enable {
21 # Make system76-firmware-cli usable by root from the command line.
22 environment.systemPackages = [ firmware-pkg ];
24 services.dbus.packages = [ firmware-pkg ];
26 systemd.services.system76-firmware-daemon = {
27 description = "The System76 Firmware Daemon";
30 ExecStart = "${firmware-pkg}/bin/system76-firmware-daemon";
32 Restart = "on-failure";
35 wantedBy = [ "multi-user.target" ];
39 power-pkg = config.boot.kernelPackages.system76-power;
40 powerConfig = mkIf cfg.power-daemon.enable {
41 # Make system76-power usable by root from the command line.
42 environment.systemPackages = [ power-pkg ];
44 services.dbus.packages = [ power-pkg ];
46 systemd.services.system76-power = {
47 description = "System76 Power Daemon";
49 ExecStart = "${power-pkg}/bin/system76-power daemon";
50 Restart = "on-failure";
52 BusName = "com.system76.PowerDaemon";
54 wantedBy = [ "multi-user.target" ];
60 enableAll = mkEnableOption "all recommended configuration for system76 systems";
62 firmware-daemon.enable = mkOption {
63 default = cfg.enableAll;
64 defaultText = literalExpression "config.${opt.enableAll}";
66 description = "Whether to enable the system76 firmware daemon";
70 kernel-modules.enable = mkOption {
71 default = cfg.enableAll;
72 defaultText = literalExpression "config.${opt.enableAll}";
74 description = "Whether to make the system76 out-of-tree kernel modules available";
78 power-daemon.enable = mkOption {
79 default = cfg.enableAll;
80 defaultText = literalExpression "config.${opt.enableAll}";
82 description = "Whether to enable the system76 power daemon";
88 config = mkMerge [ moduleConfig firmwareConfig powerConfig ];