From 6badac486f3c914dcca8f49c5aff35a3e4b0ef07 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 18 Oct 2025 16:08:29 +0900 Subject: [PATCH] nixos/tests/logkeys: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/logkeys.nix | 34 +++++++++++++++++++++++++++++ pkgs/by-name/lo/logkeys/package.nix | 3 +++ 3 files changed, 38 insertions(+) create mode 100644 nixos/tests/logkeys.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 66a599383a95..1f9c38680cbd 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -853,6 +853,7 @@ in localsend = runTest ./localsend.nix; locate = runTest ./locate.nix; login = runTest ./login.nix; + logkeys = runTest ./logkeys.nix; logrotate = runTest ./logrotate.nix; loki = runTest ./loki.nix; #logstash = handleTest ./logstash.nix {}; diff --git a/nixos/tests/logkeys.nix b/nixos/tests/logkeys.nix new file mode 100644 index 000000000000..eeb4c27ee2b0 --- /dev/null +++ b/nixos/tests/logkeys.nix @@ -0,0 +1,34 @@ +{ lib, ... }: +{ + name = "logkeys"; + meta.maintainers = with lib.maintainers; [ h7x4 ]; + + nodes.machine = + { pkgs, ... }: + { + imports = [ ./common/user-account.nix ]; + + services.getty.autologinUser = "alice"; + + services.logkeys = { + enable = true; + device = "virtio-kbd"; + }; + + # logkeys doesn't support specifying a device in `by-path`. + # In order not to make the test dependend on the ordering of the input event devices, + # we'll create a custom symlink before starting the service. + systemd.services.logkeys.serviceConfig.ExecStartPre = [ + "+${lib.getExe' pkgs.coreutils "ln"} -s /dev/input/by-path/pci-0000:00:0a.0-event-kbd /dev/input/virtio-kbd" + ]; + }; + + testScript = '' + machine.wait_for_unit("getty@tty1.service") + machine.wait_until_succeeds("pgrep -f 'agetty.*tty1'") + machine.wait_for_unit("logkeys.service") + + machine.send_chars("hello world\n") + machine.wait_until_succeeds("grep 'hello world' /var/log/logkeys.log") + ''; +} diff --git a/pkgs/by-name/lo/logkeys/package.nix b/pkgs/by-name/lo/logkeys/package.nix index 16bb1c6ba666..812028117977 100644 --- a/pkgs/by-name/lo/logkeys/package.nix +++ b/pkgs/by-name/lo/logkeys/package.nix @@ -7,6 +7,7 @@ which, procps, kbd, + nixosTests, }: stdenv.mkDerivation { @@ -38,6 +39,8 @@ stdenv.mkDerivation { preConfigure = "./autogen.sh"; + passthru.tests.nixos = nixosTests.logkeys; + meta = with lib; { description = "GNU/Linux keylogger that works"; license = licenses.gpl3;