36a53d9f26
This process was automated by [my fork of `nix-doc-munge`]. All conversions were automatically checked to produce the same DocBook result when converted back, modulo minor typographical/formatting differences on the acceptable-to-desirable spectrum. To reproduce this commit, run: $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \ nix shell nixpkgs#coreutils \ -c find . -name '*.nix' \ -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \ {} + $ ./format [my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
160 lines
4.9 KiB
Nix
160 lines
4.9 KiB
Nix
# Wrapper around xidlehook.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.services.xidlehook;
|
|
|
|
notEmpty = list: filter (x: x != "" && x != null) (flatten list);
|
|
|
|
timers = let
|
|
toTimer = timer:
|
|
"--timer ${toString timer.delay} ${
|
|
escapeShellArgs [ timer.command timer.canceller ]
|
|
}";
|
|
in map toTimer (filter (timer: timer.command != null) cfg.timers);
|
|
|
|
script = pkgs.writeShellScript "xidlehook" ''
|
|
${concatStringsSep "\n"
|
|
(mapAttrsToList (name: value: "export ${name}=${value}")
|
|
cfg.environment or { })}
|
|
${concatStringsSep " " (notEmpty [
|
|
"${cfg.package}/bin/xidlehook"
|
|
(optionalString cfg.once "--once")
|
|
(optionalString cfg.detect-sleep "--detect-sleep")
|
|
(optionalString cfg.not-when-fullscreen "--not-when-fullscreen")
|
|
(optionalString cfg.not-when-audio "--not-when-audio")
|
|
timers
|
|
])}
|
|
'';
|
|
in {
|
|
meta.maintainers = [ maintainers.dschrempf hm.maintainers.bertof ];
|
|
|
|
options.services.xidlehook = {
|
|
enable = mkEnableOption (lib.mdDoc "xidlehook systemd service");
|
|
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.xidlehook;
|
|
defaultText = "pkgs.xidlehook";
|
|
description = lib.mdDoc "The package to use for xidlehook.";
|
|
};
|
|
|
|
environment = mkOption {
|
|
type = types.attrsOf types.str;
|
|
default = { };
|
|
example = literalExpression ''
|
|
{
|
|
"primary-display" = "$(xrandr | awk '/ primary/{print $1}')";
|
|
}
|
|
'';
|
|
description = lib.mdDoc ''
|
|
Extra environment variables to be exported in the script.
|
|
These options are passed unescaped as `export name=value`.
|
|
'';
|
|
};
|
|
|
|
detect-sleep = mkEnableOption (lib.mdDoc
|
|
"detecting when the system wakes up from a suspended state and resetting the idle timer");
|
|
|
|
not-when-fullscreen = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
example = true;
|
|
description =
|
|
lib.mdDoc "Disable locking when a fullscreen application is in use.";
|
|
};
|
|
|
|
not-when-audio = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
example = true;
|
|
description = lib.mdDoc "Disable locking when audio is playing.";
|
|
};
|
|
|
|
once = mkEnableOption (lib.mdDoc "running the program once and exiting");
|
|
|
|
timers = mkOption {
|
|
type = types.listOf (types.submodule {
|
|
options = {
|
|
delay = mkOption {
|
|
type = types.ints.unsigned;
|
|
example = 60;
|
|
description = lib.mdDoc "Time before executing the command.";
|
|
};
|
|
command = mkOption {
|
|
type = types.nullOr types.str;
|
|
example = literalExpression ''
|
|
''${pkgs.libnotify}/bin/notify-send "Idle" "Sleeping in 1 minute"
|
|
'';
|
|
description = lib.mdDoc ''
|
|
Command executed after the idle timeout is reached.
|
|
Path to executables are accepted.
|
|
The command is automatically escaped.
|
|
'';
|
|
};
|
|
canceller = mkOption {
|
|
type = types.str;
|
|
default = "";
|
|
example = literalExpression ''
|
|
''${pkgs.libnotify}/bin/notify-send "Idle" "Resuming activity"
|
|
'';
|
|
description = lib.mdDoc ''
|
|
Command executed when the user becomes active again.
|
|
This is only executed if the next timer has not been reached.
|
|
Path to executables are accepted.
|
|
The command is automatically escaped.
|
|
'';
|
|
};
|
|
};
|
|
});
|
|
default = [ ];
|
|
example = literalExpression ''
|
|
[
|
|
{
|
|
delay = 60;
|
|
command = "xrandr --output \"$PRIMARY_DISPLAY\" --brightness .1";
|
|
canceller = "xrandr --output \"$PRIMARY_DISPLAY\" --brightness 1";
|
|
}
|
|
{
|
|
delay = 120;
|
|
command = "''${pkgs.writeShellScript "my-script" '''
|
|
# A complex script to run
|
|
'''}";
|
|
}
|
|
]
|
|
'';
|
|
description = lib.mdDoc ''
|
|
A set of commands to be executed after a specific idle timeout.
|
|
The commands specified in `command` and `canceller`
|
|
are passed escaped to the script.
|
|
To use or re-use environment variables that are script-dependent, specify them
|
|
in the `environment` section.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [
|
|
(lib.hm.assertions.assertPlatform "services.xidlehook" pkgs
|
|
lib.platforms.linux)
|
|
];
|
|
|
|
systemd.user.services.xidlehook = {
|
|
Unit = {
|
|
Description = "xidlehook service";
|
|
PartOf = [ "graphical-session.target" ];
|
|
After = [ "graphical-session.target" ];
|
|
ConditionEnvironment = [ "DISPLAY" ];
|
|
};
|
|
Service = {
|
|
Type = if cfg.once then "oneshot" else "simple";
|
|
ExecStart = "${script}";
|
|
};
|
|
Install.WantedBy = [ "graphical-session.target" ];
|
|
};
|
|
};
|
|
}
|