spacefrogg-overlay/x-plane/default.nix

231 lines
7.8 KiB
Nix
Raw Normal View History

2020-10-18 14:34:40 +02:00
# Does not touch paths inside xplanePathStr.
# Setup needed to integrate the addons.
# HeadShake
# Create the following softlink:
# ln -sf /xplane-extra/HeadShake $xplanePathStr/Resources/plugins
# Beautiful Roads:
# Rename the following directory in "$xplanePathStr/Resources/default scenery/1000 roads":
# mv textures textures.orig
#
# and create the following softlink to textures:
# ln -sf /xplane-extra/beautiful-roads textures
#
# To switch to the old roads, callPackage this file with the beautifulRoads
# attribute set to null.
{ stdenv
, lib
, writeScript
, buildFHSUserEnv
2022-06-08 14:01:14 +02:00
, xplanePathStr, unzip
, addons ? []
, name ? "x-plane-env"
}:
2020-10-18 14:34:40 +02:00
let
2022-06-08 14:01:14 +02:00
inherit (lib) concatMapStrings optionalString unique;
2020-10-18 14:34:40 +02:00
runScript = writeScript "x-plane-script" ''
#!${stdenv.shell}
2022-06-08 14:01:14 +02:00
usage() {
cat <<EOF >&2
${name} OPT
2022-06-08 14:01:14 +02:00
X-Plane run X-Plane (default)
Airfoil run Airfoil Maker
Plane run Plane Maker
Installer run Installer
SHELL run bash inside FHS environment
prepare prepare all currently activated addons
revert [ADDON]...
remove modifications from named addons
navdata FILE [OLDCYCLE]
update navigation DB
ortho update links to zOrtho4XP scenery files
/abs/path [ARG]...
run /abs/path inside FHS environment
rel/path [ARG]...
run $XPLANEPATH/rel/path inside FHS environment
2022-06-08 14:01:14 +02:00
EOF
}
2020-10-18 14:34:40 +02:00
sys=${stdenv.targetPlatform.system}
sys=''${sys%-linux}
bin=$1
: ''${XPLANEPATH:=${xplanePathStr}}
export XPLANEPATH
case "$bin" in
2022-06-08 14:01:14 +02:00
--help) usage; exit ;;
2020-10-18 14:34:40 +02:00
X-Plane) exec "''${XPLANEPATH}/X-Plane-$sys" ;;
Airfoil*) exec "''${XPLANEPATH}/Airfoil Maker-$sys" ;;
Plane*) exec "''${XPLANEPATH}/Plane Maker-$sys" ;;
2022-10-03 10:08:58 +02:00
Installer*) for f in "''${XPLANEPATH}/X-Plane "*" Installer Linux"; do exec "$f"; break; done ;;
2020-10-18 14:34:40 +02:00
''') exec "''${XPLANEPATH}/X-Plane-$sys" ;;
SHELL) exec "bash" ;;
prepare) exec ${prepareScript} ;;
revert) shift; exec ${revertScript} "$@" ;;
2022-06-08 14:01:14 +02:00
navdata) shift; exec ${navdbScript} "$@" ;;
ortho) exec ${orthoScript} ;;
2020-10-18 14:34:40 +02:00
/*) exec "$@" ;;
*) shift; exec "''${XPLANEPATH}/$bin" "$@" ;;
esac
'';
uniqueAddons = unique addons;
prepareScript = writeScript "x-plane-addons-prepare" (''
#!${stdenv.shell}
set -e
: ''${XPLANEPATH:=${xplanePathStr}}
printf "Preparing %s for accessing addons\n" "$XPLANEPATH" >&2
mkdir -p "$XPLANEPATH/.addons"
if [ -f "$XPLANEPATH/.addons/dont-prepare" ]; then
printf "Warning: %s found. Not preparing tree.\n" "$XPLANEPATH/.addons/dont-prepare" >&2
exit 1
fi
'' + (concatMapStrings (addon:
optionalString (addon.passthru ? prepare) (''
# Addon ${addon.pname}-${addon.version}
ADDONPATH=${addon}
printf "Preparing %s\n" "${addon.pname}-${addon.version}" >&2
if [ -f "$XPLANEPATH/.addons/revert-${addon.pname}" ]; then
printf "Warning: Old revert script found. Not modifying X-Plane tree. Revert first.\n" >&2
else
${addon.passthru.prepare}
'' + (if (addon.passthru ? revert) then ''
cat <<'EOF' >"$XPLANEPATH/.addons/revert-${addon.pname}"
2022-06-08 14:01:14 +02:00
#!/usr/bin/env bash
2020-10-18 14:34:40 +02:00
set -e
${addon.passthru.revert}
rm $0
EOF
chmod +x "$XPLANEPATH/.addons/revert-${addon.pname}"
fi
'' else ''
fi
''))) uniqueAddons));
revertScript = writeScript "x-plane-addons-revert" ''
2020-11-28 20:42:36 +01:00
#!/bin/sh
2020-10-18 14:34:40 +02:00
set -e
: ''${XPLANEPATH:=${xplanePathStr}}
printf "Reverting modifications made to %s\n" "$XPLANEPATH";
if [ $# -eq 0 ]; then
printf "Reverting all modifications\n"
for f in "$XPLANEPATH/.addons"/revert-* ; do
printf "Reverting %s\n" "''${f##*/revert-}"
2022-10-09 14:02:44 +02:00
"''${f}" || { printf "Failed reverting %s\n" "''${f##*/revert-}. Stopping"; exit 1; }
2020-10-18 14:34:40 +02:00
done
else
for f in "$@" ; do
printf "Reverting %s\n" "''${f##*/revert-}"
"$XPLANEPATH"/.addons/revert-"''${f##*/revert-}"
done
fi
'';
2022-06-08 14:01:14 +02:00
navdbScript = writeScript "update-navdata" ''
#!/usr/bin/env bash
set -euo pipefail
: ''${XPLANEPATH:=${xplanePathStr}}
[ $# -ne 0 ] || {
printf "usage: update-navdata FILE [OLDCYCLE]\n\nFILE xplane11_native_CYCL.zip file\nOLDCYCLE old cycle ID for backup (default auto detect)\n" >&2
exit 1; }
if [ $# -ge 2 ]; then
oldcycle=$2
elif [ -e "$XPLANEPATH/Custom Data/cycle_info.txt" ]; then
oldcycle=$(head -n1 "$XPLANEPATH/Custom Data/cycle_info.txt" | sed -E -n -e "s/^AIRAC cycle[ :]+([0-9]+)\r$/\1/p")
[ -n "$oldcycle" ] || { printf "Unable to determine old AIRAC cycle\n" >&2; exit 1; }
2022-10-09 14:02:30 +02:00
else
oldcycle=
2022-06-08 14:01:14 +02:00
fi
f=$1
[ -e "$f" ] || { printf "No such file or directory\n" >&2; exit 1; }
cycle=''${1##*_}
cycle=''${cycle%.zip}
newpath="$XPLANEPATH/Custom Data AIRAC$cycle"
2022-10-09 14:02:30 +02:00
if [ -z "$oldcycle" ]; then
rm -r "$XPLANEPATH/Custom Data"
elif [ ! -h "$XPLANEPATH/Custom Data" ]; then
2022-06-08 14:01:14 +02:00
mv "$XPLANEPATH/Custom Data" "$XPLANEPATH/Custom Data AIRAC$oldcycle"
fi
if [ -d "$newpath" ]; then
rm -rf "$newpath"
fi
${lib.getBin unzip}/bin/unzip -d "$newpath" "$f"
cat <<EOF >"$newpath/Readme.txt"
Place newer navigational data for the global database in THIS folder.
If you want to replace any of X-Plane's
earth_nav.dat
earth_awy.dat
earth_fix.dat
CIFP/*
with newer data, then place them HERE IN THIS FOLDER to avoid conflicts with the X-Plane updater.
Note that this database is also used by X-Planes GPS and previously needed files in other subfolders are now ignored.
Also, you can place the FAACIFP18 file here, which you can get from the FAA website: https://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/cifp/
If the file FAACIFP18 is found in this folder, X-Plane will load instrument flight procedures from this file.
EOF
2022-10-09 14:02:30 +02:00
rm -f "$XPLANEPATH/Custom Data"
2022-06-08 14:01:14 +02:00
ln -sf "$newpath" "$XPLANEPATH/Custom Data"
'';
orthoScript = writeScript "update-scenery-packs-ini" ''
: ''${XPLANEPATH:=${xplanePathStr}}
(
cd "$XPLANEPATH"
sed -i -e '/^SCENERY_PACK Custom Scenery\/zOrtho4XP_.*$/d' "Custom Scenery/scenery_packs.ini"
for f in "Custom Scenery/zOrtho4XP_"*; do
2022-06-09 22:11:18 +02:00
echo "SCENERY_PACK $f/"
done >>"Custom Scenery/scenery_packs.ini"
)
'';
2020-10-18 14:34:40 +02:00
in buildFHSUserEnv rec {
inherit name;
2020-10-18 14:34:40 +02:00
passthru = { inherit addons; };
# Also add GAppsWrapper environment stuff such that binaries see the GTK theme...
2022-10-03 10:00:15 +02:00
targetPkgs = pkgs: (with pkgs; [ unzip atk gdk-pixbuf cairo pango mesa_glu libGL openalSoft gtk2 glib dbus pulseaudio vulkan-tools vulkan-loader ] ++
2020-10-18 14:34:40 +02:00
(with xorg; [ libX11 libXext libXrandr libXcursor libXinerama ]) ++
2022-10-03 10:00:15 +02:00
# X-Plane 12
[ nss harfbuzz nspr cups at-spi2-core at-spi2-atk libdrm expat alsa-lib mesa ] ++
(with xorg; [ libXcomposite libXdamage libXfixes libxcb libxkbcommon ]) ++
2020-10-18 14:34:40 +02:00
# For reality expansion pack
[ stdenv.cc.cc.lib curl openssl ] ++
# For fly with lua
2022-09-11 09:55:14 +02:00
[ freeglut udev ]);
2020-10-18 14:34:40 +02:00
extraBuildCommands = ''
chmod u+w $out/etc
mkdir $out/etc/openal
chmod u-w $out/etc
echo "drivers=pulse" > $out/etc/openal/alsoft.conf
mkdir -p $out/xplane-extra
2020-10-18 14:34:40 +02:00
'' + (concatMapStrings (addon:
optionalString (addon.passthru ? build) ''
ADDONPATH=${addon}
printf "Addon ${addon.pname}\n" >&2
${addon.passthru.build}
'') uniqueAddons);
extraInstallCommands = ''
mkdir -p $out/share/zsh/site-functions
ln -s ${./x-plane-env.zcomp} $out/share/zsh/site-functions/_${name}
'';
2020-10-18 14:34:40 +02:00
inherit runScript;
}