{ config, lib, ... }:
{
  sops.secrets.wifi-password-pi = {
    sopsFile = ./../secrets/wifi.yaml;
  };

  networking.wireless = {
    enable = true;
    secretsFile = config.sops.secrets.wifi-password-pi.path;
    networks = {
      "pi" = {
        pskRaw = "ext:pi";
      };
    };
    # Only enable on wireless interface, not ethernet
    interfaces = [ "wlan0" ];
  };

  # Prefer wifi over ethernet, but keep ethernet as fallback
  networking.dhcpcd.extraConfig = ''
    # Prefer wlan0 over ethernet interfaces
    interface wlan0
    metric 100

    interface eth0
    metric 200
  '';

  # Persist wireless configuration across reboots (for impermanence)
  environment.persistence.${config.custom.impermanence.persistPath} = {
    files = [
      "/etc/wpa_supplicant.conf"
    ];
  };
}
