···382383</section>
384385+<section xml:id="sec-steam">
386+387+<title>Steam</title>
388+389+<section xml:id="sec-steam-nix">
390+391+<title>Steam in Nix</title>
392+393+<para>
394+ Steam is distributed as a <filename>.deb</filename> file, for now only
395+ as an i686 package (the amd64 package only has documentation).
396+ When unpacked, it has a script called <filename>steam</filename> that
397+ in ubuntu (their target distro) would go to <filename>/usr/bin
398+ </filename>. When run for the first time, this script copies some
399+ files to the user's home, which include another script that is the
400+ ultimate responsible for launching the steam binary, which is also
401+ in $HOME.
402+</para>
403+<para>
404+ Nix problems and constraints:
405+<itemizedlist>
406+ <listitem><para>We don't have <filename>/bin/bash</filename> and many
407+ scripts point there. Similarly for <filename>/usr/bin/python</filename>
408+ .</para></listitem>
409+ <listitem><para>We don't have the dynamic loader in <filename>/lib
410+ </filename>.</para></listitem>
411+ <listitem><para>The <filename>steam.sh</filename> script in $HOME can
412+ not be patched, as it is checked and rewritten by steam.</para></listitem>
413+ <listitem><para>The steam binary cannot be patched, it's also checked.</para></listitem>
414+</itemizedlist>
415+</para>
416+<para>
417+ The current approach to deploy Steam in NixOS is composing a FHS-compatible
418+ chroot environment, as documented
419+ <link xlink:href="http://sandervanderburg.blogspot.nl/2013/09/composing-fhs-compatible-chroot.html">here</link>.
420+ This allows us to have binaries in the expected paths without disrupting the system,
421+ and to avoid patching them.
422+</para>
423+424+</section>
425+426+<section xml:id="sec-steam-play">
427+428+<title>How to play</title>
429+430+<para>
431+ For 64-bit systems it's important to have
432+ <programlisting>hardware.opengl.driSupport32Bit = true;</programlisting>
433+ in your <filename>/etc/nixos/configuration.nix</filename>. You'll also need
434+ <programlisting>hardware.pulseaudio.support32Bit = true;</programlisting>
435+ if you are using PulseAudio - this will enable 32bit ALSA apps integration.
436+ To use the Steam controller, you need to add
437+ <programlisting>services.udev.extraRules = ''
438+ SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666"
439+ KERNEL=="uinput", MODE="0660", GROUP="users", OPTIONS+="static_node=uinput"
440+ '';</programlisting>
441+ to your configuration.
442+</para>
443+444+</section>
445+446+<section xml:id="sec-steam-troub">
447+448+<title>Troubleshooting</title>
449+450+<para>
451+<variablelist>
452+453+ <varlistentry>
454+ <term>Steam fails to start. What do I do?</term>
455+ <listitem><para>Try to run
456+ <programlisting>strace steam</programlisting>
457+ to see what is causing steam to fail.</para></listitem>
458+ </varlistentry>
459+460+ <varlistentry>
461+ <term>Game X fails to start</term>
462+ <listitem><para>Games may fail to start because they lack
463+ dependencies (this should be added to the script, for now),
464+ or because they cannot be patched.The steps to launch a game
465+ directly are:
466+ <orderedlist>
467+ <listitem><para>Patch the script/binary if you can.</para></listitem>
468+ <listitem><para>Add a file named <filename>steam_appid.txt</filename> in
469+ the binary folder, with the appid as contents (it can be found in the
470+ stdout from steam).</para></listitem>
471+ <listitem><para>Using the LD_LIBRARY_PATH from the nix/store steam script,
472+ with some additions, launch the game binary:
473+ <programlisting>LD_LIBRARY_PATH=~/.steam/bin32:$LD_LIBRARY_PATH:/nix/store/pfsa... blabla ...curl-7.29.0/lib:. ./Osmos.bin3
474+ </programlisting> (if you could not patchelf the game, call ld.so directly
475+ with the binary as param). With this technique, I can play many games
476+ directly from steam. Others, like Team Fortress, cannot be patched
477+ so I only managed to run them from the cmd line.
478+ </para></listitem>
479+ </orderedlist>
480+ </para>
481+ </listitem>
482+ </varlistentry>
483+484+ <varlistentry>
485+ <term>Using the FOSS Radeon drivers</term>
486+ <listitem><itemizedlist><listitem><para>
487+ The open source radeon drivers need a newer libc++ than is provided
488+ by the default runtime, which leads to a crash on launch. Use
489+ <programlisting>environment.systemPackages = [(pkgs.steam.override { newStdcpp = true; })];</programlisting>
490+ in your config if you get an error like
491+ <programlisting>
492+libGL error: unable to load driver: radeonsi_dri.so
493+libGL error: driver pointer missing
494+libGL error: failed to load driver: radeonsi
495+libGL error: unable to load driver: swrast_dri.so
496+libGL error: failed to load driver: swrast</programlisting></para></listitem>
497+ <listitem><para>
498+ Steam ships statically linked with a version of libcrypto that
499+ conflics with the one dynamically loaded by radeonsi_dri.so.
500+ If you get the error
501+ <programlisting>steam.sh: line 713: 7842 Segmentation fault (core dumped)</programlisting>
502+ have a look at <link xlink:href="https://github.com/NixOS/nixpkgs/pull/20269">this pull request</link>.
503+ </para></listitem>
504+ </itemizedlist></listitem></varlistentry>
505+506+ <varlistentry>
507+ <term>Known issues</term>
508+ <listitem><orderedlist>
509+ <listitem><para>
510+ No java in steam chrootenv. Games affected: Towns:
511+ <programlisting>/home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found</programlisting>
512+ </para></listitem>
513+ </orderedlist></listitem></varlistentry>
514+515+</variablelist>
516+</para>
517+518+</section>
519+520+</section>
521+522</chapter>