[Game] Got starsector to run on NixOS

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 :frowning:.

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; [

  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
1 Like

I’m not sure what the policies are around it, but there is a mechanism for including this kind of thing in nixpkgs. It’s the requireFile builder.

1 Like

The pname is set as “starcaster” instead of “starsector”

1 Like

it’s starsector, I think i first search for starcaster when i was looking for the game, and it’s been stuck in my head since :frowning:

I’ve seen that once before, but forgot what it was called. I’ll throw up a PR later :slight_smile:

Just wanted to say thanks, you showed me an excellent game and your derivation worked fine for me.

1 Like

:open_mouth: How did I miss this thread? I was wondering how to run that game a while ago.

I figured last night that the game also runs with steam-run (I learned about that on this forum this week).

Thanks for the derivation :heart:

I’m trying it but I get:

$ ./result/bin/starsector
mkdir: cannot create directory '/starsector': Permission denied

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.

I think I used $XDG_DATA_HOME to determine save location