0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/services.libinput: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-27 20:43:20 +02:00
parent 8cf91e2c5b
commit 3314fc7215

View file

@ -1,14 +1,11 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let cfg = config.services.libinput; let cfg = config.services.libinput;
xorgBool = v: if v then "on" else "off"; xorgBool = v: if v then "on" else "off";
mkConfigForDevice = deviceType: { mkConfigForDevice = deviceType: {
dev = mkOption { dev = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "/dev/input/event0"; example = "/dev/input/event0";
description = '' description = ''
@ -17,8 +14,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelProfile = mkOption { accelProfile = lib.mkOption {
type = types.enum [ "flat" "adaptive" "custom" ]; type = lib.types.enum [ "flat" "adaptive" "custom" ];
default = "adaptive"; default = "adaptive";
example = "flat"; example = "flat";
description = '' description = ''
@ -36,8 +33,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelSpeed = mkOption { accelSpeed = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "-0.5"; example = "-0.5";
description = '' description = ''
@ -46,8 +43,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelPointsFallback = mkOption { accelPointsFallback = lib.mkOption {
type = types.nullOr (types.listOf types.number); type = lib.types.nullOr (lib.types.listOf lib.types.number);
default = null; default = null;
example = [ 0.0 1.0 2.4 2.5 ]; example = [ 0.0 1.0 2.4 2.5 ];
description = '' description = ''
@ -56,8 +53,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelPointsMotion = mkOption { accelPointsMotion = lib.mkOption {
type = types.nullOr (types.listOf types.number); type = lib.types.nullOr (lib.types.listOf lib.types.number);
default = null; default = null;
example = [ 0.0 1.0 2.4 2.5 ]; example = [ 0.0 1.0 2.4 2.5 ];
description = '' description = ''
@ -66,8 +63,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelPointsScroll = mkOption { accelPointsScroll = lib.mkOption {
type = types.nullOr (types.listOf types.number); type = lib.types.nullOr (lib.types.listOf lib.types.number);
default = null; default = null;
example = [ 0.0 1.0 2.4 2.5 ]; example = [ 0.0 1.0 2.4 2.5 ];
description = '' description = ''
@ -76,8 +73,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelStepFallback = mkOption { accelStepFallback = lib.mkOption {
type = types.nullOr types.number; type = lib.types.nullOr lib.types.number;
default = null; default = null;
example = 0.1; example = 0.1;
description = '' description = ''
@ -87,8 +84,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelStepMotion = mkOption { accelStepMotion = lib.mkOption {
type = types.nullOr types.number; type = lib.types.nullOr lib.types.number;
default = null; default = null;
example = 0.1; example = 0.1;
description = '' description = ''
@ -98,8 +95,8 @@ let cfg = config.services.libinput;
''; '';
}; };
accelStepScroll = mkOption { accelStepScroll = lib.mkOption {
type = types.nullOr types.number; type = lib.types.nullOr lib.types.number;
default = null; default = null;
example = 0.1; example = 0.1;
description = '' description = ''
@ -109,8 +106,8 @@ let cfg = config.services.libinput;
''; '';
}; };
buttonMapping = mkOption { buttonMapping = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "1 6 3 4 5 0 7"; example = "1 6 3 4 5 0 7";
description = '' description = ''
@ -123,8 +120,8 @@ let cfg = config.services.libinput;
''; '';
}; };
calibrationMatrix = mkOption { calibrationMatrix = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "0.5 0 0 0 0.8 0.1 0 0 1"; example = "0.5 0 0 0 0.8 0.1 0 0 1";
description = '' description = ''
@ -133,8 +130,8 @@ let cfg = config.services.libinput;
''; '';
}; };
clickMethod = mkOption { clickMethod = lib.mkOption {
type = types.nullOr (types.enum [ "none" "buttonareas" "clickfinger" ]); type = lib.types.nullOr (lib.types.enum [ "none" "buttonareas" "clickfinger" ]);
default = null; default = null;
example = "buttonareas"; example = "buttonareas";
description = '' description = ''
@ -145,14 +142,14 @@ let cfg = config.services.libinput;
''; '';
}; };
leftHanded = mkOption { leftHanded = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Enables left-handed button orientation, i.e. swapping left and right buttons."; description = "Enables left-handed button orientation, i.e. swapping left and right buttons.";
}; };
middleEmulation = mkOption { middleEmulation = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Enables middle button emulation. When enabled, pressing the left and right buttons Enables middle button emulation. When enabled, pressing the left and right buttons
@ -160,14 +157,14 @@ let cfg = config.services.libinput;
''; '';
}; };
naturalScrolling = mkOption { naturalScrolling = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Enables or disables natural scrolling behavior."; description = "Enables or disables natural scrolling behavior.";
}; };
scrollButton = mkOption { scrollButton = lib.mkOption {
type = types.nullOr types.int; type = lib.types.nullOr lib.types.int;
default = null; default = null;
example = 1; example = 1;
description = '' description = ''
@ -176,8 +173,8 @@ let cfg = config.services.libinput;
''; '';
}; };
scrollMethod = mkOption { scrollMethod = lib.mkOption {
type = types.enum [ "twofinger" "edge" "button" "none" ]; type = lib.types.enum [ "twofinger" "edge" "button" "none" ];
default = "twofinger"; default = "twofinger";
example = "edge"; example = "edge";
description = '' description = ''
@ -186,8 +183,8 @@ let cfg = config.services.libinput;
''; '';
}; };
horizontalScrolling = mkOption { horizontalScrolling = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Enables or disables horizontal scrolling. When disabled, this driver will discard any Enables or disables horizontal scrolling. When disabled, this driver will discard any
@ -196,8 +193,8 @@ let cfg = config.services.libinput;
''; '';
}; };
sendEventsMode = mkOption { sendEventsMode = lib.mkOption {
type = types.enum [ "disabled" "enabled" "disabled-on-external-mouse" ]; type = lib.types.enum [ "disabled" "enabled" "disabled-on-external-mouse" ];
default = "enabled"; default = "enabled";
example = "disabled"; example = "disabled";
description = '' description = ''
@ -206,24 +203,24 @@ let cfg = config.services.libinput;
''; '';
}; };
tapping = mkOption { tapping = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Enables or disables tap-to-click behavior. Enables or disables tap-to-click behavior.
''; '';
}; };
tappingButtonMap = mkOption { tappingButtonMap = lib.mkOption {
type = types.nullOr (types.enum [ "lrm" "lmr" ]); type = lib.types.nullOr (lib.types.enum [ "lrm" "lmr" ]);
default = null; default = null;
description = '' description = ''
Set the button mapping for 1/2/3-finger taps to left/right/middle or left/middle/right, respectively. Set the button mapping for 1/2/3-finger taps to left/right/middle or left/middle/right, respectively.
''; '';
}; };
tappingDragLock = mkOption { tappingDragLock = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
description = '' description = ''
Enables or disables drag lock during tapping behavior. When enabled, a finger up during tap- Enables or disables drag lock during tapping behavior. When enabled, a finger up during tap-
@ -232,8 +229,8 @@ let cfg = config.services.libinput;
''; '';
}; };
transformationMatrix = mkOption { transformationMatrix = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "0.5 0 0 0 0.8 0.1 0 0 1"; example = "0.5 0 0 0 0.8 0.1 0 0 1";
description = '' description = ''
@ -242,16 +239,16 @@ let cfg = config.services.libinput;
''; '';
}; };
disableWhileTyping = mkOption { disableWhileTyping = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Disable input method while typing. Disable input method while typing.
''; '';
}; };
additionalOptions = mkOption { additionalOptions = lib.mkOption {
type = types.lines; type = lib.types.lines;
default = ""; default = "";
example = example =
'' ''
@ -269,28 +266,28 @@ let cfg = config.services.libinput;
Identifier "libinput ${deviceType} configuration" Identifier "libinput ${deviceType} configuration"
MatchDriver "libinput" MatchDriver "libinput"
MatchIs${matchIs} "${xorgBool true}" MatchIs${matchIs} "${xorgBool true}"
${optionalString (cfg.${deviceType}.dev != null) ''MatchDevicePath "${cfg.${deviceType}.dev}"''} ${lib.optionalString (cfg.${deviceType}.dev != null) ''MatchDevicePath "${cfg.${deviceType}.dev}"''}
Option "AccelProfile" "${cfg.${deviceType}.accelProfile}" Option "AccelProfile" "${cfg.${deviceType}.accelProfile}"
${optionalString (cfg.${deviceType}.accelSpeed != null) ''Option "AccelSpeed" "${cfg.${deviceType}.accelSpeed}"''} ${lib.optionalString (cfg.${deviceType}.accelSpeed != null) ''Option "AccelSpeed" "${cfg.${deviceType}.accelSpeed}"''}
${optionalString (cfg.${deviceType}.accelPointsFallback != null) ''Option "AccelPointsFallback" "${toString cfg.${deviceType}.accelPointsFallback}"''} ${lib.optionalString (cfg.${deviceType}.accelPointsFallback != null) ''Option "AccelPointsFallback" "${toString cfg.${deviceType}.accelPointsFallback}"''}
${optionalString (cfg.${deviceType}.accelPointsMotion != null) ''Option "AccelPointsMotion" "${toString cfg.${deviceType}.accelPointsMotion}"''} ${lib.optionalString (cfg.${deviceType}.accelPointsMotion != null) ''Option "AccelPointsMotion" "${toString cfg.${deviceType}.accelPointsMotion}"''}
${optionalString (cfg.${deviceType}.accelPointsScroll != null) ''Option "AccelPointsScroll" "${toString cfg.${deviceType}.accelPointsScroll}"''} ${lib.optionalString (cfg.${deviceType}.accelPointsScroll != null) ''Option "AccelPointsScroll" "${toString cfg.${deviceType}.accelPointsScroll}"''}
${optionalString (cfg.${deviceType}.accelStepFallback != null) ''Option "AccelStepFallback" "${toString cfg.${deviceType}.accelStepFallback}"''} ${lib.optionalString (cfg.${deviceType}.accelStepFallback != null) ''Option "AccelStepFallback" "${toString cfg.${deviceType}.accelStepFallback}"''}
${optionalString (cfg.${deviceType}.accelStepMotion != null) ''Option "AccelStepMotion" "${toString cfg.${deviceType}.accelStepMotion}"''} ${lib.optionalString (cfg.${deviceType}.accelStepMotion != null) ''Option "AccelStepMotion" "${toString cfg.${deviceType}.accelStepMotion}"''}
${optionalString (cfg.${deviceType}.accelStepScroll != null) ''Option "AccelStepScroll" "${toString cfg.${deviceType}.accelStepScroll}"''} ${lib.optionalString (cfg.${deviceType}.accelStepScroll != null) ''Option "AccelStepScroll" "${toString cfg.${deviceType}.accelStepScroll}"''}
${optionalString (cfg.${deviceType}.buttonMapping != null) ''Option "ButtonMapping" "${cfg.${deviceType}.buttonMapping}"''} ${lib.optionalString (cfg.${deviceType}.buttonMapping != null) ''Option "ButtonMapping" "${cfg.${deviceType}.buttonMapping}"''}
${optionalString (cfg.${deviceType}.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.${deviceType}.calibrationMatrix}"''} ${lib.optionalString (cfg.${deviceType}.calibrationMatrix != null) ''Option "CalibrationMatrix" "${cfg.${deviceType}.calibrationMatrix}"''}
${optionalString (cfg.${deviceType}.transformationMatrix != null) ''Option "TransformationMatrix" "${cfg.${deviceType}.transformationMatrix}"''} ${lib.optionalString (cfg.${deviceType}.transformationMatrix != null) ''Option "TransformationMatrix" "${cfg.${deviceType}.transformationMatrix}"''}
${optionalString (cfg.${deviceType}.clickMethod != null) ''Option "ClickMethod" "${cfg.${deviceType}.clickMethod}"''} ${lib.optionalString (cfg.${deviceType}.clickMethod != null) ''Option "ClickMethod" "${cfg.${deviceType}.clickMethod}"''}
Option "LeftHanded" "${xorgBool cfg.${deviceType}.leftHanded}" Option "LeftHanded" "${xorgBool cfg.${deviceType}.leftHanded}"
Option "MiddleEmulation" "${xorgBool cfg.${deviceType}.middleEmulation}" Option "MiddleEmulation" "${xorgBool cfg.${deviceType}.middleEmulation}"
Option "NaturalScrolling" "${xorgBool cfg.${deviceType}.naturalScrolling}" Option "NaturalScrolling" "${xorgBool cfg.${deviceType}.naturalScrolling}"
${optionalString (cfg.${deviceType}.scrollButton != null) ''Option "ScrollButton" "${toString cfg.${deviceType}.scrollButton}"''} ${lib.optionalString (cfg.${deviceType}.scrollButton != null) ''Option "ScrollButton" "${toString cfg.${deviceType}.scrollButton}"''}
Option "ScrollMethod" "${cfg.${deviceType}.scrollMethod}" Option "ScrollMethod" "${cfg.${deviceType}.scrollMethod}"
Option "HorizontalScrolling" "${xorgBool cfg.${deviceType}.horizontalScrolling}" Option "HorizontalScrolling" "${xorgBool cfg.${deviceType}.horizontalScrolling}"
Option "SendEventsMode" "${cfg.${deviceType}.sendEventsMode}" Option "SendEventsMode" "${cfg.${deviceType}.sendEventsMode}"
Option "Tapping" "${xorgBool cfg.${deviceType}.tapping}" Option "Tapping" "${xorgBool cfg.${deviceType}.tapping}"
${optionalString (cfg.${deviceType}.tappingButtonMap != null) ''Option "TappingButtonMap" "${cfg.${deviceType}.tappingButtonMap}"''} ${lib.optionalString (cfg.${deviceType}.tappingButtonMap != null) ''Option "TappingButtonMap" "${cfg.${deviceType}.tappingButtonMap}"''}
Option "TappingDragLock" "${xorgBool cfg.${deviceType}.tappingDragLock}" Option "TappingDragLock" "${xorgBool cfg.${deviceType}.tappingDragLock}"
Option "DisableWhileTyping" "${xorgBool cfg.${deviceType}.disableWhileTyping}" Option "DisableWhileTyping" "${xorgBool cfg.${deviceType}.disableWhileTyping}"
${cfg.${deviceType}.additionalOptions} ${cfg.${deviceType}.additionalOptions}
@ -298,7 +295,7 @@ let cfg = config.services.libinput;
in { in {
imports = imports =
(map (option: mkRenamedOptionModule ([ "services" "xserver" "libinput" option ]) [ "services" "libinput" "touchpad" option ]) [ (map (option: lib.mkRenamedOptionModule ([ "services" "xserver" "libinput" option ]) [ "services" "libinput" "touchpad" option ]) [
"accelProfile" "accelProfile"
"accelSpeed" "accelSpeed"
"buttonMapping" "buttonMapping"
@ -318,15 +315,15 @@ in {
"disableWhileTyping" "disableWhileTyping"
"additionalOptions" "additionalOptions"
]) ++ [ ]) ++ [
(mkRenamedOptionModule [ "services" "xserver" "libinput" "enable" ] [ "services" "libinput" "enable" ]) (lib.mkRenamedOptionModule [ "services" "xserver" "libinput" "enable" ] [ "services" "libinput" "enable" ])
(mkRenamedOptionModule [ "services" "xserver" "libinput" "mouse" ] [ "services" "libinput" "mouse" ]) (lib.mkRenamedOptionModule [ "services" "xserver" "libinput" "mouse" ] [ "services" "libinput" "mouse" ])
(mkRenamedOptionModule [ "services" "xserver" "libinput" "touchpad" ] [ "services" "libinput" "touchpad" ]) (lib.mkRenamedOptionModule [ "services" "xserver" "libinput" "touchpad" ] [ "services" "libinput" "touchpad" ])
]; ];
options = { options = {
services.libinput = { services.libinput = {
enable = mkEnableOption "libinput" // { enable = lib.mkEnableOption "libinput" // {
default = config.services.xserver.enable; default = config.services.xserver.enable;
defaultText = lib.literalExpression "config.services.xserver.enable"; defaultText = lib.literalExpression "config.services.xserver.enable";
}; };
@ -336,7 +333,7 @@ in {
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.xserver.modules = [ pkgs.xorg.xf86inputlibinput ]; services.xserver.modules = [ pkgs.xorg.xf86inputlibinput ];