Last active
June 28, 2024 06:52
-
-
Save YellowOnion/aace96e072947def00bc37b9e4e4b52d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
let | |
cfg = config.games; | |
withExtraGameScripts = scripts: | |
(pkgs.writeShellScriptBin "run.sh" | |
''${ | |
let f = a: b: "exec ${a}/bin/run.sh " + b; in lib.foldr f ''"$@"'' scripts | |
} | |
''); | |
gameEnv = '' | |
export MANGOHUD_CONFIG=gpu_temp,fps_limit=180+120+90+0 | |
export PIPEWIRE_NODE=input.game | |
export PULSE_SINK=input.game | |
''; | |
gameScripts = withExtraGameScripts cfg.extraGameScripts; | |
runVKGame = (pkgs.writeShellScriptBin "runVKGame" | |
'' | |
${gameEnv} | |
OBS_VKCAPTURE=1 MANGOHUD=1 systemd-inhibit ${gameScripts}/bin/run.sh "$@" | |
''); | |
runOGLGame = (pkgs.writeShellScriptBin "runOGLGame" | |
'' | |
${gameEnv} | |
systemd-inhibit ${pkgs.obs-studio-plugins.obs-vkcapture}/bin/obs-gamecapture ${pkgs.mangohud}/bin/mangohud ${gameScripts}/bin/run.sh "$@" | |
''); | |
runOGL32Game = (pkgs.writeShellScriptBin "runOGL32Game" | |
(let pkgs32 = pkgs.pkgsi686Linux; in | |
'' | |
${gameEnv} | |
systemd-inhibit ${pkgs32.obs-studio-plugins.obs-vkcapture}/bin/obs-gamecapture ${pkgs32.mangohud}/bin/mangohud ${gameScripts}/bin/run.sh "$@" | |
'')); | |
withSwayFloating = (pkgs.writeShellScriptBin "withSwayFloating" | |
'' | |
ID=$(base64 /dev/urandom | head -c 8) | |
( kill -SIGSTOP $BASHPID; exec "$@" ) & | |
PID=$! | |
[ -z "$GAME_NAME" ] && GAME_NAME=$ID | |
swaymsg "for_window [ pid = $PID ] mark --replace \"game:$GAME_NAME\"" | |
kill -SIGCONT $PID | |
wait $PID | |
''); | |
in | |
{ | |
options = { | |
games = { | |
extraGameScripts = lib.mkOption { | |
type = lib.types.listOf lib.types.package; | |
default = [ ]; | |
description = lib.mdDoc "a list of extra scripts to run with a game"; | |
}; | |
}; | |
}; | |
config = lib.mkMerge [ | |
( | |
{ | |
home.stateVersion = "24.05"; | |
home.packages = [ | |
pkgs.jq | |
runVKGame | |
runOGLGame | |
runOGL32Game | |
withSwayFloating | |
]; | |
} | |
) | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment