CCE

nixcfg/wrapWine.nix at e542e743774f499f996a4f886a8d4a4133fce258 · lucasew/nixcfg

Archive

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.

nix:tangle ~/nix/lib/wrapWine.nix
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