2021-12-05 22:40:24 +03:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2020-09-23 13:44:40 +03:00
|
|
|
|
|
|
|
let
|
2021-12-05 22:40:24 +03:00
|
|
|
inherit (lib) literalExpression mkOption mkEnableOption types mkIf mkMerge optional versionOlder;
|
2020-09-23 13:44:40 +03:00
|
|
|
cfg = config.hardware.system76;
|
2021-12-05 22:40:24 +03:00
|
|
|
opt = options.hardware.system76;
|
2020-09-23 13:44:40 +03:00
|
|
|
|
|
|
|
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 {
|
2021-04-07 05:12:33 +03:00
|
|
|
# Make system76-firmware-cli usable by root from the command line.
|
|
|
|
environment.systemPackages = [ firmware-pkg ];
|
|
|
|
|
2020-09-23 13:44:40 +03:00
|
|
|
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" ];
|
|
|
|
};
|
|
|
|
};
|
2021-06-12 12:35:19 +03:00
|
|
|
|
2021-06-26 16:16:59 +03:00
|
|
|
power-pkg = config.boot.kernelPackages.system76-power;
|
2021-06-12 12:35:19 +03:00
|
|
|
powerConfig = mkIf cfg.power-daemon.enable {
|
|
|
|
# Make system76-power usable by root from the command line.
|
|
|
|
environment.systemPackages = [ power-pkg ];
|
|
|
|
|
|
|
|
services.dbus.packages = [ power-pkg ];
|
|
|
|
|
|
|
|
systemd.services.system76-power = {
|
|
|
|
description = "System76 Power Daemon";
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${power-pkg}/bin/system76-power daemon";
|
|
|
|
Restart = "on-failure";
|
|
|
|
Type = "dbus";
|
|
|
|
BusName = "com.system76.PowerDaemon";
|
|
|
|
};
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
};
|
2020-09-23 13:44:40 +03:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
hardware.system76 = {
|
|
|
|
enableAll = mkEnableOption (lib.mdDoc "all recommended configuration for system76 systems");
|
|
|
|
|
|
|
|
firmware-daemon.enable = mkOption {
|
|
|
|
default = cfg.enableAll;
|
2021-12-05 22:40:24 +03:00
|
|
|
defaultText = literalExpression "config.${opt.enableAll}";
|
2020-09-23 13:44:40 +03:00
|
|
|
example = true;
|
|
|
|
description = lib.mdDoc "Whether to enable the system76 firmware daemon";
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
kernel-modules.enable = mkOption {
|
|
|
|
default = cfg.enableAll;
|
2021-12-05 22:40:24 +03:00
|
|
|
defaultText = literalExpression "config.${opt.enableAll}";
|
2020-09-23 13:44:40 +03:00
|
|
|
example = true;
|
|
|
|
description = lib.mdDoc "Whether to make the system76 out-of-tree kernel modules available";
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2021-06-12 12:35:19 +03:00
|
|
|
|
|
|
|
power-daemon.enable = mkOption {
|
|
|
|
default = cfg.enableAll;
|
2021-12-05 22:40:24 +03:00
|
|
|
defaultText = literalExpression "config.${opt.enableAll}";
|
2021-06-12 12:35:19 +03:00
|
|
|
example = true;
|
|
|
|
description = lib.mdDoc "Whether to enable the system76 power daemon";
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2020-09-23 13:44:40 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-12 12:35:19 +03:00
|
|
|
config = mkMerge [ moduleConfig firmwareConfig powerConfig ];
|
2020-09-23 13:44:40 +03:00
|
|
|
}
|