{
  description = "Stonks Oracle dev environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        python = pkgs.python312;
        pythonPkgs = python.pkgs;
      in
      {
        devShells.default = pkgs.mkShell {
          buildInputs = [
            # Python + core deps
            python
            pythonPkgs.pip
            pythonPkgs.virtualenv

            # Native build deps for asyncpg, etc.
            pkgs.postgresql_16.lib
            pkgs.openssl
            pkgs.pkg-config
            pkgs.gcc

            # Dev tools
            pkgs.ruff
            pkgs.kubectl
            pkgs.kubernetes-helm
            pkgs.docker-client

            # Useful extras
            pkgs.jq
            pkgs.yq-go
            pkgs.curl
            pkgs.git
          ];

          shellHook = ''
            # Create venv if it doesn't exist
            if [ ! -d .venv ]; then
              echo "Creating Python venv..."
              python -m venv .venv
            fi
            source .venv/bin/activate

            # Ensure nix-provided tools take precedence over venv
            export PATH="${builtins.concatStringsSep ":" [
              "${pkgs.ruff}/bin"
              "${pkgs.kubectl}/bin"
              "${pkgs.kubernetes-helm}/bin"
            ]}:$PATH"

            # Install deps if needed
            if [ ! -f .venv/.installed ]; then
              echo "Installing Python dependencies..."
              pip install -q --exclude ruff -r requirements.txt 2>/dev/null || pip install -q -r requirements.txt
              touch .venv/.installed
            fi

            export PYTHONPATH="$PWD:$PYTHONPATH"
            echo "Stonks Oracle dev shell ready. Python $(python --version), ruff $(ruff --version)"
          '';
        };
      });
}
