diff --git a/nixos/modules/hardware/system-76.nix b/nixos/modules/hardware/system-76.nix index ed661fd3303..3a50c5aa0f0 100644 --- a/nixos/modules/hardware/system-76.nix +++ b/nixos/modules/hardware/system-76.nix @@ -34,6 +34,25 @@ let wantedBy = [ "multi-user.target" ]; }; }; + + power-pkg = pkgs.system76-power; + 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" ]; + }; + }; in { options = { hardware.system76 = { @@ -52,8 +71,15 @@ in { description = "Whether to make the system76 out-of-tree kernel modules available"; type = types.bool; }; + + power-daemon.enable = mkOption { + default = cfg.enableAll; + example = true; + description = "Whether to enable the system76 power daemon"; + type = types.bool; + }; }; }; - config = mkMerge [ moduleConfig firmwareConfig ]; + config = mkMerge [ moduleConfig firmwareConfig powerConfig ]; } diff --git a/pkgs/os-specific/linux/system76-power/default.nix b/pkgs/os-specific/linux/system76-power/default.nix new file mode 100644 index 00000000000..fbc26ca8719 --- /dev/null +++ b/pkgs/os-specific/linux/system76-power/default.nix @@ -0,0 +1,30 @@ +{ pkg-config, libusb1, dbus, lib, rustPlatform, fetchFromGitHub }: + +rustPlatform.buildRustPackage rec { + pname = "system76-power"; + version = "1.1.16"; + + src = fetchFromGitHub { + owner = "pop-os"; + repo = "system76-power"; + rev = version; + sha256 = "sha256-OtrhvUkNNgg6KlrqjwiBKL4zuQZBWevb0xgtSlEW2rQ="; + }; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ dbus libusb1 ]; + + cargoSha256 = "sha256-ImACDbnUbwc0ZXgF3xxzes8+vUjt76B1xxgqzhgAYX4="; + + postInstall = '' + install -D -m 0644 data/system76-power.conf $out/etc/dbus-1/system.d/system76-power.conf + ''; + + meta = with lib; { + description = "System76 Power Management"; + homepage = "https://github.com/pop-os/system76-power"; + license = licenses.gpl3Plus; + platforms = [ "i686-linux" "x86_64-linux" ]; + maintainers = [ maintainers.jwoudenberg ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 34e5d3ab0ba..2dd49d30523 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -20829,6 +20829,8 @@ in system76-acpi = callPackage ../os-specific/linux/system76-acpi { }; + system76-power = callPackage ../os-specific/linux/system76-power { }; + system76-io = callPackage ../os-specific/linux/system76-io { }; tmon = callPackage ../os-specific/linux/tmon { };