nix: home-manager module fixes

This commit is contained in:
Austin Horstman 2024-02-17 23:03:47 -06:00 committed by Mihai Fufezan
parent 80abfa0dfd
commit c030553b50
1 changed files with 62 additions and 28 deletions

View File

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