| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2007-04-04 17:10:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2009-09-25 19:55:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-04 17:10:38 +00:00
										 |  |  | let | 
					
						
							| 
									
										
										
										
											2009-05-28 16:03:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 05:27:56 +02:00
										 |  |  |   makeColor = n: value: "COLOR_${toString n}=${value}"; | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |   makeColorCS = | 
					
						
							|  |  |  |     let positions = [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ]; | 
					
						
							| 
									
										
										
										
											2016-07-24 15:08:49 +03:00
										 |  |  |     in n: value: "\\033]P${elemAt positions (n - 1)}${value}"; | 
					
						
							| 
									
										
										
										
											2016-01-17 17:54:33 +01:00
										 |  |  |   colors = concatImapStringsSep "\n" makeColor config.i18n.consoleColors; | 
					
						
							| 
									
										
										
										
											2015-09-03 05:27:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |   isUnicode = hasSuffix "UTF-8" (toUpper config.i18n.defaultLocale); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   optimizedKeymap = pkgs.runCommand "keymap" { | 
					
						
							| 
									
										
										
										
											2018-02-27 21:19:12 -05:00
										 |  |  |     nativeBuildInputs = [ pkgs.buildPackages.kbd ]; | 
					
						
							| 
									
										
										
										
											2016-07-18 23:46:38 +03:00
										 |  |  |     LOADKEYS_KEYMAP_PATH = "${kbdEnv}/share/keymaps/**"; | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |   } ''
 | 
					
						
							|  |  |  |     loadkeys -b ${optionalString isUnicode "-u"} "${config.i18n.consoleKeyMap}" > $out | 
					
						
							|  |  |  |   '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Sadly, systemd-vconsole-setup doesn't support binary keymaps. | 
					
						
							| 
									
										
										
										
											2016-01-17 17:54:33 +01:00
										 |  |  |   vconsoleConf = pkgs.writeText "vconsole.conf" ''
 | 
					
						
							|  |  |  |     KEYMAP=${config.i18n.consoleKeyMap} | 
					
						
							|  |  |  |     FONT=${config.i18n.consoleFont} | 
					
						
							|  |  |  |     ${colors} | 
					
						
							|  |  |  |   '';
 | 
					
						
							| 
									
										
										
										
											2016-02-09 03:00:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 03:29:21 +03:00
										 |  |  |   kbdEnv = pkgs.buildEnv { | 
					
						
							|  |  |  |     name = "kbd-env"; | 
					
						
							|  |  |  |     paths = [ pkgs.kbd ] ++ config.i18n.consolePackages; | 
					
						
							|  |  |  |     pathsToLink = [ "/share/consolefonts" "/share/consoletrans" "/share/keymaps" "/share/unimaps" ]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 03:00:53 +03:00
										 |  |  |   setVconsole = !config.boot.isContainer; | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ###### interface | 
					
						
							| 
									
										
										
										
											2009-05-28 16:03:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |     # most options are defined in i18n.nix | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 13:53:17 -04:00
										 |  |  |     # FIXME: still needed? | 
					
						
							| 
									
										
										
										
											2009-09-25 19:55:08 +00:00
										 |  |  |     boot.extraTTYs = mkOption { | 
					
						
							| 
									
										
										
										
											2009-05-28 16:03:48 +00:00
										 |  |  |       default = []; | 
					
						
							| 
									
										
										
										
											2015-06-15 18:18:46 +02:00
										 |  |  |       type = types.listOf types.str; | 
					
						
							| 
									
										
										
										
											2009-09-25 19:55:08 +00:00
										 |  |  |       example = ["tty8" "tty9"]; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							| 
									
										
										
										
											2009-05-28 16:03:48 +00:00
										 |  |  |         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 | 
					
						
							| 
									
										
										
										
											2009-09-25 19:55:08 +00:00
										 |  |  |         <option>boot.extraTTYs</option> to <literal>["tty7"]</literal>. | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2009-05-28 16:03:48 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |     boot.earlyVconsoleSetup = mkOption { | 
					
						
							|  |  |  |       default = false; | 
					
						
							|  |  |  |       type = types.bool; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							| 
									
										
										
										
											2016-07-18 23:27:45 +03:00
										 |  |  |         Enable setting font as early as possible (in initrd). | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2007-04-04 17:10:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 11:19:11 +00:00
										 |  |  |   ###### implementation | 
					
						
							| 
									
										
										
										
											2007-04-04 17:10:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 03:00:53 +03:00
										 |  |  |   config = mkMerge [ | 
					
						
							| 
									
										
										
										
											2017-02-16 16:45:19 +03:00
										 |  |  |     (mkIf (!setVconsole) { | 
					
						
							| 
									
										
										
										
											2016-02-09 03:00:53 +03:00
										 |  |  |       systemd.services."systemd-vconsole-setup".enable = false; | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |     (mkIf setVconsole (mkMerge [ | 
					
						
							|  |  |  |       { environment.systemPackages = [ pkgs.kbd ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Let systemd-vconsole-setup.service do the work of setting up the | 
					
						
							|  |  |  |         # virtual consoles. | 
					
						
							|  |  |  |         environment.etc."vconsole.conf".source = vconsoleConf; | 
					
						
							| 
									
										
										
										
											2016-07-13 03:55:12 +03:00
										 |  |  |         # Provide kbd with additional packages. | 
					
						
							|  |  |  |         environment.etc."kbd".source = "${kbdEnv}/share"; | 
					
						
							| 
									
										
										
										
											2016-07-18 23:27:45 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         boot.initrd.preLVMCommands = mkBefore ''
 | 
					
						
							|  |  |  |           kbd_mode ${if isUnicode then "-u" else "-a"} -C /dev/console | 
					
						
							|  |  |  |           printf "\033%%${if isUnicode then "G" else "@"}" >> /dev/console | 
					
						
							|  |  |  |           loadkmap < ${optimizedKeymap} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           ${optionalString config.boot.earlyVconsoleSetup ''
 | 
					
						
							|  |  |  |             setfont -C /dev/console $extraUtils/share/consolefonts/font.psf | 
					
						
							|  |  |  |           ''}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           ${concatImapStringsSep "\n" (n: color: ''
 | 
					
						
							|  |  |  |             printf "${makeColorCS n color}" >> /dev/console | 
					
						
							|  |  |  |           '') config.i18n.consoleColors}
 | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         systemd.services."systemd-vconsole-setup" = | 
					
						
							| 
									
										
										
										
											2017-09-27 23:34:42 +02:00
										 |  |  |           { before = [ "display-manager.service" ]; | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |             after = [ "systemd-udev-settle.service" ]; | 
					
						
							| 
									
										
										
										
											2016-07-13 03:55:12 +03:00
										 |  |  |             restartTriggers = [ vconsoleConf kbdEnv ]; | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  |           }; | 
					
						
							| 
									
										
										
										
											2017-02-16 16:45:19 +03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-07-08 20:01:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       (mkIf config.boot.earlyVconsoleSetup { | 
					
						
							|  |  |  |         boot.initrd.extraUtilsCommands = ''
 | 
					
						
							|  |  |  |           mkdir -p $out/share/consolefonts | 
					
						
							|  |  |  |           ${if substring 0 1 config.i18n.consoleFont == "/" then ''
 | 
					
						
							|  |  |  |             font="${config.i18n.consoleFont}" | 
					
						
							|  |  |  |           '' else '' | 
					
						
							|  |  |  |             font="$(echo ${kbdEnv}/share/consolefonts/${config.i18n.consoleFont}.*)" | 
					
						
							|  |  |  |           ''}
 | 
					
						
							|  |  |  |           if [[ $font == *.gz ]]; then | 
					
						
							|  |  |  |             gzip -cd $font > $out/share/consolefonts/font.psf | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             cp -L $font $out/share/consolefonts/font.psf | 
					
						
							|  |  |  |           fi | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     ])) | 
					
						
							| 
									
										
										
										
											2016-02-09 03:00:53 +03:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2007-04-04 17:10:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |