Seen several youtubers, that I follow, rave how interesting of a game starsector is. I created a default.nix which will build package the game given it’s in the same directory. Unfortunately the game itself is copyrighted so i can’t throw it up on nixpkgs .
I’ve been able to play the tutorial, save, and load from save. So it should work, however, i give no guarantees that this works perfectly as I’m using openjdk instead of oracle java 7 (author makes it very clear that only java7 is officially supported).
# default.nix
with import <nixpkgs> {};
stdenv.mkDerivation rec {
pname = "starsector";
version = "0.9.1a";
src = ./.;
nativeBuildInputs = [ makeWrapper ];
buildInputs = with xorg; [
alsaLib
at-spi2-atk
cairo
fontconfig
freetype
gdk-pixbuf
glib.out
gtk2-x11
libav
libX11
libXcursor
libXext
libxml2
libXrandr
libxslt
libXtst
libXxf86vm
openal
openjdk.out
pango
stdenv.cc.cc
];
doBuild = false;
# need to cd into $out in order for classpath to pick up correct jar files
installPhase = ''
mkdir -p $out/bin
cp -r ./* $out
rm -r $out/jre_linux # remove jre7
wrapProgram $out/starsector.sh \
--prefix PATH : ${openjdk}/bin \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs} \
--run "mkdir -p \$XDG_DATA_HOME/starsector; cd $out"
ln -s $out/starsector.sh $out/bin/starsector
'';
# it tries to run everything with relative paths, which makes it CWD dependent
# also point mod, screenshot, and save directory to $XDG_DATA_HOME
prePatch = ''
substituteInPlace starsector.sh \
--replace "./jre_linux/bin/java" "${openjdk}/bin/java" \
--replace "./native/linux" "$out/native/linux" \
--replace "./" "\$XDG_DATA_HOME/starsector/"
substituteInPlace data/config/settings.json \
--replace "allowAnyJavaVersion\":false" "allowAnyJavaVersion\":true"
'';
}
installation steps are as follows:
# download starsector linux client after purchasing
nix-shell -p unzip # need ensureNewerSourcesHook for unzip to work properly
unzip starsector_linux-0.9.1a-RC8.zip
cd starsector
# copy default.nix
nix-build # adds package to store, creates result out-link
./result/bin/starsector
Is it normal that I need to create that directory? Shouldn’t it uses one in $HOME?
Also when I alt-tab to get back on my desktop, I still have the game cursor and I can’t click anything (I have the same problem with steam-run). I wonder if this happens with most games and if we can do anything about it.
TL;DR: Switching openjdk to openjdk8 and using an absolute path for XDG_HOME_DIR works nicely for me.
Just an update - it looks like the current version of openjdk no longer works with the game. I get:
Unrecognized VM option 'CompilerThreadHintNoPreempt'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
There’s some discussion on this in the game forum here where the dev mentioned trying an older version of Java.
It looks like openjdk8 begins to work nicely, though I’m presented with a new issue:
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: ./starsector.log (Read-only file system)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:273)
at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:156)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:152)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:247)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:123)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:87)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:645)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:603)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:500)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:406)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:432)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:113)
at org.apache.log4j.Logger.getLogger(Logger.java:107)
at com.fs.starfarer.StarfarerLauncher.<clinit>(Unknown Source)
0 [main] INFO com.fs.starfarer.StarfarerLauncher - Starting Starsector 0.95a-RC15 launcher
0 [main] INFO com.fs.starfarer.StarfarerLauncher - Running in /nix/store/dhkkm92bk6368rvpkkqlw8gsrzj990ak-starsector-0.95a
0 [main] INFO com.fs.starfarer.StarfarerLauncher - OS: Linux 5.14.2
0 [main] INFO com.fs.starfarer.StarfarerLauncher - Java version: 1.8.0_272 (64-bit)
4 [main] ERROR com.fs.starfarer.StarfarerLauncher - java.lang.RuntimeException: Mod location [/nix/store/dhkkm92bk6368rvpkkqlw8gsrzj990ak-starsector-0.95a/./starsector/mods] is not a directory
java.lang.RuntimeException: Mod location [/nix/store/dhkkm92bk6368rvpkkqlw8gsrzj990ak-starsector-0.95a/./starsector/mods] is not a directory
at com.fs.starfarer.launcher.ModManager.updateList(Unknown Source)
at com.fs.starfarer.launcher.ModManager.<init>(Unknown Source)
at com.fs.starfarer.launcher.ModManager.getInstance(Unknown Source)
at com.fs.starfarer.StarfarerLauncher.<init>(Unknown Source)
at com.fs.starfarer.StarfarerLauncher.<init>(Unknown Source)
at com.fs.starfarer.StarfarerLauncher.main(Unknown Source)
The first exception where the log file can’t be written to makes sense as the nix store is immutable, however it looks like the game continues to attempt to launch anway.
The second exception seems to cause issues though, resulting in this popup:
Turns out this was because I was just setting XDG_HOME_DIR with a relative path, i.e. XDG_HOME_DIR=./. After changing this to use an absolute path, it appears to be working nicely.