-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add usbip module for usb support in WSL
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
imports = [ | ||
./modules | ||
|
||
({ ... }: { | ||
(_: { | ||
wsl.version.rev = mkIf (self ? rev) self.rev; | ||
}) | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
./interop.nix | ||
./recovery.nix | ||
./systemd | ||
./usbip.nix | ||
./version.nix | ||
./welcome.nix | ||
./wsl-conf.nix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
usbipd-win-auto-attach = pkgs.fetchurl { | ||
url = "https://raw.githubusercontent.com/dorssel/usbipd-win/v3.1.0/Usbipd/wsl-scripts/auto-attach.sh"; | ||
hash = "sha256-KJ0tEuY+hDJbBQtJj8nSNk17FHqdpDWTpy9/DLqUFaM="; | ||
}; | ||
|
||
cfg = config.wsl.usbip; | ||
in | ||
{ | ||
options.wsl.usbip = with types; { | ||
enable = mkEnableOption "USB/IP integration"; | ||
autoAttach = mkOption { | ||
type = listOf str; | ||
default = [ ]; | ||
example = [ "4-1" ]; | ||
description = "Auto attach devices with provided Bus IDs."; | ||
}; | ||
}; | ||
|
||
config = mkIf (config.wsl.enable && cfg.enable) { | ||
environment.systemPackages = [ | ||
pkgs.linuxPackages.usbip | ||
]; | ||
|
||
services.udev.enable = true; | ||
|
||
systemd = { | ||
services."usbip-auto-attach@" = { | ||
description = "Auto attach device having busid %i with usbip"; | ||
after = [ "network.target" ]; | ||
|
||
scriptArgs = "%i"; | ||
path = [ pkgs.linuxPackages.usbip ]; | ||
|
||
script = '' | ||
busid="$1" | ||
ip="$(grep nameserver /etc/resolv.conf | cut -d' ' -f2)" | ||
echo "Starting auto attach for busid $busid on $ip." | ||
source ${usbipd-win-auto-attach} "$ip" "$busid" | ||
''; | ||
}; | ||
|
||
targets.multi-user.wants = map (busid: "usbip-auto-attach@${busid}.service") cfg.autoAttach; | ||
}; | ||
}; | ||
} |