diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f5d85cd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "usda-vision"] + path = usda-vision + url = git@github.com:salirezav/usda-vision.git diff --git a/default.nix b/default.nix index ad53602..b84f9a7 100644 --- a/default.nix +++ b/default.nix @@ -9,7 +9,7 @@ # nix-lxc = { # devices = { # "usda-dash" = builtins.fetchGit { -# url = "https://github.com/UGA-Innovation-Factory/usda-dash-config"; +# url = "https://git.factory.uga.edu/MODEL/usda-dash-config.git"; # rev = "commit-hash"; # }; # }; @@ -22,31 +22,120 @@ ... }: +let + # Create a derivation that packages the usda-vision directory + usda-vision-app = pkgs.stdenv.mkDerivation { + pname = "usda-vision"; + version = "1.0.0"; + + # Use the directory from this repository + src = ./usda-vision; + + nativeBuildInputs = [ pkgs.makeWrapper ]; + + installPhase = '' + mkdir -p $out/opt/usda-vision + + # Copy all application files + cp -r $src/* $out/opt/usda-vision/ + + # Create convenience scripts + mkdir -p $out/bin + + cat > $out/bin/usda-vision-start <<'EOF' + #!/usr/bin/env bash + cd $out/opt/usda-vision + ${pkgs.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 + ${pkgs.docker-compose}/bin/docker-compose down + EOF + + cat > $out/bin/usda-vision-logs <<'EOF' + #!/usr/bin/env bash + cd $out/opt/usda-vision + ${pkgs.docker-compose}/bin/docker-compose logs -f "$@" + EOF + + cat > $out/bin/usda-vision-restart <<'EOF' + #!/usr/bin/env bash + cd $out/opt/usda-vision + ${pkgs.docker-compose}/bin/docker-compose restart "$@" + EOF + + chmod +x $out/bin/usda-vision-* + ''; + + meta = { + description = "USDA Vision camera management system"; + maintainers = [ "UGA Innovation Factory" ]; + }; + }; +in + { # ========== Module Configuration ========== config = { # System packages specific to usda-dash environment.systemPackages = with pkgs; [ - # Add any dashboard-specific tools here + # Core tools git vim htop curl wget + + # Docker and Docker Compose for running usda-vision + docker + docker-compose + + # USDA Vision application package with convenience scripts + usda-vision-app ]; - # SSH is already configured by the host type module - # Only override if you need different settings: - # services.openssh.settings.PermitRootLogin = lib.mkForce "no"; - - # Configure users (these will be added via inventory.nix extraUsers) + # Enable Docker service + virtualisation.docker = { + enable = true; + autoPrune.enable = true; + # Configure users athenix.users.sv22900.enable = true; athenix.users.hdh20267.enable = true; - # Dashboard-specific services could go here - # Example: - # services.nginx.enable = true; - # services.postgresql.enable = true; + # Add users to docker group + users.users.sv22900.extraGroups = [ "docker" ]; + users.users.hdh20267.extraGroups = [ "docker" ]; + + # Systemd service to manage usda-vision docker compose + systemd.services.usda-vision = { + description = "USDA Vision Docker Compose Stack"; + after = [ "docker.service" "network-online.target" ]; + wants = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + WorkingDirectory = "${usda-vision-app}/opt/usda-vision"; + + # Start: pull latest images and start containers + ExecStart = "${pkgs.docker-compose}/bin/docker-compose up -d --build"; + + # Stop: gracefully stop containers + ExecStop = "${pkgs.docker-compose}/bin/docker-compose down"; + + # Reload: restart containers + ExecReload = "${pkgs.bash}/bin/bash -c '${pkgs.docker-compose}/bin/docker-compose down && ${pkgs.docker-compose}/bin/docker-compose up -d --build'"; + + TimeoutStartSec = 300; + TimeoutStopSec = 120; + }; + }; TimeoutStartSec = 300; + TimeoutStopSec = 120; + }; + }; # Firewall configuration # networking.firewall.allowedTCPPorts = [ 80 443 ]; diff --git a/usda-vision b/usda-vision new file mode 160000 index 0000000..0ef87a9 --- /dev/null +++ b/usda-vision @@ -0,0 +1 @@ +Subproject commit 0ef87a9aea0685b24c0a6a7532b5e4ca7845d0b4