Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

steam: add wrapper testing for libGL #33213

Merged
merged 2 commits into from Jan 2, 2018
Merged

steam: add wrapper testing for libGL #33213

merged 2 commits into from Jan 2, 2018

Conversation

wchresta
Copy link
Member

Motivation for this change

Failing to set hardware.opengl.driSupport32Bit will lead to a
confusing error message about missing libGL.so.1 as described in #19518

Things done

We include a wrapper around the steam bin to test for working 32bit
opengl with glxinfo. When failing, we display a proper warning hinting
towards the option.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Tested on local NixOS machine by activating/deactivating hardware.opengl.driSupport and hardware.opengl.driSupport32Bit. In all cases it gave the expected result:

[nix-shell:~/src/nixpkgs]$ steam
*** WARNING: Test for 32-bit libGL unsuccessful.
             This could mean you forgot to activate hardware.opengl.driSupport32Bit
cp: cannot create regular file '/home/user/.local/share/Steam/bootstrap.tar.xz': Permission denied
Running Steam on nixos 17.09.2476.53e6d671a96 64-bit
STEAM_RUNTIME has been set by the user to: /steamrt
Pins potentially out-of-date, rebuilding...
mkdir: cannot create directory ‘/nix/store/rcdiw6bpzdx4i3lqj4pyz546svjlqc96-steam-fhs/steamrt/pinned_libs_32’: Read-only file system
mkdir: cannot create directory ‘/nix/store/rcdiw6bpzdx4i3lqj4pyz546svjlqc96-steam-fhs/steamrt/pinned_libs_64’: Read-only file system
Error: You are missing the following 32-bit libraries, and Steam may not run:
libGL.so.1
Error:
You are missing the following 32-bit libraries, and Steam may not run:
libGL.so.1
Press enter to continue: ^C

NixOS: Failing to set hardware.opengl.driSupport32Bit will lead to a
confusing error message about missing libGL.so.1. We include a wrapper
around the steam bin to test for working 32bit opengl with glxinfo. When
failing, we display a proper warning hinting towards the option.

Fixes: #19518
glxinfo >/dev/null 2>&1
if [ ! "$?" = "0" ]; then
echo "*** WARNING: Test for 32-bit libGL unsuccessful."
echo " This could mean you forgot to activate hardware.opengl.driSupport32Bit"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into stderr. Also, heredoc would be preferrable:

cat <<EOF > /dev/stderr
WARNING: Test for 32-bit libGL unsuccessful.
This could mean you forgot to activate hardware.opengl.driSupport32Bit
EOF

@lukateras
Copy link
Member

lukateras commented Dec 30, 2017

While it would make Steam start, to make it actually work one would also need to enable hardware.pulseaudio.support32Bit. Also, if glxinfo doesn't run, we can say for sure that Steam won't start, so warning message could be worded more confidently. For example:

**
WARNING: Steam is not set up. Add the following options to /etc/nixos/configuration.nix
and then run `sudo nixos-rebuild switch`:
{ 
  hardware.opengl.driSupport32Bit = true;
  hardware.pulseaudio.support32Bit = true;
}
**

Also, Steam can be installed on other Linux distributions and not just NixOS. It should check if /host/etc/NIXOS file exists.

Copy link
Member

@lukateras lukateras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@wchresta
Copy link
Member Author

@yegortimoshenko checking for /host/etc/NIXOS causes the following assert to fail:

if [ -e /host/etc/NIXOS ]; then
sudo: /nix/store/3xsjm8rfpy0ysfjs1pcybj33fsigszgp-wrapper.c:203: main: Assertion `!(st.st_mode & S_ISUID) || (st.st_uid == geteuid())' failed.

Any pointers?

Also, the HEREDOC leads to ugly indentations; what's your preference here?

@lukateras
Copy link
Member

lukateras commented Dec 30, 2017

I don't understand why it fails: it works in underlying chrootenv and steam-run:

$ ./chrootenv sh -c 'if [ -e /host/etc/NIXOS ]; then echo dakkon; fi'
dakkon
$ steam-run sh -c 'if [ -e /host/etc/NIXOS ]; then echo morte; fi'
morte

Also, the HEREDOC leads to ugly indentations; what's your preference here?

It is just less error-prone: for example, if someone were to add another line to the message, with echo they would have to wrap it in echo "..." > /dev/stderr or something equivalent, while with heredoc they would just add another line. It's ugly syntactically, but semantically it's much prettier than the alternative, because it forms a single multi-line string, while echo presents itself as series of lines that only incidentally form a cohesive message.

@lukateras
Copy link
Member

lukateras commented Dec 30, 2017

Presumably, this is a bug in nixos/modules/security/wrappers/wrapper.c. But I don't understand why Steam has any business with setuid wrapper.

@lukateras
Copy link
Member

/cc @ixmatus

@wchresta
Copy link
Member Author

Maybe my build/test-environment was somehow tainted; I don't understand it either. I will dig into it tomorrow and try to get a proper and clean build.

As for the heredoc:

if [ x ]; then
  if [ y ]; then
    echo <<EOF >&2
This is ugly
And breaks indentation.
EOF
  fi
fi

I'm not reall happy with this.

@lukateras
Copy link
Member

lukateras commented Dec 30, 2017

Compare:

  wrapperScript = ''
    if [ -e /host/etc/NIXOS ]; then
      echo "**" >&2
      echo "WARNING: Steam is not set up. Add the following options to /etc/nixos/configuration.nix" >&2
      echo "and then run `sudo nixos-rebuild switch`:" >&2
      echo "{" >&2
      echo "hardware.opengl.driSupport32Bit = true;" >&2
      echo "hardware.pulseaudio.support32Bit = true;" >&2
      echo "}" >&2
      echo "**" >&2
    fi
  '';

and:

  wrapperScript = ''
    if [ -e /host/etc/NIXOS ]; then
      cat <<EOF >&2
**
WARNING: Steam is not set up. Add the following options to /etc/nixos/configuration.nix
and then run `sudo nixos-rebuild switch`:
{ 
  hardware.opengl.driSupport32Bit = true;
  hardware.pulseaudio.support32Bit = true;
}
**
EOF
    fi
  '';

Breaking indentation is actually a feature: it lets you fit 80 chars in a line no matter how deep your shell script is nested up to that point.

@wchresta
Copy link
Member Author

assert: I'm an idiot and missed escaping the backticks, explaining the assert failure perfectly.
heredoc: agreed and implemented

@wchresta
Copy link
Member Author

wchresta commented Jan 2, 2018

@yegortimoshenko Sorry, I'm not sure if I'm supposed to tag you after I think I did all the changes you wanted.

Edit: I also just now noticed that the current wrapper does not pass-through the arguments. Adding that is probably a good idea, even though the steam binary doesn't seem to take any.

Copy link
Member

@lukateras lukateras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lukateras lukateras merged commit 63c1a54 into NixOS:master Jan 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants