Unity3D Development on NixOS with Rider
The joys of Unity… how can such a big and popular game engine be so finnicky? Even if I knew the answer, this probably is not the place to put it. Instead, let’s talk about how we can get game-making on the much more pleasant NixOS!
Because we’re using this wonderfully esoteric Linux distribution, the recommended installation methods for both Unity Hub and JetBrains Rider will not work. Thankfully, both the packages we’ll need are packaged in Nixpkgs and ready for you to use!
Well, mostly. We’ll want to do a bit of configuring to make sure that everything is working properly.
Unity Hub
Unity Hub is the program that Unity3D recommends you use for installing different versions of Unity3D on your systems. The latest version is available in Nixpkgs as unityhub
and can be installed by adding it to your environment.systemPackages
like any other program:
1{
2 environment.systemPackages = [
3 pkgs.unityhub
4 ];
5}
Once you have it installed, you can simply launch it, log in, and use it as you would on any other Linux distribution!
This derivation can also be overridden if you need any other system libraries or packages available for your Unity game. For example, I have this in my system configuration for development on Rhythm Doctor:
1{
2 environment.systemPackages = [
3 (pkgs.unityhub.override {
4 extraPkgs = fhsPkgs: [
5 fhsPkgs.harfbuzz
6 fhsPkgs.libogg
7 ];
8 })
9 ];
10}
OpenSSL Woes
Unity Editor versions before 2022 depend on an older version of OpenSSL that is now marked as insecure. Running any of those versions without any tweaks will give the annoying error message No usable version of libssl was found
and prevent you from running your game.
The ideal workaround would be to update your Unity editor to a version that works with OpenSSL 3, but if that’s not a solution, for now you can manually add the insecure version of OpenSSL to your Unity Hub:
1{
2 environment.systemPackages = [
3 (pkgs.unityhub.override {
4 extraLibs = fhsPkgs; [
5 fhsPkgs.openssl_1_1
6 ];
7 })
8 ];
9}
See this GitHub issue for more information.
Login page not opening?
Unity Hub is packaged in a FHS environment, which causes a bug where xdg-open
simply does not work. This program is often used to open pages in the users browser, such as what Unity Hub does in order to allow you to sign in. To work around this, we can use the xdgOpenUsePortal
option to enable an alternate implementation that works:
1{
2 xdg.portal = {
3 enable = true;
4 xdgOpenUsePortal = true;
5 };
6}
See this issue and this broader issue for more info.
JetBrains Rider
JetBrains recommends using JetBrains Toolbox in order to install Rider, and Toolbox is available in Nixpkgs. I personally have not used this much, but it should work if you prefer the traditional method of installing JetBrains products.
Alternatively, you can use the version of Rider directly provided by Nixpkgs at jetbrains.rider
. This will require some tweaking to get it to work perfectly with the Unity Editor integration though.
The first step is to add some extra tools and libraries to Rider’s PATH
and LD_LIBRARY_PATH
, and the second is to modify Rider’s file structure to match what the Unity plugin expects:
1let
2 extra-path = with pkgs; [
3 dotnetCorePackages.sdk_6_0
4 dotnetPackages.Nuget
5 mono
6 msbuild
7 # Add any extra binaries you want accessible to Rider here
8 ];
9
10 extra-lib = with pkgs;[
11 # Add any extra libraries you want accessible to Rider here
12 ];
13
14 rider = pkgs.jetbrains.rider.overrideAttrs (attrs: {
15 postInstall = ''
16 # Wrap rider with extra tools and libraries
17 mv $out/bin/rider $out/bin/.rider-toolless
18 makeWrapper $out/bin/.rider-toolless $out/bin/rider \
19 --argv0 rider \
20 --prefix PATH : "${lib.makeBinPath extra-path}" \
21 --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath extra-lib}"
22
23 # Making Unity Rider plugin work!
24 # The plugin expects the binary to be at /rider/bin/rider,
25 # with bundled files at /rider/
26 # It does this by going up two directories from the binary path
27 # Our rider binary is at $out/bin/rider, so we need to link $out/rider/ to $out/
28 shopt -s extglob
29 ln -s $out/rider/!(bin) $out/
30 shopt -u extglob
31 '' + attrs.postInstall or "";
32 });
33in
34{
35 environment.systemPackages = [
36 rider
37 ];
38}
In addition, you’ll need to create a dummy .desktop
file in .local/share
to allow the extension to find the application. (This is because this is where JetBrains Toolbox would create a .desktop
file for the application). You can do this via home-manager if you’d wish:
1# Unity Rider plugin looks here for a .desktop file,
2# which it uses to find the path to the rider binary.
3{
4 environment.systemPackages = [
5 rider
6 ];
7
8 home-manager.users.huantian.home.file = {
9 ".local/share/applications/jetbrains-rider.desktop".source =
10 let
11 desktopFile = pkgs.makeDesktopItem {
12 name = "jetbrains-rider";
13 desktopName = "Rider";
14 exec = "\"${rider}/bin/rider\"";
15 icon = "rider";
16 type = "Application";
17 # Don't show desktop icon in search or run launcher
18 extraConfig.NoDisplay = "true";
19 };
20 in
21 "${desktopFile}/share/applications/jetbrains-rider.desktop";
22 };
23}
Wrap-up
That’s all you should need to get started for making games on NixOS! As always, if there are any issues or improvements that you notice could be made, feel free to let me know.
I’ll also link to the relevant Unity Hub and Rider configs in my personal NixOS config for reference.