about summary refs log tree commit diff
path: root/nixpkgs/doc/functions/fhs-environments.xml
blob: 79682080be314a1d545d3429af06214ee1f5740d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<section xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xml:id="sec-fhs-environments">
 <title>buildFHSUserEnv</title>

 <para>
  <function>buildFHSUserEnv</function> provides a way to build and run
  FHS-compatible lightweight sandboxes. It creates an isolated root with bound
  <filename>/nix/store</filename>, so its footprint in terms of disk space
  needed is quite small. This allows one to run software which is hard or
  unfeasible to patch for NixOS -- 3rd-party source trees with FHS assumptions,
  games distributed as tarballs, software with integrity checking and/or
  external self-updated binaries. It uses Linux namespaces feature to create
  temporary lightweight environments which are destroyed after all child
  processes exit, without root user rights requirement. Accepted arguments are:
 </para>

 <variablelist>
  <varlistentry>
   <term>
    <literal>name</literal>
   </term>
   <listitem>
    <para>
     Environment name.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>targetPkgs</literal>
   </term>
   <listitem>
    <para>
     Packages to be installed for the main host's architecture (i.e. x86_64 on
     x86_64 installations). Along with libraries binaries are also installed.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>multiPkgs</literal>
   </term>
   <listitem>
    <para>
     Packages to be installed for all architectures supported by a host (i.e.
     i686 and x86_64 on x86_64 installations). Only libraries are installed by
     default.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>extraBuildCommands</literal>
   </term>
   <listitem>
    <para>
     Additional commands to be executed for finalizing the directory structure.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>extraBuildCommandsMulti</literal>
   </term>
   <listitem>
    <para>
     Like <literal>extraBuildCommands</literal>, but executed only on multilib
     architectures.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>extraOutputsToInstall</literal>
   </term>
   <listitem>
    <para>
     Additional derivation outputs to be linked for both target and
     multi-architecture packages.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>extraInstallCommands</literal>
   </term>
   <listitem>
    <para>
     Additional commands to be executed for finalizing the derivation with
     runner script.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term>
    <literal>runScript</literal>
   </term>
   <listitem>
    <para>
     A command that would be executed inside the sandbox and passed all the
     command line arguments. It defaults to <literal>bash</literal>.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>

 <para>
  One can create a simple environment using a <literal>shell.nix</literal> like
  that:
 </para>

<programlisting><![CDATA[
{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSUserEnv {
  name = "simple-x11-env";
  targetPkgs = pkgs: (with pkgs;
    [ udev
      alsaLib
    ]) ++ (with pkgs.xorg;
    [ libX11
      libXcursor
      libXrandr
    ]);
  multiPkgs = pkgs: (with pkgs;
    [ udev
      alsaLib
    ]);
  runScript = "bash";
}).env
]]></programlisting>

 <para>
  Running <literal>nix-shell</literal> would then drop you into a shell with
  these libraries and binaries available. You can use this to run closed-source
  applications which expect FHS structure without hassles: simply change
  <literal>runScript</literal> to the application path, e.g.
  <filename>./bin/start.sh</filename> -- relative paths are supported.
 </para>
</section>