summaryrefslogtreecommitdiffstats
path: root/nixos/tests/ayatana-indicators.nix
blob: 7efbc3d5f160348b212c9f041710d4485f4ac031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{ pkgs, lib, ... }:
let
  user = "alice";
in
{
  name = "ayatana-indicators";

  meta = {
    maintainers = lib.teams.lomiri.members;
  };

  nodes.machine =
    { config, ... }:
    {
      imports = [
        ./common/auto.nix
        ./common/user-account.nix
      ];

      test-support.displayManager.auto = {
        enable = true;
        inherit user;
      };

      services.xserver = {
        enable = true;
        desktopManager.mate.enable = true;
      };
      services.displayManager.defaultSession = lib.mkForce "mate";

      services.ayatana-indicators = {
        enable = true;
        packages =
          with pkgs;
          [
            ayatana-indicator-bluetooth
            ayatana-indicator-datetime
            ayatana-indicator-display
            ayatana-indicator-messages
            ayatana-indicator-power
            ayatana-indicator-session
            ayatana-indicator-sound
          ]
          ++ (with pkgs.lomiri; [
            lomiri-indicator-datetime
            lomiri-indicator-network
            lomiri-telephony-service
          ]);
      };

      # Setup needed by some indicators

      services.accounts-daemon.enable = true; # messages

      # Lomiri-ish setup for Lomiri indicators
      # TODO move into a Lomiri module, once the package set is far enough for the DE to start

      networking.networkmanager.enable = true; # lomiri-network-indicator
      # TODO potentially urfkill for lomiri-network-indicator?

      services.dbus.packages = with pkgs.lomiri; [ libusermetrics ];

      environment.systemPackages = with pkgs.lomiri; [ lomiri-schemas ];

      services.telepathy.enable = true;

      users.users.usermetrics = {
        group = "usermetrics";
        home = "/var/lib/usermetrics";
        createHome = true;
        isSystemUser = true;
      };

      users.groups.usermetrics = { };
    };

  # TODO session indicator starts up in a semi-broken state, but works fine after a restart. maybe being started before graphical session is truly up & ready?
  testScript =
    { nodes, ... }:
    let
      runCommandOverServiceList = list: command: lib.strings.concatMapStringsSep "\n" command list;

      runCommandOverAyatanaIndicators = runCommandOverServiceList nodes.machine.systemd.user.targets.ayatana-indicators.wants;

      runCommandOverLomiriIndicators = runCommandOverServiceList nodes.machine.systemd.user.targets.lomiri-indicators.wants;
    in
    ''
      start_all()
      machine.wait_for_x()

      # Desktop environment should reach graphical-session.target
      machine.wait_for_unit("graphical-session.target", "${user}")

      # MATE relies on XDG autostart to bring up the indicators.
      # Not sure *when* XDG autostart fires them up, and awaiting pgrep success seems to misbehave?
      machine.sleep(10)

      # Now check if all indicators were brought up successfully, and kill them for later
    ''
    + (runCommandOverAyatanaIndicators (
      service:
      let
        serviceExec = builtins.replaceStrings [ "." ] [ "-" ] service;
      in
      ''
        machine.wait_until_succeeds("pgrep -u ${user} -f ${serviceExec}")
        machine.succeed("pkill -f ${serviceExec}")
      ''
    ))
    + ''

      # Ayatana target is the preferred way of starting up indicators on SystemD session, the graphical session is responsible for starting this if it supports them.
      # Mate currently doesn't do this, so start it manually for checking (https://github.com/mate-desktop/mate-indicator-applet/issues/63)
      machine.systemctl("start ayatana-indicators.target", "${user}")
      machine.wait_for_unit("ayatana-indicators.target", "${user}")

      # Let all indicator services do their startups, potential post-launch crash & restart cycles so we can properly check for failures
      # Not sure if there's a better way of awaiting this without false-positive potential
      machine.sleep(10)

      # Now check if all indicator services were brought up successfully
    ''
    + runCommandOverAyatanaIndicators (service: ''
      machine.wait_for_unit("${service}", "${user}")
    '')
    + ''
      # Stop the target
      machine.systemctl("stop ayatana-indicators.target", "${user}")

      # Let all indicator services do their shutdowns
      # Not sure if there's a better way of awaiting this without false-positive potential
      machine.sleep(10)

      # Lomiri uses a different target, which launches a slightly different set of indicators
      machine.systemctl("start lomiri-indicators.target", "${user}")
      machine.wait_for_unit("lomiri-indicators.target", "${user}")

      # Let all indicator services do their startups, potential post-launch crash & restart cycles so we can properly check for failures
      # Not sure if there's a better way of awaiting this without false-positive potential
      machine.sleep(10)

      # Now check if all indicator services were brought up successfully
    ''
    + runCommandOverLomiriIndicators (service: ''
      machine.wait_for_unit("${service}", "${user}")
    '');
}