How to allow wine to change the NICE?

So, running Steam games with Proton I can always see the following message: wine: RLIMIT_NICE is <= 20, unable to use setpriority safely, there is a supposed workaround to allow wine to change the priotiry with echo "* hard nice -20" | sudo tee -a /etc/security/limits.conf, but then again, this is NixOS and such a file does not exist.

I see that gamescope provides options for changing the NICE, for instance, programs.gamemode.enableRenice and programs.gamescope.capSysNice, but then again, Steam is using Proton/Wine and Proton/Wine wants to change the NICE.

Do you have any clues on how to change “limits.conf” the NixOS way?

I’ve ported realtime group from Arch Linux. Just change the user.

{
  # ported from https://gitlab.archlinux.org/archlinux/packaging/packages/realtime-privileges
  users = {
    users.adomas.extraGroups = [ "realtime" ];
    groups.realtime = { };
  };
  services.udev.extraRules = ''
    KERNEL=="cpu_dma_latency", GROUP="realtime"
  '';
  security.pam.loginLimits = [
    {
      domain = "@realtime";
      type = "-";
      item = "rtprio";
      value = 98;
    }
    {
      domain = "@realtime";
      type = "-";
      item = "memlock";
      value = "unlimited";
    }
    {
      domain = "@realtime";
      type = "-";
      item = "nice";
      value = -11;
    }
  ];
}

gamescopes priority is changed by a script in my system.

{ pkgs, ... }: {
  programs = {
    steam = {
      enable = true;
      package = pkgs.steam.override {
        extraPkgs = pkgs:
          with pkgs; [
            xorg.libXcursor
            xorg.libXi
            xorg.libXinerama
            xorg.libXScrnSaver
            libpng
            libvorbis
            stdenv.cc.cc.lib
            libkrb5
            keyutils
            mangohud
            (writeShellScriptBin "launch-gamescope" ''
              (sleep 1; pgrep gamescope| xargs renice -n -11 -p)&
              exec gamescope "$@"
            '')
          ];
      };
    };
    # use
    # `gamescope -f -- %command% & sleep 2 && renice -n -11 -p $(pgrep gamescope)`
    # as launch options
    gamescope = {
      enable = true;
      env.XKB_LAYOUT = "us";
    };
  };
}

Use launch-gamescope -f -- %command% in Steam command line options for a game.