JourNix https://journix.dev This is JourNix feed Tue, 13 Aug 2024 16:56:54 GMT https://validator.w3.org/feed/docs/rss2.html https://github.com/jpmonette/feed en © JourNix, 2024-2024 <![CDATA[Effortless Minecraft Servers on NixOS | Simple Declarative Setup]]> https://journix.dev/posts/effortless-minecraft-servers-on-nixos posts/effortless-minecraft-servers-on-nixos Tue, 13 Aug 2024 00:00:00 GMT


There is a surprising overlap between people who Use NixOS, and people who own a minecraft server. And if you happen to be one of them, or want to become one in just a couple of minutes, then this video is for you.

Because NixOS makes creating minecraft servers even easier than it already was. See for yourself, it's literally just two lines in your nixos configuration, and you don't even have to worry about installing java, downloading the server, opening ports, setting up a systemd service or anything like that.

And so in this post I'll show you how to manage a minecraft server on nixos, including declaratively managing all of it's options, installing mods, or even managing several servers all at once.

So just like I've said, the module needed to set up a minecraft server declaratively is already built into NixOS, meaning all we have to do is add these two lines to your configuration.nix, to get a fully working server accessible at the default 25565 port.

# configuration.nix. Example of all options that are explained below.

{ pkgs, lib, ...}: {
  services.minecraft = {
    enable = true;
    eula = true;
    declarative = true;

    package = pkgs.minecraft-server-1-12;
    dataDir = "/var/lib/someotherdir";

    serverProperties = {
      gamemode = "survival";
      difficulty = "hard";
      simulation-distance = 10;
      level-seed = "4";
    };

    whitelist = {
      vimjoyer = "3f96da12-a55c-4871-8e26-09256adac319";
    };

    jvmOpts = "-Xms4092M -Xmx4092M -XX:+UseG1GC";
  };
}

After enabling these and rebuilding your nixos configuration, you'll find your server in the /var/lib/minecraft directory, which can be changed using the dataDir option if you want.

The server will automatically be started as a systemd service. meaning you can use the regular systemctl commands, to restart it, or check the logs.

And by default, the server will run the latest available version of minecraft packaged in your current channel of nixpkgs, which you can check by searching for the minecraft-server package on search.nixos.org. It can, of course, be changed to anything you like using the package option.

And nixpkgs provides packages for all major versions from 1.2 to the most recent version, and also a couple of other versions like PaperMC.

It unfortunately does not provide any modded versions at the moment, but I'll show you how you can enable those later.

But first, let's see how we can cofigure this server declaratively.

Because while you can just straight up edit any files in the generated server directory, a more nix way to do it would be using the declarative option.

And what this option does, is allow us to define server properties and server's whitelist using serverProperties and whitelist options respectively. I must say that I find this option rather confusing, because the other two could have been of type attribute set or null to check if they are enabled without any additional steps for the users. But I'm assuming this is just a remnant of the past because the module is more than 10 years old at this point.

Anyway, everything you put into the server properties option will be translated into the usual ini format, meaning you can define everything from gamemode and difficulty to simulation-distance and level-seed here. The whitelist also works more or less like how you would expect it to, so by assigning usernames to user IDs you can select just a handful of accounts that can access your server.

And last but not least, You can also define jvmOpts here, which will be appended to your Java start command to start the server.

So we now know how to quickly roll out simple vanilla servers for you and your friends.

But for more complicated servers with mods or plugins, the builtin module will simply not be sufficient. And so now, I'll show you an alternative nix solution that you can use to define more complex servers.

Nix-minecraft

Accessible with a flake, nix-minecraft provides a module, that allows you to define and run multiple minecraft servers simultaneously, while also giving you access to way more many different version of minecraft including all versions of Fabric, Quilt, Paper, Velocity, and of course Vanilla in it's overlay.

To include nix-minecraft in your nixos configuration, add this url to your flake's inputs, and make sure that the inputs are passed all the way to your nixos modules with specialArgs.

# flake input
nix-minecraft.url = "github:Infinidoge/nix-minecraft";
# configuration.nix. Example of all options that are explained below.

{ pkgs, lib, inputs, ... }:

{
  imports = [ inputs.nix-minecraft.nixosModules.minecraft-servers ];
  nixpkgs.overlays = [ inputs.nix-minecraft.overlay ];

  services.minecraft-servers = {
    enable = true;
    eula = true;

    package = pkgs.minecraft-server-1-12;
    dataDir = "/var/lib/someotherdir";

    servers = {
      cool-server1 = {
        enable = true;
        package = pkgs.fabricServers.fabric-1_18_2;

        serverProperties = {/* */};
        whitelist = {/* */};

        symlinks = 
        let
          modpack = (pkgs.fetchPackwizModpack {
            url = "https://github.com/Misterio77/Modpack/raw/0.2.9/pack.toml";
            packHash = "sha256-L5RiSktqtSQBDecVfGj1iDaXV+E90zrNEcf4jtsg+wk=";
          })
        in
          # Modpack example
          # "mods" = "${modpack}/mods";

          # Directories
          # "mods" = ./mods;

          # Fetching from the internet
          # "mods" = pkgs.linkFarmFromDrvs "mods" (builtins.attrValues {
          #   Starlight = fetchurl { url = "https://cdn.modrinth.com/data/H8CaAYZC/versions/XGIsoVGT/starlight-1.1.2%2Bfabric.dbc156f.jar"; sha512 = "6b0e363fc2d6cd2f73b466ab9ba4f16582bb079b8449b7f3ed6e11aa365734af66a9735a7203cf90f8bc9b24e7ce6409eb04d20f84e04c7c6b8e34f4cc8578bb"; };
          #   Lithium = fetchurl { url = "https://cdn.modrinth.com/data/gvQqBUqZ/versions/ZSNsJrPI/lithium-fabric-mc1.20.1-0.11.2.jar"; sha512 = "d1b5c90ba8b4879814df7fbf6e67412febbb2870e8131858c211130e9b5546e86b213b768b912fc7a2efa37831ad91caf28d6d71ba972274618ffd59937e5d0d"; };
          #   FerriteCore = fetchurl { url = "https://cdn.modrinth.com/data/uXXizFIs/versions/ULSumfl4/ferritecore-6.0.0-forge.jar"; sha512 = "e78ddd02cca0a4553eb135dbb3ec6cbc59200dd23febf3491d112c47a0b7e9fe2b97f97a3d43bb44d69f1a10aad01143dcd84dc575dfa5a9eaa315a3ec182b37"; };
          #   Krypton = fetchurl { url = "https://cdn.modrinth.com/data/fQEb0iXm/versions/jiDwS0W1/krypton-0.2.3.jar"; sha512 = "92b73a70737cfc1daebca211bd1525de7684b554be392714ee29cbd558f2a27a8bdda22accbe9176d6e531d74f9bf77798c28c3e8559c970f607422b6038bc9e"; };
          #   LazyDFU = fetchurl { url = "https://cdn.modrinth.com/data/hvFnDODi/versions/0.1.3/lazydfu-0.1.3.jar"; sha512 = "dc3766352c645f6da92b13000dffa80584ee58093c925c2154eb3c125a2b2f9a3af298202e2658b039c6ee41e81ca9a2e9d4b942561f7085239dd4421e0cce0a"; };
          #   C2ME = fetchurl { url = "https://cdn.modrinth.com/data/VSNURh3q/versions/t4juSkze/c2me-fabric-mc1.20.1-0.2.0%2Balpha.10.91.jar"; sha512 = "562c87a50f380c6cd7312f90b957f369625b3cf5f948e7bee286cd8075694a7206af4d0c8447879daa7a3bfe217c5092a7847247f0098cb1f5417e41c678f0c1"; };
          # });
        };
      };
      cool-server2 = {
        enable = true;
        package = pkgs.vanillaServers.vanilla-1_21
      };
    };
  };

  # ...
}

Afterwards, open your configuration.nix, and here, include the module in the imports, to get access to all new options provided by nix-minecraft, and an overlay to get the server packages in your pkgs instance.

Now we can simply enable the newly added service, and get back to creating servers.

Like I've said earlier, nix-minecraft allows you to define multiple servers at once, so to demonstrate, let's define one by simply adding an attribute named whatever you want to the servers set.

Every server you add here, can be cofigured with options very similar to the ones we applied to the builtin module, with just a couple of differences.

We obviously don't have to accept the eula for every server, since we can simply set it to true it the service set , and the options like serverProperties and whitelist work the same way, except you don't even have to enable the declarative option, because here is everything handled automatically, just like you would expect it to.

And if you decide to create multiple servers, don't forget to assign unique ports to each one of them, because otherwise they will clash to claim the default 25565

Just like with the default service, we can select the version of our server using the package option, which can be assigned to various packages from the overlay.

To avoid collisions with nixpkgs, all servers live within their own set, following a simple naming convention.

So you'll find every vanilla server in the vanillaServers set of your pkgs, every Fabric server in the fabricServers, and so on.

But be careful here, because every fabric package is also named after a minecraft version, so if you need some specific version of fabric itself, we can override the package, and set the loaderVersion there.

But of course, who needs a modloader without any mods, so to install mods on your server, nix-minecraft does not try to reinvent the wheel, and simply gives you a qiuck access to your servers directory through the symlinks option.

Meaning you can simply assign it to an existing mods directory from your filesystem, or generate one by fetching every mod with fetchurl, or even, straight up extract it from a modpack using a fetchPackwizModpack function.

This convinient function lets you fetch a packwiz modpack from the internet, and just like any fetch function, to use it, you can simply input your desired url, give it a fake hash, and wait for it to fail during rebuild, so you can replace the hash with a correct one.

Then we can simply access the content of the modpack as if it was a normal directory.

Like in this example where I am only linking the mods directory from it, but you could also access any other files or directories.

And after all of that, you can rebuild your system, and once again find your server running as a systemd service, albeit with a slightly different service name. Actually, every server you enable will get it's own service and directory, so you don't have to worry about them overriding one another.

By default you'll find every server in it's own subdirectory of /srv/minecraft, but that can of course be changed with the now shared dataDir option

So nix-minecraft can easily be used to define complex servers, and the only major thing it's missing at the moment is probably forge support.

But now I want to quickly run through other alternatives you may want to know about.

Flux

So one of them is called flux, which lets you define various game servers, including of course minecraft ones. And it's primary advantage is that it uses mcman, so if you know how to use that, you can give it a try,

Hey, it's me, BANana. I have a post about how I've setup my minecraft network with flux, check it out if you want.

And another one is this git repo called mkaito/nixos-modded-minecraft-servers, which works similarly to nix-minecraft, except it lets you write a start script yourself, so you can basically use any modpack you want. But it does not seem to be actively maintained anymore.

]]>
<![CDATA[Ricing linux has never been easier | NixOS + stylix]]> https://journix.dev/posts/ricing-linux-has-never-been-easier-nixos-and-stylix posts/ricing-linux-has-never-been-easier-nixos-and-stylix Sun, 19 May 2024 00:00:00 GMT


Getting into linux ricing is undoubtedly difficult. And the sheer amount of information you have to learn about your programs and their special configuration types makes it a quite time consuming hobby to say the least.

But what if I told you, that if you are using NixOS, you could rice your entire system with just a cuouple of lines?

Sounds too good to be true, right? Well, introducing stylix, a pair of modules for NixOS and home-manager that will do all of the heavy lifting for you.

Because even though customizing your desktop is a highly personal and creative process, there are some aspects that can make it tedious or even unpleasant, such as applying matching color schemes, fonts, and opacities for every single program.

Let's be realistic, most people simply want their programs to have the same backgound color and several matching accents.

Historically, this has led to the creation of dozens of templating programs and wonky bash scripts, which often turn editing and managing your desktops into a complete mess.

With NixOS, and in turn, stylix, this problem can be completely avoided, because every program in your configuration is broken into options, and it does not matter where these options are defined.

Meaning that by installing stylix we are essentially outsorcing the color option management to it, leaving us to worry about more importaint stuff like your preferred keybindings, layouts and so on.

And of course, none of these options will take effect, unless you choose to enable the programs explicitly. Meaning, your .config directory won't get cluttered with loads of dotfiles right away.

Installation

To install stylix, open your flake.nix file and include this github url in the inputs. Then make sure that you are passing your inputs to the outputs, and finally, include the module in your nixos setup.

{

  inputs = {
    # ...
    stylix.url = "github:danth/stylix";
  };

  outputs = { nixpkgs, ... }@inputs: {
    nixosConfigurations.default = nixpkgs.lib.nixosSystem {
      specialArgs = {inherit inputs;};
      modules = [
        ./configuration.nix
        inputs.stylix.nixosModules.stylix
      ];
    };
  };

}

At this point, you may be wondering why are we using a NixOS module instead of a home-manager one. And that is because the home-manager stylix module is automatically bundled within the NixOS one.

You can, of course, go ahead, and only import the home-manager module separately, but you will miss out on some of the features like styling bootloaders or display managers.

{

  inputs = {
    # ...
    stylix.url = "github:danth/stylix";
  };

  outputs = { nixpkgs, home-manager, stylix, ... }@inputs: {
    homeConfigurations."«username»" = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
      modules = [ 
        ./home.nix
        stylix.homeManagerModules.stylix
      ];
    };
  }

}

Just be careful not to include both of them at the same time, because you will run into option redeclaration issues.

Usage

Now that the module is imported, open your NixOS configuration, and let's select a colorscheme.

Stylix uses a base16 colorscheme framework, which means that it only needs 16 colors to style your desktop.

There are plenty of base16 colorschemes available online, but the easiest way to get one is through the base16-schemes package.

It contains a bunch of thmes under the /share/themes directory, and the easiest way to choose one is to simply build the package and check the result directory.

Afterwards, we can simply pass one of these schemes directly, or define them manually using a nix set.

Alternatively the theme can be autogenerated from a wallpaer, which can be defined with a stylix.image option.

Said wallpaper will also be applied automatically on supported desktop environments, but note that for some reason defining this option is mandatory, so even if you are going to use a custom theme, don't forget to include it in your configuration.

{ pkgs, ... }: 

{

  stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-medium.yaml";

  # OR

  stylix.base16Scheme = {
    base00 = "282828";
    base01 = "3c3836";
    base02 = "504945";
    base03 = "665c54";
    base04 = "bdae93";
    base05 = "d5c4a1";
    base06 = "ebdbb2";
    base07 = "fbf1c7";
    base08 = "fb4934";
    base09 = "fe8019";
    base0A = "fabd2f";
    base0B = "b8bb26";
    base0C = "8ec07c";
    base0D = "83a598";
    base0E = "d3869b";
    base0F = "d65d0e";
  };

  # Don't forget to apply wallpaper

  stylix.image = ./my-cool-wallpaper.png;

}

That's pretty much all we need to do. And if you now rebuild your system, you'll notice that all the programs you enabled in your NixOS and home-manager configurations will be themed.

I personally didn't expect the generated btop++ theme to look this good, and was really surprised to see that even mangohud got a nice gruvbox theme after a rebuild.

There can, of course, be some exceptions, but given that many programs simply rely on GTK, QT or your terminal colors, most of your programs should be covered.

Advanced usage

Now to talk about some other options, starting with applying a custom cursor. Stylix allows us to define a cursor package and the name of the specific cursor inside it. Meaning, you can simply build any of the various cursor packages from nixpkgs, and check the available cursors by their directory names.

$ nix build nixpkgs#bibata-cursors
$ nix build nixpkgs#base16-schemes

$ cd result

$ nix run nixpkgs#eza -- --tree --level 3

In this example, I am going to choose the Bibata-Modern-Ice cursor from the bibata-cursors package.

As I mentioned earlier, we can also define fonts here, with several options available, allowing you to select a serif, sans serif, and monospaced font.

{ pkgs, ... }:

{
  # ...

  stylix.cursor.package = pkgs.bibata-cursors;
  stylix.cursor.name = "Bibata-Modern-Ice";

  stylix.fonts = {
    monospace = {
      package = pkgs.nerdfonts.override {fonts = ["JetBrainsMono"];};
      name = "JetBrainsMono Nerd Font Mono";
    };
    sansSerif = {
      package = pkgs.dejavu_fonts;
      name = "DejaVu Sans";
    };
    serif = {
      package = pkgs.dejavu_fonts;
      name = "DejaVu Serif";
    };
  };

}

You obviously don't want a monospaced font in your browser or a proportional font in your terminal, so stylix will automatically choose the appropriate variant from the selected options.

Other notable options include the ability to change font sizes and opacities for different types of programs, as well as the ability to select theme polarity to force-generate a light or dark theme.

{ pkgs, ... }: 

{
  # ...

  stylix.fonts.sizes = {
    applications = 12;
    terminal = 15;
    desktop = 10;
    popups = 10;
  };

  stylix.opacity = {
    applications = 1.0;
    terminal = 1.0;
    desktop = 1.0;
    popups = 1.0;
  };

  stylix.polarity = "dark" # "light" or "either"

}

And to explore these and many many more options that Stylix provides, you can visit the Stylix Book website via the link in the description

After applying a few of these options, I launched several terminal emulators including Kitty, Foot, and WezTerm to make nice screenshot. But now I cannot tell which one is which, so we can can clearly see that Stylix did an amazing job unifying their styles.

Even then, if you don't like some options set by stylix, it is absolutely trivial to disable specific program themes with this stylix.targets.<program>.enable option, or even cheery pick a specific option like I did in this example for hyprland active border color.

To do it you will want to use a `lib.mkForce function, and you can still access your selected colors, allowing you to easily swap yellow for red or magenta to green or any other color you prefer.

wayland.windowManager.hyprland.settings.general."col.active_border" =
  lib.mkForce "rgb(${config.stylix.base16Scheme.base0E})";

Just don't forget to include the lib in paramer set at the top.

]]>
<![CDATA[Gaming on nixos]]> https://journix.dev/posts/gaming-on-nixos posts/gaming-on-nixos Thu, 02 May 2024 00:00:00 GMT


NixOS is a general purpose Linux distribution capable of doing anything from serving your simple web app to being a fully-fledged desktop OS, which is why it always seems strange to me when people ask about wether or not you should or even can game on NixOS at all. And so, answering the question from the clickbaity thumbnail, NixOS is not the best gaming distro - because there probably isn't one.

However, if you, like me, want it to be a great gaming distro, then this post is definetely for you, because today I will showcase several different programs and options you can set for comfortable gaming experience on NixOS.

OpenGL

And the first thing we want to do is to enable OpenGL and the corrent GPU drivers. Enabling OpenGL is simply a matter of adding these several lines to your configuration.

# configuration.nix

{ pkgs, ... }:

{

  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  services.xserver.videoDrivers = ["nvidia"];
  # services.xserver.videoDrivers = ["amdgpu"];

  hardware.nvidia.modesetting.enable = true;

}

This step can be omitted entirely if you're going to enable steam, but having it in your configuration won't hurt anyway.

GPU

Now, loading GPU drivers on NixOS is done by adding them to the services.xserver.videoDrivers list, which, contrary to the option name, will enable them for both X and Wayland.

If you are using Nvidia you might also want to enable modesetting for some wayland compositors and desktop environments to work properly, but if you are not experiencing any issues, this step can be skipped too.

These are pretty much all the options you need to set on a regular desktop PC, however, if you are using a hybrid graphics laptop with an Nvidia GPU, which, I know, many of you do, you might want to configure Nvidia Optimus Prime. This step is kinda lenghty, so if it's not about you, feel free to skip to the next section

Prime has two different modes called offload and sync. In the offload mode the dedicated GPU is only enabled when needed, optimizing power consumption, and the sync mode, on the other hand, keeps your dedicated GPU running at all times, improving game performance at the expense of battery life.

For both of these to work you will need to determine the bus IDs of your GPUs, and there are several ways to do it. I personally prefer to use the lspci utility from the pciutils package, which you can run on any nix machine with this command:

nix shell nixpkgs#pciutils -c lspci | grep ' VGA '

It will output both values we need, and, judging by their names, we can determine that in this example I have an Nvidia dedicated GPU with an ID 01:00.0 and an AMD builtin with an ID 06:00.0.

01:00.0 VGA compatible controller: NVIDIA Corporation GA106M [GeForce...
06:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/...

We can now go back to our NixOS configuration and add these values here. Make sure to select the correct option for your iGPU vendor, whether it is AMD or Intel.

```nix title="Sync mode"

configuration.nix

{ pkgs, … }:

{

hardware.nvidia.prime = { sync.enable = true;

# integrated
amdgpuBusId = "PCI:6:0:0"
# intelBusId = "PCI:0:0:0";

# dedicated
nvidiaBusId = "PCI:1:0:0";

};

}

If you chose to enable the offload mode the `enableOffloadCmd` option will provide us with a convenient wrapper shell script that will tell your Nvidia gpu to take over any command given to it, meaning all you have to do is to prefix your game executables with this command for them to run on dGPU.

nix title="Offload mode"

configuration.nix

{ pkgs, … }:

{

hardware.nvidia.prime = { offload = { enable = true; enableOffloadCmd = true; };

# integrated
amdgpuBusId = "PCI:6:0:0"
# intelBusId = "PCI:0:0:0";

# dedicated
nvidiaBusId = "PCI:1:0:0";

};

}

The general rule of thumb here is to choose offload if you are traveling a lot with your laptop and sync if you always have access to the power grid.

However, if you still want to have both, NixOS specializations allow us to define system variations that will only slightly differ from the original configuration, meaning we can go ahead to choose the offload mode and then define a specialization, call it `gaming-time`, for example, that will force off your offload mode and enable sync instead. Now you will get two boot entries on every rebuild instead of one, allowing you to choose your desired mode every time you start your computer.

nix title="Specializations"

configuration.nix

{ pkgs, … }:

{

hardware.nvidia.prime = { offload = { enable = true; enableOffloadCmd = true; };

# integrated
# intelBusId = "PCI:0:0:0";
amdgpuBusId = "PCI:6:0:0"

# dedicated
nvidiaBusId = "PCI:1:0:0";

};

specialisation = { gaming-time.configuration = {

  hardware.nvidia = {
    prime.sync.enable = lib.mkForce true;
    prime.offload = {
      enable = lib.mkForce false;
      enableOffloadCmd = lib.mkForce false;
    };
  };

};

};

}

## Nixos-hardware

And now, while we are still on the topic of hardware, I want to mention the official [nixos-hardware](https://github.com/NixOS/nixos-hardware) github repo, which already includes ready to use hardware modules for many pre-built machines. These modules include optimized settings taking care of your kernel modulse, firmware, cooling, battery, CPU, and even the upper mention GPU bus IDs. It even has it's own flake, so if you wish to import a module from it, you can simply add it to your inputs and grab any module from it.

nix title="Using nixos-hardware" { description = "NixOS configuration with flakes"; inputs.nixos-hardware.url = "github:NixOS/nixos-hardware/master";

outputs = { self, nixpkgs, nixos-hardware }: { # replace with your actual hostname nixosConfigurations. = nixpkgs.lib.nixosSystem { # … modules = [ # … # add your model from this list: https://github.com/NixOS/nixos-hardware/blob/master/flake.nix nixos-hardware.nixosModules.dell-xps-13-9380 ]; }; }; }

There is also an example for importing these modules with fetchGit, which you can use if you haven't yet switched to flakes.

nix imports = [ "${builtins.fetchGit { url = "https://github.com/NixOS/nixos-hardware.git"; }}/lenovo/thinkpad/x220" ];

# Steam

Enough talking about hardware, let's finally talk software. And to kick it off, probably the most important piece of software for any gamer is steam. Now, I know that nowadays it's not the only way to run games on Linux, and we will run about some alternatives later, but it's massive influence on Linux gaming as a whole cannot be understated. And so to enable it on NixOS we can just add this one line to our config. It will install steam and set some other options you may need to run the games.

nix

configuration.nix

{ pkgs, … }:

{

programs.steam.enable = true;

}

While we are here, let's also enable a bunch of wrapper commands that will make our gaming experience smoother.

- Gamescope allows us to start a game in an optimized micro compositor that may help you if the game you are running has problems with upscaling or resolutions on your specific desktop environment or your window manager.

- Mangohud is a simple overlay program for monitoring FPS, temperature, CPU and GPU load, and more.

- And, finally, last but not least, Gamemode, that will greatly improve your game's performance by requesting a set of optimizations to be temporarily applied to the OS and the game process.

To access those capabilities, gamemode and gamescope require specific system permissions, so adding them to the `systemPackages` alone will not suffice, hence the `enable` options.

nix title="Wrappers usage"

configuration.nix

{ pkgs, … }:

{

programs.steam.enable = true; programs.steam.gamescopeSession.enable = true;

environment.systemPackages = with pkgs; [ mangohud ];

programs.gamemode.enable = true;

}

Now you can simply prepend any of these programs to the executables in any game's General options.

![Usage with steam's General options](assets/wrappersOptions.png)

# Proton-ge

Next up, let's talk about installing GloriousEggroll's proton fork, ProtonGE. It offers some additional patches not included in regular proton and may greatly improve performance in some games. We will actually use an imperative way today, but that's because steam will update some of it's components every time you start it anyway.

To install ProtonGE, we can use the convenient `protonup` command, does require us to specify the installation path. There are many ways to do it, so here are some of them.

- We can add an environment variable to our NixOS configuration and run the `protonup` command:

nix title="With environment"

configuration.nix

{ pkgs, … }:

{

environment.systemPackages = with pkgs; [ protonup ];

environment.sessionVariables = { STEAMEXTRACOMPATTOOLSPATHS = "\${HOME}/.steam/root/compatibilitytools.d"; };

}

- We can include it in our home-manager configuration and run the `protonup` command:

nix title="With home-manager"

home.nix

{ pkgs, … }:

{

home.packages = with pkgs; [ protonup ];

home.sessionVariables = { STEAMEXTRACOMPATTOOLSPATHS = "\\${HOME}/.steam/root/compatibilitytools.d"; };

}

- Or even simply pass the correct path with a -d flag.

bash protonup -d "~/.steam/root/compatibilitytools.d/"

Afterwards, you can simply select the newly installed proton version in the compatibiliy menu of any steam game.

![Selecting correct proton version](assets/protonCompat.png)

## Game launchers

And now, let's also talk about alternative ways to run games on NixOS. And, first up, we have the popular `lutris` launcher. It allows you to run games from all sorts of sources, can help with managing wine and proton versions and generally serves as a all-in-one Linux game launcher. It does not require any extra permissions, so installing it on NixOS is simply a matter of adding them to your systemPackages

nix

configuration.nix

{ pkgs, … }:

{ environment.systemPackages = with pkgs; [ lutris ]; }

Another useful game launcher you can try on NixOS is called `heroic`. It allows you to seamlessly run all of your epic and gog games and features a wide range of easy-to-use wine and proton settings.

nix

configuration.nix

{ pkgs, … }:

{ environment.systemPackages = with pkgs; [ heroic ]; }

And, finally, if the games that you want to run cannot be installed with the previous solutions, your best bet will probably be `bottles`.

Bottles is an incredible wine prefix manager that comes with some sensible presets and the most intuitive interface I've ever seen in an application like this.

nix

configuration.nix

{ pkgs, … }:

{ environment.systemPackages = with pkgs; [ bottles ]; }

```

You can use it to run regular Windows .exe files, making it a perfect solution for games not published on major platforms.

ProtonDB

And, before I finish this post, I also wanted to mention ProtonDB, which is an official steam Linux compatibility database that you can use before buying any games to know whether or not they will actually work on Linux, because, like I've said in the beginning, NixOS is just another linux distro when it comes to gaming, so any issues and fixes you see there will most probably also work for you.

]]>