Skip to content

Commit

Permalink
Nount all devices with same PID/VID and use latest kernel package
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBingman committed Oct 26, 2024
1 parent 6934fdb commit 34a214c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions nixos/modules/services/hardware/usbipd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ in
enable = mkEnableOption "usbip server";
kernelPackage = mkOption {
type = types.package;
default = config.boot.kernelPackages.usbip;
default = pkgs.linuxPackages_latest.usbip;
description = "The kernel module package to install.";
example = config.boot.kernelPackages.usbip;
};
devices = mkOption {
type = types.listOf device;
Expand Down Expand Up @@ -66,15 +67,17 @@ in
script = ''
set +e
devices=$(${cfg.kernelPackage}/bin/usbip list -l | grep -E "^.*- busid.*(${dev.vendorid}:${dev.productid})" )
output=$(${cfg.kernelPackage}/bin/usbip -d bind -b $(echo $devices | ${pkgs.gawk}/bin/awk '{ print $3 }') 2>&1)
code=$?
echo $devices | while read device; do
output=$(${cfg.kernelPackage}/bin/usbip -d bind -b $(echo $device | ${pkgs.gawk}/bin/awk '{ print $3 }') 2>&1)
code=$?
echo $output
if [[ $output =~ "already bound" ]]; then
exit 0
else
exit $code
fi
echo $output
if [[ $output =~ "already bound" ]] || [ $code -eq 0 ]; then
continue
else
exit $code
fi
done
'';
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
Expand All @@ -85,7 +88,10 @@ in
// {
usbipd = {
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${cfg.kernelPackage}/bin/usbipd -D";
script = ''
${pkgs.kmod}/bin/modprobe usbip-host usbip-core
exec ${cfg.kernelPackage}/bin/usbipd -D
'';
serviceConfig.Type = "forking";
};
};
Expand Down

0 comments on commit 34a214c

Please sign in to comment.