keyboard: make `layout` and `variant` optional

Also default these options to `null` for state version ≥ 19.09.

Fixes #811

Suggested-by: Sean Marshallsay <srm.1708@gmail.com>
This commit is contained in:
Robert Helgesson 2019-09-05 01:37:45 +02:00
parent 0083087e01
commit 824d31a21c
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
6 changed files with 82 additions and 14 deletions

View File

@ -30,6 +30,14 @@
Firefox package and defaults to <code>pkgs.firefox</code>.
</para>
</listitem>
<listitem>
<para>
The options <option>home.keyboard.layout</option> and
<option>home.keyboard.variant</option> now default to
<literal>null</literal>, which indicates that the system value should be
used.
</para>
</listitem>
</itemizedlist>
</section>
</section>

View File

@ -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 <literal>null</literal>, then the system
configuration will be used.
</para><para>
This defaults to <literal>null</literal> for state
version  19.09 and <literal>"us"</literal> 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 <literal>null</literal>, then the
system configuration will be used.
</para><para>
This defaults to <literal>null</literal> for state
version  19.09 and <literal>""</literal> otherwise.
'';
};
};

View File

@ -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}";
};
};
};

View File

@ -1,3 +1,4 @@
{
xsession-basic = ./basic.nix;
xsession-keyboard-without-layout = ./keyboard-without-layout.nix;
}

View File

@ -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

View File

@ -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;
}}
'';
};
}