From 422b0ff93b3d72b366f7473766dbbbd0fa665e47 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sun, 29 Jan 2023 14:42:38 +0100 Subject: [PATCH 1/4] steam: use writeShellScript --- pkgs/games/steam/fhsenv.nix | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkgs/games/steam/fhsenv.nix b/pkgs/games/steam/fhsenv.nix index c50176dce790..246f59cb24b5 100644 --- a/pkgs/games/steam/fhsenv.nix +++ b/pkgs/games/steam/fhsenv.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, writeScript, buildFHSUserEnv, steam, glxinfo-i686, runtimeShell +{ lib, stdenv, writeShellScript, buildFHSUserEnv, steam, glxinfo-i686 , steam-runtime-wrapped, steam-runtime-wrapped-i686 ? null , extraPkgs ? pkgs: [ ] # extra packages to add to targetPkgs , extraLibraries ? pkgs: [ ] # extra packages to add to multiPkgs @@ -228,8 +228,7 @@ in buildFHSUserEnv rec { export SDL_JOYSTICK_DISABLE_UDEV=1 '' + extraProfile; - runScript = writeScript "steam-wrapper.sh" '' - #!${runtimeShell} + runScript = writeShellScript "steam-wrapper.sh" '' if [ -f /host/etc/NIXOS ]; then # Check only useful on NixOS ${glxinfo-i686}/bin/glxinfo >/dev/null 2>&1 # If there was an error running glxinfo, we know something is wrong with the configuration @@ -272,8 +271,7 @@ in buildFHSUserEnv rec { inherit multiPkgs profile extraInstallCommands; inherit unshareIpc unsharePid; - runScript = writeScript "steam-run" '' - #!${runtimeShell} + runScript = writeShellScript "steam-run" '' run="$1" if [ "$run" = "" ]; then echo "Usage: steam-run command-to-run args..." >&2 From 192c3ecd4bcc317c3d8868d3c944a75de0dee32e Mon Sep 17 00:00:00 2001 From: Atemu Date: Tue, 7 Mar 2023 20:35:30 +0100 Subject: [PATCH 2/4] buildFHSEnvBubblewrap: allow deeper introspection via passthru --- .../{env.nix => buildFHSEnv.nix} | 6 +++++- .../build-fhs-userenv-bubblewrap/default.nix | 11 ++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) rename pkgs/build-support/build-fhs-userenv-bubblewrap/{env.nix => buildFHSEnv.nix} (98%) diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix similarity index 98% rename from pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix rename to pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix index c4d967a11c69..0d98c0a2bc64 100644 --- a/pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix +++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix @@ -1,6 +1,6 @@ { stdenv, lib, buildEnv, writeText, writeShellScriptBin, pkgs, pkgsi686Linux }: -{ name, profile ? "" +args@{ name, profile ? "" , targetPkgs ? pkgs: [], multiPkgs ? pkgs: [] , extraBuildCommands ? "", extraBuildCommandsMulti ? "" , extraOutputsToInstall ? [] @@ -216,4 +216,8 @@ in stdenv.mkDerivation { ''; preferLocalBuild = true; allowSubstitutes = false; + + passthru = { + inherit args multiPaths targetPaths; + }; } diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix index 76e68573faa8..290ad35c0640 100644 --- a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix +++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix @@ -19,9 +19,9 @@ args @ { with builtins; let - buildFHSEnv = callPackage ./env.nix { }; + buildFHSEnv = callPackage ./buildFHSEnv.nix { }; - env = buildFHSEnv (removeAttrs args [ + fhsenv = buildFHSEnv (removeAttrs args [ "runScript" "extraInstallCommands" "meta" "passthru" "extraBwrapArgs" "dieWithParent" "unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc" ]); @@ -102,7 +102,7 @@ let ro_mounts=() symlinks=() etc_ignored=() - for i in ${env}/*; do + for i in ${fhsenv}/*; do path="/''${i##*/}" if [[ $path == '/etc' ]]; then : @@ -115,8 +115,8 @@ let fi done - if [[ -d ${env}/etc ]]; then - for i in ${env}/etc/*; do + if [[ -d ${fhsenv}/etc ]]; then + for i in ${fhsenv}/etc/*; do path="/''${i##*/}" # NOTE: we're binding /etc/fonts and /etc/ssl/certs from the host so we # don't want to override it with a path from the FHS environment. @@ -215,6 +215,7 @@ in runCommandLocal name { echo >&2 "" exit 1 ''; + inherit args fhsenv; }; } '' mkdir -p $out/bin From 473159871236e584af08386ed408aef30102395c Mon Sep 17 00:00:00 2001 From: Atemu Date: Tue, 7 Mar 2023 20:24:28 +0100 Subject: [PATCH 3/4] nixos/steam: always apply extraLibraries and make them additive Before, setting {option}`programs.steam.package` would result in a steam without the {option}`hardware.opengl.package`, {option}`hardware.opengl.extraPackages` etc. You had to manually add them yourself. Additionally, overlaying `steam = prev.steam.override { extraLibraries = [ ... ]; }` resulted in those extra libraries not actually being put into the fhsenv because they'd be fully overridden by the option's default. Now, the user can supply a custom steam to {option}`programs.steam.package` with its own list of extraLibraries which will not be overridden and overlays work as expected too. --- nixos/modules/programs/steam.nix | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/nixos/modules/programs/steam.nix b/nixos/modules/programs/steam.nix index 98269f6250db..6935ac93bf74 100644 --- a/nixos/modules/programs/steam.nix +++ b/nixos/modules/programs/steam.nix @@ -9,23 +9,31 @@ in { enable = mkEnableOption (lib.mdDoc "steam"); package = mkOption { - type = types.package; - default = pkgs.steam.override { - extraLibraries = pkgs: with config.hardware.opengl; - if pkgs.stdenv.hostPlatform.is64bit - then [ package ] ++ extraPackages - else [ package32 ] ++ extraPackages32; - }; - defaultText = literalExpression '' - pkgs.steam.override { - extraLibraries = pkgs: with config.hardware.opengl; + type = types.package; + default = pkgs.steam; + defaultText = literalExpression "pkgs.steam"; + example = literalExpression '' + pkgs.steam-small.override { + extraLibraries = with pkgs; [ + atk + ]; + } + ''; + apply = steam: steam.override (prev: { + extraLibraries = pkgs: let + prevLibs = if prev ? extraLibraries then prev.extraLibraries pkgs else [ ]; + additionalLibs = with config.hardware.opengl; if pkgs.stdenv.hostPlatform.is64bit then [ package ] ++ extraPackages else [ package32 ] ++ extraPackages32; - } - ''; + in prevLibs ++ additionalLibs; + }); description = lib.mdDoc '' - steam package to use. + The Steam package to use. Additional libraries are added from the system + configuration to ensure graphics work properly. + + Use this option to customise the Steam package rather than adding your + custom Steam to {option}`environment.systemPackages` yourself. ''; }; From 1f27e0b77a63fd243ab40dfce22edf106424faea Mon Sep 17 00:00:00 2001 From: Atemu Date: Sun, 29 Jan 2023 14:56:57 +0100 Subject: [PATCH 4/4] steam: add extraEnv option --- nixos/modules/programs/steam.nix | 7 ++++++- pkgs/games/steam/fhsenv.nix | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/nixos/modules/programs/steam.nix b/nixos/modules/programs/steam.nix index 6935ac93bf74..fc63f0f187e8 100644 --- a/nixos/modules/programs/steam.nix +++ b/nixos/modules/programs/steam.nix @@ -14,7 +14,12 @@ in { defaultText = literalExpression "pkgs.steam"; example = literalExpression '' pkgs.steam-small.override { - extraLibraries = with pkgs; [ + extraEnv = { + MANGOHUD = true; + OBS_VKCAPTURE = true; + RADV_TEX_ANISO = 16; + }; + extraLibraries = p: with p; [ atk ]; } diff --git a/pkgs/games/steam/fhsenv.nix b/pkgs/games/steam/fhsenv.nix index 246f59cb24b5..8d461104eaac 100644 --- a/pkgs/games/steam/fhsenv.nix +++ b/pkgs/games/steam/fhsenv.nix @@ -4,6 +4,7 @@ , extraLibraries ? pkgs: [ ] # extra packages to add to multiPkgs , extraProfile ? "" # string to append to profile , extraArgs ? "" # arguments to always pass to steam +, extraEnv ? { } # Environment variables to pass to Steam , withGameSpecificLibraries ? true # exclude game specific libraries }: @@ -52,6 +53,8 @@ let fi ''; + envScript = lib.toShellVars extraEnv; + in buildFHSUserEnv rec { name = "steam"; @@ -248,6 +251,9 @@ in buildFHSUserEnv rec { ${exportLDPath} ${fixBootstrap} + + set -o allexport # Export the following env vars + ${envScript} exec steam ${extraArgs} "$@" ''; @@ -281,6 +287,9 @@ in buildFHSUserEnv rec { ${exportLDPath} ${fixBootstrap} + + set -o allexport # Export the following env vars + ${envScript} exec -- "$run" "$@" '';