diff --git a/home/toph/common/optional/gaming/default.nix b/home/toph/common/optional/gaming/default.nix index 9f3a40a..936fcf2 100644 --- a/home/toph/common/optional/gaming/default.nix +++ b/home/toph/common/optional/gaming/default.nix @@ -8,10 +8,6 @@ }: let - - path = lib.custom.relativeToRoot "pkgs/common/citron-emu/package.nix"; - citron-emu = pkgs.callPackage path { inherit pkgs; }; - monitor = lib.head (lib.filter (m: m.primary) config.monitors); steam-session = let @@ -50,10 +46,10 @@ let ''; in { + imports = lib.custom.scanPaths ./.; + home.packages = with pkgs; [ - citron-emu prismlauncher - ryubing steam-session # modrinth-app (lutris.override { diff --git a/home/toph/common/optional/gaming/scripts/backup.nix b/home/toph/common/optional/gaming/scripts/backup.nix new file mode 100644 index 0000000..f9333d4 --- /dev/null +++ b/home/toph/common/optional/gaming/scripts/backup.nix @@ -0,0 +1,76 @@ +{ + pkgs, + ... +}: +pkgs.writeScript "backup-wrapper" '' + #!/usr/bin/env fish + + ## Helpers ## + function backup + # Uses $src, $dest, $max_backups from outer scope + set timestamp (date +%Y%m%d-%H%M%S) + set outfile "$dest/backup-$timestamp.tar.zst" + + mkdir -p $dest + echo "→ Creating backup: $outfile" + + tar cf - $src | + ${pkgs.zstd}/bin/zstd -- -c -T5 -15 -v > $outfile + + # Rotate: keep only the newest $max_backups + set files (ls -1t $dest/backup-*.tar.zst) + if test (count $files) -gt $max_backups + for f in $files[(math "$max_backups + 1")..-1] + rm $f + echo " • Removed old backup: $f" + end + end + end + + function periodic_backups --argument-names pid + while test -d /proc/$pid + sleep $interval + echo "Interval backup at "(date) + backup + end + end + + + ## Arg parsing ## + if test (count $argv) -lt 5 + echo "Usage: $argv[0] -- [args...]" + exit 1 + end + + set src $argv[1] + set dest $argv[2] + set interval $argv[3] + set max_backups $argv[4] + + # strip leading “--” if present + set rest $argv[5..-1] + if test $rest[1] = "--" + set rest $rest[2..-1] + end + + + ## Workflow ## + echo "BACKUP: Initial backup of '$src' → '$dest'" + backup + + echo "BACKUP: Launching your program: $rest" + # fish will expand $rest as command + args + $rest &; set pid $last_pid + echo " → PID is $pid" + + echo "BACKUP: Starting periodic backups every $interval seconds…" + periodic_backups $pid & + + echo "BACKUP: Waiting for PID $pid to exit…" + wait $pid + + echo "BACKUP: Program exited at "(date)"; doing final backup." + backup + + exit 0 +'' diff --git a/home/toph/common/optional/gaming/scripts/default.nix b/home/toph/common/optional/gaming/scripts/default.nix new file mode 100644 index 0000000..af99a4f --- /dev/null +++ b/home/toph/common/optional/gaming/scripts/default.nix @@ -0,0 +1,3 @@ +{ + # :D +} diff --git a/home/toph/common/optional/gaming/switch.nix b/home/toph/common/optional/gaming/switch.nix new file mode 100644 index 0000000..4cb725b --- /dev/null +++ b/home/toph/common/optional/gaming/switch.nix @@ -0,0 +1,77 @@ +# This module just provides a customized .desktop file with gamescope args dynamically created based on the +# host's monitors configuration +{ + pkgs, + config, + lib, + ... +}: + +let + + path = lib.custom.relativeToRoot "pkgs/common/citron-emu/package.nix"; + citron-emu = pkgs.callPackage path { inherit pkgs; }; + + backup-wrapper = import ./scripts/backup.nix { inherit pkgs; }; + + user = config.hostSpec.username; + +in +{ + home.packages = with pkgs; [ + citron-emu + ryubing + ]; + + xdg.desktopEntries = { + Ryujinx = { + name = "Ryubing w/ Backups"; + comment = "Ryubing Emulator with Save Backups"; + exec = ''fish ${backup-wrapper} /home/${user}/.config/Ryujinx/bis/user/save /pool/Backups/Switch/RyubingSaves 960 20 -- ryujinx''; # Should amount to be ~8 hours of playtime in 30 backups + icon = "Ryujinx"; + type = "Application"; + terminal = false; + categories = [ + "Game" + "Emulator" + ]; + mimeType = [ + "application/x-nx-nca" + "application/x-nx-nro" + "application/x-nx-nso" + "application/x-nx-nsp" + "application/x-nx-xci" + ]; + prefersNonDefaultGPU = true; + settings = { + StartupWMClass = "Ryujinx"; + GenericName = "Nintendo Switch Emulator"; + }; + }; + + citron-emu = { + name = "Citron w/ Backups"; + comment = "Citron Emulator with Save Backups"; + exec = ''fish ${backup-wrapper} /home/${user}/.local/share/citron/nand/user/save /pool/Backups/Switch/CitronSaves 960 20 -- citron-emu''; # Should amount to be ~8 hours of playtime in 30 backups + icon = "applications-games"; + type = "Application"; + terminal = false; + categories = [ + "Game" + "Emulator" + ]; + mimeType = [ + "application/x-nx-nca" + "application/x-nx-nro" + "application/x-nx-nso" + "application/x-nx-nsp" + "application/x-nx-xci" + ]; + prefersNonDefaultGPU = true; + settings = { + StartupWMClass = "Citron"; + GenericName = "Nintendo Switch Emulator"; + }; + }; + }; +}