From 070aeae8db9caac7cac9e4acfaced233a0e79ba3 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Wed, 17 Sep 2025 13:54:27 +0800 Subject: [PATCH] feat: gaming (#223) * refactor: configure gaming suite via options, use pkgs-x64 * fix: gaming on apple silicon (not work yet) --- home/linux/gui/base/gaming.nix | 109 +++++++++++------- home/linux/gui/base/media.nix | 7 +- hosts/12kingdoms-shoukei/apple-silicon.nix | 7 ++ hosts/idols-ai/default.nix | 1 - hosts/idols-ai/gaming.nix | 64 ---------- modules/nixos/desktop/gaming.nix | 84 ++++++++++++++ .../aarch64-linux/src/12kingdoms-shoukei.nix | 25 ++-- outputs/x86_64-linux/src/idols-ai.nix | 19 ++- 8 files changed, 191 insertions(+), 125 deletions(-) delete mode 100644 hosts/idols-ai/gaming.nix create mode 100644 modules/nixos/desktop/gaming.nix diff --git a/home/linux/gui/base/gaming.nix b/home/linux/gui/base/gaming.nix index 48ce46fb..341db0be 100644 --- a/home/linux/gui/base/gaming.nix +++ b/home/linux/gui/base/gaming.nix @@ -1,48 +1,71 @@ -{ pkgs, osConfig, ... }: { - # ========================================================================== - # Other Optimizations - # Usage: - # Lutris - enable advanced options, go to the System options -> Command prefix, add: `mangohud` - # Steam - add this as a launch option: `mangohud %command%` / `gamemoderun %command%` - # ========================================================================== + pkgs, + pkgs-x64, + osConfig, + config, + lib, + ... +}: +with lib; +let + cfg = config.modules.desktop.gaming; +in +{ + options.modules.desktop = { + gaming = { + enable = mkEnableOption "Install Game Suite(steam, lutris, etc)"; + }; + }; - home.packages = with pkgs; [ - # https://github.com/flightlessmango/MangoHud - # a simple overlay program for monitoring FPS, temperature, CPU and GPU load, and more. - mangohud - # a game launcher - great for epic games and gog games - (heroic.override { - extraPkgs = pkgs: [ - pkgs.gamescope + config = mkIf cfg.enable { + # ========================================================================== + # Other Optimizations + # Usage: + # Lutris - enable advanced options, go to the System options -> Command prefix, add: `mangohud` + # Steam - add this as a launch option: `mangohud %command%` / `gamemoderun %command%` + # ========================================================================== + + home.packages = + (with pkgs; [ + # https://github.com/flightlessmango/MangoHud + # a simple overlay program for monitoring FPS, temperature, CPU and GPU load, and more. + mangohud + + # GUI for installing custom Proton versions like GE_Proton + # proton - a Wine distribution aimed at gaming + protonplus + # Script to install various redistributable runtime libraries in Wine. + winetricks + # https://github.com/Open-Wine-Components/umu-launcher + # a unified launcher for Windows games on Linux + umu-launcher + ]) + ++ (with pkgs-x64; [ + # a game launcher - great for epic games and gog games + (heroic.override { + extraPkgs = _pkgs: [ + pkgs.gamescope # aarch64 + ]; + }) + ]); + + # a GUI game launcher for Steam/GoG/Epic + programs.lutris = { + enable = true; + defaultWinePackage = pkgs-x64.proton-ge-bin; + steamPackage = osConfig.programs.steam.package; + protonPackages = [ pkgs-x64.proton-ge-bin ]; + winePackages = with pkgs-x64; [ + wineWow64Packages.full + wineWowPackages.stagingFull ]; - }) - # GUI for installing custom Proton versions like GE_Proton - # proton - a Wine distribution aimed at gaming - protonplus - # Script to install various redistributable runtime libraries in Wine. - winetricks - # https://github.com/Open-Wine-Components/umu-launcher - # a unified launcher for Windows games on Linux - umu-launcher - ]; - - # a GUI game launcher for Steam/GoG/Epic - programs.lutris = { - enable = true; - defaultWinePackage = pkgs.proton-ge-bin; - steamPackage = osConfig.programs.steam.package; - protonPackages = [ pkgs.proton-ge-bin ]; - winePackages = with pkgs; [ - wineWow64Packages.full - wineWowPackages.stagingFull - ]; - extraPackages = with pkgs; [ - winetricks - gamescope - gamemode - mangohud - umu-launcher - ]; + extraPackages = with pkgs; [ + winetricks + gamescope + gamemode + mangohud + umu-launcher + ]; + }; }; } diff --git a/home/linux/gui/base/media.nix b/home/linux/gui/base/media.nix index fa8e31b2..6862e619 100644 --- a/home/linux/gui/base/media.nix +++ b/home/linux/gui/base/media.nix @@ -1,5 +1,6 @@ { pkgs, + pkgs-x64, pkgs-unstable, nur-ryan4yin, ... @@ -21,10 +22,8 @@ vulkan-tools glxinfo nvitop - ] - ++ (lib.optionals pkgs.stdenv.isx86_64 [ - (zoom-us.override { hyprlandXdgDesktopPortalSupport = true; }) - ]); + (pkgs-x64.zoom-us.override { hyprlandXdgDesktopPortalSupport = true; }) + ]; programs.mpv = { enable = true; diff --git a/hosts/12kingdoms-shoukei/apple-silicon.nix b/hosts/12kingdoms-shoukei/apple-silicon.nix index 46794ef4..6477d88a 100644 --- a/hosts/12kingdoms-shoukei/apple-silicon.nix +++ b/hosts/12kingdoms-shoukei/apple-silicon.nix @@ -9,6 +9,13 @@ nixos-apple-silicon.nixosModules.default ]; + environment.systemPackages = with pkgs-unstable; [ + box64 # Linux Userspace x86 and x86_64 Emulator, run x86_64 apps(such as games, gui apps) on aarch64. + # https://asahilinux.org/2024/12/muvm-x11-bridging/ + # https://github.com/nix-community/nixos-apple-silicon/issues/237 + muvm # run x86_64 Apps/Games in a microVM, used as a workaround of apple silicon's 16k page size. + ]; + networking.wireless.iwd = { enable = true; settings.General.EnableNetworkConfiguration = true; diff --git a/hosts/idols-ai/default.nix b/hosts/idols-ai/default.nix index 2d296efa..43f38d45 100644 --- a/hosts/idols-ai/default.nix +++ b/hosts/idols-ai/default.nix @@ -19,7 +19,6 @@ in ./hardware-configuration.nix ./nvidia.nix ./ai - ./gaming.nix ./preservation.nix ./secureboot.nix diff --git a/hosts/idols-ai/gaming.nix b/hosts/idols-ai/gaming.nix deleted file mode 100644 index 25191a20..00000000 --- a/hosts/idols-ai/gaming.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ - pkgs, - nix-gaming, - aagl, - ... -}: -{ - # ========================================================================== - # Gaming on Linux - # - # can give you an idea what works where and how. - # Begineer Guide: - # ========================================================================== - - # Games installed by Steam works fine on NixOS, no other configuration needed. - programs.steam = { - # Some location that should be persistent: - # ~/.local/share/Steam - The default Steam install location - # ~/.local/share/Steam/steamapps/common - The default Game install location - # ~/.steam/root - A symlink to ~/.local/share/Steam - # ~/.steam - Some Symlinks & user info - enable = pkgs.stdenv.isx86_64; - # https://github.com/ValveSoftware/gamescope - # Run a GameScope driven Steam session from your display-manager - # fix resolution upscaling and stretched aspect ratios - gamescopeSession.enable = true; - # https://github.com/Winetricks/winetricks - # Whether to enable protontricks, a simple wrapper for running Winetricks commands for Proton-enabled games. - protontricks.enable = true; - # Whether to enable Load the extest library into Steam, to translate X11 input events to uinput events (e.g. for using Steam Input on Wayland) . - extest.enable = true; - fontPackages = [ - pkgs.wqy_zenhei # Need by steam for Chinese - ]; - }; - - # see https://github.com/fufexan/nix-gaming/#pipewire-low-latency - services.pipewire.lowLatency.enable = true; - programs.steam.platformOptimizations.enable = true; - imports = with nix-gaming.nixosModules; [ - pipewireLowLatency - platformOptimizations - - # run anime games on Linux - aagl.nixosModules.default - ]; - - # Optimise Linux system performance on demand - # https://github.com/FeralInteractive/GameMode - # https://wiki.archlinux.org/title/Gamemode - # - # Usage: - # 1. For games/launchers which integrate GameMode support: - # https://github.com/FeralInteractive/GameMode#apps-with-gamemode-integration - # simply running the game will automatically activate GameMode. - programs.gamemode.enable = pkgs.stdenv.isx86_64; - - # run anime games on Linux - # https://github.com/an-anime-team/ - programs.anime-game-launcher.enable = true; # Genshin: Impact - programs.honkers-railway-launcher.enable = true; # Honkai: Star Rail - programs.honkers-launcher.enable = false; # Honkai: Impact 3 - programs.sleepy-launcher.enable = false; # Zenless Zon Zero -} diff --git a/modules/nixos/desktop/gaming.nix b/modules/nixos/desktop/gaming.nix new file mode 100644 index 00000000..2bdf4780 --- /dev/null +++ b/modules/nixos/desktop/gaming.nix @@ -0,0 +1,84 @@ +{ + pkgs, + pkgs-x64, + nix-gaming, + aagl, + config, + lib, + ... +}: +with lib; +let + cfg = config.modules.desktop.gaming; +in +{ + imports = [ + nix-gaming.nixosModules.pipewireLowLatency + nix-gaming.nixosModules.platformOptimizations + + # run anime games on Linux + aagl.nixosModules.default + ]; + + options.modules.desktop = { + gaming = { + enable = mkEnableOption "Install Game Suite(steam, lutris, etc)"; + }; + }; + + config = mkIf cfg.enable { + # ========================================================================== + # Gaming on Linux + # + # can give you an idea what works where and how. + # Begineer Guide: + # ========================================================================== + + # Games installed by Steam works fine on NixOS, no other configuration needed. + # https://github.com/NixOS/nixpkgs/blob/master/doc/packages/steam.section.md + programs.steam = { + # Some location that should be persistent: + # ~/.local/share/Steam - The default Steam install location + # ~/.local/share/Steam/steamapps/common - The default Game install location + # ~/.steam/root - A symlink to ~/.local/share/Steam + # ~/.steam - Some Symlinks & user info + enable = true; + package = pkgs-x64.steam; + # https://github.com/ValveSoftware/gamescope + # Run a GameScope driven Steam session from your display-manager + # fix resolution upscaling and stretched aspect ratios + gamescopeSession.enable = true; + # https://github.com/Winetricks/winetricks + # Whether to enable protontricks, a simple wrapper for running Winetricks commands for Proton-enabled games. + protontricks.enable = true; + # Whether to enable Load the extest library into Steam, to translate X11 input events to uinput events (e.g. for using Steam Input on Wayland) . + extest.enable = true; + fontPackages = [ + pkgs.wqy_zenhei # Need by steam for Chinese + ]; + }; + + # see https://github.com/fufexan/nix-gaming/#pipewire-low-latency + services.pipewire.lowLatency.enable = true; + programs.steam.platformOptimizations.enable = true; + + # Optimise Linux system performance on demand + # https://github.com/FeralInteractive/GameMode + # https://wiki.archlinux.org/title/Gamemode + # + # Usage: + # 1. For games/launchers which integrate GameMode support: + # https://github.com/FeralInteractive/GameMode#apps-with-gamemode-integration + # simply running the game will automatically activate GameMode. + programs.gamemode.enable = true; + + # run anime games on Linux + # https://github.com/an-anime-team/r + networking.mihoyo-telemetry.block = true; + environment.systemPackages = with aagl.packages."x86_64-linux"; [ + anime-game-launcher # Genshin: Impact + honkers-railway-launcher # Honkai: Star Rail + sleepy-launcher # Zenless Zon Zero + ]; + }; +} diff --git a/outputs/aarch64-linux/src/12kingdoms-shoukei.nix b/outputs/aarch64-linux/src/12kingdoms-shoukei.nix index 61ff28ea..cddefced 100644 --- a/outputs/aarch64-linux/src/12kingdoms-shoukei.nix +++ b/outputs/aarch64-linux/src/12kingdoms-shoukei.nix @@ -33,14 +33,23 @@ let modules.desktop.wayland.enable = true; modules.secrets.desktop.enable = true; modules.secrets.preservation.enable = true; + # not supported yet + modules.desktop.gaming.enable = false; + } + ]; + home-modules = + (map mylib.relativeToRoot [ + # common + "home/linux/gui.nix" + # host specific + "hosts/12kingdoms-${name}/home.nix" + ]) + ++ [ + { + # not supported yet + modules.desktop.gaming.enable = false; } ]; - home-modules = map mylib.relativeToRoot [ - # common - "home/linux/gui.nix" - # host specific - "hosts/12kingdoms-${name}/home.nix" - ]; }; modules-hyprland = { @@ -48,7 +57,9 @@ let ] ++ base-modules.nixos-modules; home-modules = [ - { modules.desktop.hyprland.enable = true; } + { + modules.desktop.hyprland.enable = true; + } ] ++ base-modules.home-modules; }; diff --git a/outputs/x86_64-linux/src/idols-ai.nix b/outputs/x86_64-linux/src/idols-ai.nix index ed43cd18..e888c16f 100644 --- a/outputs/x86_64-linux/src/idols-ai.nix +++ b/outputs/x86_64-linux/src/idols-ai.nix @@ -34,14 +34,21 @@ let modules.desktop.wayland.enable = true; modules.secrets.desktop.enable = true; modules.secrets.preservation.enable = true; + modules.desktop.gaming.enable = true; + } + ]; + home-modules = + (map mylib.relativeToRoot [ + # common + "home/linux/gui.nix" + # host specific + "hosts/idols-${name}/home.nix" + ]) + ++ [ + { + modules.desktop.gaming.enable = true; } ]; - home-modules = map mylib.relativeToRoot [ - # common - "home/linux/gui.nix" - # host specific - "hosts/idols-${name}/home.nix" - ]; }; modules-hyprland = {