1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 makeColor = n: value: "COLOR_${toString n}=${value}";
8 colors = concatImapStringsSep "\n" makeColor config.i18n.consoleColors;
9
10 vconsoleConf = pkgs.writeText "vconsole.conf" ''
11 KEYMAP=${config.i18n.consoleKeyMap}
12 FONT=${config.i18n.consoleFont}
13 ${colors}
14 '';
15
16 setVconsole = !config.boot.isContainer;
17in
18
19{
20 ###### interface
21
22 options = {
23
24 # most options are defined in i18n.nix
25
26 # FIXME: still needed?
27 boot.extraTTYs = mkOption {
28 default = [];
29 type = types.listOf types.str;
30 example = ["tty8" "tty9"];
31 description = ''
32 Tty (virtual console) devices, in addition to the consoles on
33 which mingetty and syslogd run, that must be initialised.
34 Only useful if you have some program that you want to run on
35 some fixed console. For example, the NixOS installation CD
36 opens the manual in a web browser on console 7, so it sets
37 <option>boot.extraTTYs</option> to <literal>["tty7"]</literal>.
38 '';
39 };
40
41 };
42
43
44 ###### implementation
45
46 config = mkMerge [
47 (mkIf (!setVconsole) {
48 systemd.services."systemd-vconsole-setup".enable = false;
49 })
50
51 (mkIf setVconsole {
52 environment.systemPackages = [ pkgs.kbd ];
53
54 # Let systemd-vconsole-setup.service do the work of setting up the
55 # virtual consoles. FIXME: trigger a restart of
56 # systemd-vconsole-setup.service if /etc/vconsole.conf changes.
57 environment.etc = [ {
58 target = "vconsole.conf";
59 source = vconsoleConf;
60 } ];
61
62 # This is identical to the systemd-vconsole-setup.service unit
63 # shipped with systemd, except that it uses /dev/tty1 instead of
64 # /dev/tty0 to prevent putting the X server in non-raw mode, and
65 # it has a restart trigger.
66 systemd.services."systemd-vconsole-setup" =
67 { wantedBy = [ "multi-user.target" ];
68 before = [ "display-manager.service" ];
69 after = [ "systemd-udev-settle.service" ];
70 restartTriggers = [ vconsoleConf ];
71 };
72 })
73 ];
74
75}