From 824d31a21c7199a20f55dcb5f6311178e706dd72 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 5 Sep 2019 01:37:45 +0200 Subject: [PATCH] keyboard: make `layout` and `variant` optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also default these options to `null` for state version ≥ 19.09. Fixes #811 Suggested-by: Sean Marshallsay --- doc/release-notes/rl-1909.xml | 8 +++++ modules/home-environment.nix | 28 ++++++++++++---- modules/xsession.nix | 14 ++++---- tests/modules/misc/xsession/default.nix | 1 + .../keyboard-without-layout-expected.service | 12 +++++++ .../misc/xsession/keyboard-without-layout.nix | 33 +++++++++++++++++++ 6 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 tests/modules/misc/xsession/keyboard-without-layout-expected.service create mode 100644 tests/modules/misc/xsession/keyboard-without-layout.nix diff --git a/doc/release-notes/rl-1909.xml b/doc/release-notes/rl-1909.xml index 3094debc..99a2f27c 100644 --- a/doc/release-notes/rl-1909.xml +++ b/doc/release-notes/rl-1909.xml @@ -30,6 +30,14 @@ Firefox package and defaults to pkgs.firefox. + + + The options and + now default to + null, which indicates that the system value should be + used. + + diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 4b14d2d4..6321bcb7 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -55,10 +55,18 @@ let keyboardSubModule = types.submodule { options = { layout = mkOption { - type = types.str; - default = "us"; + type = with types; nullOr str; + default = + if versionAtLeast config.home.stateVersion "19.09" + then null + else "us"; + defaultText = literalExample "null"; description = '' - Keyboard layout. + Keyboard layout. If null, then the system + configuration will be used. + + This defaults to null for state + version ≥ 19.09 and "us" otherwise. ''; }; @@ -81,11 +89,19 @@ let }; variant = mkOption { - type = types.str; - default = ""; + type = with types; nullOr str; + default = + if versionAtLeast config.home.stateVersion "19.09" + then null + else ""; + defaultText = literalExample "null"; example = "colemak"; description = '' - X keyboard variant. + X keyboard variant. If null, then the + system configuration will be used. + + This defaults to null for state + version ≥ 19.09 and "" otherwise. ''; }; }; diff --git a/modules/xsession.nix b/modules/xsession.nix index b0558151..164fe503 100644 --- a/modules/xsession.nix +++ b/modules/xsession.nix @@ -104,16 +104,14 @@ in Type = "oneshot"; RemainAfterExit = true; ExecStart = + with config.home.keyboard; let - args = concatStringsSep " " ( - [ - "-layout '${config.home.keyboard.layout}'" - "-variant '${config.home.keyboard.variant}'" - ] ++ - (map (v: "-option '${v}'") config.home.keyboard.options) - ); + args = + optional (layout != null) "-layout '${layout}'" + ++ optional (variant != null) "-variant '${variant}'" + ++ map (v: "-option '${v}'") options; in - "${pkgs.xorg.setxkbmap}/bin/setxkbmap ${args}"; + "${pkgs.xorg.setxkbmap}/bin/setxkbmap ${toString args}"; }; }; }; diff --git a/tests/modules/misc/xsession/default.nix b/tests/modules/misc/xsession/default.nix index fdacd3bb..2ddbf47e 100644 --- a/tests/modules/misc/xsession/default.nix +++ b/tests/modules/misc/xsession/default.nix @@ -1,3 +1,4 @@ { xsession-basic = ./basic.nix; + xsession-keyboard-without-layout = ./keyboard-without-layout.nix; } diff --git a/tests/modules/misc/xsession/keyboard-without-layout-expected.service b/tests/modules/misc/xsession/keyboard-without-layout-expected.service new file mode 100644 index 00000000..a04af53d --- /dev/null +++ b/tests/modules/misc/xsession/keyboard-without-layout-expected.service @@ -0,0 +1,12 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +ExecStart=@setxkbmap@/bin/setxkbmap -option 'ctrl:nocaps' -option 'altwin:no_win' +RemainAfterExit=true +Type=oneshot + +[Unit] +After=graphical-session-pre.target +Description=Set up keyboard in X +PartOf=graphical-session.target diff --git a/tests/modules/misc/xsession/keyboard-without-layout.nix b/tests/modules/misc/xsession/keyboard-without-layout.nix new file mode 100644 index 00000000..b7eb3dec --- /dev/null +++ b/tests/modules/misc/xsession/keyboard-without-layout.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + home.stateVersion = "19.09"; + + home.homeDirectory = "/test-home"; + + home.keyboard = { + options = [ "ctrl:nocaps" "altwin:no_win" ]; + }; + + xsession = { + enable = true; + windowManager.command = "window manager command"; + importedVariables = [ "EXTRA_IMPORTED_VARIABLE" ]; + initExtra = "init extra commands"; + profileExtra = "profile extra commands"; + }; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/setxkbmap.service + assertFileContent \ + home-files/.config/systemd/user/setxkbmap.service \ + ${pkgs.substituteAll { + src = ./keyboard-without-layout-expected.service; + inherit (pkgs.xorg) setxkbmap; + }} + ''; + }; +}