nixos-config/users/simon/modules/games.nix

109 lines
3.9 KiB
Nix
Raw Normal View History

{ lib, nixosConfig, pkgs, ... }:
let
cfg = nixosConfig.sbruder.games;
inherit (nixosConfig.sbruder) unfree;
2021-10-04 16:33:40 +02:00
steam-sandbox = pkgs.writeShellScriptBin "steam-sandbox" /* bash */ ''
set -euo pipefail
shopt -s nullglob # make for loop work for glob if files do not exist
2021-10-04 16:33:40 +02:00
base_dir="''${XDG_DATA_HOME:-$HOME/.local/share}/steam-sandbox"
mkdir -p "$base_dir"/{.local/share,.steam,.config,.factorio,data}
2021-10-04 16:33:40 +02:00
bubblewrap_args=(
# sandboxing
--unshare-all
--share-net
--die-with-parent
--new-session
# basic filesystem
--tmpfs /tmp
--proc /proc
--dev /dev
--dir "$HOME"
--dir "$XDG_RUNTIME_DIR"
--ro-bind /nix/store /nix/store
# path
--ro-bind /run/current-system/sw /run/current-system/sw
--ro-bind /etc/profiles/per-user/$USER/bin /etc/profiles/per-user/$USER/bin
# system-wide configuration
--ro-bind /etc/fonts /etc/fonts
--ro-bind /etc/localtime /etc/localtime
--ro-bind /etc/machine-id /etc/machine-id
--ro-bind /etc/os-release /etc/os-release
--ro-bind /etc/passwd /etc/passwd
2021-10-04 16:33:40 +02:00
--ro-bind /etc/resolv.conf /etc/resolv.conf
--ro-bind /etc/ssl/certs /etc/ssl/certs
--ro-bind /etc/static /etc/static
# gui
--ro-bind /tmp/.X11-unix /tmp/.X11-unix
--ro-bind "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
--dev-bind /dev/dri /dev/dri
--ro-bind /run/opengl-driver /run/opengl-driver
--ro-bind-try /run/opengl-driver-32 /run/opengl-driver-32
# audio
--ro-bind "$XDG_RUNTIME_DIR/pulse" "$XDG_RUNTIME_DIR/pulse"
--setenv PULSE_SERVER "$XDG_RUNTIME_DIR/pulse/native"
--ro-bind "''${XDG_CONFIG_HOME:-$HOME/.config}/pulse/cookie" "''${XDG_CONFIG_HOME:-$HOME/.config}/pulse/cookie"
--setenv PULSE_COOKIE "''${XDG_CONFIG_HOME:-$HOME/.config}/pulse/cookie/pulse/cookie"
--ro-bind-try /etc/asound.conf /etc/asound.conf
--ro-bind-try /etc/alsa/conf.d /etc/alsa/conf.d
--ro-bind-try "$XDG_RUNTIME_DIR/pipewire-0" "$XDG_RUNTIME_DIR/pipewire-0"
# dbus
--ro-bind /run/dbus/system_bus_socket /run/dbus/system_bus_socket
--ro-bind "$XDG_RUNTIME_DIR/bus" "$XDG_RUNTIME_DIR/bus"
# shared data
--bind "$base_dir/.local/share" "$HOME/.local/share"
--bind "$base_dir/.steam" "$HOME/.steam"
--bind "$base_dir/.config" "$HOME/.config"
--bind "$base_dir/.factorio" "$HOME/.factorio"
2021-10-04 16:33:40 +02:00
--bind "$base_dir/data" "$HOME/data"
2022-05-01 10:30:31 +02:00
--ro-bind-try "$HOME/.config/MangoHud" "$HOME/.config/MangoHud"
2021-10-04 16:33:40 +02:00
# input
--dev-bind /dev/input /dev/input
--dev-bind-try /dev/uinput /dev/uinput
--ro-bind /sys /sys # required for discovery
2021-10-04 16:33:40 +02:00
)
for hidraw in /dev/hidraw*; do
bubblewrap_args+=(--dev-bind $hidraw $hidraw)
done
2021-10-04 16:33:40 +02:00
unset SDL_VIDEODRIVER QT_QPA_PLATFORM # games generally dont support wayland
2022-05-01 10:30:31 +02:00
export PATH="${pkgs.unstable.mangohud}/bin:$PATH"
2021-10-04 16:33:40 +02:00
${pkgs.bubblewrap}/bin/bwrap \
"''${bubblewrap_args[@]}" \
''${SANDBOX_COMMAND:-${pkgs.unstable.steam}/bin/steam} \
"$@"
'';
steam-sandbox-with-icons = pkgs.runCommand "steam-sandbox-with-icons" { } ''
mkdir -p $out/{bin,share}
ln -s ${pkgs.steamPackages.steam}/share/icons $out/share
ln -s ${pkgs.steamPackages.steam}/share/pixmaps $out/share
ln -s ${steam-sandbox}/bin/steam-sandbox $out/bin/steam-sandbox
'';
in
lib.mkIf cfg.enable {
home.packages = with pkgs; [
unstable.mangohud
] ++ lib.optionals (cfg.performanceIndex >= 2) [
2021-08-07 00:30:49 +02:00
mgba
] ++ lib.optionals (cfg.performanceIndex >= 4) [
desmume
2022-02-23 20:46:33 +01:00
unstable.dolphin-emu-beta
2022-08-16 00:27:01 +02:00
] ++ lib.optionals (cfg.performanceIndex >= 8) [
unstable.ryujinx
unstable.yuzu-mainline
] ++ lib.optionals unfree.allowSoftware [
2021-10-04 16:33:40 +02:00
unstable.osu-lazer-sandbox
steam-sandbox-with-icons
2021-10-04 16:33:40 +02:00
];
2021-01-07 18:29:18 +01:00
}