{
  inputs,
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.modules.obs;
in
{
  options.modules.obs = {
    enable = lib.mkEnableOption "obs";
    autostart = lib.mkEnableOption "autostart with reply";
  };
  config = lib.mkIf cfg.enable {
    programs = {
      obs-studio = {
        enable = true;
        package = (
          pkgs.obs-studio.override {
            cudaSupport = true;
          }
        );
        plugins = with pkgs.obs-studio-plugins; [
          obs-pipewire-audio-capture
          obs-vkcapture
        ];
      };
    };
    systemd.user.services.pw-discordaudio-virtual-device = {
      Install = {
        WantedBy = [ "hyprland-session.target" ];
      };
      Service = {
        ExecStart = "${pkgs.writeShellScript "discord_audio_virt_device" ''
          				#!/run/current-system/sw/bin/bash
          				pw-loopback -m '[ FL FR]' --capture-props='media.class=Audio/Sink node.name=DiscordSink' -n DiscordSink
          			''}";
      };
    };
    systemd.user.services.pw-gameaudio-virtual-device = {
      Install = {
        WantedBy = [ "hyprland-session.target" ];
      };
      Service = {
        ExecStart = "${pkgs.writeShellScript "game_audio_virt_device" ''
          				#!/run/current-system/sw/bin/bash
          				pw-loopback -m '[ FL FR]' --capture-props='media.class=Audio/Sink node.name=GameAudioSink' -n GameAudioSink
          			''}";
      };
    };
    systemd.user.services.obs-autostart = lib.mkIf cfg.autostart {
      Unit = {
        Description = "OBS daemon";
        After = [ "hyprland-session.target" ];
      };
      Install = {
        WantedBy = [ "default.target" ];
      };
      Service = {
        # wait for hyprland to start
        ExecStart = "${config.programs.obs-studio.finalPackage}/bin/obs --startreplaybuffer";
        Restart = "on-failure";
        RestartSec = "5s";
      };
    };
  };
}
