Add starbound server

This commit is contained in:
Tristan Daniël Maat 2022-04-23 04:08:45 +01:00
parent e7102adec1
commit cd92ec64c2
Signed by: tlater
GPG key ID: 49670FD774E43268
8 changed files with 253 additions and 6 deletions

View file

@ -13,4 +13,7 @@ in {
# Minecraft modpacks
voor-kia = callPackage ./minecraft/voor-kia.nix { };
voor-kia-client = callPackage ./minecraft/voor-kia-client.nix { };
# Starbound
starbound = callPackage ./starbound { };
}

View file

@ -0,0 +1,34 @@
{
stdenv,
lib,
makeWrapper,
patchelf,
steamPackages,
replace-secret,
}: let
# Use the directory in which starbound is installed so steamcmd
# doesn't have to be reinstalled constantly (we're using DynamicUser
# with StateDirectory to persist this).
steamcmd = steamPackages.steamcmd.override {
steamRoot = "/var/lib/starbound/.steamcmd";
};
wrapperPath = lib.makeBinPath [patchelf steamcmd replace-secret];
in
stdenv.mkDerivation {
name = "starbound-update-script";
nativeBuildInputs = [makeWrapper];
dontUnpack = true;
patchPhase = ''
interpreter="$(cat $NIX_CC/nix-support/dynamic-linker)"
substitute ${./launch-starbound.sh} launch-starbound --subst-var interpreter
'';
installPhase = ''
mkdir -p $out/bin
cp launch-starbound $out/bin/launch-starbound
chmod +x $out/bin/launch-starbound
'';
postFixup = ''
wrapProgram $out/bin/launch-starbound \
--prefix PATH : "${wrapperPath}"
'';
}

View file

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -eu
if ! [[ -v STATE_DIRECTORY && -v CREDENTIALS_DIRECTORY ]]; then
echo "Error: Runtime dir or credential not set"
exit 1
fi
# Update the server to the latest version
echo "Updating/installing starbound"
mkdir -p "${STATE_DIRECTORY}/.steamcmd"
steamcmd <<EOF
force_install_dir $STATE_DIRECTORY
login tlater $(cat "$CREDENTIALS_DIRECTORY/steam")
app_update 211820
quit
EOF
echo "Updating config"
if [ -f "$1" ]; then
mkdir -p ./storage
cp "$1" ./storage/starbound_server.config
fi
echo "Running starbound server"
patchelf --set-interpreter '@interpreter@' ./linux/starbound_server
# Must be run from the directory that the binary is in (why do game
# devs do this?)
cd linux
./starbound_server