mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
nixos/xscreensaver: add service to handle events
This commit is contained in:
parent
14bc70c00a
commit
7ffc11106a
1 changed files with 48 additions and 0 deletions
48
nix/nixosModules/common/xscreensaver.nix
Normal file
48
nix/nixosModules/common/xscreensaver.nix
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#
|
||||
# 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
|
||||
case $event in
|
||||
${handlers}
|
||||
esac
|
||||
done
|
||||
'';
|
||||
path = [
|
||||
cfg.package # contains xscreensaver-command
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue