2024-02-17 23:02:47 +01:00
|
|
|
self: {
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit (builtins) toString;
|
2024-02-18 06:03:47 +01:00
|
|
|
inherit (lib.types) bool int listOf package str submodule;
|
2024-02-17 23:02:47 +01:00
|
|
|
inherit (lib.modules) mkIf;
|
|
|
|
inherit (lib.options) mkOption mkEnableOption;
|
|
|
|
inherit (lib.meta) getExe;
|
|
|
|
|
|
|
|
cfg = config.services.hypridle;
|
|
|
|
in {
|
|
|
|
options.services.hypridle = {
|
|
|
|
enable = mkEnableOption "Hypridle, Hyprland's idle daemon";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
description = "The hypridle package";
|
|
|
|
type = package;
|
|
|
|
default = self.packages.${pkgs.stdenv.hostPlatform.system}.hypridle;
|
|
|
|
};
|
|
|
|
|
2024-02-18 06:03:47 +01:00
|
|
|
listeners = mkOption {
|
|
|
|
description = "The hypridle listeners";
|
|
|
|
type = listOf (submodule {
|
|
|
|
options = {
|
|
|
|
timeout = mkOption {
|
|
|
|
description = "The timeout for the hypridle service, in seconds";
|
|
|
|
type = int;
|
|
|
|
default = 500;
|
|
|
|
};
|
2024-02-17 23:02:47 +01:00
|
|
|
|
2024-02-18 06:03:47 +01:00
|
|
|
onTimeout = mkOption {
|
|
|
|
description = "The command to run when the timeout is reached";
|
|
|
|
type = str;
|
|
|
|
default = "echo 'timeout reached'";
|
|
|
|
};
|
2024-02-17 23:02:47 +01:00
|
|
|
|
2024-02-18 06:03:47 +01:00
|
|
|
onResume = mkOption {
|
|
|
|
description = "The command to run when the service resumes";
|
|
|
|
type = str;
|
|
|
|
default = "echo 'service resumed'";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2024-02-21 23:54:12 +01:00
|
|
|
default = [];
|
2024-02-17 23:02:47 +01:00
|
|
|
};
|
|
|
|
|
2024-02-18 06:03:47 +01:00
|
|
|
lockCmd = mkOption {
|
2024-02-17 23:02:47 +01:00
|
|
|
description = "The command to run when the service locks";
|
|
|
|
type = str;
|
|
|
|
default = "echo 'lock!'";
|
|
|
|
};
|
|
|
|
|
2024-02-18 06:03:47 +01:00
|
|
|
unlockCmd = mkOption {
|
2024-02-17 23:02:47 +01:00
|
|
|
description = "The command to run when the service unlocks";
|
|
|
|
type = str;
|
|
|
|
default = "echo 'unlock!'";
|
|
|
|
};
|
|
|
|
|
2024-02-18 06:03:47 +01:00
|
|
|
afterSleepCmd = mkOption {
|
|
|
|
description = "The command to run after the service sleeps";
|
|
|
|
type = str;
|
|
|
|
default = "echo 'Awake...'";
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeSleepCmd = mkOption {
|
2024-02-17 23:02:47 +01:00
|
|
|
description = "The command to run before the service sleeps";
|
|
|
|
type = str;
|
|
|
|
default = "echo 'Zzz...'";
|
|
|
|
};
|
2024-02-18 06:03:47 +01:00
|
|
|
|
|
|
|
ignoreDbusInhibit = mkOption {
|
|
|
|
description = "Whether to ignore dbus-sent idle-inhibit requests (used by e.g. firefox or steam)";
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2024-02-17 23:02:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
xdg.configFile."hypr/hypridle.conf".text = ''
|
2024-02-18 06:03:47 +01:00
|
|
|
general {
|
2024-02-17 23:02:47 +01:00
|
|
|
lock_cmd = ${cfg.lockCmd}
|
|
|
|
unlock_cmd = ${cfg.unlockCmd}
|
|
|
|
before_sleep_cmd = ${cfg.beforeSleepCmd}
|
2024-02-18 06:03:47 +01:00
|
|
|
after_sleep_cmd = ${cfg.afterSleepCmd}
|
|
|
|
ignore_dbus_inhibit = ${
|
|
|
|
if cfg.ignoreDbusInhibit
|
|
|
|
then "true"
|
|
|
|
else "false"
|
|
|
|
}
|
2024-02-17 23:02:47 +01:00
|
|
|
}
|
2024-02-18 06:03:47 +01:00
|
|
|
|
|
|
|
${builtins.concatStringsSep "\n" (map (listener: ''
|
|
|
|
listener {
|
|
|
|
timeout = ${toString listener.timeout}
|
|
|
|
on-timeout = ${listener.onTimeout}
|
|
|
|
on-resume = ${listener.onResume}
|
|
|
|
}
|
|
|
|
'')
|
|
|
|
cfg.listeners)}
|
2024-02-17 23:02:47 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.user.services.hypridle = {
|
2024-02-18 06:03:47 +01:00
|
|
|
Unit = {
|
|
|
|
Description = "Hypridle";
|
|
|
|
After = ["graphical-session.target"];
|
|
|
|
};
|
|
|
|
|
|
|
|
Service = {
|
2024-02-17 23:02:47 +01:00
|
|
|
ExecStart = "${getExe cfg.package}";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "10";
|
|
|
|
};
|
2024-02-19 00:56:14 +01:00
|
|
|
|
|
|
|
Install.WantedBy = [ "default.target" ];
|
2024-02-17 23:02:47 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|