Skip to content

Instantly share code, notes, and snippets.

@binarin
Created April 19, 2016 11:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save binarin/380eda7b08a1c230abbc186887fc5823 to your computer and use it in GitHub Desktop.
Save binarin/380eda7b08a1c230abbc186887fc5823 to your computer and use it in GitHub Desktop.
packageOverrides = super: {
xorg = super.xorg // rec {
xkeyboard_config_dvp = super.pkgs.lib.overrideDerivation super.xorg.xkeyboardconfig (old: {
patches = [
(builtins.toFile "ru-dvp.patch" ''
--- xkeyboard-config-2.16-orig/symbols/ru 2014-12-11 01:56:38.000000000 +0300
+++ xkeyboard-config-2.16/symbols/ru 2016-04-15 14:27:25.075214654 +0300
@@ -719,3 +719,24 @@
key <TLDE> { [ bracketright, bracketleft ] };
key <BKSL> { [ Cyrillic_io, Cyrillic_IO ] };
};
+partial default alphanumeric_keys
+xkb_symbols "dvp" {
+ include "ru(common)"
+
+ name[Group1]= "Russia";
+
+ key <AE01> { [ numerosign, percent ] };
+ key <AE02> { [ quotedbl, 7 ] };
+ key <AE03> { [ question, 5 ] };
+ key <AE04> { [ slash, 3 ] };
+ key <AE05> { [ parenleft, 1 ] };
+ key <AE06> { [ equal, 9 ] };
+ key <AE07> { [ asterisk, 0 ] };
+ key <AE08> { [ parenright, 2 ] };
+ key <AE09> { [ plus, 4 ] };
+ key <AE10> { [ minus, 6 ] };
+ key <AE11> { [ exclam, 8 ] };
+ key <AE12> { [ semicolon, colon ] };
+ key <AB10> { [ period, comma ] };
+ key <BKSL> { [ backslash, bar ] };
+};
'')
];
});
xorgserver = super.pkgs.lib.overrideDerivation super.xorg.xorgserver (old: {
postInstall = ''
rm -fr $out/share/X11/xkb/compiled
ln -s /var/tmp $out/share/X11/xkb/compiled
wrapProgram $out/bin/Xephyr \
--set XKB_BINDIR "${xkbcomp}/bin" \
--add-flags "-xkbdir ${xkeyboard_config_dvp}/share/X11/xkb"
wrapProgram $out/bin/Xvfb \
--set XKB_BINDIR "${xkbcomp}/bin" \
--set XORG_DRI_DRIVER_PATH ${super.mesa}/lib/dri \
--add-flags "-xkbdir ${xkeyboard_config_dvp}/share/X11/xkb"
( # assert() keeps runtime reference xorgserver-dev in xf86-video-intel and others
cd "$dev"
for f in include/xorg/*.h; do # */
sed "1i#line 1 \"${old.name}/$f\"" -i "$f"
done
)
'';
});
setxkbmap = super.pkgs.lib.overrideDerivation super.xorg.setxkbmap (old: {
postInstall =
''
mkdir -p $out/share
ln -sfn ${xkeyboard_config_dvp}/etc/X11 $out/share/X11
'';
});
xkbcomp = super.pkgs.lib.overrideDerivation super.xorg.xkbcomp (old: {
configureFlags = "--with-xkb-config-root=${xkeyboard_config_dvp}/share/X11/xkb";
});
};
};
};
@mdevlamynck
Copy link

Is this still up to date? Building xorgserver fails on ln -s /var/tmp $out/share/X11/xkb/compiled (the xkb folder doesn't exists, a mkdir fixes the xorgserver build). Once I could get it building, when trying to activate the added custom keymap setxkbmap fails.

@stesie
Copy link

stesie commented Sep 14, 2018

No, you need to override xorg.xorgserver differently now, ... and there's also xkbvalidate now, that has to be overridden.

        xorgserver = super.xorg.xorgserver.overrideAttrs (old: {
          configureFlags = old.configureFlags ++ [
            "--with-xkb-bin-directory=${xkbcomp}/bin"
            "--with-xkb-path=${xkeyboardconfig_rolf}/share/X11/xkb"
          ];
        }); 
      xkbvalidate = super.xkbvalidate.override {
        libxkbcommon = super.libxkbcommon.override {
          xkeyboard_config = xorg.xkeyboardconfig_rolf;
        };
      };

... see http://stesie.github.io/2018/09/nixos-custom-keyboard-layout-revisited for a full example

@akaihola
Copy link

akaihola commented Dec 2, 2021

Where should I get the original rules/ru file from?

Edit: Found it in /nix/store/xifpfl33xirk2ysc740lckj7lf0z6k42-xkeyboard-config-2.33.tar.bz2, but doing this kind of a modification seems to trigger re-compilation of Xorg and GNOME packages :(

@binarin
Copy link
Author

binarin commented Dec 3, 2021

Yeah, I didn't care about recompilation that much, as I was usually doing this on a dedicated beefy machine. But nowadays I've gave up on idea of software-based custom layouts - too many programs that I need are handling it very badly. And there is hardly anything that you can do about it.

@akaihola
Copy link

akaihola commented Dec 11, 2021

I actually found out that the XKB version in NixOS 21.11 supports loading keyboard layouts from users' home directories! I just had to add this to my configuration.nix:

  environment.sessionVariables = rec {
    XDG_CONFIG_HOME = "\${HOME}/.config";
  };

and create correct ~/.config/xkb/rules/evdev, ~/.config/xkb/rules/evdev.xml and ~/.config/kxb/symbols/* files.

I have my customized Dvorak layout and two shortcuts with which I can activate either a standard layout or my custom one with one keypress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment