Help running Stardew Valley in NixOS

I used to be able to play Stardew Valley on my 2013 Macbook Air when I had OSX installed. When I run it now, I get:

Could not start dynamically linked executable: ./Stardew Valley
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld

When I run nix-shell -p steam-run --run "steam-run ./'Stardew Valley'" I get:

Unhandled exception. Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException: Failed to create graphics device!
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoGame.OpenGL.GL.LoadExtensions() in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Platform\Graphics\OpenGL.cs:line 1443
   at MonoGame.OpenGL.GraphicsContext..ctor(IWindowInfo info) in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Platform\Graphics\GraphicsContext.SDL.cs:line 49
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformSetup() in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Platform\Graphics\GraphicsDevice.OpenGL.cs:line 249
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Setup() in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Graphics\GraphicsDevice.cs:line 297
   at Microsoft.Xna.Framework.Graphics.GraphicsDevice..ctor(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, Boolean preferHalfPixelOffset, PresentationParameters presentationParameters) in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Graphics\GraphicsDevice.cs:line 273
   at Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice(GraphicsDeviceInformation gdi) in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\GraphicsDeviceManager.cs:line 144
   at Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice() in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\GraphicsDeviceManager.cs:line 115
   --- End of inner exception stack trace ---
   at Microsoft.Xna.Framework.GraphicsDeviceManager.CreateDevice() in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\GraphicsDeviceManager.cs:line 123
   at Microsoft.Xna.Framework.Game.DoInitialize() in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Game.cs:line 941
   at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\MonoGame.Desktop\MonoGame.Framework\Game.cs:line 465
   at StardewValley.Program.Main(String[] args) in D:\GitlabRunner\builds\Gq5qA5P4\1\ConcernedApe\stardewvalley\Farmer\Farmer\Program.cs:line 200

I also tried a dozen or so versions of proton and all of them failed to load. Any suggestions?

I set this up recently for a young acquaintance. The way I did it involved running ${pkgs.dotnet-runtime_7}/bin/dotnet "./Stardew Valley.dll", without the wrapper script, and without steam-run or nix-alien or anything like that. But in order for that to work, I had to keep it from using its vendored .NET stuff with the following:

  • Edit Stardew Valley.runtimeconfig.json, replacing includedFrameworks with frameworks
  • Edit Stardew Valley.deps.json and delete the section (or sections?) that reference(s) runtimepack.Microsoft.NETCore.App.Runtime.linux-x64/6.0.11
  • Set the environment variable DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2

I also deleted many of the DLLs in the game directory, but I don’t think that was strictly necessary. I didn’t keep the game files to experiment with so I can’t verify that just the previous steps are sufficient, sorry. Hope that helps!

(Why dotnet-runtime_7? I think I was worried about the 6.0 runtime falling out of Nixpkgs support and I wanted to make sure it worked on at least one newer runtime. I don’t remember if I tried _8.)

1 Like