[module/wakeup] Improve reliability
This commit is contained in:
parent
485b366437
commit
ee8b03375d
|
@ -61,7 +61,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
# Prevent GPP0 from waking up the device!
|
# Prevent GPP0 from waking up the device!
|
||||||
wakeup.toggleDevice = ["GPP0"];
|
wakeup.GPP0 = "disable";
|
||||||
|
|
||||||
services.xserver.videoDrivers = lib.mkForce ["amdgpu"];
|
services.xserver.videoDrivers = lib.mkForce ["amdgpu"];
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,30 +6,47 @@
|
||||||
}: let
|
}: let
|
||||||
cfg = config.wakeup;
|
cfg = config.wakeup;
|
||||||
|
|
||||||
createServiceName = dev: "toggle-acpi-${dev}";
|
mkScript = type: dev: let
|
||||||
createService = dev: {
|
expected =
|
||||||
description = "Toggle ${dev} wakeup setting";
|
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.Type = "oneshot";
|
||||||
serviceConfig.ExecStart = ''
|
serviceConfig.ExecStart = "${mkScript type dev}/bin/wakeup-${type}-${dev}";
|
||||||
/bin/sh -c "${pkgs.coreutils}/bin/echo ${dev} > /proc/acpi/wakeup"
|
wantedBy = ["default.target"];
|
||||||
'';
|
|
||||||
wantedBy = ["multi-user.target"];
|
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
options.wakeup = with lib; {
|
options.wakeup = lib.mkOption {
|
||||||
toggleDevice = mkOption {
|
type = with lib.types; attrsOf (enum ["enable" "disable"]);
|
||||||
type = types.listOf types.str;
|
default = {};
|
||||||
default = [];
|
example = {GPP0 = "disable";};
|
||||||
description = "ACPI devices to toggle as wakeup devices";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config.systemd.services =
|
||||||
systemd.services = let
|
lib.attrsets.mapAttrs' (dev: type: {
|
||||||
pairs = map (dev:
|
name = createServiceName type dev;
|
||||||
lib.attrsets.nameValuePair (createServiceName dev) (createService dev))
|
value = createService type dev;
|
||||||
cfg.toggleDevice;
|
})
|
||||||
in
|
cfg;
|
||||||
builtins.listToAttrs pairs;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue