Unverified Commit 91f5aa34 authored by Atemu's avatar Atemu Committed by GitHub
Browse files

Merge pull request #213378 from Atemu/steam-env-vars

steam: add extraEnv argument
parents 2e0bb262 1f27e0b7
Loading
Loading
Loading
Loading
+26 −13
Original line number Diff line number Diff line
@@ -10,22 +10,35 @@ in {

    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;
      default = pkgs.steam;
      defaultText = literalExpression "pkgs.steam";
      example = literalExpression ''
        pkgs.steam-small.override {
          extraEnv = {
            MANGOHUD = true;
            OBS_VKCAPTURE = true;
            RADV_TEX_ANISO = 16;
          };
      defaultText = literalExpression ''
        pkgs.steam.override {
          extraLibraries = pkgs: with config.hardware.opengl;
          extraLibraries = p: with p; [
            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.
      '';
    };

+5 −1
Original line number Diff line number Diff line
{ 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;
  };
}
+6 −5
Original line number Diff line number Diff line
@@ -20,9 +20,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"
    "version"
@@ -104,7 +104,7 @@ let
    ro_mounts=()
    symlinks=()
    etc_ignored=()
    for i in ${env}/*; do
    for i in ${fhsenv}/*; do
      path="/''${i##*/}"
      if [[ $path == '/etc' ]]; then
        :
@@ -117,8 +117,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.
@@ -221,6 +221,7 @@ in runCommandLocal nameAndVersion {
      echo >&2 ""
      exit 1
    '';
    inherit args fhsenv;
  };
} ''
  mkdir -p $out/bin
+12 −5
Original line number Diff line number Diff line
{ 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
, 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";

@@ -228,8 +231,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
@@ -249,6 +251,9 @@ in buildFHSUserEnv rec {

    ${exportLDPath}
    ${fixBootstrap}

    set -o allexport # Export the following env vars
    ${envScript}
    exec steam ${extraArgs} "$@"
  '';

@@ -272,8 +277,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
@@ -283,6 +287,9 @@ in buildFHSUserEnv rec {

      ${exportLDPath}
      ${fixBootstrap}

      set -o allexport # Export the following env vars
      ${envScript}
      exec -- "$run" "$@"
    '';