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

usbipd: add usbipd service with autobind #348301

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ChristianBingman
Copy link

Manage usbip devices with a simple service!

  • Automatically installs and starts the usbip daemon
  • Automatically binds devices to be shared on the network using udev and systemd
  • Opens relevant ports

tested on an x86 vm and a raspberry pi 4

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.11 Release Notes (or backporting 23.11 and 24.05 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.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` labels Oct 13, 2024
@NixOSInfra NixOSInfra added the 12. first-time contribution This PR is the author's first one; please be gentle! label Oct 13, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Oct 13, 2024
@ChristianBingman ChristianBingman changed the title Add usbipd service with autobind usbipd: add usbipd service with autobind Oct 13, 2024
@h7x4 h7x4 added the 8.has: module (new) This PR adds a module in `nixos/` label Oct 14, 2024
@ChristianBingman
Copy link
Author

Which is more idiomatic here? Disable sandboxing or use pkgs.linuxPackages_latest.usbip? Thanks!

@kraftnix
Copy link
Contributor

I have a similar module for running usbip in my internal repos, this implementation this looks fairly similar.

One issue I can spot is that this setup does not work if you own or use more than 1 device with the same productId / vendorId, which is suprisingly common if you use more than 1 yubikey.

You would be unable to bind more than 1 device, and only the first plugged in device would be bound (and the other ignored).

@ChristianBingman
Copy link
Author

That should be all passing now, and it should mount all devices that have the same PID/VID.

@FliegendeWurst FliegendeWurst added the awaiting_changes (old Marvin label, do not use) label Dec 2, 2024
nixos/modules/services/hardware/usbipd.nix Outdated Show resolved Hide resolved
nixos/modules/services/hardware/usbipd.nix Outdated Show resolved Hide resolved
nixos/modules/services/hardware/usbipd.nix Outdated Show resolved Hide resolved
nixos/modules/services/hardware/usbipd.nix Outdated Show resolved Hide resolved
usbipd = {
wantedBy = [ "multi-user.target" ];
script = ''
${lib.getExe' pkgs.kmod "modprobe"} usbip-host usbip-core
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 done via boot.kernelModules already, I think?

Copy link
Author

Choose a reason for hiding this comment

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

It is not, e.g. rke2 does this and several others.

Copy link
Member

Choose a reason for hiding this comment

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

rke2 does not set boot.kernelModules. My understanding is that putting something in boot.kernelModules is almost equivalent to a modprobe call at boot time.

Copy link
Author

Choose a reason for hiding this comment

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

If I could get confirmation, I am happy to remove it. Though when I initially tested this case the module was not loaded until after reboot, so that is why I added it.

Copy link
Author

Choose a reason for hiding this comment

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

Looking at kernel.nix it seems like it is supposed to autoload, but in my experience it didn’t and the wording seems to indicate otherwise “The set of kernel modules to be loaded in the second stage of the boot process”. In any case I will remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Though when I initially tested this case the module was not loaded until after reboot, so that is why I added it.

That is correct. It will not work with a simple nixos-rebuild switch, only a reboot will apply a change to boot.kernelModules.

@FliegendeWurst FliegendeWurst removed the awaiting_changes (old Marvin label, do not use) label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 8.has: module (new) This PR adds a module in `nixos/` 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 12. first-time contribution This PR is the author's first one; please be gentle!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants