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/logiops: init #287399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

nixos/logiops: init #287399

wants to merge 1 commit into from

Conversation

kylechui
Copy link
Contributor

@kylechui kylechui commented Feb 9, 2024

Description of changes

Logiops is third-party software for configuring Logitech mice, e.g remapping buttons or scroll behavior. It is already packaged in nixpkgs, but there is no systemd service associated with it.

Closes #226575

Note: I'm not quite sure how to write tests for this service, so any help in that department would be much appreciated!

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@kylechui kylechui changed the title feat: Add logiops service. logiops: Add logiops service Feb 9, 2024
@h7x4
Copy link
Member

h7x4 commented Feb 10, 2024

Ref #167388

@kylechui kylechui force-pushed the feat/add-logiops branch 2 times, most recently from 8f3bdff to 900394b Compare February 10, 2024 23:17
@kylechui
Copy link
Contributor Author

What would be the most idiomatic way to test my fork using my NixOS machine (which uses a flake)? Would it be to add my fork as an upstream flake input, or perhaps rebuild and point to my local copy of nixpkgs somehow?

@h7x4
Copy link
Member

h7x4 commented Feb 11, 2024

What would be the most idiomatic way to test my fork using my NixOS machine (which uses a flake)? Would it be to add my fork as an upstream flake input, or perhaps rebuild and point to my local copy of nixpkgs somehow?

I'm not entirely sure. I've had a bit of trouble testing PRs with modules myself, without ruining my local setup. AFAIK, there are at least these alternatives:

  • include the changes to your config locally, and override with package overlays and disabledModules.
  • (arguably the best option, but takes a bit to set up, especially considering this is a hardware module) create a nixos configuration with the settings you need, and spin it up in a QEMU VM with nixos-rebuild build-vm.
  • Set up a test machine or a permanent test VM.
  • override your local nixpkgs to the unstable fork - be very careful with this, as it might run migrations and do irreversible changes to the state of the system.

Usually, I'd encourage to write a nixos test, but since this is hardware dependent it might be a bit difficult.

@kylechui
Copy link
Contributor Author

Some of the changes in here only make sense with respect to #289701.

P.S. I've set up a test VM, but have yet to figure out how to perform PCIe passthrough in order to fully test the behavior of the mouse on the VM. I've been able to observe the configuration getting created in the right location though.

Copy link
Member

@ckiee ckiee left a comment

Choose a reason for hiding this comment

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

Hi,

I'm rather confused by why you branched off from keyd for this instead of continuing the previous PR? @h7x4 and I had a whole saga implementing the libconfig serializer which makes me feel a bit bad about this, as it seems you didn't look at the history of this much at all?

You're finishing it up which is great for others; but I wish you'd use some of the code I've been running for almost 3 years now (#167388). It's proven to be very stable. (Last commit)

nixos/modules/services/hardware/logiops.nix Outdated Show resolved Hide resolved
nixos/modules/services/hardware/logiops.nix Outdated Show resolved Hide resolved
nixos/modules/services/hardware/logiops.nix Outdated Show resolved Hide resolved
@ckiee ckiee mentioned this pull request Feb 18, 2024
13 tasks
@kylechui
Copy link
Contributor Author

kylechui commented Feb 19, 2024

Hey @ckiee, I didn't mean any offense by implementing this code myself. If your PR has been working well, then should that be marked as non-draft and merged into nixpkgs instead (i.e. close this one)? I'm afraid I'm a bit confused as to what the current state of things is, or exactly which parts of your code you "wish I could've used" in this PR.

Edit: I was roughly following the keyd PR because (in my mind), both pieces of software seemed roughly similar (i.e. consisting of some application binary relating to hardware + some systemd service). Thus I wanted to try emulating it via some services.logiops.enable setting.

@ckiee
Copy link
Member

ckiee commented Feb 19, 2024

Yeah thank you for the response, I'm sorry about my initial hostility.

I meant it'd have been nice if you'd continued off from where I stopped with my PR's code saving us some review time here (and making me happy to see my code get used after all) but it doesn't matter too much now since you've already done a pretty good job with this new PR which I assume works. It's just a bit of a shame for my end, but it is better to get you happy & contributing to nixpkgs so I'd be glad if you went ahead.

A few more notes:

  • PR title should be nixos/logiops: init
  • Commits should be rebased and formatted as in CONTRIBUTING.md and my PR can serve as a reference too.

Good luck! I'll try to stick around for the review but I have less time for nixpkgs at the moment.

@ckiee
Copy link
Member

ckiee commented Feb 19, 2024

Oh also, for the tests I think just making sure the service starts up is enough. We don't do any such thing for nvidia/… afaik.

@kylechui kylechui changed the title logiops: Add logiops service nixos/logiops: init Feb 19, 2024
@ckiee
Copy link
Member

ckiee commented Feb 22, 2024

The commit title is wrong, should be nixos/logiops: init too. And you were right about example, it doesn't need pkgs., sorry about that.

weird udev rule aside (probably ok) and lack of testing on my machine it looks pretty good. i have other matters to attend to though, so ping me in a while if you haven't found another reviewer. cc @h7x4

@kylechui kylechui force-pushed the feat/add-logiops branch 3 times, most recently from 4ed9525 to 2d5937c Compare February 22, 2024 19:40
@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/3509

# Add a `udev` rule to restart `logiops` when the mouse is connected
# https://github.com/PixlOne/logiops/issues/239#issuecomment-1044122412
services.udev.extraRules = ''
ACTION=="add", SUBSYSTEM=="input", ATTRS{id/vendor}=="046d", RUN{program}="${pkgs.systemd}/bin/systemctl --no-block try-restart logiops.service"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ACTION=="add", SUBSYSTEM=="input", ATTRS{id/vendor}=="046d", RUN{program}="${pkgs.systemd}/bin/systemctl --no-block try-restart logiops.service"
ACTION=="add", SUBSYSTEM=="input", ATTRS{id/vendor}=="046d", RUN{program}="${config.systemd.package}/bin/systemctl --no-block try-restart logiops.service"

Copy link
Contributor Author

@kylechui kylechui Feb 25, 2024

Choose a reason for hiding this comment

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

Is this so the udev rule will (potentially) use an overridden version of systemd?

Comment on lines +104 to +71
after = [ "multi-user.target" ];
wants = [ "multi-user.target" ];
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason why we need this? Usually I thought wantedBy multi-user.target is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used in the original package, see this file

nixos/modules/services/hardware/logiops.nix Outdated Show resolved Hide resolved
Also see <https://github.com/PixlOne/logiops/blob/main/logid.example.cfg> for an example config.
'';
default = { };
example = {
Copy link
Member

Choose a reason for hiding this comment

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

This is way to big to properly render on search.nixos.org

nixos/modules/services/hardware/logiops.nix Outdated Show resolved Hide resolved
The logiops package already exists, but without a systemd service.

refactor: Use `udev` to restart service when mouse connected.

Old method used a somewhat jank `modprobe` to load the
`hid_logitech_hidpp` kernel module.

fix: Remove `IPAddressDeny` from service.

It is redundant since we already set `PrivateNetwork = true`.

fix: Allow service access to all of `/dev`.

If the user has many devices connected, they may run into issues with
the `DeviceAllow` permission. Ideally, we would only allow access to
`/dev/uinput` and `/dev/hidraw*`, but globbing is unavailable for device
node path specifications:

https://www.freedesktop.org/software/systemd/man/252/systemd.resource-control.html

refactor: Use `libconfig` generator.

fix: Format type should be `libconfig`.

fix: Incorrect way to add a file to `/etc`.

fix: DeviceAllow permissions.

`hidraw` is a character device in `/proc/devices`, so we should be able
to match it in `DeviceAllow`. Additionally, matching against `/dev`
doesn't do anything, as device node path specifications need to be fully
specified.

feat: Allow access to `AF_UNIX`.

This is needed since the newer version of `logiops` requires GDBus.

See PR#289701.

fix: Update service restart condition.

Sometimes the service will error out and fail to apply the user's
configuration if the mouse is disconnected and then reconnected. The
updated `udev` rule restarts the service any time a Logitech device is
connected.

feat: Add example config.

fix: systemd wantedBy option.

See: https://github.com/NixOS/nixpkgs/pull/287399/files/15700feac734cbacb3fb9dd0f5cbfc04a27058d9#r1493869013

feat: Allow package override.

fix: Use `literalExpression` for example package.

fix: Stop using `literalExpression` for example.

test: Add test to see if service starts properly.

fix: Revert `pkgs.` prefix for example.

fix: Only restart the service if it is already running.

refactor: Use overridden `systemd`.
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.

Package request: logiops
7 participants