···382382383383</section>
384384385385+<section xml:id="sec-steam">
386386+387387+<title>Steam</title>
388388+389389+<section xml:id="sec-steam-nix">
390390+391391+<title>Steam in Nix</title>
392392+393393+<para>
394394+ Steam is distributed as a <filename>.deb</filename> file, for now only
395395+ as an i686 package (the amd64 package only has documentation).
396396+ When unpacked, it has a script called <filename>steam</filename> that
397397+ in ubuntu (their target distro) would go to <filename>/usr/bin
398398+ </filename>. When run for the first time, this script copies some
399399+ files to the user's home, which include another script that is the
400400+ ultimate responsible for launching the steam binary, which is also
401401+ in $HOME.
402402+</para>
403403+<para>
404404+ Nix problems and constraints:
405405+<itemizedlist>
406406+ <listitem><para>We don't have <filename>/bin/bash</filename> and many
407407+ scripts point there. Similarly for <filename>/usr/bin/python</filename>
408408+ .</para></listitem>
409409+ <listitem><para>We don't have the dynamic loader in <filename>/lib
410410+ </filename>.</para></listitem>
411411+ <listitem><para>The <filename>steam.sh</filename> script in $HOME can
412412+ not be patched, as it is checked and rewritten by steam.</para></listitem>
413413+ <listitem><para>The steam binary cannot be patched, it's also checked.</para></listitem>
414414+</itemizedlist>
415415+</para>
416416+<para>
417417+ The current approach to deploy Steam in NixOS is composing a FHS-compatible
418418+ chroot environment, as documented
419419+ <link xlink:href="http://sandervanderburg.blogspot.nl/2013/09/composing-fhs-compatible-chroot.html">here</link>.
420420+ This allows us to have binaries in the expected paths without disrupting the system,
421421+ and to avoid patching them.
422422+</para>
423423+424424+</section>
425425+426426+<section xml:id="sec-steam-play">
427427+428428+<title>How to play</title>
429429+430430+<para>
431431+ For 64-bit systems it's important to have
432432+ <programlisting>hardware.opengl.driSupport32Bit = true;</programlisting>
433433+ in your <filename>/etc/nixos/configuration.nix</filename>. You'll also need
434434+ <programlisting>hardware.pulseaudio.support32Bit = true;</programlisting>
435435+ if you are using PulseAudio - this will enable 32bit ALSA apps integration.
436436+ To use the Steam controller, you need to add
437437+ <programlisting>services.udev.extraRules = ''
438438+ SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666"
439439+ KERNEL=="uinput", MODE="0660", GROUP="users", OPTIONS+="static_node=uinput"
440440+ '';</programlisting>
441441+ to your configuration.
442442+</para>
443443+444444+</section>
445445+446446+<section xml:id="sec-steam-troub">
447447+448448+<title>Troubleshooting</title>
449449+450450+<para>
451451+<variablelist>
452452+453453+ <varlistentry>
454454+ <term>Steam fails to start. What do I do?</term>
455455+ <listitem><para>Try to run
456456+ <programlisting>strace steam</programlisting>
457457+ to see what is causing steam to fail.</para></listitem>
458458+ </varlistentry>
459459+460460+ <varlistentry>
461461+ <term>Game X fails to start</term>
462462+ <listitem><para>Games may fail to start because they lack
463463+ dependencies (this should be added to the script, for now),
464464+ or because they cannot be patched.The steps to launch a game
465465+ directly are:
466466+ <orderedlist>
467467+ <listitem><para>Patch the script/binary if you can.</para></listitem>
468468+ <listitem><para>Add a file named <filename>steam_appid.txt</filename> in
469469+ the binary folder, with the appid as contents (it can be found in the
470470+ stdout from steam).</para></listitem>
471471+ <listitem><para>Using the LD_LIBRARY_PATH from the nix/store steam script,
472472+ with some additions, launch the game binary:
473473+ <programlisting>LD_LIBRARY_PATH=~/.steam/bin32:$LD_LIBRARY_PATH:/nix/store/pfsa... blabla ...curl-7.29.0/lib:. ./Osmos.bin3
474474+ </programlisting> (if you could not patchelf the game, call ld.so directly
475475+ with the binary as param). With this technique, I can play many games
476476+ directly from steam. Others, like Team Fortress, cannot be patched
477477+ so I only managed to run them from the cmd line.
478478+ </para></listitem>
479479+ </orderedlist>
480480+ </para>
481481+ </listitem>
482482+ </varlistentry>
483483+484484+ <varlistentry>
485485+ <term>Using the FOSS Radeon drivers</term>
486486+ <listitem><itemizedlist><listitem><para>
487487+ The open source radeon drivers need a newer libc++ than is provided
488488+ by the default runtime, which leads to a crash on launch. Use
489489+ <programlisting>environment.systemPackages = [(pkgs.steam.override { newStdcpp = true; })];</programlisting>
490490+ in your config if you get an error like
491491+ <programlisting>
492492+libGL error: unable to load driver: radeonsi_dri.so
493493+libGL error: driver pointer missing
494494+libGL error: failed to load driver: radeonsi
495495+libGL error: unable to load driver: swrast_dri.so
496496+libGL error: failed to load driver: swrast</programlisting></para></listitem>
497497+ <listitem><para>
498498+ Steam ships statically linked with a version of libcrypto that
499499+ conflics with the one dynamically loaded by radeonsi_dri.so.
500500+ If you get the error
501501+ <programlisting>steam.sh: line 713: 7842 Segmentation fault (core dumped)</programlisting>
502502+ have a look at <link xlink:href="https://github.com/NixOS/nixpkgs/pull/20269">this pull request</link>.
503503+ </para></listitem>
504504+ </itemizedlist></listitem></varlistentry>
505505+506506+ <varlistentry>
507507+ <term>Known issues</term>
508508+ <listitem><orderedlist>
509509+ <listitem><para>
510510+ No java in steam chrootenv. Games affected: Towns:
511511+ <programlisting>/home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found</programlisting>
512512+ </para></listitem>
513513+ </orderedlist></listitem></varlistentry>
514514+515515+</variablelist>
516516+</para>
517517+518518+</section>
519519+520520+</section>
521521+385522</chapter>