Skip to content

Commit

Permalink
nixos/games: init
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Sep 20, 2023
1 parent 7ce34c4 commit bf300e3
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 91 deletions.
2 changes: 1 addition & 1 deletion hosts/miku-nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ in
imports = [
./hardware-configuration.nix
../../nixos
../../nixos/games.nix
inputs.hardware.nixosModules.common-cpu-intel
];

nixos = {
audio.lowLatency.enable = true;
cross-compiling.enable = true;
dev.enable = true;
games.enable = true;
server = {
plex.enable = true;
rtorrent.enable = true;
Expand Down
10 changes: 5 additions & 5 deletions hosts/sankyuu-nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,7 +11,6 @@ in
imports = [
./hardware-configuration.nix
../../nixos
../../nixos/games.nix
inputs.hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1
];

Expand Down Expand Up @@ -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 = {
Expand All @@ -67,9 +70,6 @@ in
programs.steam.gamescopeSession.args = [
"-w 1600"
"-h 900"
"--fsr-sharpness 10"
"-U"
"--adaptive-sync"
];

# Used for firmware updates
Expand Down
1 change: 1 addition & 0 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
./desktop
./dev
./fonts.nix
./games
./home.nix
./laptop
./minimal.nix
Expand Down
85 changes: 0 additions & 85 deletions nixos/games.nix

This file was deleted.

21 changes: 21 additions & 0 deletions nixos/games/corectrl.nix
Original file line number Diff line number Diff line change
@@ -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" ];
};
}
58 changes: 58 additions & 0 deletions nixos/games/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
37 changes: 37 additions & 0 deletions nixos/games/osu.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
17 changes: 17 additions & 0 deletions nixos/games/ratbag.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
26 changes: 26 additions & 0 deletions nixos/games/retroarch.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
39 changes: 39 additions & 0 deletions nixos/games/steam.nix
Original file line number Diff line number Diff line change
@@ -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"
];
};
};
};
};
}

0 comments on commit bf300e3

Please sign in to comment.