Skip to content

Commit

Permalink
chore: make config RFC42-compliant
Browse files Browse the repository at this point in the history
The .config option used to be types.attrs which (mostly) worked but
introduced problems when merging (#62).

Now config is using the pkgs.format.yaml along with standard machinery
for generation.

New directory in repo -- "checka" -- will contain automated tests that
can be executed on supported systems to run unattended NixOS tests. For
now the only implemented test checks that basic remapping works without
any desktop environment.

Fixes #22 #62

Progress on #16
  • Loading branch information
VTimofeenko committed Feb 29, 2024
1 parent 91e3bc4 commit a064ca6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
17 changes: 17 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ self, pkgs, lib, ... }:
let
checks = [
./xremap-no-features-root-test.nix
];
in
lib.pipe checks
[
(map (checkFile:
{
name = builtins.toString checkFile;
value = pkgs.testers.runNixOSTest (import checkFile { inherit self; });
}
))
builtins.listToAttrs
]

39 changes: 39 additions & 0 deletions checks/xremap-no-features-root-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ self, ... }:
{
name = "xremap-no-features-root-test";
nodes.machine1 =
{ config, pkgs, ... }:
{
services.getty.autologinUser = "root";
imports = [
self.nixosModules.default
{ services.xremap.config.keymap = [{ name = "First remap"; remap = { "9" = "0"; }; }]; }
{ services.xremap.config.keymap = [{ name = "Other remap"; remap = { "z" = "q"; }; }]; }
];

};

# This test makes sure that both remaps are applied
testScript =
# python
''
output_file = "/tmp/xremap-output"
start_all()
machine.wait_for_unit("xremap.service")
machine.sleep(2)
machine.send_chars(f"echo -n 'z' > {output_file}\n")
machine.sleep(2)
output = machine.execute(f"cat {output_file}")[1]
assert output == "q", "Not the expected symbol!"
machine.send_chars(f"echo -n '9' > {output_file}\n")
machine.sleep(2)
output = machine.execute(f"cat {output_file}")[1]
assert output == "0", "Not the expected symbol!"
'';
}
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
perSystem = { config, self', inputs', pkgs, system, ... }:
let
craneLib = inputs.crane.lib.${system};
inherit (pkgs) lib;
in
{
formatter = pkgs.nixpkgs-fmt;
Expand Down Expand Up @@ -122,11 +123,13 @@
inherit (pkgs.rustPackages) clippy;
};
};

checks = import ./checks { inherit self pkgs lib; };
};
flake = {
nixosModules.default = importApply ./modules { localFlake = self; inherit withSystem; };
homeManagerModules.default = importApply ./homeManagerModules { localFlake = self; inherit withSystem; };
nixosConfigurations = import ./nixosConfigurations { localFlake = self; inherit inputs; };
# nixosConfigurations = import ./nixosConfigurations { localFlake = self; inherit inputs; }; # TODO: restore
localLib = import ./lib { localFlake = self; };
};
}
Expand Down
21 changes: 14 additions & 7 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
let
inherit (pkgs.stdenv.hostPlatform) system;
selfPkgs' = localFlake.packages.${system};

settingsFormat = pkgs.formats.yaml { };
in
{
commonOptions = with lib; {
Expand Down Expand Up @@ -41,7 +43,7 @@ in
;
};
config = mkOption {
type = types.attrs;
type = types.submodule { freeformType = settingsFormat.type; };
description = "Xremap configuration. See xremap repo for examples. Cannot be used together with .yamlConfig";
default = { };
example = ''
Expand Down Expand Up @@ -110,12 +112,17 @@ in
};
debug = mkEnableOption "run xremap with RUST_LOG=debug in case upstream needs logs";
};
configFile = pkgs.writeTextFile {
name = "xremap-config.yml";
text =
assert ((cfg.yamlConfig == "" && cfg.config != { }) || (cfg.yamlConfig != "" && cfg.config == { })) || throw "Xremap's config needs to be specified either in .yamlConfig or in .config";
if cfg.yamlConfig == "" then pkgs.lib.generators.toYAML { } cfg.config else cfg.yamlConfig;
};

configFile =
assert ((cfg.yamlConfig == "" && cfg.config != { }) || (cfg.yamlConfig != "" && cfg.config == { })) || throw "Xremap's config needs to be specified either in .yamlConfig or in .config";
if cfg.yamlConfig == "" then
settingsFormat.generate "config.yml" cfg.config
else
pkgs.writeTextFile {
name = "xremap-config.yml";
text = cfg.yamlConfig;
};

mkExecStart = configFile:
builtins.concatStringsSep " "
(lib.flatten
Expand Down

0 comments on commit a064ca6

Please sign in to comment.