nixos/tests/logkeys: init

This commit is contained in:
h7x4
2025-10-18 16:08:29 +09:00
parent 1a8abfdf07
commit 6badac486f
3 changed files with 38 additions and 0 deletions

View File

@@ -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 {};

34
nixos/tests/logkeys.nix Normal file
View File

@@ -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")
'';
}

View File

@@ -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;