2022-03-23 13:10:18 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
2022-03-12 23:23:53 +01:00
|
|
|
cfg = config.wakeup;
|
|
|
|
|
2022-04-23 18:02:17 +02:00
|
|
|
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";
|
2022-03-15 15:22:22 +01:00
|
|
|
serviceConfig.Type = "oneshot";
|
2022-04-23 18:02:17 +02:00
|
|
|
serviceConfig.ExecStart = "${mkScript type dev}/bin/wakeup-${type}-${dev}";
|
|
|
|
wantedBy = ["default.target"];
|
2022-03-12 23:23:53 +01:00
|
|
|
};
|
|
|
|
in {
|
2022-04-23 18:02:17 +02:00
|
|
|
options.wakeup = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (enum ["enable" "disable"]);
|
|
|
|
default = {};
|
|
|
|
example = {GPP0 = "disable";};
|
2022-03-12 23:23:53 +01:00
|
|
|
};
|
|
|
|
|
2022-04-23 18:02:17 +02:00
|
|
|
config.systemd.services =
|
|
|
|
lib.attrsets.mapAttrs' (dev: type: {
|
|
|
|
name = createServiceName type dev;
|
|
|
|
value = createService type dev;
|
|
|
|
})
|
|
|
|
cfg;
|
2022-03-12 23:23:53 +01:00
|
|
|
}
|