summary refs log tree commit diff
path: root/modules/tasks/kbd.nix
blob: b563d33dc5b100c532d88a63ae9d57d9c0319304 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ config, pkgs, ... }:

with pkgs.lib;

let

  # think about where to put this chunk of code!
  # required by other pieces as well
  requiredTTYs = config.services.mingetty.ttys
    ++ config.boot.extraTTYs
    ++ [ config.services.syslogd.tty ];
  ttys = map (dev: "/dev/${dev}") requiredTTYs;
  defaultLocale = config.i18n.defaultLocale;
  consoleFont = config.i18n.consoleFont;
  consoleKeyMap = config.i18n.consoleKeyMap;

in

{
  ###### interface

  options = {

    # most options are defined in i18n.nix

    boot.extraTTYs = mkOption {
      default = [];
      example = ["tty8" "tty9"];
      description = ''
        Tty (virtual console) devices, in addition to the consoles on
        which mingetty and syslogd run, that must be initialised.
        Only useful if you have some program that you want to run on
        some fixed console.  For example, the NixOS installation CD
        opens the manual in a web browser on console 7, so it sets
        <option>boot.extraTTYs</option> to <literal>["tty7"]</literal>.
      '';
    };

    # dummy option so that requiredTTYs can be passed
    requiredTTYs = mkOption {
      default = [];
      description = "
        FIXME: find another place for this option.
        FIXME: find a good description.
      ";
    };

  };


  ###### implementation

  config = {

    inherit requiredTTYs; # pass it to ./modules/tasks/tty-backgrounds.nix

    environment.systemPackages = [ pkgs.kbd ];

    /* FIXME - remove; this is handled by systemd now.
    
    jobs.kbd =
      { description = "Keyboard / console initialisation";

        startOn = "started udev";

        task = true;

        script = ''
          export LANG=${defaultLocale}
          export LOCALE_ARCHIVE=/var/run/current-system/sw/lib/locale/locale-archive
          export PATH=${pkgs.gzip}/bin:$PATH # Needed by setfont

          set +e # continue in case of errors


          # Enable or disable UTF-8 mode.  This is based on
          # unicode_{start,stop}.
          echo 'Enabling or disabling Unicode mode...'

          charMap=$(${pkgs.glibc}/bin/locale charmap)

          if test "$charMap" = UTF-8; then

            for tty in ${toString ttys}; do

              # Tell the console output driver that the bytes arriving are
              # UTF-8 encoded multibyte sequences.
              echo -n -e '\033%G' > $tty

            done

            # Set the keyboard driver in UTF-8 mode.
            # !!! Commented out because it running this while the X
            # server is running kicks the X server out of raw mode.
            # UTF-8 mode is the default nowadays anyway.
            # ${pkgs.kbd}/bin/kbd_mode -u

          else

            for tty in ${toString ttys}; do

              # Tell the console output driver that the bytes arriving are
              # UTF-8 encoded multibyte sequences.
              echo -n -e '\033%@' > $tty

            done

            # Set the keyboard driver in ASCII (or any 8-bit character
            # set) mode.
            ${pkgs.kbd}/bin/kbd_mode -a

          fi


          # Set the console font.
          for tty in ${toString ttys}; do
            ${pkgs.kbd}/bin/setfont -C $tty ${consoleFont}
          done


          # Set the keymap.
          ${pkgs.kbd}/bin/loadkeys '${consoleKeyMap}'
        '';
      };
    */

  };

}