diff options
author | Profpatsch <mail@profpatsch.de> | 2022-03-16 17:21:22 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2022-03-16 17:22:17 +0100 |
commit | 652ac49da16123016c36537dc28331649a63bf7b (patch) | |
tree | a69f2488877c416a7b1c0a9b51e691830e549d12 /modules/services/upower-minimal.nix | |
parent | 57c8f476c83847f90dda16327aa76bb11f912e88 (diff) |
machines/profpatsch/base-workstation: add upower with suspend
Upstream is dumb, but the tool is certainly useful, so let’s patch it to make it workable and then also patch the nixos module …
Diffstat (limited to 'modules/services/upower-minimal.nix')
-rw-r--r-- | modules/services/upower-minimal.nix | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/modules/services/upower-minimal.nix b/modules/services/upower-minimal.nix new file mode 100644 index 00000000..25de830d --- /dev/null +++ b/modules/services/upower-minimal.nix @@ -0,0 +1,84 @@ +# this is the +# Upower daemon. +# module from nixpkgs, but with the option to suspend and less configuration + +{ config, lib, pkgs, ... }: + +let + + cfg = config.vuizvui.services.upower; + + ini = pkgs.formats.ini {}; + + pkg = pkgs.upower.overrideAttrs (old: { + patches = [ + # Adds a "Suspend" action to what to do when the battery is critical + (pkgs.fetchpatch { + url = "https://gitlab.freedesktop.org/upower/upower/-/merge_requests/11.patch"; + sha256 = "sha256-y8ysD+fJIi5SZkWp2n061VBA5cs1EMftOof/h2tvDGo="; + }) + ]; + }); + +in + +{ + + ###### interface + + options = { + + vuizvui.services.upower = { + + enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether to enable Upower, a DBus service that provides power + management support to applications. + ''; + }; + + settings = lib.mkOption { + type = lib.types.nullOr ini.type; + default = null; + description = '' + The upower configuration. + + If null, the default values in <literal>${pkg}/etc/UPower/UPower.conf<literal> are used. + + So far it looks like there is always only one Section called <literal>UPower</literal> + ''; + example = { + UPower = { + TimeCritical = 300; + CriticalPowerAction = "Hibernate"; + }; + }; + }; + + }; + + }; + + + ###### implementation + + config = lib.mkIf cfg.enable { + + + # this is … questionable … l o w e f f o r t + + environment.systemPackages = [ pkg ]; + + services.dbus.packages = [ pkg ]; + + services.udev.packages = [ pkg ]; + + systemd.packages = [ pkg ]; + + environment.etc."UPower/UPower.conf".source = + ini.generate "UPower.conf" cfg.settings; + }; + +} |