{ pkgs, lib, config, ... }:
let
  nvidia = config.hardware.nvidia.package;
  vrr-off = pkgs.writeScriptBin "vrr-off" ''
    #!${pkgs.stdenv.shell}
    ${nvidia}/bin/nvidia-settings -a AllowVRR=0
  '';
in {
  config = {
    systemd.user.services.vrr-off = {
      description = "vrr-off";
      serviceConfig = {
        ExecStart = "${vrr-off}/bin/vrr-off";
        Type = "oneshot";
      };
      wantedBy = [ "graphical-session.target" ];
    };

    services.xserver.displayManager.setupCommands = ''
      ${vrr-off}/bin/vrr-off
    '';
  };
}
