.files/nix/nixosModules/common/xscreensaver.nix
Léana 江 ebf8468807
tree-wide: format with nixfmt
Another saturday another useless formatter change.
It's my dotfiles, after all

alejandra doesn't handle c-style inline comments well.
2025-11-08 10:15:58 +08:00

54 lines
1.3 KiB
Nix

#
# This module provides a service react to xscreensaver events
#
{
config,
lib,
...
}:
let
cfg = config.services.xscreensaver;
in
{
options = {
services.xscreensaver.hooks = lib.mkOption {
type = with lib.types; attrsOf str;
description = "An attrset of events mapped a block of shell command to be run";
default = { };
};
};
config = lib.mkIf cfg.enable {
systemd.user.services = {
"xscreensaver-hooks" = {
description = "Run commands on xscreensaver events";
after = [
"graphical-session.target"
"xscreensaver.service"
];
partOf = [ "graphical-session.target" ];
wantedBy = [ "graphical-session.target" ];
script =
let
handlers = lib.concatMapAttrsStringSep "\n" (event: action: ''
"${event}")
( ${action}
)
;;
'') cfg.hooks;
in
''
xscreensaver-command -watch | while read event rest; do
echo "The handler script got \"$event\""
case $event in
${handlers}
esac
done
'';
path = [
cfg.package # contains xscreensaver-command
];
};
};
};
}