Services.kanata "attribute 'lib' missing"

Hi there! First time posting, though I’ve lurked the site for years.

I’m on unstable, trying to use the kanata module to configure a keyboard rebind, as described in this discourse post.

Here’s my kanata.nix module where I configure it:

{config, lib, pkgs, ...}: {
	environment.systemPackages = [
		pkgs.kanata
	];

	services.kanata = {
		enable = true;
		keyboards = {
			"macha".config = ''
			(defsrc
				caps
			)

			(deflayer caps_to_esc
				esc
			)
			'';
		};
	};
}

When I run nixos-rebuild, I get a stack trace ending with the following:

       error: attribute 'lib' missing

       at /nix/store/bd4fmzws6n5542khxbifbkr6nrygi232-source/nixos/modules/services/hardware/kanata.nix:118:13:

          117|           ${lib.optionalString (keyboard.port != null) "--port ${toString keyboard.port}"} \
          118|           ${utils.lib.escapeSystemdExecArgs keyboard.extraArgs}
             |             ^
          119|       '';

Here’s the source file where utils is being included as an attr to the module.

Checking out nixos/lib/utils.nix, the desired utility function is right there, not under the lib attr. This leads me to believe that a potential fix could be to swap utils.lib.escapeSystemdExecArgs for utils.escapeSystemdExecArgs.

What’s I would love some clarification on is how utils is being passed in as an extra attr to the module here. From my “nixos user’s” understanding, the module system supplies just a few attrs on its own ({config, lib, pkgs}). Anything else can be passed in through nixosSystem {specialArgs = {...}}.

Additionally, how could I test a patch to the nixos repo? Whether or not my suspected solution works, it would be awesome to be able to try the patch and see for myself how it changes things :thinking:

This was caused by nixos/services.kanata: remove `with lib;` · NixOS/nixpkgs@3b7622d · GitHub.

Got fixed in nixos/services.kanata: fix utils by Stunkymonkey · Pull Request #338859 · NixOS/nixpkgs · GitHub.

1 Like