nixfiles/home-manager/modules/gaming.nix
2026-02-27 05:10:36 -07:00

84 lines
2.4 KiB
Nix

inputs: {
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.gaming;
in {
options.gaming = {
enable = mkEnableOption "Enable gaming stuff";
steamService = mkOption {
type = types.bool;
description = "Enable running steam as a service";
};
scService = mkOption {
type = types.bool;
description = "Enable running sc-controller as a service. This integrates with steamService to make sure your steam controller will continuously be mapped.";
};
};
config = mkIf cfg.enable {
gaming.steamService = mkOptionDefault false;
gaming.scService = mkOptionDefault cfg.steamService;
home.sessionVariables = {
STAGING_RT_PRIORITY_SERVER = 90;
};
home.packages = with pkgs;
[
sc-controller
]
++ lib.optional cfg.steamService (pkgs.writeShellScriptBin "steam" "${pkgs.systemd}/bin/systemctl --user start steam");
systemd.user.services.scc = mkIf cfg.scService {
Unit = {
Description = "User-mode driver and GTK3 based GUI for Steam Controller";
After = ["graphical-session-pre.target"];
PartOf = ["graphical-session.target"];
};
Service = {
Type = "simple";
ExecStart = "${pkgs.sc-controller}/bin/scc-daemon debug";
Restart = "always";
RestartSec = 5;
};
Install = {WantedBy = ["graphical-session.target"];};
};
systemd.user.services.steam = mkIf cfg.steamService {
Unit = {
Description = "Start Steam gaming platform";
After = ["graphical-session-pre.target"];
PartOf = ["graphical-session.target"];
};
Service = {
Type = "simple";
ExecStart = let
steamStart = pkgs.writeShellScript "steam-start" ''
${pkgs.systemd}/bin/systemctl --user stop scc
# no sleep is needed here because steam is slow as fuck lol
/run/current-system/sw/bin/steam -fulldesktopres
'';
in
lib.mkIf cfg.scService "${steamStart}";
ExecStop = let
steamStop = pkgs.writeShellScript "steam-stop" ''
${pkgs.coreutils}/bin/sleep 5 # give time for controller to reset
${pkgs.systemd}/bin/systemctl --user start scc
'';
in
lib.mkIf cfg.scService "${steamStop}";
};
Install = {WantedBy = ["graphical-session.target"];};
};
};
}