inputs: { config, lib, pkgs, ... }: with lib; let cfg = config.gaming; in { options.gaming = { enable = mkEnableOption "Enable gaming stuff"; newWine = mkOption { type = types.bool; default = false; description = "If you want to include wine-staging as new-wine"; }; 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 = let newwine = (pkgs.wineFull.override { wineBuild = "wineWow"; wineRelease = "staging"; }); newwinetricks = pkgs.winetricks.overrideAttrs (old: rec { pathAdd = "${newwine}/bin:" + old.pathAdd; postInstall = '' sed -i \ -e '2i PATH="${pathAdd}"' \ "$out/bin/winetricks" ''; }); oldwine = pkgs.wineWowPackages.full; oldwinetricks = pkgs.winetricks.overrideAttrs (old: rec { pathAdd = "${oldwine}/bin:" + old.pathAdd; postInstall = '' sed -i \ -e '2i PATH="${pathAdd}"' \ "$out/bin/winetricks" ''; }); in with pkgs; [ oldwine oldwinetricks sc-controller dolphinEmuMaster tuxpaint extremetuxracer ] ++ lib.optionals cfg.newWine [ ( pkgs.runCommand "new-wine-stuff" { } '' mkdir -p $out/bin ln -s ${newwine}/bin/wine $out/bin/new-wine ln -s ${newwine}/bin/winecfg $out/bin/new-winecfg ln -s ${newwinetricks}/bin/winetricks $out/bin/new-winetricks '' ) ] ++ 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" ]; }; }; }; }