Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/libinput: Make every option optional #107676

Closed
wants to merge 2 commits into from
Closed

nixos/libinput: Make every option optional #107676

wants to merge 2 commits into from

Conversation

thiagokokada
Copy link
Contributor

@thiagokokada thiagokokada commented Dec 26, 2020

Motivation for this change

The libinput module nowadays set some options as optional (i.e.: accepts null) and other options as required (i.e.: if not set it will be set with a default).

However, this module, since PR #73785, applies to all input devices. And this is an issue since many of the options here only make sense to touchpad (for example, NaturalScrolling). Worse than that, once any option is in this configuration it cannot be overriden by any of the existing mechanisms to override, like:

  • services.xserver.extraConfig
  • services.xserver.inputClassSections

The only one that works is services.xserver.libinput.additionalOptions, but this one does not support applying options to many targets. You can set additionalOptions with MatchIsTouchpad "on", for example, but now you cannot apply options in other target unless you use one of the options above.

So what this PR does is convert every option to optional, and also setting to null any option that is already default in libinput itself. This way, most options will be available to override using
services.xserver.extraConfig or services.xserver.inputClassSections.

Closes #75007.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@thiagokokada
Copy link
Contributor Author

thiagokokada commented Dec 26, 2020

I don't have a clue how to test this, but since the changes are so minimal I thought that opening a PR as-is shouldn't hurt.

@thiagokokada
Copy link
Contributor Author

Tagging @worldofpeace since its is the author of #73785.

@thiagokokada
Copy link
Contributor Author

thiagokokada commented Dec 26, 2020

Also, I don't think this is the best solution. Something better would be to have separate sections for each type of input class in libinput (like described in #75007), so we could have something like:

{
  xserver.libinput.touchpad = {
    naturallScrolling = true;
  };
  xserver.libinput.mouse = {
    accelProfile = "flat";
  };
}

If someone things that the above is a good idea, I can give it a try too.

@thiagokokada
Copy link
Contributor Author

Marking @zackelan @pmyjavec @karthikiyengar, since they commented in issue #75007 and maybe can help review/validate this.

@thiagokokada thiagokokada changed the title libinput: Make every option optional nixos/libinput: Make every option optional Dec 31, 2020
@thiagokokada
Copy link
Contributor Author

So I applied the changes (using sudo nixos-rebuild -I nixpkgs=$NIXPKGS_LOCAL switch), and made the following changes in my /etc/nixos/configuration.nix:

{
  services = {
    xserver = {
      enable = true;
      libinput.enable = true;
      inputClassSections = [
        ''
          Identifier "mouse"
          MatchIsPointer "on"
          Option "AccelProfile" "flat"
        ''
        ''
          Identifier "touchpad"
          MatchIsTouchpad "on"
          Option "NaturalScrolling" "on"
          Option "Tapping" "on"
          Option "TappingButtonMap" "lmr"
        ''
      ];
    };
  };
}

This seems to work, I have natural scrolling enabled in my touchpad but not in my mouse. Just to make sure that all devices are running with libinput and not evdev, I did a cat /var/log/X.0.log | grep libinput and this is the result:

[  2846.661] (II) Using input driver 'libinput' for 'Power Button'
[  2846.693] (II) Using input driver 'libinput' for 'Video Bus'
[  2846.715] (II) Using input driver 'libinput' for 'Video Bus'
[  2846.735] (II) Using input driver 'libinput' for 'Power Button'
[  2846.754] (II) Using input driver 'libinput' for 'Sleep Button'
[  2846.775] (II) Using input driver 'libinput' for 'Integrated_Webcam_HD: Integrate'
[  2846.803] (II) Using input driver 'libinput' for 'DLL07BF:01 06CB:7A13 Mouse'
[  2846.834] (II) Using input driver 'libinput' for 'DLL07BF:01 06CB:7A13 Touchpad'
[  2846.871] (II) Using input driver 'libinput' for 'Corsair Raptor HS40'
[  2846.905] (II) Using input driver 'libinput' for 'Logitech MX518 Gaming Mouse'
[  2847.047] (II) Using input driver 'libinput' for 'Logitech MX518 Gaming Mouse Keyboard'
[  2847.076] (II) Using input driver 'libinput' for 'Logitech MX518 Gaming Mouse Consumer Control'
[  2847.101] (II) Using input driver 'libinput' for 'Logitech MX518 Gaming Mouse System Control'
[  2847.123] (II) Using input driver 'libinput' for 'Logitech Gaming Keyboard G610'
[  2847.151] (II) Using input driver 'libinput' for 'Logitech Gaming Keyboard G610 Keyboard'
[  2847.172] (II) Using input driver 'libinput' for 'Logitech Gaming Keyboard G610 Consumer Control'
[  2847.203] (II) Using input driver 'libinput' for 'Intel HID events'
[  2847.217] (II) Using input driver 'libinput' for 'Intel HID 5 button array'
[  2847.230] (II) Using input driver 'libinput' for 'Dell WMI hotkeys'
[  2847.254] (II) Using input driver 'libinput' for 'AT Translated Set 2 keyboard'
[  2847.270] (II) Using input driver 'libinput' for 'PS/2 Synaptics TouchPad'
[  2847.325] (II) Using input driver 'libinput' for 'Logitech MX518 Gaming Mouse Consumer Control'

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/419

The libinput module nowadays set some options as optional (i.e.: accepts
null) and other options as required (i.e.: if not set it will be set
with a default).

However, this module, since PR #73785, applies to all input devices. And
this is an issue since many of the options here only make sense to
touchpad (for example, NaturalScrolling). Worse than that, once any option is
in this configuration it cannot be overriden by any of the existing mechanisms
to override, like:

- `services.xserver.extraConfig`
- `services.xserver.inputClassSections`

The only one that works is `services.xserver.libinput.additionalOptions`, but
this one does not support applying options to many targets. You can set
`additionalOptions` with `MatchIsTouchpad "on"`, for example, but now
you cannot apply options in other target unless you use one of the
options above.

So what this PR does is convert every option to optional, and also
setting to `null` any option that is already default in libinput itself.
This way, most options will be available to override using
`services.xserver.extraConfig` or `services.xserver.inputClassSections`.

Closes #75007.
@thiagokokada
Copy link
Contributor Author

/marvin opt-in
/status needs_reviewer

@marvin-mk2 marvin-mk2 bot added the marvin label Jan 5, 2021
@marvin-mk2
Copy link

marvin-mk2 bot commented Jan 5, 2021

Hi! I'm an experimental bot. My goal is to guide this PR through its stages, hopefully ending with a merge. You can read up on the usage here.

@vikanezrimaya
Copy link
Member

@thiagokokada I have a question! ✨ do you know how this could affect Wayland compositors using libinput, e.g. sway? Can you explain how can I maybe test it on my system, what settings could I try to tweak to see if there's a useful difference in behavior there, or maybe bugs?

@thiagokokada
Copy link
Contributor Author

thiagokokada commented Jan 9, 2021

do you know how this could affect Wayland compositors using libinput, e.g. sway?

@kisik21 Shouldn't affect Wayland, since Wayland doesn't use Xorg.conf AFAIK. SwayWM for example uses its own completely custom configuration file for input devices: https://github.com/swaywm/sway/wiki#input-configuration.

Can you explain how can I maybe test it on my system, what settings could I try to tweak to see if there's a useful difference in behavior there, or maybe bugs?

Well, the easiest way I found to test modules is something like this:

{ ... }:

let
  libinputModuleRefactor = fetchTarball {
    url = "https://github.com/thiagokokada/nixpkgs/archive/a27a2ff9a3605a9ddc740a3c3fa3d51392fde040.tar.gz";
    sha256 = "..."; # get the correct SHA for commit
  };
in {
  imports = [
    "${libinputModuleRefactor}/nixos/modules/services/x11/hardware/libinput.nix"
  ];

  disabledModules = [
    "services/x11/hardware/libinput.nix"
  ];

  xserver.libinput.enable = true;
  # Set some custom X config here so you can test the changes too.
  # This comment may help: https://github.com/NixOS/nixpkgs/pull/107676#issuecomment-752844528
}

Maybe there is someway easier to test this (for example, I can try to write some tests if this would make the review easier), but this is what I found the easiest way to test it.

@thiagokokada
Copy link
Contributor Author

For what behavior you're testing to see if this fix it, try this:

{
  services = {
    xserver = {
      enable = true;
      libinput.enable = true;
      inputClassSections = [
        ''
          Identifier "mouse"
          MatchIsPointer "on"
          Option "AccelProfile" "flat"
        ''
        ''
          Identifier "touchpad"
          MatchIsTouchpad "on"
          Option "NaturalScrolling" "on"
        ''
      ];
    };
  };
}

Now this is slightly trick to test since you need a notebook with a touchpad and a external mouse. But what will happen in master is that both mouse and touchpad will not have natural scrolling (https://github.com/NixOS/nixpkgs/pull/107676/files#diff-27164ac6e7f2a68c13050fa6e230c23671056d1357c534e79bb1d2969110bddeL103), even if you're explicitly overriding there. Also, mouse will not have the accel profile flat, instead using the default: https://github.com/NixOS/nixpkgs/pull/107676/files#diff-27164ac6e7f2a68c13050fa6e230c23671056d1357c534e79bb1d2969110bddeL28.

Now with my branch, it should work as expected: touchpad will have natural scrolling and mouse will have accel profile flat. More details can be seen in #75007.

@thiagokokada
Copy link
Contributor Author

I created another possible solution for #75007: #108909. It is a more elegant solution but involves more changes.

I think both solutions are fine, so I will keep both PRs open and after one is merged I will close the other one.

@thiagokokada
Copy link
Contributor Author

I will close this PR in favor of #108909, because it seems a better solution.

@thiagokokada thiagokokada deleted the refactor-libinput branch January 11, 2021 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

services.xserver.libinput: Allow configuration by input type
3 participants