{ config, pkgs, lib, ... }: let layouts = config.custom.customKeyboardLayouts; xkeyboard_config_custom = pkgs.xkeyboard_config.overrideAttrs (old: { patches = [(let nlayouts = builtins.length (builtins.attrNames layouts); in builtins.toFile "add-layout.patch" '' --- a/rules/evdev.xml.in +++ b/rules/evdev.xml.in @@ -6059,6 +6059,${toString (6+9*nlayouts)} @@ ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: '' + + + ${k} + <_shortDescription>${v.short or k} + <_description>${v.desc} + + + + '' ) layouts)} '')]; }); xkbDir = pkgs.buildEnv { name = "xkbdir_custom"; paths = [ "${xkeyboard_config_custom}/share/X11/xkb" (pkgs.runCommand "xkbdir_custom" {} '' mkdir -p $out/symbols ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: '' ln -s ${v.src} $out/symbols/${k} '') layouts)} '') ]; }; in { options = { custom.customKeyboardLayouts = lib.mkOption { default = {}; type = lib.types.attrs; }; }; config = lib.mkIf (layouts != {}) { custom.overrideXkbDir = true; services.xserver.xkbDir = xkbDir; }; }