fork/slippi-nix
git clone https://git.julia.blue/fork/slippi-nix
0da163f
remove-trace
1{ 2lib , 3pkgs , 4config , 5 ... 6} : 7let 8hashes = import ../../hashes.nix ; 9inherit ( lib ) 10mkEnableOption 11mkOption 12types 13mkIf 14; 15cfg = config . slippi-launcher ; 16netplay-beta-package = 17version :hash : 18pkgs . callPackage ../../packages/slippi-netplay-beta.nix { 19inherit version hash ; 20}; 21netplay-package = 22version :hash : 23pkgs . callPackage ../../packages/slippi-netplay.nix { 24inherit version hash ; 25}; 26playback-package = 27version :hash : 28pkgs . callPackage ../../packages/slippi-playback.nix { 29inherit version hash ; 30}; 31launcher-package = 32version :hash : 33pkgs . callPackage ../../packages/slippi-launcher.nix { 34inherit version hash ; 35}; 36in 37{ 38options . slippi-launcher = { 39enable = mkEnableOption "Install Slippi Launcher" // { 40default = true ; 41}; 42 43netplayVersion = mkOption { 44default = hashes . netplay . version ; 45type = types . str ; 46description = "The version of Slippi Netplay to install." ; 47}; 48netplayHash = mkOption { 49default = hashes . netplay . hash ; 50type = types . str ; 51description = "The hash of the Slippi Netplay AppImage to install." ; 52}; 53 54netplayBetaVersion = mkOption { 55default = hashes . netplay-beta . version ; 56type = types . str ; 57description = "The version of Slippi Netplay (Mainline beta) to install." ; 58}; 59netplayBetaHash = mkOption { 60default = hashes . netplay-beta . hash ; 61type = types . str ; 62description = "The hash of the Slippi Netplay (Mainline beta) AppImage to install." ; 63}; 64 65playbackVersion = mkOption { 66default = hashes . playback . version ; 67type = types . str ; 68description = "The version of Slippi Playback to install." ; 69}; 70playbackHash = mkOption { 71default = hashes . playback . hash ; 72type = types . str ; 73description = "The hash of the Slippi Playback AppImage to install." ; 74}; 75 76launcherVersion = mkOption { 77default = hashes . launcher . version ; 78type = types . str ; 79description = "The version of Slippi Launcher to install." ; 80}; 81launcherHash = mkOption { 82default = hashes . launcher . hash ; 83type = types . str ; 84description = "The hash of the Slippi Launcher AppImage to install." ; 85}; 86 87isoPath = mkOption { 88default = "" ; 89type = types . str ; 90description = "The path to an NTSC Melee ISO." ; 91}; 92useNetplayBeta = mkEnableOption "Use the mainline Dolphin instead of the stable version." // { 93default = false ; 94}; 95 96launchMeleeOnPlay = mkEnableOption "Launch Melee in Dolphin when the Play button is pressed." // { 97default = true ; 98}; 99 100enableJukebox = 101mkEnableOption "Enable in-game music via Slippi Jukebox. Incompatible with WASAPI." 102// { 103default = true ; 104}; 105 106rootSlpPath = mkOption { 107default = " ${ config . home . homeDirectory } /Slippi" ; 108type = types . str ; 109description = "The folder where your SLP replays should be saved." ; 110}; 111 112useMonthlySubfolders = mkEnableOption "Save replays to monthly subfolders" ; 113 114spectateSlpPath = mkOption { 115default = " ${ cfg . rootSlpPath } /Spectate" ; 116type = types . nullOr types . str ; 117description = "The folder where spectated games should be saved." ; 118}; 119 120extraSlpPaths = mkOption { 121default = [ ]; 122type = types . listOf types . str ; 123description = "Choose any additional SLP directories that should show up in the replay browser." ; 124}; 125}; 126config = mkIf cfg . enable ( 127let 128cfgNetplayPackage = netplay-package cfg . netplayVersion cfg . netplayHash ; 129cfgNetplayBetaPackage = netplay-beta-package cfg . netplayBetaVersion cfg . netplayBetaHash ; 130cfgPlaybackPackage = playback-package cfg . playbackVersion cfg . playbackHash ; 131cfgLauncherPackage = launcher-package cfg . launcherVersion cfg . launcherHash ; 132in 133{ 134home . packages = [ cfgLauncherPackage ]; 135home . file . ".config/Slippi Launcher/netplay/Slippi_Online-x86_64.AppImage" = { 136source = " ${ lib . getExe cfgNetplayPackage } " ; 137recursive = false ; 138}; 139home . file . ".config/Slippi Launcher/netplay/Sys" = { 140source = " ${ cfgNetplayPackage . raw-zip } /Sys" ; 141recursive = false ; 142}; 143home . file . ".config/Slippi Launcher/netplay-beta/Slippi_Netplay_Mainline-x86_64.AppImage" = { 144source = " ${ lib . getExe cfgNetplayBetaPackage } " ; 145recursive = false ; 146}; 147home . file . ".config/Slippi Launcher/netplay-beta/Sys" = { 148source = " ${ cfgNetplayBetaPackage . raw-zip } /Sys" ; 149recursive = false ; 150}; 151home . file . ".config/Slippi Launcher/playback/Slippi_Playback-x86_64.AppImage" = { 152source = " ${ lib . getExe cfgPlaybackPackage } " ; 153recursive = false ; 154}; 155home . file . ".config/Slippi Launcher/playback/Sys" = { 156source = " ${ cfgPlaybackPackage . raw-zip } /Sys" ; 157recursive = false ; 158}; 159 160xdg = { 161mimeApps . defaultApplications = { 162"application/x-slippi" = "slippi-launcher.desktop" ; 163}; 164dataFile . "mime/packages/x-slippi.xml" . text = '' 165<?xml version="1.0" encoding="UTF-8"?> 166<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> 167<mime-type type="application/x-slippi"> 168<comment>Slippi Replay</comment> 169<glob pattern="*.slp"/> 170<icon name="slippi-launcher"/> 171</mime-type> 172</mime-info> 173'' ; 174}; 175 176# Use an activation script instead of xdg.configFile so the settings 177# file is mutable. The launcher needs to write to it (e.g. login 178# credentials). Nix-managed settings are merged on each activation, 179# preserving any extra keys the launcher has written. 180home . activation . slippiLauncherSettings = 181let 182jsonFormat = pkgs . formats . json { }; 183settingsFile = jsonFormat . generate "slippi-config" { 184settings = { 185isoPath = cfg . isoPath ; 186 187launchMeleeOnPlay = cfg . launchMeleeOnPlay ; 188enableJukebox = cfg . enableJukebox ; 189useNetplayBeta = cfg . useNetplayBeta ; 190 191rootSlpPath = cfg . rootSlpPath ; 192useMonthlySubfolders = cfg . useMonthlySubfolders ; 193spectateSlpPath = cfg . spectateSlpPath ; 194extraSlpPaths = cfg . extraSlpPaths ; 195 196netplayDolphinPath = " ${ 197if cfg . useNetplayBeta then cfgNetplayBetaPackage else cfgNetplayPackage 198} /bin/" ; 199playbackDolphinPath = " ${ cfgPlaybackPackage } /bin/" ; 200 201autoUpdateLauncher = false ; 202}; 203}; 204in 205lib . hm . dag . entryAfter [ "writeBoundary" ] '' 206slippi_dir=" ${ config . xdg . configHome } /Slippi Launcher" 207slippi_settings="$slippi_dir/Settings" 208 209mkdir -p "$slippi_dir" 210 211# Remove stale symlink from previous module version 212if [ -L "$slippi_settings" ]; then 213rm "$slippi_settings" 214fi 215 216if [ -f "$slippi_settings" ]; then 217# Merge existing settings with Nix-managed settings (Nix wins on conflicts) 218${ pkgs . jq } /bin/jq -s '.[0] * .[1]' \ 219"$slippi_settings" \ 220" ${ settingsFile } " > "$slippi_settings.tmp" 221mv "$slippi_settings.tmp" "$slippi_settings" 222else 223cp " ${ settingsFile } " "$slippi_settings" 224chmod u+w "$slippi_settings" 225fi 226'' ; 227} 228); 229}