From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Subject: bug#22572: Handling of system 'locale' field needs improvement Date: Sun, 07 Feb 2016 22:19:42 +0100 Message-ID: <871t8orzf5.fsf@gnu.org> References: <87k2mhudex.fsf@netris.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSWkW-0001wV-1X for bug-guix@gnu.org; Sun, 07 Feb 2016 16:20:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSWkU-0001kS-TV for bug-guix@gnu.org; Sun, 07 Feb 2016 16:20:03 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:57263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSWkU-0001kO-QH for bug-guix@gnu.org; Sun, 07 Feb 2016 16:20:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aSWkU-0001yr-Ln for bug-guix@gnu.org; Sun, 07 Feb 2016 16:20:02 -0500 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <87k2mhudex.fsf@netris.org> (Mark H. Weaver's message of "Sat, 06 Feb 2016 09:22:14 -0500") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: Mark H Weaver Cc: 22572@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mark H Weaver skribis: > Better yet, the value of the 'locale' field should be automatically > added to the default value of 'locale-definitions' if it's not already > there. The overwhelming majority of users set their 'locale' and have > no interest in 'locale-definitions'. What about this? This is not ideal in that it guesses the charset based on the locale name, which won=E2=80=99t always work (the locale name is sup= posed to use the normalized name, like =E2=80=9Cutf8=E2=80=9D, whereas the real n= ame is, say, =E2=80=9CUTF-8=E2=80=9D), but it should cover 90% of the use cases. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable diff --git a/doc/guix.texi b/doc/guix.texi index 66ab384..f35a9fe 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6452,11 +6452,12 @@ Usually, you will want to specify the default local= e for the machine using the @code{locale} field of the @code{operating-system} declaration (@pxref{operating-system Reference, @code{locale}}). =20 -That locale must be among the @dfn{locale definitions} that are known to -the system---and these are specified in the @code{locale-definitions} -slot of @code{operating-system}. The default value includes locale -definitions for some widely used locales, but not for all the available -locales, in order to save space. +The selected locale is automatically added to the @dfn{locale +definitions} known to the system. Additional locale definitions can be +specified in the @code{locale-definitions} slot of +@code{operating-system}. The default value includes locale definitions +for some widely used locales, but not for all the available locales, in +order to save space. =20 If the locale specified in the @code{locale} field is not among the definitions listed in @code{locale-definitions}, @command{guix system} diff --git a/gnu/system.scm b/gnu/system.scm index d4759a0..324d071 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -669,14 +669,25 @@ hardware-related operations as necessary when booting= a Linux container." "Return the directory containing the locales compiled for the definitions listed in OS. The C library expects to find it under /run/current-system/locale." - ;; While we're at it, check whether the locale of OS is defined. - (unless (member (operating-system-locale os) - (map locale-definition-name - (operating-system-locale-definitions os))) - (raise (condition - (&message (message "system locale lacks a definition"))))) + (define name + (operating-system-locale os)) =20 - (locale-directory (operating-system-locale-definitions os) + (define definitions + ;; While we're at it, check whether the locale of OS is defined. + (if (member (operating-system-locale os) + (map locale-definition-name + (operating-system-locale-definitions os))) + (operating-system-locale-definitions os) + (cons (match (locale-name->definition name) + (#f + (raise (condition + (&message + (message (format #f (_ "~a: invalid locale name") + name)))))) + (def def)) + (operating-system-locale-definitions os)))) + + (locale-directory definitions #:libcs (operating-system-locale-libcs os))) =20 (define (kernel->grub-label kernel) diff --git a/gnu/system/locale.scm b/gnu/system/locale.scm index e798827..9d695b3 100644 --- a/gnu/system/locale.scm +++ b/gnu/system/locale.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright =C2=A9 2014, 2015 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2014, 2015, 2016 Ludovic Court=C3=A8s ;;; ;;; This file is part of GNU Guix. ;;; @@ -33,6 +33,7 @@ locale-definition-source locale-definition-charset =20 + locale-name->definition locale-directory =20 %default-locale-libcs @@ -52,6 +53,22 @@ (charset locale-definition-charset ;string--e.g., "UTF-8" (default "UTF-8"))) =20 +(define %not-dot + (char-set-complement (char-set #\.))) + +(define (locale-name->definition name) + "Return a corresponding to NAME, guessing the charse= t, +or #f on failure." + (match (string-tokenize name %not-dot) + ((source charset) + (locale-definition (name name) + (source source) + (charset (if (string-ci=3D? charset "utf8") + "UTF-8" + charset)))) + (_ + #f))) + (define* (localedef-command locale #:key (libc (canonical-package glibc))) "Return a gexp that runs 'localedef' from LIBC to build LOCALE." --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 DQpUaGFua3MsDQpMdWRv4oCZLg0K --=-=-=--