Skip to content

Commit

Permalink
Works
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kuznetsov <[email protected]>
  • Loading branch information
jsvapiav committed Dec 27, 2024
1 parent 01ce5ef commit 252a0be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions hardware/fmo-os-rugged-laptop-7330.nix
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@
}; # services.fmo-dci
fmo-dci-passthrough = {
enable = true;
container-name = "swarm-server-pmc01-swarm-server-1";
vendor-id = "1050";
};
avahi = {
enable = true;
Expand Down
2 changes: 2 additions & 0 deletions hardware/fmo-os-rugged-tablet-7230.nix
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@
}; # services.fmo-dci
fmo-dci-passthrough = {
enable = true;
container-name = "swarm-server-pmc01-swarm-server-1";
vendor-id = "1050";
};
avahi = {
enable = true;
Expand Down
23 changes: 19 additions & 4 deletions modules/fmo-dci-passthrough/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ let
cfg = config.services.fmo-dci-passthrough;

dockerDevPassScript = pkgs.writeShellScriptBin "docker-dev-pass" ''
CONTAINERNAME=swarm-server-pmc01-swarm-server-1
CONTAINERNAME="${cfg.container-name}"
echo "\n\n\nDevice connection rule has been triggered" >> /tmp/opkey.log
set -x
if [ -n "$(${pkgs.docker}/bin/docker ps --quiet --filter name=$CONTAINERNAME)" ] && [ -n "$2" ] && [[ "$5" == 1050/* ]]; then
echo ""
echo ""
echo "Device connection rule has been triggered" >> /tmp/opkey.log
if [ -n "$(${pkgs.docker}/bin/docker ps --quiet --filter name=$CONTAINERNAME)" ] && [ -n "$2" ] && [[ "$5" == ${cfg.vendor-id}/* ]]; then
echo "Container $CONTAINERNAME has been found" >> /tmp/opkey.log
if [ "$1" == "plugged" ]; then
echo "Device plugged $1 $2 $3 $4 $5" >> /tmp/opkey.log
Expand All @@ -21,9 +25,10 @@ let
else
echo "Device unplugged $1 $2 $3 $4 $5" >> /tmp/opkey.log
${pkgs.docker}/bin/docke exec --user root $CONTAINERNAME rm -f $2
${pkgs.docker}/bin/docker exec --user root $CONTAINERNAME service pcscd restart
fi
else
echo "Container $CONTAINERNAME has not been found" >> /tmp/opkey.log
echo "Container $CONTAINERNAME has not been found or wrong device" >> /tmp/opkey.log
echo "Unknown error $1 $2 $3 $4 $5" >> /tmp/opkey.log
fi
'';
Expand All @@ -35,6 +40,16 @@ in {
type = types.str;
description = "Path to docker-compose's .yml file";
};

container-name = mkOption {
type = types.str;
description = "Container name to inject a usb device";
};

vendor-id = mkOption {
type = types.str;
description = "Vendor id to passthrough";
};
};

config = mkIf cfg.enable {
Expand Down

0 comments on commit 252a0be

Please sign in to comment.