130 lines
3.8 KiB
Nix
130 lines
3.8 KiB
Nix
{ lib
|
|
, stdenv
|
|
, makeWrapper
|
|
, rsync
|
|
, gnused
|
|
, gawk
|
|
, docker-compose
|
|
}:
|
|
|
|
stdenv.mkDerivation {
|
|
pname = "usda-vision";
|
|
version = "1.0.0";
|
|
|
|
# Use the directory from this repository with explicit source filtering
|
|
src = lib.cleanSourceWith {
|
|
src = ./.;
|
|
filter = path: type:
|
|
let
|
|
baseName = baseNameOf path;
|
|
in
|
|
# Exclude git, but include everything else
|
|
baseName != ".git" &&
|
|
baseName != ".cursor" &&
|
|
baseName != "__pycache__" &&
|
|
baseName != "node_modules" &&
|
|
baseName != ".venv" &&
|
|
baseName != ".age" &&
|
|
baseName != "flake.nix" &&
|
|
baseName != "flake.lock" &&
|
|
baseName != "package.nix" &&
|
|
baseName != "camera-sdk.nix";
|
|
};
|
|
|
|
nativeBuildInputs = [ makeWrapper rsync ];
|
|
|
|
# Don't run these phases, we'll do everything in installPhase
|
|
dontBuild = true;
|
|
dontConfigure = true;
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/opt/usda-vision
|
|
|
|
# Debug: show what's in source
|
|
echo "Source directory contents:"
|
|
ls -la $src/ || true
|
|
|
|
# Process docker-compose.yml - replace paths and configure SDK from Nix
|
|
if [ -f $src/docker-compose.yml ]; then
|
|
# Basic path replacements with sed
|
|
${gnused}/bin/sed \
|
|
-e 's|\./management-dashboard-web-app|/var/lib/usda-vision/management-dashboard-web-app|g' \
|
|
-e 's|\./media-api|/var/lib/usda-vision/media-api|g' \
|
|
-e 's|\./video-remote|/var/lib/usda-vision/video-remote|g' \
|
|
-e 's|\./scheduling-remote|/var/lib/usda-vision/scheduling-remote|g' \
|
|
-e 's|\./vision-system-remote|/var/lib/usda-vision/vision-system-remote|g' \
|
|
-e 's|\./camera-management-api|/var/lib/usda-vision/camera-management-api|g' \
|
|
$src/docker-compose.yml > $TMPDIR/docker-compose-step1.yml
|
|
|
|
# Remove SDK installation blocks using awk for better multi-line handling
|
|
${gawk}/bin/awk '
|
|
/# Only install system packages if not already installed/ { skip=1 }
|
|
skip && /^ fi$/ { skip=0; next }
|
|
/# Install camera SDK if not already installed/ { skip_sdk=1 }
|
|
skip_sdk && /^ fi;$/ { skip_sdk=0; next }
|
|
!skip && !skip_sdk { print }
|
|
' $TMPDIR/docker-compose-step1.yml > $TMPDIR/docker-compose.yml
|
|
|
|
rm -f $TMPDIR/docker-compose-step1.yml
|
|
fi
|
|
|
|
# Copy all application files using rsync with chmod
|
|
${rsync}/bin/rsync -av \
|
|
--chmod=Du+w \
|
|
--exclude='.git' \
|
|
--exclude='docker-compose.yml' \
|
|
--exclude='.env' \
|
|
--exclude='*.age' \
|
|
--exclude='flake.nix' \
|
|
--exclude='flake.lock' \
|
|
--exclude='package.nix' \
|
|
--exclude='camera-sdk.nix' \
|
|
--exclude='management-dashboard-web-app/.env' \
|
|
$src/ $out/opt/usda-vision/
|
|
|
|
# Copy the processed docker-compose.yml
|
|
if [ -f $TMPDIR/docker-compose.yml ]; then
|
|
cp $TMPDIR/docker-compose.yml $out/opt/usda-vision/docker-compose.yml
|
|
fi
|
|
|
|
# Verify files were copied
|
|
echo "Destination directory contents:"
|
|
ls -la $out/opt/usda-vision/ || true
|
|
|
|
# Create convenience scripts
|
|
mkdir -p $out/bin
|
|
|
|
cat > $out/bin/usda-vision-start <<'EOF'
|
|
#!/usr/bin/env bash
|
|
cd $out/opt/usda-vision
|
|
${docker-compose}/bin/docker-compose up -d --build
|
|
EOF
|
|
|
|
cat > $out/bin/usda-vision-stop <<'EOF'
|
|
#!/usr/bin/env bash
|
|
cd $out/opt/usda-vision
|
|
${docker-compose}/bin/docker-compose down
|
|
EOF
|
|
|
|
cat > $out/bin/usda-vision-logs <<'EOF'
|
|
#!/usr/bin/env bash
|
|
cd $out/opt/usda-vision
|
|
${docker-compose}/bin/docker-compose logs -f "$@"
|
|
EOF
|
|
|
|
cat > $out/bin/usda-vision-restart <<'EOF'
|
|
#!/usr/bin/env bash
|
|
cd $out/opt/usda-vision
|
|
${docker-compose}/bin/docker-compose restart "$@"
|
|
EOF
|
|
|
|
chmod +x $out/bin/usda-vision-*
|
|
'';
|
|
|
|
meta = with lib; {
|
|
description = "USDA Vision camera management system";
|
|
maintainers = [ "UGA Innovation Factory" ];
|
|
platforms = platforms.linux;
|
|
};
|
|
}
|