nixcitizen/default.nix
Philipp 32a252e9a4 Fix Typo and removePrefix
Signed-off-by: Philipp <philipp+dev@xndr.de>
2021-07-22 00:05:28 +02:00

183 lines
5.3 KiB
Nix

{ stdenv, lib, pkgs, fetchurl, nix, pkgsCross,
installDir ? "$HOME/.local/starcitizen",
launcherCache ? "$HOME/.local/share",
prefixBaseDir ? "$HOME/.winenix",
binName ? "starcitizen",
launcherArgs ? [ "--use-gl=osmesa" ],
winePackage ? pkgs.wineWowPackages.unstable,
wineGlobalEnv ? [ "DXVK_STATE_CACHE=0" ],
winePatches ? [ ./patches/joyaxis.patch ],
virtualDesktop ? null,
registryFiles ? [ ],
captureMouse ? true
}:
#check wether string is two positive integers separated by x
assert virtualDesktop == null ||
(lib.strings.toInt(lib.strings.concatStrings(lib.strings.splitString "x" virtualDesktop))) > 0;
#check whether paths are not terminated with a /
assert !(builtins.any (lib.strings.hasSuffix "/") [ installDir launcherCache prefixBaseDir ]);
let
winePkg = winePackage.overrideAttrs (attrs: {
patches = attrs.patches ++ winePatches;
});
dxvk = (with import ~/repositories/nixpkgs/default.nix {}; pkgsCross.mingwW64.callPackage ./dxvk.nix { });
fonts = pkgs.callPackage ./fonts.nix {};
wine64 = "${winePkg}/bin/wine64";
wineMulti = "${winePkg}/bin/wine";
regEdit = "${wine64} regedit";
reg = "${wine64} reg";
rsiInstaller = fetchurl {
url = "https://install.robertsspaceindustries.com/star-citizen/RSI-Setup-1.4.11.exe";
sha256 = "1afc4b36dd1e22d75df8da2ecb925833f9b10327c991be20e138503cde627022";
};
win10Reg = pkgs.writeTextFile {
name = "win10.reg";
text = ./win10.reg;
};
captureMouseReg = pkgs.writeTextFile {
name = "captureMouse.reg";
text = ./captureMouse.reg;
};
script = pkgs.writeShellScriptBin binName ''
#sane bash
set -eo pipefail
function installPrefix () {
if [ ! -d "$WINEPREFIX" ]; then
${winePkg}/bin/wineboot -i
#set win 10
${regEdit} ${win10Reg}
#install dxvk
for library in ${dxvk}/bin/*.dll ; do
cp $library "$WINEPREFIX/drive_c/windows/system32"
local libraryFile=$(basename $library)
${reg} add 'HKEY_CURRENT_USER\Software\Wine\DllOverrides' /v ''${libraryFile/\.dll/} /d native /f
done
#install fonts
cp ${fonts}/share/fonts/*.TTF "$WINEPREFIX/drive_c/windows/Fonts"
${regEdit} ${fonts}/share/regs/fonts.reg
#symlink persistent game and launcher binaries into prefix.
gameBinariesPers="${installDir}/Roberts Space Industries"
gameBinariesLinkDest="$WINEPREFIX/drive_c/Program Files/"
mkdir -p "$gameBinariesPers" "$gameBinariesLinkDest"
ln -s "$gameBinariesPers" "$gameBinariesLinkDest"
#symlink launcher cache
launcherCachePers="${launcherCache}/rsilauncher"
mkdir -p "$launcherCachePers" "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/"
ln -s "$launcherCachePers" "$WINEPREFIX/drive_c/users/$USER/AppData/Roaming/"
${lib.optionalString captureMouse "${regEdit} ${captureMouseReg.text}"}
#apply custom user registry files
${lib.concatMapStrings (x: "${regEdit} " + x + "\n") registryFiles}
fi
}
function installLauncher () {
installPrefix
#install the launcher
echo "Install with default parameters, launcherArgs won't be used when you launch the launcher from the setup"
${winePkg}/bin/wine ${rsiInstaller}
}
function runGame () {
installPrefix
#install the launcher conditionally here and not in the launcher to allow force reinstalls.
if [ ! -f "${installDir}/Roberts Space Industries/RSI Launcher/RSI Launcher.exe" ]; then
installLauncher
fi
${wineMulti} \
${if virtualDesktop != null then "explorer /desktop=${binName},${virtualDesktop}" else ""} \
"$WINEPREFIX/drive_c/Program Files/Roberts Space Industries/RSI Launcher/RSI Launcher.exe" \
${lib.concatStringsSep " " launcherArgs}
}
function printPrefix () {
echo "$WINEPREFIX"
}
function clean () {
find "${prefixBaseDir}" -maxdepth 1 -type d -name ????????????????????????????????-"${binName}" -and -not -wholename "$WINEPREFIX" -delete
}
function removePrefix () {
#Good thing the GPL contains a no warranty clause
rm -rf "$WINEPREFIX"
}
function help () {
echo "Gid gud!"
}
function wine () {
installPrefix
${winePkg}/bin/"$@"
}
#base setup
if [ ! -d "${installDir}" ]; then
mkdir -p "${installDir}/Roberts Space Industries"
fi
#create base dir for nix installs
if [ ! -d ${prefixBaseDir} ]; then
mkdir -p "${prefixBaseDir}"
fi
#core idea: Generate UUID from storage path of this script, ensure
#new prefix for any changes. Needs fast prefix installs and state outside.
uuid=$(basename $(${pkgs.nix}/bin/nix path-info "$BASH_SOURCE"))
export WINEPREFIX="${prefixBaseDir}/$uuid"
#export all global env vars
${lib.concatMapStrings (x: "export " + x + "\n") wineGlobalEnv }
#parse input
case "$@" in
--install-prefix)
installPrefix
;;
--install-launcher)
installLauncher
;;
--clean)
clean
;;
--remove-prefix)
removePrefix
;;
--run-game|"")
runGame
;;
--print-prefix)
printPrefix
;;
--help)
help
;;
--wine*)
shift
wine "$@"
;;
*)
help
exit 1
esac
'';
in script