summary refs log tree commit diff
path: root/doc/builders
diff options
context:
space:
mode:
authorFrederik Rietdijk <fridh@fridh.nl>2019-10-21 11:39:46 +0200
committerFrederik Rietdijk <fridh@fridh.nl>2019-10-21 11:39:46 +0200
commit2b9713c2815aafaa410acca8600da5dbf7ca6821 (patch)
tree759dd16f4124a48897cf6ddbc4f28712b8312f4d /doc/builders
parent24b1ef51337cc8267955eedda818cfccb222f2ea (diff)
downloadnixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.tar
nixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.tar.gz
nixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.tar.bz2
nixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.tar.lz
nixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.tar.xz
nixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.tar.zst
nixpkgs-2b9713c2815aafaa410acca8600da5dbf7ca6821.zip
doc: move fhs and mkShell under builders/special
In my opinion Functions should only contain pure functions. These are
both meant to provide derivations so I put them under Builders. Don't
know exactly *where* to put them so "special" it is...
Diffstat (limited to 'doc/builders')
-rw-r--r--doc/builders/special.xml12
-rw-r--r--doc/builders/special/fhs-environments.xml122
-rw-r--r--doc/builders/special/mkshell.xml24
3 files changed, 158 insertions, 0 deletions
diff --git a/doc/builders/special.xml b/doc/builders/special.xml
new file mode 100644
index 00000000000..56d98f02527
--- /dev/null
+++ b/doc/builders/special.xml
@@ -0,0 +1,12 @@
+<chapter xmlns="http://docbook.org/ns/docbook"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xml:id="chap-special">
+ <title>Special builders</title>
+ <para>
+  This chapter describes several special builders.
+ </para>
+ <xi:include href="special/fhs-environments.xml" />
+ <xi:include href="special/mkshell.xml" />
+</chapter>
+
+
diff --git a/doc/builders/special/fhs-environments.xml b/doc/builders/special/fhs-environments.xml
new file mode 100644
index 00000000000..e7b81e97a23
--- /dev/null
+++ b/doc/builders/special/fhs-environments.xml
@@ -0,0 +1,122 @@
+<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>
diff --git a/doc/builders/special/mkshell.xml b/doc/builders/special/mkshell.xml
new file mode 100644
index 00000000000..cef65d06b88
--- /dev/null
+++ b/doc/builders/special/mkshell.xml
@@ -0,0 +1,24 @@
+<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-pkgs-mkShell">
+ <title>pkgs.mkShell</title>
+
+ <para>
+  <function>pkgs.mkShell</function> is a special kind of derivation that is only useful when using it combined with <command>nix-shell</command>. It will in fact fail to instantiate when invoked with <command>nix-build</command>.
+ </para>
+
+ <section xml:id="sec-pkgs-mkShell-usage">
+  <title>Usage</title>
+
+<programlisting><![CDATA[
+{ pkgs ? import <nixpkgs> {} }:
+pkgs.mkShell {
+  # this will make all the build inputs from hello and gnutar
+  # available to the shell environment
+  inputsFrom = with pkgs; [ hello gnutar ];
+  buildInputs = [ pkgs.gnumake ];
+}
+]]></programlisting>
+ </section>
+</section>