From 69851e4c354f42ea4415d200480f6517c9dedb7b Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 11 Apr 2019 01:09:27 +0200 Subject: [PATCH] home-environment: make `home.keyboard` optional When set to `null` then the `xsession` module will not attempt to manage the keyboard settings. (cherry picked from commit b6e1d826850fdcd79e067677ec0d5ec20fdf12b7) --- modules/home-environment.nix | 7 ++-- modules/xsession.nix | 66 +++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index e1087f8d..10cef05e 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -139,9 +139,12 @@ in }; home.keyboard = mkOption { - type = keyboardSubModule; + type = types.nullOr keyboardSubModule; default = {}; - description = "Keyboard configuration."; + description = '' + Keyboard configuration. Set to null to + disable Home Manager keyboard management. + ''; }; home.sessionVariables = mkOption { diff --git a/modules/xsession.nix b/modules/xsession.nix index 1c562dd0..42fe45bb 100644 --- a/modules/xsession.nix +++ b/modules/xsession.nix @@ -66,39 +66,43 @@ in }; config = mkIf cfg.enable { - systemd.user.services.setxkbmap = { - Unit = { - Description = "Set up keyboard in X"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + systemd.user = { + services = mkIf (config.home.keyboard != null) { + setxkbmap = { + Unit = { + Description = "Set up keyboard in X"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + + Service = { + Type = "oneshot"; + ExecStart = + let + args = concatStringsSep " " ( + [ + "-layout '${config.home.keyboard.layout}'" + "-variant '${config.home.keyboard.variant}'" + ] ++ + (map (v: "-option '${v}'") config.home.keyboard.options) + ); + in + "${pkgs.xorg.setxkbmap}/bin/setxkbmap ${args}"; + }; + }; }; - Install = { - WantedBy = [ "graphical-session.target" ]; - }; - - Service = { - Type = "oneshot"; - ExecStart = - let - args = concatStringsSep " " ( - [ - "-layout '${config.home.keyboard.layout}'" - "-variant '${config.home.keyboard.variant}'" - ] ++ - (map (v: "-option '${v}'") config.home.keyboard.options) - ); - in - "${pkgs.xorg.setxkbmap}/bin/setxkbmap ${args}"; - }; - }; - - # A basic graphical session target for Home Manager. - systemd.user.targets.hm-graphical-session = { - Unit = { - Description = "Home Manager X session"; - Requires = [ "graphical-session-pre.target" ]; - BindsTo = [ "graphical-session.target" ]; + # A basic graphical session target for Home Manager. + targets.hm-graphical-session = { + Unit = { + Description = "Home Manager X session"; + Requires = [ "graphical-session-pre.target" ]; + BindsTo = [ "graphical-session.target" ]; + }; }; };