{ config, lib, pkgs, home-manager, ... }: let steam_dolphin = pkgs.writeScriptBin "steam_dolphin" '' export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.libglvnd}/lib" exec ${pkgs.dolphin-emu}/bin/dolphin-emu "''${@}" ''; in { imports = [ ]; options.me = { dolphin.enable = lib.mkOption { type = lib.types.bool; default = false; example = true; description = "Whether we want to install dolphin."; }; }; config = lib.mkIf config.me.dolphin.enable ( lib.mkMerge [ (lib.mkIf config.me.graphical { home.packages = with pkgs; [ dolphin-emu steam_dolphin ]; home.file.".config/dolphin-emu/Dolphin.ini" = { source = ./files/Dolphin.ini; }; home.file.".config/dolphin-emu/GFX.ini" = { source = ./files/GFX.ini; }; home.file.".config/dolphin-emu/Profiles/GCPad/deck.ini" = { source = ./files/deck.ini; }; home.file.".config/dolphin-emu/GCPadNew.ini" = { source = ./files/GCPadNew.ini; }; home.persistence."/home/deck/.persist" = { directories = [ { # The system memory directory = ".local/share/dolphin-emu/Wii"; method = "symlink"; } { # Memory card(s) directory = ".local/share/dolphin-emu/Load"; method = "symlink"; } { # Gamecube directory = ".local/share/dolphin-emu/GC"; method = "symlink"; } { # Screenshots directory = ".local/share/dolphin-emu/ScreenShots"; method = "symlink"; } { # GameBoy Advanced directory = ".local/share/dolphin-emu/GBA/Saves"; method = "symlink"; } ]; }; home.persistence."/home/deck/.state" = { directories = [ { directory = ".cache/dolphin-emu"; method = "symlink"; } { directory = ".local/share/dolphin-emu/Shaders"; method = "symlink"; } { directory = ".local/share/dolphin-emu/StateSaves"; method = "symlink"; } ]; }; home.activation = { createDolphinDirectories = home-manager.lib.hm.dag.entryAfter [ "writeBoundary" ] '' for dir in '.local/share/dolphin-emu/Wii' '.cache/dolphin-emu' '.local/share/dolphin-emu/Load' '.local/share/dolphin-emu/GC' '.local/share/dolphin-emu/ScreenShots' '.local/share/dolphin-emu/GBA/Saves' '.local/share/dolphin-emu/Shaders' '.local/share/dolphin-emu/StateSaves' ; do echo "checking $dir" if [[ ! -d "$HOME/.persist/$dir" ]]; then $DRY_RUN_CMD mkdir $VERBOSE_ARG -p "$HOME/.persist/$dir" fi done ''; }; nixpkgs.overlays = [ ( final: prev: let optimizeWithFlags = pkg: flags: pkg.overrideAttrs (old: { NIX_CFLAGS_COMPILE = [ (old.NIX_CFLAGS_COMPILE or "") ] ++ flags; }); original_package = if config.me.optimizations.enable then (optimizeWithFlags prev.dolphin-emu [ # Verified working with ps "-march=znver2" "-mtune=znver2" ]) else prev.dolphin-emu; in { dolphin-emu = pkgs.buildEnv { name = prev.dolphin-emu.name; paths = [ (config.lib.nixGL.wrap original_package) ]; extraOutputsToInstall = [ "man" "doc" "info" ]; # We have to use 555 instead of the normal 444 here because the .desktop file ends up inside $HOME on steam deck and desktop files must be either not in $HOME or must be executable, otherwise KDE Plasma refuses to execute them. postBuild = '' chmod 0555 $out/share/applications/dolphin-emu.desktop ''; }; } ) ]; }) ] ); }