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/evdevremapkeys: init #94100

Closed
wants to merge 1 commit into from
Closed

Conversation

q3k
Copy link
Member

@q3k q3k commented Jul 28, 2020

Motivation for this change

Implement a basic evdevremapkeys service. The tool itself already exists as a derivation, this merely adds a module to turn it into a service.

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.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some comments I hope you find useful.

description = "Remap Evdev Input";
after = [ "systemd-udev-settle.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add some systemd hardening options here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he means:

Can we run the daemon as a DynamicUser=yes instead of as root

Also we could set things like:

RestrictAddressFamilies=AF_NETLINK
PrivateTmp=yes

Etc.. (See man systemd.exec for more isolation options)

However I expect that this unit probably has to run as root to be able to create new input events

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to take a look if this is possible to harden by running as a less privileged user. But I'm also not expecting much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if you still end up running as root there are some settings you can apply to limit the abilities this service can have on a system. Though still hoping for a non root user, maybe with some capabilities or something.


systemd.services.evdevremapkeys = {
description = "Remap Evdev Input";
after = [ "systemd-udev-settle.service" ];
Copy link
Member

@arianvp arianvp Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading the manpage of systemd-udev-settle and it said:

    Using this service is not recommended.  There can be no guarantee that hardware is fully discovered at any specific
   time, because the kernel does hardware detection asynchronously, and certain buses and devices take a very long
   time to become ready, and also additional hardware may be plugged in at any time. Instead, services should
   subscribe to udev events and react to any new hardware as it is discovered. Services that, based on configuration,
   expect certain devices to appear, may warn or report failure after a timeout. This timeout should be tailored to
   the hardware type. Waiting for systemd-udev-settle.service usually slows boot significantly, because it means
   waiting for all unrelated events too.

I also saw that the example upstream provides doesn't depend on it https://github.com/philipl/evdevremapkeys/blob/master/examples/evdevremapkeys.service

Why do we need it?

Copy link
Member

@arianvp arianvp Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the source code of evdevremapkeys it seems they subscribe to udev events properly; so I don't think there is any need to wait for systemd-udev-settle

https://github.com/philipl/evdevremapkeys/blob/6626275333818fbdedc9b6ab20dc12531e29b399/evdevremapkeys/evdevremapkeys.py#L344-L345

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I did indeed copy this mindlessly this from somewhere else in nixpkgs during development and then forgot to actually make this sensible :). I've updated the service definition to reflect upstream's service example.

@q3k q3k force-pushed the q3k/nixos-evdevremapkeys branch from 8e8d27a to ccbe0a5 Compare July 29, 2020 16:29
@stale
Copy link

stale bot commented Jan 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 26, 2021
@evan-goode evan-goode mentioned this pull request Feb 8, 2023
12 tasks
@dali99
Copy link
Member

dali99 commented Nov 30, 2023

Superseded by #215247

@dali99 dali99 closed this Nov 30, 2023
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.

None yet

4 participants