summaryrefslogtreecommitdiffstats
path: root/nixos/tests/espanso.nix
blob: 1634d9b0de37dabc0d9c67c0120baf49415207ed (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
{ lib, runTest }:
let
  makeTest =
    conf:
    runTest {
      name = "espanso";
      meta.maintainers = with lib.maintainers; [ n8henrie ];

      nodes.machine =
        let
          base =
            { pkgs, config, ... }:
            {
              imports = [ ./common/user-account.nix ];
              services.espanso.enable = true;
              systemd.tmpfiles.settings.espanso =
                let
                  confdir = "${config.users.users.alice.home}/.config/espanso";
                  mode = "0755";
                  user = config.users.users.alice.name;
                  group = config.users.users.alice.group;
                in
                {
                  "${config.users.users.alice.home}/.config".d = { inherit mode user group; };
                  "${confdir}".d = { inherit mode user group; };
                  "${confdir}/config".d = { inherit mode user group; };
                  "${confdir}/match".d = { inherit mode user group; };
                  "${confdir}/config/default.yml".f = {
                    mode = "0644";
                    inherit user group;
                  };
                  "${confdir}/match/base.yml".f = {
                    mode = "0644";
                    inherit user group;
                    argument = lib.toJSON {
                      matches = [
                        {
                          trigger = ":nixostest";
                          replace = "My NixOS Test Passed!";
                        }
                      ];
                    };
                  };
                };
            };
        in
        {
          imports = [
            base
            conf
          ];
        };

      enableOCR = true;
      testScript = ''
        machine.wait_for_unit("graphical.target")
        machine.wait_for_text("Espanso is running!")
        machine.send_chars(":nixostest")
        machine.wait_for_text("My NixOS Test Passed!")
      '';
    };
in
{
  x11 = makeTest {
    imports = [ ./common/x11.nix ];
    test-support.displayManager.auto.user = "alice";
    users.users.alice.extraGroups = [ "input" ];
  };
  wayland = makeTest (
    { pkgs, config, ... }:
    {
      programs.sway.enable = true;
      services = {
        greetd =
          let
            initial_session = {
              user = config.users.users.alice.name;
              command = lib.getExe pkgs.sway;
            };
          in
          {
            enable = true;
            settings = {
              inherit initial_session;
              default_session = initial_session;
            };
          };
        espanso.package = pkgs.espanso-wayland;
      };
    }
  );
}