{ pkgs, ... }: let
  amixer = "${pkgs.alsa-utils}/bin/amixer";
  script = pkgs.writeScriptBin "scarlett-air" ''
    #!${pkgs.stdenv.shell}
    which=0
    controlName=""

    find_control() {
      for i in /dev/snd/controlC*; do
        r=$(${amixer} controls -c $which | grep "name='Line In 2 Air Capture Enum'")

        if [[ -z $r ]]; then
          ((which++))
          continue
        fi

        echo "found: $r"

        controlName=$r
      done
    }

    for n in {1..30}; do
      find_control
      if [[ -z $controlName ]]; then
        echo "control not found this loop, waiting..."
        sleep 1s
        continue
      fi

      ${amixer} cset -c $which "$controlName" 2 && exit 0
    done
  '';
in {
  systemd.user.services.scarlett-air = {
    enable = true;
    wantedBy = [ "graphical-session.target" ];
    description = "Enables yellow Air on the DAC";
    serviceConfig = {
      Type = "oneshot";
      ExecStart = "${script}/bin/scarlett-air";
    };
  };
}
