mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
swayidle: minor cleanups
Some checks are pending
GitHub Pages / publish (ubuntu-latest) (push) Waiting to run
Some checks are pending
GitHub Pages / publish (ubuntu-latest) (push) Waiting to run
This commit is contained in:
parent
4803bf558b
commit
0b052dd811
2 changed files with 34 additions and 31 deletions
|
@ -6,18 +6,6 @@ let
|
||||||
|
|
||||||
cfg = config.services.swayidle;
|
cfg = config.services.swayidle;
|
||||||
|
|
||||||
mkTimeout = t:
|
|
||||||
[ "timeout" (toString t.timeout) (escapeShellArg t.command) ]
|
|
||||||
++ optionals (t.resumeCommand != null) [
|
|
||||||
"resume"
|
|
||||||
(escapeShellArg t.resumeCommand)
|
|
||||||
];
|
|
||||||
|
|
||||||
mkEvent = e: [ e.event (escapeShellArg e.command) ];
|
|
||||||
|
|
||||||
args = cfg.extraArgs ++ (concatMap mkTimeout cfg.timeouts)
|
|
||||||
++ (concatMap mkEvent cfg.events);
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ maintainers.c0deaddict ];
|
meta.maintainers = [ maintainers.c0deaddict ];
|
||||||
|
|
||||||
|
@ -127,7 +115,16 @@ in {
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
# swayidle executes commands using "sh -c", so the PATH needs to contain a shell.
|
# swayidle executes commands using "sh -c", so the PATH needs to contain a shell.
|
||||||
Environment = [ "PATH=${makeBinPath [ pkgs.bash ]}" ];
|
Environment = [ "PATH=${makeBinPath [ pkgs.bash ]}" ];
|
||||||
ExecStart = "${cfg.package}/bin/swayidle ${concatStringsSep " " args}";
|
ExecStart = let
|
||||||
|
mkTimeout = t:
|
||||||
|
[ "timeout" (toString t.timeout) t.command ]
|
||||||
|
++ optionals (t.resumeCommand != null) [ "resume" t.resumeCommand ];
|
||||||
|
|
||||||
|
mkEvent = e: [ e.event e.command ];
|
||||||
|
|
||||||
|
args = cfg.extraArgs ++ (concatMap mkTimeout cfg.timeouts)
|
||||||
|
++ (concatMap mkEvent cfg.events);
|
||||||
|
in "${getExe cfg.package} ${escapeShellArgs args}";
|
||||||
};
|
};
|
||||||
|
|
||||||
Install = { WantedBy = [ cfg.systemdTarget ]; };
|
Install = { WantedBy = [ cfg.systemdTarget ]; };
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{
|
{
|
||||||
services.swayidle = {
|
services.swayidle = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = config.lib.test.mkStubPackage { };
|
package = config.lib.test.mkStubPackage { outPath = "@swayidle@"; };
|
||||||
timeouts = [
|
timeouts = [
|
||||||
{
|
{
|
||||||
timeout = 50;
|
timeout = 50;
|
||||||
|
@ -31,24 +31,30 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
nmt.script = let
|
nmt.script = ''
|
||||||
escapeForRegex = builtins.replaceStrings [ "'" "*" ] [ "'\\''" "\\*" ];
|
|
||||||
expectedArgs = escapeForRegex (lib.concatStringsSep " " [
|
|
||||||
"-w"
|
|
||||||
"timeout 50 'notify-send -t 10000 -- \"Screen lock in 10 seconds\"'"
|
|
||||||
"timeout 60 'swaylock -fF'"
|
|
||||||
"timeout 300 'swaymsg \"output * dpms off\"' resume 'swaymsg \"output * dpms on\"'"
|
|
||||||
"before-sleep 'swaylock -fF'"
|
|
||||||
"lock 'swaylock -fF'"
|
|
||||||
]);
|
|
||||||
in ''
|
|
||||||
serviceFile=home-files/.config/systemd/user/swayidle.service
|
serviceFile=home-files/.config/systemd/user/swayidle.service
|
||||||
|
|
||||||
assertFileExists $serviceFile
|
assertFileExists "$serviceFile"
|
||||||
assertFileRegex $serviceFile 'ExecStart=.*/bin/swayidle ${expectedArgs}'
|
|
||||||
assertFileRegex $serviceFile 'Restart=always'
|
serviceFileNormalized="$(normalizeStorePaths "$serviceFile")"
|
||||||
assertFileRegex $serviceFile 'Environment=.*PATH=${
|
|
||||||
lib.makeBinPath [ pkgs.bash ]
|
assertFileContent "$serviceFileNormalized" ${
|
||||||
}'
|
builtins.toFile "expected.service" ''
|
||||||
|
[Install]
|
||||||
|
WantedBy=graphical-session.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Environment=PATH=/nix/store/00000000000000000000000000000000-bash/bin
|
||||||
|
ExecStart=@swayidle@/bin/dummy -w timeout 50 'notify-send -t 10000 -- "Screen lock in 10 seconds"' timeout 60 'swaylock -fF' timeout 300 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' before-sleep 'swaylock -fF' lock 'swaylock -fF'
|
||||||
|
Restart=always
|
||||||
|
Type=simple
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
ConditionEnvironment=WAYLAND_DISPLAY
|
||||||
|
Description=Idle manager for Wayland
|
||||||
|
Documentation=man:swayidle(1)
|
||||||
|
PartOf=graphical-session.target
|
||||||
|
''
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue