This Nix derivation is used to create WINE prefixes for applications to be packaged in Nix but still have working writeable wine directories. it can also run Wine Tricks.
with builtins;
{ pkgs }:
{ wine ? pkgs.wine
, wineFlags ? ""
, executable
, chdir ? null
, name
, tricks ? [ ]
, setupScript ? ""
, teardownScript ? ""
, firstrunScript ? ""
, wineCommand ? ''wine ${wineFlags} "$EXECUTABLE" "$@"''
}:
let
tricksStmt =
if (length tricks) > 0 then
concatStringsSep " " tricks
else
"-V";
script = pkgs.writeShellScriptBin name ''
PATH=$PATH:${wine}/bin:${pkgs.winetricks}/bin
HOME="$(echo ~)"
WINE_NIX="$HOME/.wine-nix"
export WINEPREFIX="$WINE_NIX/${name}"
EXECUTABLE="${executable}"
mkdir -p "$WINE_NIX"
${setupScript}
if [ ! -d "$WINEPREFIX" ]
then
wine cmd /c dir > /dev/null 2> /dev/null # initialize prefix
wineserver -w
winetricks ${tricksStmt}
${firstrunScript}
fi
${if chdir != null then ''cd "${chdir}"'' else ""}
if [ ! "$REPL" == "" ];
then
bash
exit 0
fi
${wineCommand}
wineserver -w
${teardownScript}
'';
in
script