diff --git a/hosts/miku-nixos/default.nix b/hosts/miku-nixos/default.nix index 480647c7..00eccd37 100644 --- a/hosts/miku-nixos/default.nix +++ b/hosts/miku-nixos/default.nix @@ -11,7 +11,6 @@ in imports = [ ./hardware-configuration.nix ../../nixos - ../../nixos/games.nix inputs.hardware.nixosModules.common-cpu-intel ]; @@ -19,6 +18,7 @@ in audio.lowLatency.enable = true; cross-compiling.enable = true; dev.enable = true; + games.enable = true; server = { plex.enable = true; rtorrent.enable = true; diff --git a/hosts/sankyuu-nixos/default.nix b/hosts/sankyuu-nixos/default.nix index bfc91c9b..5e7d5b0e 100644 --- a/hosts/sankyuu-nixos/default.nix +++ b/hosts/sankyuu-nixos/default.nix @@ -2,7 +2,7 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, flake, lib, ... }: +{ config, pkgs, flake, ... }: let inherit (flake) inputs; @@ -11,7 +11,6 @@ in imports = [ ./hardware-configuration.nix ../../nixos - ../../nixos/games.nix inputs.hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1 ]; @@ -55,6 +54,10 @@ in # The audio device from this notebook doesn't seem to like short buffers too much quantum = 128; }; + games = { + enable = true; + gpu = "amd"; + }; laptop.tlp = { cpuFreqGovernor = "schedutil"; batteryThreshold = { @@ -67,9 +70,6 @@ in programs.steam.gamescopeSession.args = [ "-w 1600" "-h 900" - "--fsr-sharpness 10" - "-U" - "--adaptive-sync" ]; # Used for firmware updates diff --git a/nixos/default.nix b/nixos/default.nix index ed1f65be..91ef23ea 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -7,6 +7,7 @@ ./desktop ./dev ./fonts.nix + ./games ./home.nix ./laptop ./minimal.nix diff --git a/nixos/games.nix b/nixos/games.nix deleted file mode 100644 index 3705ec56..00000000 --- a/nixos/games.nix +++ /dev/null @@ -1,85 +0,0 @@ -{ pkgs, lib, config, ... }: - -let - inherit (config.meta) username; - nvidia-offload = lib.findFirst (p: lib.isDerivation p && p.name == "nvidia-offload") - null - config.environment.systemPackages; - import-osu-songs = pkgs.writeShellApplication { - name = "import-osu-songs"; - runtimeInputs = [ pkgs.coreutils ]; - text = '' - declare -r osu_song_dir="$HOME/.osu/drive_c/osu/Songs" - mkdir -p "$osu_song_dir" - cp -v "''${@}" "$osu_song_dir" - ''; - }; -in -{ - # Fix: MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0 - boot.kernelParams = [ "dev.i915.perf_stream_paranoid=0" ]; - - environment = { - systemPackages = with pkgs; [ - gaming.osu-lazer-bin - gaming.osu-stable - gamescope - import-osu-songs - lutris - mangohud - piper - retroarchFull - ]; - - # Use nvidia-offload script in gamemode - variables.GAMEMODERUNEXEC = lib.mkIf (nvidia-offload != null) - "${nvidia-offload}/bin/nvidia-offload"; - }; - - programs = { - corectrl.enable = true; - gamemode = { - enable = true; - settings = { - general = { - softrealtime = "auto"; - renice = 10; - }; - custom = { - start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'"; - end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'"; - }; - }; - }; - - gamescope = { - args = [ "--rt" ]; - capSysNice = true; - }; - - steam = { - enable = true; - remotePlay.openFirewall = true; - gamescopeSession.enable = true; - }; - }; - - hardware = { - # Enable opentabletdriver (for osu!) - opentabletdriver = { - enable = true; - package = pkgs.opentabletdriver; - }; - - # Alternative driver for Xbox One/Series S/Series X controllers - xpadneo.enable = true; - }; - - services = { - # Enable ratbagd (i.e.: piper) for Logitech devices - ratbagd.enable = true; - }; - - # Added user to groups - users.users.${username}.extraGroups = [ "corectrl" ]; -} diff --git a/nixos/games/corectrl.nix b/nixos/games/corectrl.nix new file mode 100644 index 00000000..7413c8a4 --- /dev/null +++ b/nixos/games/corectrl.nix @@ -0,0 +1,21 @@ +{ lib, config, ... }: + +let + inherit (config.meta) username; + cfg = config.nixos.games.corectrl; +in +{ + options.nixos.games.corectrl.enable = lib.mkEnableOption "corectrl config" // { + default = config.nixos.games.enable && (config.nixos.games.gpu == "amd"); + }; + + config = lib.mkIf cfg.enable { + programs.corectrl = { + enable = true; + gpuOverclock.enable = true; + }; + + # Added user to groups + users.users.${username}.extraGroups = [ "corectrl" ]; + }; +} diff --git a/nixos/games/default.nix b/nixos/games/default.nix new file mode 100644 index 00000000..b13016fb --- /dev/null +++ b/nixos/games/default.nix @@ -0,0 +1,58 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.nixos.games; + nvidia-offload = lib.findFirst (p: lib.isDerivation p && p.name == "nvidia-offload") + null + config.environment.systemPackages; +in +{ + imports = [ + ./corectrl.nix + ./osu.nix + ./ratbag.nix + ./retroarch.nix + ./steam.nix + ]; + + options.nixos.games = { + enable = lib.mkEnableOption "games config"; + gpu = lib.mkOption { + type = lib.types.nullOr (lib.types.enum [ "amd" "intel" "nvidia" ]); + default = null; + description = "GPU maker."; + }; + }; + + config = lib.mkIf cfg.enable { + # Fix: MESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0 + boot.kernelParams = lib.mkIf (cfg.gpu == "intel") [ "dev.i915.perf_stream_paranoid=0" ]; + + environment = { + systemPackages = with pkgs; [ + lutris + ]; + + # Use nvidia-offload script in gamemode + variables.GAMEMODERUNEXEC = lib.mkIf (cfg.gpu == "nvidia" && nvidia-offload != null) + "${nvidia-offload}/bin/nvidia-offload"; + }; + + programs.gamemode = { + enable = true; + settings = { + general = { + softrealtime = "auto"; + renice = 10; + }; + custom = { + start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'"; + end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'"; + }; + }; + }; + + # Alternative driver for Xbox One/Series S/Series X controllers + hardware.xone.enable = true; + }; +} diff --git a/nixos/games/osu.nix b/nixos/games/osu.nix new file mode 100644 index 00000000..82ff46b9 --- /dev/null +++ b/nixos/games/osu.nix @@ -0,0 +1,37 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.nixos.games.osu; +in +{ + options.nixos.games.osu.enable = lib.mkEnableOption "osu! config" // { + default = config.nixos.games.enable; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; let + import-osu-songs = pkgs.writeShellApplication { + name = "import-osu-songs"; + runtimeInputs = [ pkgs.coreutils ]; + text = '' + declare -r $osu_dir="$HOME/.osu" + if [[ ! -d "$osu_dir" ]]; then + >&2 echo "'$osu_dir' directory not found! Start 'osu-stable' once to create it." + exit 1 + fi + declare -r osu_song_dir="$osu_dir/drive_c/osu/Songs" + mkdir -p "$osu_song_dir" + cp -v "''${@}" "$osu_song_dir" + ''; + }; + in + [ + gaming.osu-lazer-bin + gaming.osu-stable + import-osu-songs + ]; + + # Enable opentabletdriver + hardware.opentabletdriver.enable = true; + }; +} diff --git a/nixos/games/ratbag.nix b/nixos/games/ratbag.nix new file mode 100644 index 00000000..0a9ec728 --- /dev/null +++ b/nixos/games/ratbag.nix @@ -0,0 +1,17 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.nixos.games.ratbag; +in +{ + options.nixos.games.ratbag.enable = lib.mkEnableOption "Ratbag/Piper (e.g. Logitech devices) config" // { + default = config.nixos.games.enable; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ piper ]; + + # Enable ratbagd (i.e.: piper) for Logitech devices + services.ratbagd.enable = true; + }; +} diff --git a/nixos/games/retroarch.nix b/nixos/games/retroarch.nix new file mode 100644 index 00000000..b31754da --- /dev/null +++ b/nixos/games/retroarch.nix @@ -0,0 +1,26 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.nixos.games.retroarch; +in +{ + options.nixos.games.retroarch = { + enable = lib.mkEnableOption "RetroArch config" // { + default = config.nixos.games.enable; + }; + package = lib.mkPackageOption pkgs "retroarch" { + default = "retroarchFull"; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ + cfg.package + ]; + + services.xserver.desktopManager.retroarch = { + enable = true; + package = cfg.package; + }; + }; +} diff --git a/nixos/games/steam.nix b/nixos/games/steam.nix new file mode 100644 index 00000000..0a5eee53 --- /dev/null +++ b/nixos/games/steam.nix @@ -0,0 +1,39 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.nixos.games.steam; +in +{ + options.nixos.games.steam = { + enable = lib.mkEnableOption "Steam config" // { + default = config.nixos.games.enable; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + gamescope + mangohud + ]; + + programs = { + gamescope = { + args = [ "--rt" ]; + capSysNice = true; + }; + + steam = { + enable = true; + remotePlay.openFirewall = true; + gamescopeSession = { + enable = true; + args = [ + "--fsr-sharpness 10" + "-U" + "--adaptive-sync" + ]; + }; + }; + }; + }; +}