I'm using NixOS with X11 and don't have administrator privileges. AltGr is already configured, but several of the characters it produces aren't useful to me. I'd like to replace them with characters or key combinations I use more often, such as º, ª, or a different arrangement of {, [, ], and @. What's the best way to customize this layout using only files and tools available in my home directory?
2 Answers
You may also need to inspect the later columns rather than only the first two, since AltGr mappings are usually represented there. Keep the existing keycode structure and change only the symbols assigned to the modifier combinations you want. This approach is specific to X11; if you later switch to Wayland, you’ll likely need a different keyboard-layout configuration method.
For an X11-only remapping, you can use xmodmap without root access. First export your current keymap with `xmodmap -pke > new_config`. Edit the relevant keycode lines in that file, then load the changes with `xmodmap new_config`. A line such as `keycode 38 = a A a A ae AE ae` lists the symbols produced by that key under the different modifier combinations. The first column is the unmodified key and the second is Shift; the later columns cover combinations such as AltGr. Replace the symbols you don’t want with the ones you need, then run the command again to apply the file.

This should work as a user-level configuration. For example, you can run `xmodmap` from your session startup or place the command in `.xinitrc`, so it doesn’t need to run as root.