dot

NixOS dotfiles
git clone https://git.echoz.io/dot.git
Log | Files | Refs

default.nix (3497B)


      1 {
      2   bash,
      3   bubblewrap,
      4   cacert,
      5   coreutils,
      6   curl,
      7   dxvk,
      8   gnugrep,
      9   makeDesktopItem,
     10   symlinkJoin,
     11   wineWow64Packages,
     12   writeShellApplication,
     13 }:
     14 
     15 let
     16   winePkg = wineWow64Packages.stagingFull;
     17 
     18   inner = writeShellApplication {
     19     name = "bnet-inner";
     20     runtimeInputs = [ winePkg curl coreutils bash gnugrep ];
     21     text = ''
     22       export WINEPREFIX="$HOME/prefix"
     23       export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
     24 
     25       if [ ! -e "$WINEPREFIX/.setup-done" ]; then
     26         echo "Initializing wineprefix" >&2
     27         wineboot -u
     28         wineserver -w
     29 
     30         echo "Installing DXVK" >&2
     31         ln -sf ${dxvk.dxvk64}/bin/*.dll "$WINEPREFIX/drive_c/windows/system32/"
     32         ln -sf ${dxvk.dxvk32}/bin/*.dll "$WINEPREFIX/drive_c/windows/syswow64/"
     33         for dll in d3d8 d3d9 d3d10core d3d11 dxgi; do
     34           wine reg add 'HKCU\Software\Wine\DllOverrides' /v "$dll" /d native /f
     35         done
     36         wineserver -w
     37 
     38         echo "Downloading Battle.net installer" >&2
     39         curl -Lo /tmp/Battle.net-Setup.exe \
     40           'https://downloader.battle.net/download/getInstaller?os=win&installer=Battle.net-Setup.exe'
     41         wine /tmp/Battle.net-Setup.exe
     42         wineserver -w
     43 
     44         touch "$WINEPREFIX/.setup-done"
     45       fi
     46 
     47       exec wine "$WINEPREFIX/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe" "$@"
     48     '';
     49   };
     50 
     51   launcher = writeShellApplication {
     52     name = "bnet";
     53     runtimeInputs = [ bubblewrap coreutils ];
     54     text = ''
     55       data="''${XDG_DATA_HOME:-$HOME/.local/share}/bnet"
     56       mkdir -p "$data"
     57       run="''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
     58 
     59       args=(
     60         --unshare-all --share-net
     61         --die-with-parent
     62         --proc /proc
     63         --dev /dev
     64         --tmpfs /tmp
     65         --ro-bind /nix /nix
     66         --ro-bind /sys /sys
     67         --dev-bind /dev/dri /dev/dri
     68         --ro-bind /etc/resolv.conf /etc/resolv.conf
     69         --ro-bind-try /etc/ssl /etc/ssl
     70         --ro-bind-try /etc/pki /etc/pki
     71         --ro-bind-try /etc/static /etc/static
     72         --ro-bind-try /etc/hosts /etc/hosts
     73         --ro-bind-try /etc/localtime /etc/localtime
     74         --ro-bind-try /etc/fonts /etc/fonts
     75         --ro-bind-try /etc/machine-id /etc/machine-id
     76         --ro-bind-try /run/opengl-driver /run/opengl-driver
     77         --ro-bind-try /run/opengl-driver-32 /run/opengl-driver-32
     78         --bind "$data" "$HOME"
     79         --dir "$run"
     80         --setenv XDG_RUNTIME_DIR "$run"
     81       )
     82 
     83       if [ -n "''${DISPLAY:-}" ]; then
     84         args+=( --ro-bind-try /tmp/.X11-unix /tmp/.X11-unix --setenv DISPLAY "$DISPLAY" )
     85         if [ -n "''${XAUTHORITY:-}" ]; then
     86           args+=( --ro-bind-try "$XAUTHORITY" "$XAUTHORITY" --setenv XAUTHORITY "$XAUTHORITY" )
     87         fi
     88       fi
     89 
     90       if [ -n "''${WAYLAND_DISPLAY:-}" ] && [ -e "$run/$WAYLAND_DISPLAY" ]; then
     91         args+=( --bind "$run/$WAYLAND_DISPLAY" "$run/$WAYLAND_DISPLAY" \
     92                 --setenv WAYLAND_DISPLAY "$WAYLAND_DISPLAY" )
     93       fi
     94 
     95       for sock in pulse/native pipewire-0; do
     96         if [ -e "$run/$sock" ]; then
     97           args+=( --bind "$run/$sock" "$run/$sock" )
     98         fi
     99       done
    100 
    101       exec bwrap "''${args[@]}" ${inner}/bin/bnet-inner "$@"
    102     '';
    103   };
    104 
    105   desktopItem = makeDesktopItem {
    106     name = "bnet";
    107     desktopName = "Battle.net";
    108     comment = "Battle.net launcher";
    109     exec = "${launcher}/bin/bnet";
    110     categories = [ "Game" ];
    111     startupWMClass = "battle.net.exe";
    112   };
    113 in
    114 symlinkJoin {
    115   name = "bnet";
    116   paths = [ launcher desktopItem ];
    117 }