Integrates backup wrapper with switch emulators
• Adds a new backup script that automates creating and rotating backups • Updates gaming module to include dynamic configuration imports • Creates desktop entries for emulators using the backup wrapper
This commit is contained in:
parent
adcd16e3e6
commit
d2cec468c3
4 changed files with 158 additions and 6 deletions
|
@ -8,10 +8,6 @@
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
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);
|
monitor = lib.head (lib.filter (m: m.primary) config.monitors);
|
||||||
steam-session =
|
steam-session =
|
||||||
let
|
let
|
||||||
|
@ -50,10 +46,10 @@ let
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
imports = lib.custom.scanPaths ./.;
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
citron-emu
|
|
||||||
prismlauncher
|
prismlauncher
|
||||||
ryubing
|
|
||||||
steam-session
|
steam-session
|
||||||
# modrinth-app
|
# modrinth-app
|
||||||
(lutris.override {
|
(lutris.override {
|
||||||
|
|
76
home/toph/common/optional/gaming/scripts/backup.nix
Normal file
76
home/toph/common/optional/gaming/scripts/backup.nix
Normal file
|
@ -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] <src> <dest> <interval_s> <max_backups> -- <program> [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
|
||||||
|
''
|
3
home/toph/common/optional/gaming/scripts/default.nix
Normal file
3
home/toph/common/optional/gaming/scripts/default.nix
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
# :D
|
||||||
|
}
|
77
home/toph/common/optional/gaming/switch.nix
Normal file
77
home/toph/common/optional/gaming/switch.nix
Normal file
|
@ -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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue