Snippet #2390 (python)

  • #2390
Expires in: 0 minutes View Raw
  1. { config, pkgs, lib, ... }:
  2. let
  3.  layouts = config.custom.customKeyboardLayouts;
  4.  
  5.  xkeyboard_config_custom = pkgs.xkeyboard_config.overrideAttrs (old: {
  6.    patches = [(let
  7.      nlayouts = builtins.length (builtins.attrNames layouts);
  8.    in builtins.toFile "add-layout.patch" ''
  9.      --- a/rules/evdev.xml.in
  10.      +++ b/rules/evdev.xml.in
  11.      @@ -6059,6 +6059,${toString (6+9*nlayouts)} @@
  12.              </variant>
  13.             </variantList>
  14.           </layout>
  15.      ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: ''
  16.        +    <layout>
  17.        +      <configItem>
  18.        +        <name>${k}</name>
  19.        +        <_shortDescription>${v.short or k}</_shortDescription>
  20.        +        <_description>${v.desc}</_description>
  21.        +        <languageList/>
  22.        +      </configItem>
  23.        +      <variantList/>
  24.        +    </layout>''
  25.      ) layouts)}
  26.         </layoutList>
  27.         <optionList>
  28.           <group allowMultipleSelection="true">
  29.    '')];
  30.  });
  31.  
  32.  xkbDir = pkgs.buildEnv {
  33.    name = "xkbdir_custom";
  34.    paths = [
  35.      "${xkeyboard_config_custom}/share/X11/xkb"
  36.      (pkgs.runCommand "xkbdir_custom" {} ''
  37.        mkdir -p $out/symbols
  38.        ${lib.concatStringsSep "\n" (lib.mapAttrsToList (k: v: ''
  39.          ln -s ${v.src} $out/symbols/${k}
  40.        '') layouts)}
  41.      '')
  42.    ];
  43.  };
  44. in
  45.  
  46. {
  47.  options = {
  48.    custom.customKeyboardLayouts = lib.mkOption {
  49.      default = {};
  50.      type = lib.types.attrs;
  51.    };
  52.  };
  53.  
  54.  config = lib.mkIf (layouts != {}) {
  55.    custom.overrideXkbDir = true;
  56.    services.xserver.xkbDir = xkbDir;
  57.  };
  58. }

Reply to this snippet →

Honeypot, don't fill.
⌘+⏎ or Ctrl+⏎