Commit 6267196d authored by Nathan Henrie's avatar Nathan Henrie
Browse files

nixos/espanso: add espanso integration tests for x11 and wayland

parent 53cc22c0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ in
      source = lib.getExe (
        pkgs.espanso-wayland.override { securityWrapperPath = config.security.wrapperDir; }
      );

    };
    systemd.user.services.espanso = {
      description = "Espanso daemon";
+4 −0
Original line number Diff line number Diff line
@@ -523,6 +523,10 @@ in
  ergo = runTest ./ergo.nix;
  ergochat = runTest ./ergochat.nix;
  ersatztv = handleTest ./ersatztv.nix { };
  espanso = import ./espanso.nix {
    inherit (pkgs) lib;
    inherit runTest;
  };
  esphome = runTest ./esphome.nix;
  etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
  etcd = import ./etcd/default.nix { inherit pkgs runTest; };
+86 −0
Original line number Diff line number Diff line
{ 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;
              system.activationScripts.espanso-config = {
                deps = [ "users" ];
                text =
                  let
                    confdir = "${config.users.users.alice.home}/.config/espanso";
                    espanso_conf =
                      let
                        settingsFormat = pkgs.formats.yaml { };
                      in
                      settingsFormat.generate "base.yaml" {
                        matches = [
                          {
                            trigger = ":nixostest";
                            replace = "My NixOS Test Passed!";
                          }
                        ];
                      };
                  in
                  ''
                    mkdir -p ${confdir}/{config,match}
                    touch ${confdir}/config/default.yml
                    cp ${espanso_conf} ${confdir}/match/base.yml
                    chown -R ${config.users.users.alice.name} ${confdir}
                  '';
              };
            };
        in
        lib.mkMerge [
          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;
      };
    }
  );
}
+16 −3
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
  waylandSupport ? false,
  x11Support ? stdenv.hostPlatform.isLinux,
  testers,
  nixosTests,
  fetchpatch,
}:
# espanso does not support building with both X11 and Wayland support at the same time
assert stdenv.hostPlatform.isLinux -> x11Support != waylandSupport;
@@ -88,6 +90,15 @@ rustPlatform.buildRustPackage (finalAttrs: {
    xdotool
  ];

  patches = [
    # remove when version > 2.3.0
    (fetchpatch {
      name = "fix-welcome-screen-expansion.patch";
      url = "https://github.com/espanso/espanso/commit/5d5fc84df695d628d1d9c3e7e3854c2991a64d64.patch";
      hash = "sha256-dhoqq0V8b8mGvZvPInHiHKGmGDDFO/SH5HqMY7EA134=";
    })
  ];

  postPatch =
    lib.optionalString stdenv.hostPlatform.isDarwin ''
      substituteInPlace scripts/create_bundle.sh \
@@ -132,10 +143,12 @@ rustPlatform.buildRustPackage (finalAttrs: {

  passthru = {
    inherit waylandSupport;
    tests.version = testers.testVersion {
    tests = nixosTests.espanso // {
      version = testers.testVersion {
        package = finalAttrs.finalPackage;
        inherit (finalAttrs) version;
      };
    };
    updateScript = nix-update-script { };
  };