python312Packages.millheater: 0.11.8 -> 0.12.0
[NixPkgs.git] / nixos / tests / systemd-lock-handler.nix
blobd6fb8f545900488ebf3e899aa01c8764e0b1c115
1 { lib, ... }: {
2   name = "systemd-lock-handler";
4   meta.maintainers = with lib.maintainers; [ liff ];
6   enableOCR = true;
8   nodes.machine = { config, pkgs, lib, ... }:
9     let
10       touch = "${lib.getBin pkgs.coreutils}/bin/touch";
11     in
12     {
13       imports = [ common/wayland-cage.nix ];
15       services.systemd-lock-handler.enable = true;
17       systemd.user.services = {
18         test-lock = {
19           partOf = [ "lock.target" ];
20           onSuccess = [ "unlock.target" ];
21           before = [ "lock.target" ];
22           wantedBy = [ "lock.target" ];
23           serviceConfig.ExecStart = "${touch} /tmp/lock.target.activated";
24         };
25         test-unlock = {
26           partOf = [ "unlock.target" ];
27           after = [ "unlock.target" ];
28           wantedBy = [ "unlock.target" ];
29           serviceConfig.ExecStart = "${touch} /tmp/unlock.target.activated";
30         };
31         test-sleep = {
32           partOf = [ "sleep.target" ];
33           before = [ "sleep.target" ];
34           wantedBy = [ "sleep.target" ];
35           serviceConfig.ExecStart = "${touch} /tmp/sleep.target.activated";
36         };
37       };
38     };
40   testScript = ''
41     machine.wait_for_unit('graphical.target')
42     machine.wait_for_text('alice@machine')
44     machine.send_chars('loginctl lock-session\n')
45     machine.wait_for_file('/tmp/lock.target.activated')
46     machine.wait_for_file('/tmp/unlock.target.activated')
48     machine.send_chars('systemctl suspend\n')
49     # wait_for_file won’t complete before the machine is asleep,
50     # so we’ll watch the log instead.
51     machine.wait_for_console_text('Started test-sleep.service.')
53     # The VM is asleep, regular shutdown won’t work.
54     machine.crash()
55   '';