Xmodmap in configuration.nix

I’m not sure I understand how to put this code into configuration.nix, as I only get syntax error.

https://nixos.wiki/wiki/Keyboard_Layout_Customization#Using_xmodmap

Where am I supposed to place this code?

I just get unexpected “let”:wink:

let “binds” a value to the scope after it, and can’t be put inside of a scope as a value itself. You can put it in places like this:

# This is supposed to look like configuration.nix
{ config, pkgs, lib, ...}: let
  foo = "bar";
in {
  programs.baz = foo;
}
{
  programs.baz = let
    foo = "bar";
  in
    foo;
}

i.e., immediately after a declaration of some kind starts.

1 Like

I edited the wiki to avoid the let block confusion

cat /etc/nixos/configuration.nix

services.xserver.displayManager.sessionCommands =
  ${pkgs.xorg.xmodmap}/bin/xmodmap "${pkgs.writeText  "xkb-layout" ''
    ! Map umlauts to RIGHT ALT + <key>
      keycode 108 = Mode_switch
      keysym e = e E EuroSign
      keysym c = c C cent
      keysym a = a A adiaeresis Adiaeresis
      keysym o = o O odiaeresis Odiaeresis
      keysym u = u U udiaeresis Udiaeresis
      keysym s = s S ssharp
    
      ! disable capslock
      ! remove Lock = Caps_Lock
  ''}"

IMO Difference between revisions of "Keyboard Layout Customization" - NixOS Wiki is a poorer style, as the extra nesting just makes it harder to read and easier to misquote the value, like you did. Also previously, the ellipses hinted that this is not the full content of the file (as the cat command on the top would imply).

There is a full chapter of the NixOS manual on creating or modifying existing keyboard layouts. It’s up-to-date, warns about common mistakes and shows how to test the changes.

Sometimes I just wish the wiki didn’t exist.

1 Like

getting error on this:

λ sudo nixos-rebuild switch -I nixos-config=$HOME/Cfg/configuration.nix
error: syntax error, unexpected DOLLAR_CURLY

       at /home/dym/Cfg/configuration.nix:187:22:

          186|         sessionCommands =
          187|           sleep 5 && ${pkgs.xorg.xmodmap}/bin/xmodmap "${pkgs.writeText  "xkb-layout" ''
             |                      ^
          188|             clear Lock
(use '--show-trace' to show detailed location information)

i bet you didnt paste entirety of that cat command