From bca405ae44113f95d44aeaf2eb77c0412f77feb9 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Fri, 6 Mar 2009 12:25:38 +0000 Subject: [PATCH] Convert "kbd" (i18n) svn path=/nixos/branches/fix-style/; revision=14361 --- system/i18n.nix | 47 +++++++++++++++ system/options.nix | 39 ++----------- upstart-jobs/default.nix | 14 +---- upstart-jobs/kbd.nix | 123 ++++++++++++++++++++++++--------------- 4 files changed, 131 insertions(+), 92 deletions(-) create mode 100644 system/i18n.nix diff --git a/system/i18n.nix b/system/i18n.nix new file mode 100644 index 00000000000..836fa2200a2 --- /dev/null +++ b/system/i18n.nix @@ -0,0 +1,47 @@ +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption mkIf; + + options = { + i18n = { + defaultLocale = mkOption { + default = "en_US.UTF-8"; + example = "nl_NL.UTF-8"; + description = " + The default locale. It determines the language for program + messages, the format for dates and times, sort order, and so on. + It also determines the character set, such as UTF-8. + "; + }; + + consoleFont = mkOption { + default = "lat9w-16"; + example = "LatArCyrHeb-16"; + description = " + The font used for the virtual consoles. Leave empty to use + whatever the setfont program considers the + default font. + "; + }; + + consoleKeyMap = mkOption { + default = "us"; + example = "fr"; + description = " + The keyboard mapping table for the virtual consoles. + "; + }; + }; + }; +in + +###### implementation + +mkIf config.services.pulseaudio.enable { + require = [ + options + ]; + +} diff --git a/system/options.nix b/system/options.nix index c0e09721259..efa9372fcf4 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2083,39 +2083,6 @@ in }; - i18n = { - - defaultLocale = mkOption { - default = "en_US.UTF-8"; - example = "nl_NL.UTF-8"; - description = " - The default locale. It determines the language for program - messages, the format for dates and times, sort order, and so on. - It also determines the character set, such as UTF-8. - "; - }; - - consoleFont = mkOption { - default = "lat9w-16"; - example = "LatArCyrHeb-16"; - description = " - The font used for the virtual consoles. Leave empty to use - whatever the setfont program considers the - default font. - "; - }; - - consoleKeyMap = mkOption { - default = "us"; - example = "fr"; - description = " - The keyboard mapping table for the virtual consoles. - "; - }; - - }; - - nesting = { children = mkOption { default = []; @@ -2154,6 +2121,9 @@ in # security (import ../system/sudo.nix) + # i18n + (import ../system/i18n.nix) + # environment (import ../etc/default.nix) @@ -2186,6 +2156,9 @@ in (import ../upstart-jobs/rogue.nix) (import ../upstart-jobs/guest-users.nix) (import ../upstart-jobs/pulseaudio.nix) + (import ../upstart-jobs/kbd.nix) + + # fonts (import ../system/fonts.nix) diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index f96b9cb3084..04e4a470b0d 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -66,10 +66,7 @@ let optional = cond: service: pkgs.lib.optional cond (makeJob service); - requiredTTYs = - config.services.mingetty.ttys - ++ config.boot.extraTTYs - ++ [config.services.syslogd.tty]; + requiredTTYs = config.requiredTTYs; jobs = map makeJob ([ @@ -138,15 +135,6 @@ let inherit nssModulesPath; }) - # Console font and keyboard maps. - (import ../upstart-jobs/kbd.nix { - inherit (pkgs) glibc kbd gzip; - ttyNumbers = requiredTTYs; - defaultLocale = config.i18n.defaultLocale; - consoleFont = config.i18n.consoleFont; - consoleKeyMap = config.i18n.consoleKeyMap; - }) - # Handles the maintenance/stalled event (single-user shell). (import ../upstart-jobs/maintenance-shell.nix { inherit (pkgs) bash; diff --git a/upstart-jobs/kbd.nix b/upstart-jobs/kbd.nix index 8be001b03d6..504b902bcb1 100644 --- a/upstart-jobs/kbd.nix +++ b/upstart-jobs/kbd.nix @@ -1,78 +1,109 @@ -{glibc, kbd, gzip, ttyNumbers, defaultLocale, consoleFont, consoleKeyMap}: +{pkgs, config, ...}: let + inherit (pkgs.lib) mkOption; + # 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]; + ttyNumbers = requiredTTYs; ttys = map (nr: "/dev/tty" + toString nr) ttyNumbers; + defaultLocale = config.i18n.defaultLocale; + consoleFont = config.i18n.consoleFont; + consoleKeyMap = config.i18n.consoleKeyMap; in +###### implementation + +# most options are defined in i18n.nix + { - name = "kbd"; - extraPath = [ - kbd + inherit requiredTTYs; # pass them to upstart-job/default.nix + + # dummy option so that requiredTTYs can be passed, see above (FIXME) + require = [ + { + requiredTTYs = mkOption { + default = []; + }; + } ]; - - job = " - description \"Keyboard / console initialisation\" - start on udev - - script - - export LANG=${defaultLocale} - export PATH=${gzip}/bin:$PATH # Needed by setfont - - set +e # continue in case of errors + services = { + extraJobs = [{ + name = "kbd"; + extraPath = [ + pkgs.kbd + ]; - # Enable or disable UTF-8 mode. This is based on - # unicode_{start,stop}. - echo 'Enabling or disabling Unicode mode...' + job = " + description \"Keyboard / console initialisation\" - charMap=$(${glibc}/bin/locale charmap) + start on udev - if test \"$charMap\" = UTF-8; then + script - for tty in ${toString ttys}; do + export LANG=${defaultLocale} + export PATH=${pkgs.gzip}/bin:$PATH # Needed by setfont - # Tell the console output driver that the bytes arriving are - # UTF-8 encoded multibyte sequences. - echo -n -e '\\033%G' > $tty + set +e # continue in case of errors - done + + # Enable or disable UTF-8 mode. This is based on + # unicode_{start,stop}. + echo 'Enabling or disabling Unicode mode...' - # Set the keyboard driver in UTF-8 mode. - ${kbd}/bin/kbd_mode -u + charMap=$(${pkgs.glibc}/bin/locale charmap) - else + if test \"$charMap\" = UTF-8; then - for tty in ${toString ttys}; do + 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 + # Tell the console output driver that the bytes arriving are + # UTF-8 encoded multibyte sequences. + echo -n -e '\\033%G' > $tty - done + done - # Set the keyboard driver in ASCII (or any 8-bit character - # set) mode. - ${kbd}/bin/kbd_mode -a + # Set the keyboard driver in UTF-8 mode. + ${pkgs.kbd}/bin/kbd_mode -u - fi + 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 - ${kbd}/bin/setfont -C $tty ${consoleFont} - done + # Set the console font. + for tty in ${toString ttys}; do + ${pkgs.kbd}/bin/setfont -C $tty ${consoleFont} + done - # Set the keymap. - ${kbd}/bin/loadkeys '${consoleKeyMap}' + # Set the keymap. + ${pkgs.kbd}/bin/loadkeys '${consoleKeyMap}' - end script - "; - + end script + "; + + }]; + }; + }