From e6ed60548397627bf10f561f9438201dbba0a36e Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 21 Apr 2024 02:15:42 +0300 Subject: 2024-04-21 --- modules/games/default.nix | 27 ++++++++++++++ modules/games/gamemode.nix | 14 +++++++ modules/games/lutris.nix | 31 ++++++++++++++++ modules/games/mangohud.nix | 28 ++++++++++++++ modules/games/minecraft.nix | 86 +++++++++++++++++++++++++++++++++++++++++++ modules/games/steam-run.nix | 89 +++++++++++++++++++++++++++++++++++++++++++++ modules/games/steam.nix | 33 +++++++++++++++++ 7 files changed, 308 insertions(+) create mode 100644 modules/games/default.nix create mode 100644 modules/games/gamemode.nix create mode 100644 modules/games/lutris.nix create mode 100644 modules/games/mangohud.nix create mode 100644 modules/games/minecraft.nix create mode 100644 modules/games/steam-run.nix create mode 100644 modules/games/steam.nix (limited to 'modules/games') diff --git a/modules/games/default.nix b/modules/games/default.nix new file mode 100644 index 0000000..dea9d3c --- /dev/null +++ b/modules/games/default.nix @@ -0,0 +1,27 @@ +{ config, lib, ... }: +with lib; +let + cfg = config.nixfiles.modules.games; +in +{ + imports = attrValues (modulesIn ./.); + + options.nixfiles.modules.games.enable32BitSupport = mkEnableOption "support for games"; + + config = mkIf cfg.enable32BitSupport { + services = { + jack.alsa.support32Bit = config.services.jack.alsa.enable; + + pipewire.alsa.support32Bit = config.services.pipewire.alsa.enable; + }; + + hardware = { + opengl = mkIf config.hardware.opengl.enable { + extraPackages32 = config.hardware.opengl.extraPackages; + driSupport32Bit = config.hardware.opengl.driSupport; + }; + + pulseaudio.support32Bit = config.hardware.pulseaudio.enable; + }; + }; +} diff --git a/modules/games/gamemode.nix b/modules/games/gamemode.nix new file mode 100644 index 0000000..eb485f8 --- /dev/null +++ b/modules/games/gamemode.nix @@ -0,0 +1,14 @@ +{ config, lib, ... }: +with lib; +let + cfg = config.nixfiles.modules.games.gamemode; +in +{ + options.nixfiles.modules.games.gamemode.enable = mkEnableOption "Feral GameMode"; + + config = mkIf cfg.enable { + hm.xdg.configFile."gamemode.ini".text = generators.toINI { } { general.softrealtime = "auto"; }; + + programs.gamemode.enable = true; + }; +} diff --git a/modules/games/lutris.nix b/modules/games/lutris.nix new file mode 100644 index 0000000..62fe521 --- /dev/null +++ b/modules/games/lutris.nix @@ -0,0 +1,31 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.nixfiles.modules.games.lutris; +in +{ + options.nixfiles.modules.games.lutris.enable = mkEnableOption "Lutris"; + + config = mkIf cfg.enable { + nixfiles.modules.games = { + gamemode.enable = true; + mangohud.enable = true; + steam-run.enable = true; + }; + + hm.home.packages = with pkgs; [ + (lutris.override { + extraPkgs = _: [ + vkBasalt + wine + winetricks + ]; + }) + ]; + }; +} diff --git a/modules/games/mangohud.nix b/modules/games/mangohud.nix new file mode 100644 index 0000000..955f50c --- /dev/null +++ b/modules/games/mangohud.nix @@ -0,0 +1,28 @@ +{ config, lib, ... }: +with lib; +let + cfg = config.nixfiles.modules.games.mangohud; +in +{ + options.nixfiles.modules.games.mangohud.enable = mkEnableOption "MangoHud"; + + config = mkIf cfg.enable { + hm = { + stylix.targets.mangohud.enable = false; + + programs.mangohud = { + enable = true; + settings = { + fps = true; + frame_timing = true; + gpu_stats = true; + gpu_temp = true; + cpu_stats = true; + cpu_temp = true; + ram = true; + vram = true; + }; + }; + }; + }; +} diff --git a/modules/games/minecraft.nix b/modules/games/minecraft.nix new file mode 100644 index 0000000..6e163dc --- /dev/null +++ b/modules/games/minecraft.nix @@ -0,0 +1,86 @@ +{ + config, + inputs, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.nixfiles.modules.games.minecraft; +in +{ + imports = [ inputs.minecraft.nixosModules.minecraft-servers ]; + + options.nixfiles.modules.games.minecraft = { + client.enable = mkEnableOption "Minecraft client"; + server = { + enable = mkEnableOption "Minecraft server"; + + port = mkOption { + description = "Server port."; + type = types.port; + default = 25565; + }; + + memory = mkOption { + description = "Amount of RAM to allocate."; + type = types.str; + default = "2G"; + }; + }; + }; + + config = mkMerge [ + (mkIf cfg.client.enable { hm.home.packages = [ pkgs.prismlauncher ]; }) + (mkIf cfg.server.enable { + nixfiles.modules.common.nix.allowedUnfreePackages = [ "minecraft-server" ]; + + ark.directories = [ config.services.minecraft-servers.dataDir ]; + + services.minecraft-servers = { + enable = true; + eula = true; + + openFirewall = true; + + servers.default = { + enable = true; + autoStart = true; + + package = pkgs.paperServers.paper-1_19_3; + + serverProperties = { + # motd = ""; + # white-list = true; + allow-flight = true; + difficulty = "hard"; + enable-command-block = true; + enforce-secure-profile = false; + enforce-whitelist = true; + gamemode = "survival"; + level-name = "default"; + max-players = 8; + online-mode = false; + previews-chat = false; + pvp = false; + server-port = cfg.server.port; + snooper-enabled = false; + }; + + jvmOpts = + (concatStringsSep " " [ + "-Xms${cfg.server.memory}" + "-Xmx${cfg.server.memory}" + "--add-modules=jdk.incubator.vector" # Required by some plugins. + ]) + + " "; + }; + }; + + nixpkgs.overlays = [ inputs.minecraft.overlay ]; + + my.extraGroups = [ config.services.minecraft-servers.group ]; + }) + ]; +} diff --git a/modules/games/steam-run.nix b/modules/games/steam-run.nix new file mode 100644 index 0000000..cfee8ae --- /dev/null +++ b/modules/games/steam-run.nix @@ -0,0 +1,89 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.nixfiles.modules.games.steam-run; +in +{ + options.nixfiles.modules.games.steam-run = { + enable = mkEnableOption "native Steam runtime"; + + quirks = { + blackIsleStudios = mkEnableOption "fixes for games from Black Isle Studios"; + cryptOfTheNecrodancer = mkEnableOption ''fixes for "Crypt of the NecroDancer" issues''; + mountAndBladeWarband = mkEnableOption ''fixes for "Mount & Blade: Warband" issues''; + }; + }; + + config = mkIf cfg.enable { + nixfiles.modules = { + common.nix.allowedUnfreePackages = [ + "steam" + "steam-run" + ]; + + games = { + enable32BitSupport = true; + gamemode.enable = true; + mangohud.enable = true; + }; + }; + + hm.home.packages = with pkgs; [ + (steam.override { + extraLibraries = + _: + with cfg.quirks; + optional blackIsleStudios openssl_1_0_0 + ++ optionals cryptOfTheNecrodancer [ + (import (builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/d1c3fea7ecbed758168787fe4e4a3157e52bc808.tar.gz"; + sha256 = "0ykm15a690v8lcqf2j899za3j6hak1rm3xixdxsx33nz7n3swsyy"; + }) { inherit (config.nixpkgs) config localSystem; }).flac + ] + ++ optionals mountAndBladeWarband [ + (glew.overrideAttrs ( + _: super: + let + opname = super.pname; + in + rec { + pname = "${opname}-steam-run-fix"; + inherit (super) version; + src = fetchurl { + url = "mirror://sourceforge/${opname}/${opname}-${version}.tgz"; + hash = "sha256-BN6R5+Z2MDm8EZQAlc2cf4gLq6ghlqd2X3J6wFqZPJU="; + }; + } + )) + (fmodex.overrideAttrs ( + _: super: + let + opname = super.pname; + in + rec { + pname = "${opname}-steam-run-fix"; + inherit (super) version; + installPhase = + let + libPath = makeLibraryPath [ + alsa-lib + libpulseaudio + stdenv.cc.cc + ]; + in + '' + install -Dm755 api/lib/libfmodex64-${version}.so $out/lib/libfmodex64.so + patchelf --set-rpath ${libPath} $out/lib/libfmodex64.so + ''; + } + )) + ]; + }).run + ]; + }; +} diff --git a/modules/games/steam.nix b/modules/games/steam.nix new file mode 100644 index 0000000..5883b0e --- /dev/null +++ b/modules/games/steam.nix @@ -0,0 +1,33 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.nixfiles.modules.games.steam; +in +{ + options.nixfiles.modules.games.steam.enable = mkEnableOption "Steam runtime"; + + config = mkIf cfg.enable { + nixfiles.modules = { + common.nix.allowedUnfreePackages = [ + "steam" + "steam-original" + ]; + + games = { + enable32BitSupport = true; + gamemode.enable = true; + mangohud.enable = true; + }; + }; + + hm.home.packages = with pkgs; [ + (steam.override { extraEnv.MANGOHUD = 1; }) + protontricks + ]; + }; +} -- cgit v1.2.3