Merge pull request #160777 from LunNova/improve-input-remapper-module

nixos/input-remapper: Fix missing [], add more options, add test
This commit is contained in:
Timo Kaufmann 2022-03-07 18:51:08 +01:00 committed by GitHub
commit 94ea3a8899
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 14 deletions

View file

@ -7,23 +7,24 @@ let cfg = config.services.input-remapper; in
options = {
services.input-remapper = {
enable = mkEnableOption "input-remapper, an easy to use tool to change the mapping of your input device buttons.";
package = mkOption {
type = types.package;
default = pkgs.input-remapper;
defaultText = literalExpression "pkgs.input-remapper";
description = ''
The input-remapper package to use.
'';
package = options.mkPackageOption pkgs "input-remapper" { };
enableUdevRules = mkEnableOption "udev rules added by input-remapper to handle hotplugged devices. Currently disabled by default due to https://github.com/sezanzeb/input-remapper/issues/140";
serviceWantedBy = mkOption {
default = [ "graphical.target" ];
example = [ "multi-user.target" ];
type = types.listOf types.str;
description = "Specifies the WantedBy setting for the input-remapper service.";
};
};
};
config = mkIf cfg.enable {
# FIXME: udev rule hangs sometimes when lots of devices connected, so let's not use it
# config.services.udev.packages = mapper-pkg;
services.dbus.packages = cfg.package;
systemd.packages = cfg.package;
environment.systemPackages = cfg.package;
systemd.services.input-remapper.wantedBy = [ "graphical.target" ];
services.udev.packages = mkIf cfg.enableUdevRules [ cfg.package ];
services.dbus.packages = [ cfg.package ];
systemd.packages = [ cfg.package ];
environment.systemPackages = [ cfg.package ];
systemd.services.input-remapper.wantedBy = cfg.serviceWantedBy;
};
meta.maintainers = with lib.maintainers; [ LunNova ];
}

View file

@ -224,6 +224,7 @@ in
initrd-network-ssh = handleTest ./initrd-network-ssh {};
initrdNetwork = handleTest ./initrd-network.nix {};
initrd-secrets = handleTest ./initrd-secrets.nix {};
input-remapper = handleTest ./input-remapper.nix {};
inspircd = handleTest ./inspircd.nix {};
installer = handleTest ./installer.nix {};
invoiceplane = handleTest ./invoiceplane.nix {};

View file

@ -0,0 +1,52 @@
import ./make-test-python.nix ({ pkgs, ... }:
{
name = "input-remapper";
meta = {
maintainers = with pkgs.lib.maintainers; [ LunNova ];
};
machine = { config, ... }:
let user = config.users.users.sybil; in
{
imports = [
./common/user-account.nix
./common/x11.nix
];
services.xserver.enable = true;
services.input-remapper.enable = true;
users.users.sybil = { isNormalUser = true; group = "wheel"; };
test-support.displayManager.auto.user = user.name;
# workaround for pkexec not working in the test environment
# Error creating textual authentication agent:
# Error opening current controlling terminal for the process (`/dev/tty'):
# No such device or address
# passwordless pkexec with polkit module also doesn't work
# to allow the program to run, we replace pkexec with sudo
# and turn on passwordless sudo
# this is not correct in general but good enough for this test
security.sudo = { enable = true; wheelNeedsPassword = false; };
security.wrappers.pkexec = pkgs.lib.mkForce
{
setuid = true;
owner = "root";
group = "root";
source = "${pkgs.sudo}/bin/sudo";
};
};
enableOCR = true;
testScript = { nodes, ... }: ''
start_all()
machine.wait_for_x()
machine.succeed("systemctl status input-remapper.service")
machine.execute("su - sybil -c input-remapper-gtk >&2 &")
machine.wait_for_text("Input Remapper")
machine.wait_for_text("Preset")
machine.wait_for_text("Change Key")
'';
})

View file

@ -18,12 +18,17 @@
, buildPythonApplication
, procps
, gtksourceview4
, nixosTests
# Change the default log level to debug for easier debugging of package issues
, withDebugLogLevel ? false
# Xmodmap is an optional dependency
# If you use Xmodmap to set keyboard mappings (or your DE does)
# it is required to correctly map keys
, withXmodmap ? true
# Some tests are flakey under high CPU load and could cause intermittent
# failures when building. Override this to true to run tests anyway
# See upstream issue: https://github.com/sezanzeb/input-remapper/issues/306
, withDoCheck ? false
# Version and rev and hash are package arguments to allow overriding
# while ensuring the values in prePatch and src match
# https://discourse.nixos.org/t/avoid-rec-expresions-in-nixpkgs/8293/7
@ -65,7 +70,7 @@ buildPythonApplication {
substituteInPlace inputremapper/logger.py --replace "logger.setLevel(logging.INFO)" "logger.setLevel(logging.DEBUG)"
'');
doCheck = true;
doCheck = withDoCheck;
checkInputs = [
psutil
];
@ -146,6 +151,8 @@ buildPythonApplication {
install -m755 -D -t $out/bin/ bin/input-remapper*
'';
passthru.tests = nixosTests.input-remapper;
meta = with lib; {
description = "An easy to use tool to change the mapping of your input device buttons";
homepage = "https://github.com/sezanzeb/input-remapper";