From patchwork Wed Mar 20 23:04:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 1507 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 12A7D16DB7; Wed, 20 Mar 2019 23:05:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 1C66616DB4 for ; Wed, 20 Mar 2019 23:05:09 +0000 (GMT) Received: from localhost ([127.0.0.1]:56161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6kGi-0007Pc-OO for patchwork@mira.cbaines.net; Wed, 20 Mar 2019 19:05:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6kGf-0007OB-W9 for guix-patches@gnu.org; Wed, 20 Mar 2019 19:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h6kGe-0002fW-Q6 for guix-patches@gnu.org; Wed, 20 Mar 2019 19:05:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38898) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h6kGe-0002fD-Ij for guix-patches@gnu.org; Wed, 20 Mar 2019 19:05:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h6kGe-0005el-AD for guix-patches@gnu.org; Wed, 20 Mar 2019 19:05:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#34929] [PATCH 03/12] Add (gnu system keyboard). Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 20 Mar 2019 23:05:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34929 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 34929@debbugs.gnu.org Received: via spool by 34929-submit@debbugs.gnu.org id=B34929.155312309921676 (code B ref 34929); Wed, 20 Mar 2019 23:05:04 +0000 Received: (at 34929) by debbugs.gnu.org; 20 Mar 2019 23:04:59 +0000 Received: from localhost ([127.0.0.1]:52430 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h6kGX-0005dV-UG for submit@debbugs.gnu.org; Wed, 20 Mar 2019 19:04:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56807) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h6kGT-0005cU-RY for 34929@debbugs.gnu.org; Wed, 20 Mar 2019 19:04:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36731) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h6kGO-0002MT-Ld; Wed, 20 Mar 2019 19:04:48 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=57670 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1h6kGN-0004wC-VV; Wed, 20 Mar 2019 19:04:48 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 21 Mar 2019 00:04:26 +0100 Message-Id: <20190320230435.25458-3-ludo@gnu.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190320230435.25458-1-ludo@gnu.org> References: <20190320230435.25458-1-ludo@gnu.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/system/keyboard.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * gnu.scm (%public-modules): Add it. --- gnu.scm | 3 +- gnu/local.mk | 1 + gnu/system/keyboard.scm | 98 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 gnu/system/keyboard.scm diff --git a/gnu.scm b/gnu.scm index 3e7e7c0ebc..2c29b6dc3f 100644 --- a/gnu.scm +++ b/gnu.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès +;;; Copyright © 2014, 2015, 2016, 2017, 2019 Ludovic Courtès ;;; Copyright © 2015 Joshua S. Grant ;;; Copyright © 2017 Mathieu Othacehe ;;; @@ -45,6 +45,7 @@ (gnu system file-systems) (gnu bootloader) (gnu bootloader grub) + (gnu system keyboard) (gnu system pam) (gnu system shadow) ; 'user-account' (gnu system linux-initrd) diff --git a/gnu/local.mk b/gnu/local.mk index af2bf87273..b1ad9c9d8b 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -536,6 +536,7 @@ GNU_SYSTEM_MODULES = \ %D%/system/accounts.scm \ %D%/system/file-systems.scm \ %D%/system/install.scm \ + %D%/system/keyboard.scm \ %D%/system/linux-container.scm \ %D%/system/linux-initrd.scm \ %D%/system/locale.scm \ diff --git a/gnu/system/keyboard.scm b/gnu/system/keyboard.scm new file mode 100644 index 0000000000..cd3ab37b27 --- /dev/null +++ b/gnu/system/keyboard.scm @@ -0,0 +1,98 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu system keyboard) + #:use-module (guix gexp) + #:use-module ((gnu packages xorg) + #:select (xkeyboard-config console-setup)) + #:use-module (srfi srfi-9 gnu) + #:use-module (ice-9 match) + #:export (keyboard-layout? + keyboard-layout + keyboard-layout-name + keyboard-layout-variant + keyboard-layout-model + keyboard-layout-options + + keyboard-layout->console-keymap)) + +;;; Commentary: +;;; +;;; This module provides a data structure to represent keyboard layouts +;;; according to the XKB naming and classification (see the 'xkeyboard-config' +;;; package). +;;; +;;; Code: + +(define-immutable-record-type + (%keyboard-layout name variant model options) + keyboard-layout? + (name keyboard-layout-name) ;string + (variant keyboard-layout-variant) ;#f | string + (model keyboard-layout-model) ;#f | string + (options keyboard-layout-options)) ;list of strings + +(define* (keyboard-layout name #:optional variant + #:key model (options '())) + "Return a new keyboard layout with the given NAME and VARIANT. + +NAME must be a string such as \"fr\"; VARIANT must be a string such as +\"bepo\" or \"nodeadkeys\". See the 'xkeyboard-config' package for valid +options." + (%keyboard-layout name variant model options)) + +(define* (keyboard-layout->console-keymap layout + #:key + (xkeyboard-config xkeyboard-config)) + "Return a Linux console keymap file for LAYOUT, a record. +Layout information is taken from the XKEYBOARD-CONFIG package." + (define build + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (ice-9 popen) + (ice-9 match)) + + (define pipe + (open-pipe* OPEN_READ + #+(file-append console-setup "/bin/ckbcomp") + (string-append "-I" + #+(file-append xkeyboard-config + "/share/X11/xkb")) + "-rules" "base" + #$@(match (keyboard-layout-model layout) + (#f '()) + (model `("-model" ,model))) + #$(keyboard-layout-name layout) + #$(or (keyboard-layout-variant layout) + "") + #$(string-join (keyboard-layout-options layout) ","))) + + (call-with-output-file #$output + (lambda (output) + (dump-port pipe output))) + + ;; Note: ckbcomp errors out when the layout name is unknown, but + ;; merely emits a warning when the variant is unknown. + (unless (zero? (close-pipe pipe)) + (error "failed to create console keymap for keyboard layout" + #$(keyboard-layout-name layout)))))) + + (computed-file (string-append "console-keymap." + (keyboard-layout-name layout)) + build))