refactor: change gaming options to be more fine grained

This commit is contained in:
Youwen Wu 2024-12-23 01:36:18 -08:00
parent ab0ccf2519
commit 005fa17ee1
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3

View file

@ -10,7 +10,19 @@ in
{ {
options.liminalOS.extras.gaming = { options.liminalOS.extras.gaming = {
enable = lib.mkEnableOption "gaming"; enable = lib.mkEnableOption "gaming";
utilities.hamachi.enable = lib.mkEnableOption "hamachi"; utilities = {
hamachi.enable = lib.mkEnableOption "hamachi";
gamemode = {
enable = lib.mkEnableOption "gamemode";
gamemodeUsers = lib.mkOption {
type = lib.types.listOf lib.types.string;
default = [ ];
description = ''
List of users to add to the gamemode group. Gamemode will likely not work unless you add your user to the group!
'';
};
};
};
roblox.enable = lib.mkOption { roblox.enable = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = config.liminalOS.extras.gaming && cfg.enable; default = config.liminalOS.extras.gaming && cfg.enable;
@ -19,77 +31,92 @@ in
''; '';
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable (
environment.systemPackages = with pkgs; [ let
ryujinx forAllGamemodeUsers = lib.genAttrs cfg.utilities.gamemode.gamemodeUsers;
lutris in
heroic {
mangohud environment.systemPackages = with pkgs; [
mangojuice ryujinx
]; lutris
heroic
mangohud
mangojuice
];
liminalOS.programs.flatpaks.enable = true; liminalOS.programs.flatpaks.enable = true;
services.flatpak.packages = lib.mkIf cfg.roblox.enable [ services.flatpak.packages = lib.mkIf cfg.roblox.enable [
{ {
flatpakref = "https://sober.vinegarhq.org/sober.flatpakref"; flatpakref = "https://sober.vinegarhq.org/sober.flatpakref";
sha256 = "sha256:1pj8y1xhiwgbnhrr3yr3ybpfis9slrl73i0b1lc9q89vhip6ym2l"; sha256 = "sha256:1pj8y1xhiwgbnhrr3yr3ybpfis9slrl73i0b1lc9q89vhip6ym2l";
} }
{ {
appId = "org.vinegarhq.Sober"; appId = "org.vinegarhq.Sober";
origin = "sober"; origin = "sober";
} }
]; ];
programs.steam = { programs.steam = {
enable = true; enable = true;
remotePlay.openFirewall = true; remotePlay.openFirewall = true;
dedicatedServer.openFirewall = true; dedicatedServer.openFirewall = true;
localNetworkGameTransfers.openFirewall = true; localNetworkGameTransfers.openFirewall = true;
gamescopeSession.enable = true; gamescopeSession.enable = true;
}; };
programs.gamescope.enable = true; programs.gamescope.enable = true;
programs.gamemode = { programs.gamemode = {
enable = true; enable = true;
enableRenice = true; enableRenice = true;
settings = { settings = {
general = { general = {
renice = 10; renice = 10;
}; };
custom = { custom = {
start = "${pkgs.libnotify}/bin/notify-send 'GameMode engaged'"; start = "${pkgs.libnotify}/bin/notify-send 'GameMode engaged'";
end = "${pkgs.libnotify}/bin/notify-send 'GameMode disengaged'"; end = "${pkgs.libnotify}/bin/notify-send 'GameMode disengaged'";
};
}; };
}; };
};
users.users.${config.liminalOS.username}.extraGroups = [ "gamemode" ]; users.users = forAllGamemodeUsers (username: {
${username}.extraGroups = [ "gamemode" ];
});
services.logmein-hamachi.enable = cfg.utilities.hamachi.enable; services.logmein-hamachi.enable = cfg.utilities.hamachi.enable;
programs.haguichi.enable = cfg.utilities.hamachi.enable; programs.haguichi.enable = cfg.utilities.hamachi.enable;
nixpkgs.config.packageOverrides = pkgs: { nixpkgs.config.packageOverrides = pkgs: {
steam = pkgs.steam.override { steam = pkgs.steam.override {
extraPkgs = extraPkgs =
pkgs: with pkgs; [ pkgs: with pkgs; [
xorg.libXcursor xorg.libXcursor
xorg.libXi xorg.libXi
xorg.libXinerama xorg.libXinerama
xorg.libXScrnSaver xorg.libXScrnSaver
libpng libpng
libpulseaudio libpulseaudio
libvorbis libvorbis
stdenv.cc.cc.lib stdenv.cc.cc.lib
libkrb5 libkrb5
(writeShellScriptBin "launch-gamescope" '' (writeShellScriptBin "launch-gamescope" ''
(sleep 1; pgrep gamescope| xargs renice -n -11 -p)& (sleep 1; pgrep gamescope| xargs renice -n -11 -p)&
exec gamescope "$@" exec gamescope "$@"
'') '')
keyutils keyutils
]; ];
};
}; };
};
}; warnings =
if cfg.utilities.gamemode.enable && (builtins.length cfg.utilities.gamemode.gamemodeUsers == 0) then
[
''You enabled gamemode without setting any gamemode users in `liminalOS.extras.gaming.utilities.gamemode.gamemodeUsers. Gamemode is unlikely to work unless you add your user to gamemodeUsers.''
]
else
[ ];
}
);
} }