[module/wakeup] Improve reliability

This commit is contained in:
Malte Tammena 2022-04-23 18:02:17 +02:00
parent 485b366437
commit ee8b03375d
2 changed files with 39 additions and 22 deletions

View file

@ -61,7 +61,7 @@
};
# Prevent GPP0 from waking up the device!
wakeup.toggleDevice = ["GPP0"];
wakeup.GPP0 = "disable";
services.xserver.videoDrivers = lib.mkForce ["amdgpu"];
}

View file

@ -6,30 +6,47 @@
}: let
cfg = config.wakeup;
createServiceName = dev: "toggle-acpi-${dev}";
createService = dev: {
description = "Toggle ${dev} wakeup setting";
mkScript = type: dev: let
expected =
if type == "enable"
then "enabled"
else "disabled";
in
pkgs.writeShellApplication {
name = "wakeup-${type}-${dev}";
runtimeInputs = [pkgs.coreutils];
text = ''
# See if our goal has already been reached and exit if so
if grep "${dev}" /proc/acpi/wakeup | grep ${expected}; then
printf "Wakeup settings are ok.\n"
exit 0
else
printf "Fixing /proc/acpi/wakeup.\n"
echo "${dev}" > /proc/acpi/wakeup
fi
# Verify our actions or fail!
grep "${dev}" /proc/acpi/wakeup | grep ${expected}
'';
};
createServiceName = type: dev: "wakeup-${type}-${dev}";
createService = type: dev: {
description = "${type} ${dev} wakeup setting";
serviceConfig.Type = "oneshot";
serviceConfig.ExecStart = ''
/bin/sh -c "${pkgs.coreutils}/bin/echo ${dev} > /proc/acpi/wakeup"
'';
wantedBy = ["multi-user.target"];
serviceConfig.ExecStart = "${mkScript type dev}/bin/wakeup-${type}-${dev}";
wantedBy = ["default.target"];
};
in {
options.wakeup = with lib; {
toggleDevice = mkOption {
type = types.listOf types.str;
default = [];
description = "ACPI devices to toggle as wakeup devices";
};
options.wakeup = lib.mkOption {
type = with lib.types; attrsOf (enum ["enable" "disable"]);
default = {};
example = {GPP0 = "disable";};
};
config = {
systemd.services = let
pairs = map (dev:
lib.attrsets.nameValuePair (createServiceName dev) (createService dev))
cfg.toggleDevice;
in
builtins.listToAttrs pairs;
};
config.systemd.services =
lib.attrsets.mapAttrs' (dev: type: {
name = createServiceName type dev;
value = createService type dev;
})
cfg;
}