{
  config,
  lib,
  inputs,
  pkgs,
  home,
  system,
  ...
}:
let
  cfg = config.modules.wivrn;
  wivrn_override = pkgs.wivrn.overrideAttrs (
    final: prev: {
      pname = "wivrn";
      version = "25.11.1";
      src = pkgs.fetchFromGitHub {
        owner = "wivrn";
        repo = "wivrn";
        rev = "v25.11.1";
        hash = "sha256-pEKMeRdI9UhdZ+NksRBcF7yPC7Ys2haE+B4PPGQ4beE=";
      };
      monado = pkgs.applyPatches {
        src = pkgs.fetchFromGitLab {
          domain = "gitlab.freedesktop.org";
          owner = "monado";
          repo = "monado";
          rev = "06e62fc7d9c5cbcbc43405bb86dfde3bf01ce043";
          hash = "sha256-0ALB9eLY4NAUqNOYZMwpvYnLxVpHsQDJc1er8Txdezs=";
        };

        postPatch = ''
          ${final.src}/patches/apply.sh ${final.src}/patches/monado/*
        '';
      };
      patches = [ ];
    }
  );
in
{
  options.modules.wivrn = {
    enable = lib.mkEnableOption "Wivrn configuration module";
  };
  config = lib.mkIf cfg.enable {
    services = {
      wivrn = {
        enable = true;
        package = wivrn_override;
        openFirewall = true;
        defaultRuntime = true;
      };
      avahi = {
        enable = true;
        publish.enable = true;
        publish.userServices = true;
      };
    };
    programs.adb.enable = true;
  };
}
