Skip to content

Commit 0f014c7

Browse files
committed
chore: implement home-manager check
1 parent b1ecfeb commit 0f014c7

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

checks/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let
1010
./xremap-single-device.nix
1111
./xremap-multiple-devices.nix
1212
./xremap-debug.nix
13+
./xremap-home-manager.nix
1314
];
1415
inherit (lib) pipe;
1516
in

checks/xremap-home-manager.nix

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
A catch-all test of home manager module implementation.
3+
4+
NOTE: in its current form this test only tests the "xremap can start and is kinda configured as expected" fact
5+
*/
6+
{ self, ... }:
7+
{
8+
name = "xremap-single-device";
9+
nodes.machine1 =
10+
{ config, lib, ... }:
11+
{
12+
services.getty.autologinUser = "alice";
13+
users.users.alice = {
14+
isNormalUser = true;
15+
password = "hunter2";
16+
extraGroups = [ "input" ];
17+
};
18+
imports = [ self.inputs.home-manager.nixosModules.home-manager ];
19+
20+
hardware.uinput.enable = true;
21+
services.udev = {
22+
# NOTE: Xremap requires the following:
23+
# https://github.com/xremap/xremap?tab=readme-ov-file#running-xremap-without-sudo
24+
extraRules = ''
25+
KERNEL=="uinput", GROUP="input", TAG+="uaccess"
26+
'';
27+
};
28+
29+
home-manager.users.alice = {
30+
imports = [
31+
self.homeManagerModules.default
32+
{ services.xremap.enable = true; }
33+
{ services.xremap.deviceNames = [ "/dev/input/event0" ]; }
34+
# Enable debug
35+
{ services.xremap.debug = true; }
36+
# NOTE: This test just checks some basic things about xremap service
37+
# Not using graphical option, setting xremap to start with default.target
38+
{ systemd.user.services.xremap.Unit.PartOf = lib.mkForce [ "default.target" ]; }
39+
{ systemd.user.services.xremap.Unit.After = lib.mkForce [ "default.target" ]; }
40+
{ systemd.user.services.xremap.Install.WantedBy = lib.mkForce [ "default.target" ]; }
41+
# Try merging FOO=BAR to env
42+
{ systemd.user.services.xremap.Service.Environment = [ "FOO=BAR" ]; }
43+
# Try setting an env var
44+
{
45+
services.xremap.config.keymap = [
46+
{
47+
name = "Other remap";
48+
remap = {
49+
"z" = "q";
50+
};
51+
}
52+
];
53+
}
54+
];
55+
home.stateVersion = "24.05";
56+
};
57+
};
58+
59+
testScript =
60+
# python
61+
''
62+
start_all()
63+
# Wait until login
64+
machine.wait_until_tty_matches("1", r"alice@machine1")
65+
machine.wait_for_unit("xremap.service", "alice")
66+
67+
# technically one should use dbus api but eh.
68+
_, stdout = machine.systemctl("show --property=Environment xremap", "alice")
69+
parsed_stdout = stdout.removeprefix("Environment=").rstrip().split(" ")
70+
# A bit flaky since we're parsing strings. Dbus API better approach. To be fixed if becomes a problem.
71+
assert "RUST_LOG=debug" in parsed_stdout, "Looks like RUST_LOG did not get passed"
72+
assert "FOO=BAR" in parsed_stdout, "Looks like a custom variable did not get merged"
73+
'';
74+
}

0 commit comments

Comments
 (0)