nixos-config/components/gui/suspend.nix

42 lines
901 B
Nix
Raw Normal View History

2024-08-29 03:26:04 +02:00
{
pkgs,
config,
lib,
...
}:
2021-03-05 17:42:00 +01:00
with lib;
2021-11-01 09:20:42 +01:00
{
2023-02-17 00:59:29 +01:00
options.components.gui.suspend.enable = mkOption {
type = lib.types.bool;
2023-05-28 20:22:23 +02:00
default = config.components.gui.enable;
2023-02-17 00:59:29 +01:00
};
2021-03-05 17:42:00 +01:00
2023-05-28 20:22:23 +02:00
config = mkIf (config.components.gui.suspend.enable) {
2021-03-05 17:42:00 +01:00
systemd.services.screenlock = {
before = [ "sleep.target" ];
requiredBy = [ "sleep.target" ];
2021-11-01 09:20:42 +01:00
environment =
let
2024-08-29 03:26:04 +02:00
display = if (config.services.xserver.display != null) then config.services.xserver.display else 0;
2021-11-01 09:20:42 +01:00
in
2024-08-29 03:26:04 +02:00
{
DISPLAY = ":${toString display}";
};
2021-03-05 17:42:00 +01:00
script = ''
${pkgs.xlockmore}/bin/xlock -mode life1d -size 1 &
sleep 1
'';
serviceConfig = {
SyslogIdentifier = "screenlock";
#Type = "simple";
Type = "forking";
User = config.users.users.mainUser.name;
};
2019-10-24 02:20:38 +02:00
};
2021-03-05 17:42:00 +01:00
services.logind.lidSwitch = "suspend";
2019-10-24 02:20:38 +02:00
2021-03-05 17:42:00 +01:00
};
2019-10-24 02:20:38 +02:00
}