From 9a3190a960b9c3e15ce1518b6545b4bc921cf459 Mon Sep 17 00:00:00 2001 From: Matt Votava Date: Mon, 14 Sep 2020 03:49:42 -0700 Subject: [PATCH 1/2] power-profiles-daemon: init at 0.1, add service module --- nixos/modules/module-list.nix | 1 + .../hardware/power-profiles-daemon.nix | 53 +++++++++++++++ .../linux/power-profiles-daemon/default.nix | 66 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 122 insertions(+) create mode 100644 nixos/modules/services/hardware/power-profiles-daemon.nix create mode 100644 pkgs/os-specific/linux/power-profiles-daemon/default.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7a656a58e9c2..f4416a06fc97 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -374,6 +374,7 @@ ./services/hardware/nvidia-optimus.nix ./services/hardware/pcscd.nix ./services/hardware/pommed.nix + ./services/hardware/power-profiles-daemon.nix ./services/hardware/ratbagd.nix ./services/hardware/sane.nix ./services/hardware/sane_extra_backends/brscan4.nix diff --git a/nixos/modules/services/hardware/power-profiles-daemon.nix b/nixos/modules/services/hardware/power-profiles-daemon.nix new file mode 100644 index 000000000000..70b7a72b8bae --- /dev/null +++ b/nixos/modules/services/hardware/power-profiles-daemon.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.power-profiles-daemon; + package = pkgs.power-profiles-daemon; +in + +{ + + ###### interface + + options = { + + services.power-profiles-daemon = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable power-profiles-daemon, a DBus daemon that allows + changing system behavior based upon user-selected power profiles. + ''; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + assertions = [ + { assertion = !config.services.tlp.enable; + message = '' + You have set services.power-profiles-daemon.enable = true; + which conflicts with services.tlp.enable = true; + ''; + } + ]; + + services.dbus.packages = [ package ]; + + services.udev.packages = [ package ]; + + systemd.packages = [ package ]; + + }; + +} diff --git a/pkgs/os-specific/linux/power-profiles-daemon/default.nix b/pkgs/os-specific/linux/power-profiles-daemon/default.nix new file mode 100644 index 000000000000..c477e6f36793 --- /dev/null +++ b/pkgs/os-specific/linux/power-profiles-daemon/default.nix @@ -0,0 +1,66 @@ +{ stdenv +, lib +, pkg-config +, meson +, ninja +, fetchFromGitLab +, libgudev +, glib +, gobject-introspection +, gettext +, gtk-doc +, docbook-xsl-nons +, docbook_xml_dtd_412 +, libxml2 +, libxslt +, upower +, systemd +}: + +stdenv.mkDerivation rec { + pname = "power-profiles-daemon"; + version = "0.1"; + + outputs = [ "out" "devdoc" ]; + + src = fetchFromGitLab { + domain = "gitlab.freedesktop.org"; + owner = "hadess"; + repo = "power-profiles-daemon"; + rev = version; + sha256 = "012w3aryw5d43dr9jj5i6wy2a0n21jidr4ggs9ix7d4z9byr175w"; + }; + + nativeBuildInputs = [ + pkg-config + meson + ninja + gettext + gtk-doc + docbook-xsl-nons + docbook_xml_dtd_412 + libxml2 # for xmllint for stripping GResources + libxslt # for xsltproc for building docs + gobject-introspection + ]; + + buildInputs = [ + libgudev + systemd + upower + glib + ]; + + mesonFlags = [ + "-Dsystemdsystemunitdir=${placeholder "out"}/lib/systemd/system" + "-Dgtk_doc=true" + ]; + + meta = with lib; { + homepage = "https://gitlab.freedesktop.org/hadess/power-profiles-daemon"; + description = "Makes user-selected power profiles handling available over D-Bus"; + platforms = platforms.linux; + license = licenses.gpl3Plus; + maintainers = with maintainers; [ mvnetbiz ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index bd6d5e94e1ae..3b097d27d00c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7173,6 +7173,8 @@ in povray = callPackage ../tools/graphics/povray { }; + power-profiles-daemon = callPackage ../os-specific/linux/power-profiles-daemon { }; + ppl = callPackage ../development/libraries/ppl { }; pplatex = callPackage ../tools/typesetting/tex/pplatex { }; From 65968a1f5948b8c428c42770a5739ebe75cf5a06 Mon Sep 17 00:00:00 2001 From: Matt Votava Date: Tue, 15 Sep 2020 01:15:48 -0700 Subject: [PATCH 2/2] power-profiles-daemon: add test --- nixos/tests/power-profiles-daemon.nix | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 nixos/tests/power-profiles-daemon.nix diff --git a/nixos/tests/power-profiles-daemon.nix b/nixos/tests/power-profiles-daemon.nix new file mode 100644 index 000000000000..422008316f07 --- /dev/null +++ b/nixos/tests/power-profiles-daemon.nix @@ -0,0 +1,45 @@ +import ./make-test-python.nix ({ pkgs, ... }: + +{ + name = "power-profiles-daemon"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ mvnetbiz ]; + }; + machine = { pkgs, ... }: { + services.power-profiles-daemon.enable = true; + environment.systemPackages = [ pkgs.glib ]; + }; + + testScript = '' + def get_profile(): + return machine.succeed( + """gdbus call --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles \ + --method org.freedesktop.DBus.Properties.Get 'net.hadess.PowerProfiles' 'ActiveProfile' + """ + ) + + + def set_profile(profile): + return machine.succeed( + """gdbus call --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles \ + --method org.freedesktop.DBus.Properties.Set 'net.hadess.PowerProfiles' 'ActiveProfile' "<'{profile}'>" + """.format( + profile=profile + ) + ) + + + machine.wait_for_unit("multi-user.target") + + set_profile("power-saver") + profile = get_profile() + if not "power-saver" in profile: + raise Exception("Unable to set power-saver profile") + + + set_profile("balanced") + profile = get_profile() + if not "balanced" in profile: + raise Exception("Unable to set balanced profile") + ''; +})