#!/usr/bin/env bash

# Configure Xbox Controller support (xpadneo) declaratively for Nomarchy NixOS.

FEATURE_FILE="/etc/nixos/nomarchy-features/xbox-controller.nix"

if [ -f "$FEATURE_FILE" ]; then
    echo "Xbox controller support is already configured in $FEATURE_FILE"
    exit 0
fi

sudo mkdir -p "/etc/nixos/nomarchy-features"
cat <<EOF | sudo tee "$FEATURE_FILE" > /dev/null
{ config, pkgs, ... }:
{
  hardware.xpadneo.enable = true;
  # Note: This automatically handles blacklisting xpad if needed and provides modules.
}
EOF

echo "Created $FEATURE_FILE."
echo "IMPORTANT: To finish enabling Xbox controller support, add './nomarchy-features/xbox-controller.nix' to your imports list in /etc/nixos/system.nix or /etc/nixos/flake.nix,"
echo "then run 'sys-update'."
