git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #47688 from grahamc/doc-breakout-functions

nixpkgs docs: breakout functions

commitf2b3bbe44e4f7e220ecb1308d1acdac5e6a0f8ba authorGraham Christensen <graham@grahamc.com> dateWed 3 Oct 2018, 21:52 (8 years ago) parent932833fc07ba7c
11 files changed+1102−1065
doc/Makefile+1−1 doc/cross-compilation.xml+4−3 doc/functions.xml+6−1011 doc/functions/debug.xml+21 doc/functions/dockertools.xml+564 doc/functions/fhs-environments.xml+142 doc/functions/generators.xml+89 doc/functions/overrides.xml+203 doc/functions/shell.xml+26 doc/package-notes.xml+46−28 doc/shell.section.md−22
doc/Makefile+1−1
@@ -69,7 +69,7 @@ highlightjs:
6969 cp -r "$$HIGHLIGHTJS/loader.js" highlightjs/
7070
7171
72−manual-full.xml: ${MD_TARGETS} .version *.xml
72+manual-full.xml: ${MD_TARGETS} .version *.xml **/*.xml
7373 xmllint --nonet --xinclude --noxincludenode manual.xml --output manual-full.xml
7474
7575.version:
doc/cross-compilation.xml+4−3
@@ -47,9 +47,10 @@
4747
4848 <para>
4949 In Nixpkgs, these three platforms are defined as attribute sets under the
50− names <literal>buildPlatform</literal>, <literal>hostPlatform</literal>, and
51− <literal>targetPlatform</literal>. They are always defined as attributes in
52− the standard environment. That means one can access them like:
50+ names <literal>buildPlatform</literal>, <literal>hostPlatform</literal>,
51+ and <literal>targetPlatform</literal>. They are always defined as
52+ attributes in the standard environment. That means one can access them
53+ like:
5354<programlisting>{ stdenv, fooDep, barDep, .. }: ...stdenv.buildPlatform...</programlisting>
5455 .
5556 </para>
doc/functions.xml+6−1011
@@ -7,1016 +7,11 @@
77 The nixpkgs repository has several utility functions to manipulate Nix
88 expressions.
99 </para>
10− <section xml:id="sec-overrides">
11− <title>Overriding</title>
1210
13− <para>
14− Sometimes one wants to override parts of <literal>nixpkgs</literal>, e.g.
15− derivation attributes, the results of derivations or even the whole package
16− set.
17− </para>
18−
19− <section xml:id="sec-pkg-override">
20− <title>&lt;pkg&gt;.override</title>
21−
22− <para>
23− The function <varname>override</varname> is usually available for all the
24− derivations in the nixpkgs expression (<varname>pkgs</varname>).
25− </para>
26−
27− <para>
28− It is used to override the arguments passed to a function.
29− </para>
30−
31− <para>
32− Example usages:
33−<programlisting>pkgs.foo.override { arg1 = val1; arg2 = val2; ... }</programlisting>
34−<programlisting>
35−import pkgs.path { overlays = [ (self: super: {
36− foo = super.foo.override { barSupport = true ; };
37− })]};
38−</programlisting>
39−<programlisting>
40−mypkg = pkgs.callPackage ./mypkg.nix {
41− mydep = pkgs.mydep.override { ... };
42− }
43−</programlisting>
44− </para>
45−
46− <para>
47− In the first example, <varname>pkgs.foo</varname> is the result of a
48− function call with some default arguments, usually a derivation. Using
49− <varname>pkgs.foo.override</varname> will call the same function with the
50− given new arguments.
51− </para>
52− </section>
53−
54− <section xml:id="sec-pkg-overrideAttrs">
55− <title>&lt;pkg&gt;.overrideAttrs</title>
56−
57− <para>
58− The function <varname>overrideAttrs</varname> allows overriding the
59− attribute set passed to a <varname>stdenv.mkDerivation</varname> call,
60− producing a new derivation based on the original one. This function is
61− available on all derivations produced by the
62− <varname>stdenv.mkDerivation</varname> function, which is most packages in
63− the nixpkgs expression <varname>pkgs</varname>.
64− </para>
65−
66− <para>
67− Example usage:
68−<programlisting>
69−helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec {
70− separateDebugInfo = true;
71−});
72−</programlisting>
73− </para>
74−
75− <para>
76− In the above example, the <varname>separateDebugInfo</varname> attribute is
77− overridden to be true, thus building debug info for
78− <varname>helloWithDebug</varname>, while all other attributes will be
79− retained from the original <varname>hello</varname> package.
80− </para>
81−
82− <para>
83− The argument <varname>oldAttrs</varname> is conventionally used to refer to
84− the attr set originally passed to <varname>stdenv.mkDerivation</varname>.
85− </para>
86−
87− <note>
88− <para>
89− Note that <varname>separateDebugInfo</varname> is processed only by the
90− <varname>stdenv.mkDerivation</varname> function, not the generated, raw
91− Nix derivation. Thus, using <varname>overrideDerivation</varname> will not
92− work in this case, as it overrides only the attributes of the final
93− derivation. It is for this reason that <varname>overrideAttrs</varname>
94− should be preferred in (almost) all cases to
95− <varname>overrideDerivation</varname>, i.e. to allow using
96− <varname>sdenv.mkDerivation</varname> to process input arguments, as well
97− as the fact that it is easier to use (you can use the same attribute names
98− you see in your Nix code, instead of the ones generated (e.g.
99− <varname>buildInputs</varname> vs <varname>nativeBuildInputs</varname>,
100− and involves less typing.
101− </para>
102− </note>
103− </section>
104−
105− <section xml:id="sec-pkg-overrideDerivation">
106− <title>&lt;pkg&gt;.overrideDerivation</title>
107−
108− <warning>
109− <para>
110− You should prefer <varname>overrideAttrs</varname> in almost all cases,
111− see its documentation for the reasons why.
112− <varname>overrideDerivation</varname> is not deprecated and will continue
113− to work, but is less nice to use and does not have as many abilities as
114− <varname>overrideAttrs</varname>.
115− </para>
116− </warning>
117−
118− <warning>
119− <para>
120− Do not use this function in Nixpkgs as it evaluates a Derivation before
121− modifying it, which breaks package abstraction and removes error-checking
122− of function arguments. In addition, this evaluation-per-function
123− application incurs a performance penalty, which can become a problem if
124− many overrides are used. It is only intended for ad-hoc customisation,
125− such as in <filename>~/.config/nixpkgs/config.nix</filename>.
126− </para>
127− </warning>
128−
129− <para>
130− The function <varname>overrideDerivation</varname> creates a new derivation
131− based on an existing one by overriding the original's attributes with the
132− attribute set produced by the specified function. This function is
133− available on all derivations defined using the
134− <varname>makeOverridable</varname> function. Most standard
135− derivation-producing functions, such as
136− <varname>stdenv.mkDerivation</varname>, are defined using this function,
137− which means most packages in the nixpkgs expression,
138− <varname>pkgs</varname>, have this function.
139− </para>
140−
141− <para>
142− Example usage:
143−<programlisting>
144−mySed = pkgs.gnused.overrideDerivation (oldAttrs: {
145− name = "sed-4.2.2-pre";
146− src = fetchurl {
147− url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
148− sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k";
149− };
150− patches = [];
151−});
152−</programlisting>
153− </para>
154−
155− <para>
156− In the above example, the <varname>name</varname>, <varname>src</varname>,
157− and <varname>patches</varname> of the derivation will be overridden, while
158− all other attributes will be retained from the original derivation.
159− </para>
160−
161− <para>
162− The argument <varname>oldAttrs</varname> is used to refer to the attribute
163− set of the original derivation.
164− </para>
165−
166− <note>
167− <para>
168− A package's attributes are evaluated *before* being modified by the
169− <varname>overrideDerivation</varname> function. For example, the
170− <varname>name</varname> attribute reference in <varname>url =
171− "mirror://gnu/hello/${name}.tar.gz";</varname> is filled-in *before* the
172− <varname>overrideDerivation</varname> function modifies the attribute set.
173− This means that overriding the <varname>name</varname> attribute, in this
174− example, *will not* change the value of the <varname>url</varname>
175− attribute. Instead, we need to override both the <varname>name</varname>
176− *and* <varname>url</varname> attributes.
177− </para>
178− </note>
179− </section>
180−
181− <section xml:id="sec-lib-makeOverridable">
182− <title>lib.makeOverridable</title>
183−
184− <para>
185− The function <varname>lib.makeOverridable</varname> is used to make the
186− result of a function easily customizable. This utility only makes sense for
187− functions that accept an argument set and return an attribute set.
188− </para>
189−
190− <para>
191− Example usage:
192−<programlisting>
193−f = { a, b }: { result = a+b; };
194−c = lib.makeOverridable f { a = 1; b = 2; };
195−</programlisting>
196− </para>
197−
198− <para>
199− The variable <varname>c</varname> is the value of the <varname>f</varname>
200− function applied with some default arguments. Hence the value of
201− <varname>c.result</varname> is <literal>3</literal>, in this example.
202− </para>
203−
204− <para>
205− The variable <varname>c</varname> however also has some additional
206− functions, like <link linkend="sec-pkg-override">c.override</link> which
207− can be used to override the default arguments. In this example the value of
208− <varname>(c.override { a = 4; }).result</varname> is 6.
209− </para>
210− </section>
211− </section>
212− <section xml:id="sec-generators">
213− <title>Generators</title>
214−
215− <para>
216− Generators are functions that create file formats from nix data structures,
217− e. g. for configuration files. There are generators available for:
218− <literal>INI</literal>, <literal>JSON</literal> and <literal>YAML</literal>
219− </para>
220−
221− <para>
222− All generators follow a similar call interface: <code>generatorName
223− configFunctions data</code>, where <literal>configFunctions</literal> is an
224− attrset of user-defined functions that format nested parts of the content.
225− They each have common defaults, so often they do not need to be set
226− manually. An example is <code>mkSectionName ? (name: libStr.escape [ "[" "]"
227− ] name)</code> from the <literal>INI</literal> generator. It receives the
228− name of a section and sanitizes it. The default
229− <literal>mkSectionName</literal> escapes <literal>[</literal> and
230− <literal>]</literal> with a backslash.
231− </para>
232−
233− <para>
234− Generators can be fine-tuned to produce exactly the file format required by
235− your application/service. One example is an INI-file format which uses
236− <literal>: </literal> as separator, the strings
237− <literal>"yes"</literal>/<literal>"no"</literal> as boolean values and
238− requires all string values to be quoted:
239− </para>
240−
241−<programlisting>
242−with lib;
243−let
244− customToINI = generators.toINI {
245− # specifies how to format a key/value pair
246− mkKeyValue = generators.mkKeyValueDefault {
247− # specifies the generated string for a subset of nix values
248− mkValueString = v:
249− if v == true then ''"yes"''
250− else if v == false then ''"no"''
251− else if isString v then ''"${v}"''
252− # and delegats all other values to the default generator
253− else generators.mkValueStringDefault {} v;
254− } ":";
255− };
256−
257−# the INI file can now be given as plain old nix values
258−in customToINI {
259− main = {
260− pushinfo = true;
261− autopush = false;
262− host = "localhost";
263− port = 42;
264− };
265− mergetool = {
266− merge = "diff3";
267− };
268−}
269−</programlisting>
270−
271− <para>
272− This will produce the following INI file as nix string:
273− </para>
274−
275−<programlisting>
276−[main]
277−autopush:"no"
278−host:"localhost"
279−port:42
280−pushinfo:"yes"
281−str\:ange:"very::strange"
282−
283−[mergetool]
284−merge:"diff3"
285−</programlisting>
286−
287− <note>
288− <para>
289− Nix store paths can be converted to strings by enclosing a derivation
290− attribute like so: <code>"${drv}"</code>.
291− </para>
292− </note>
293−
294− <para>
295− Detailed documentation for each generator can be found in
296− <literal>lib/generators.nix</literal>.
297− </para>
298− </section>
299− <section xml:id="sec-debug">
300− <title>Debugging Nix Expressions</title>
301−
302− <para>
303− Nix is a unityped, dynamic language, this means every value can potentially
304− appear anywhere. Since it is also non-strict, evaluation order and what
305− ultimately is evaluated might surprise you. Therefore it is important to be
306− able to debug nix expressions.
307− </para>
308−
309− <para>
310− In the <literal>lib/debug.nix</literal> file you will find a number of
311− functions that help (pretty-)printing values while evaluation is runnnig.
312− You can even specify how deep these values should be printed recursively,
313− and transform them on the fly. Please consult the docstrings in
314− <literal>lib/debug.nix</literal> for usage information.
315− </para>
316− </section>
317− <section xml:id="sec-fhs-environments">
318− <title>buildFHSUserEnv</title>
319−
320− <para>
321− <function>buildFHSUserEnv</function> provides a way to build and run
322− FHS-compatible lightweight sandboxes. It creates an isolated root with bound
323− <filename>/nix/store</filename>, so its footprint in terms of disk space
324− needed is quite small. This allows one to run software which is hard or
325− unfeasible to patch for NixOS -- 3rd-party source trees with FHS
326− assumptions, games distributed as tarballs, software with integrity checking
327− and/or external self-updated binaries. It uses Linux namespaces feature to
328− create temporary lightweight environments which are destroyed after all
329− child processes exit, without root user rights requirement. Accepted
330− arguments are:
331− </para>
332−
333− <variablelist>
334− <varlistentry>
335− <term>
336− <literal>name</literal>
337− </term>
338− <listitem>
339− <para>
340− Environment name.
341− </para>
342− </listitem>
343− </varlistentry>
344− <varlistentry>
345− <term>
346− <literal>targetPkgs</literal>
347− </term>
348− <listitem>
349− <para>
350− Packages to be installed for the main host's architecture (i.e. x86_64 on
351− x86_64 installations). Along with libraries binaries are also installed.
352− </para>
353− </listitem>
354− </varlistentry>
355− <varlistentry>
356− <term>
357− <literal>multiPkgs</literal>
358− </term>
359− <listitem>
360− <para>
361− Packages to be installed for all architectures supported by a host (i.e.
362− i686 and x86_64 on x86_64 installations). Only libraries are installed by
363− default.
364− </para>
365− </listitem>
366− </varlistentry>
367− <varlistentry>
368− <term>
369− <literal>extraBuildCommands</literal>
370− </term>
371− <listitem>
372− <para>
373− Additional commands to be executed for finalizing the directory
374− structure.
375− </para>
376− </listitem>
377− </varlistentry>
378− <varlistentry>
379− <term>
380− <literal>extraBuildCommandsMulti</literal>
381− </term>
382− <listitem>
383− <para>
384− Like <literal>extraBuildCommands</literal>, but executed only on multilib
385− architectures.
386− </para>
387− </listitem>
388− </varlistentry>
389− <varlistentry>
390− <term>
391− <literal>extraOutputsToInstall</literal>
392− </term>
393− <listitem>
394− <para>
395− Additional derivation outputs to be linked for both target and
396− multi-architecture packages.
397− </para>
398− </listitem>
399− </varlistentry>
400− <varlistentry>
401− <term>
402− <literal>extraInstallCommands</literal>
403− </term>
404− <listitem>
405− <para>
406− Additional commands to be executed for finalizing the derivation with
407− runner script.
408− </para>
409− </listitem>
410− </varlistentry>
411− <varlistentry>
412− <term>
413− <literal>runScript</literal>
414− </term>
415− <listitem>
416− <para>
417− A command that would be executed inside the sandbox and passed all the
418− command line arguments. It defaults to <literal>bash</literal>.
419− </para>
420− </listitem>
421− </varlistentry>
422− </variablelist>
423−
424− <para>
425− One can create a simple environment using a <literal>shell.nix</literal>
426− like that:
427− </para>
428−
429−<programlisting><![CDATA[
430−{ pkgs ? import <nixpkgs> {} }:
431−
432−(pkgs.buildFHSUserEnv {
433− name = "simple-x11-env";
434− targetPkgs = pkgs: (with pkgs;
435− [ udev
436− alsaLib
437− ]) ++ (with pkgs.xorg;
438− [ libX11
439− libXcursor
440− libXrandr
441− ]);
442− multiPkgs = pkgs: (with pkgs;
443− [ udev
444− alsaLib
445− ]);
446− runScript = "bash";
447−}).env
448−]]></programlisting>
449−
450− <para>
451− Running <literal>nix-shell</literal> would then drop you into a shell with
452− these libraries and binaries available. You can use this to run
453− closed-source applications which expect FHS structure without hassles:
454− simply change <literal>runScript</literal> to the application path, e.g.
455− <filename>./bin/start.sh</filename> -- relative paths are supported.
456− </para>
457− </section>
458− <xi:include href="shell.section.xml" />
459− <section xml:id="sec-pkgs-dockerTools">
460− <title>pkgs.dockerTools</title>
461−
462− <para>
463− <varname>pkgs.dockerTools</varname> is a set of functions for creating and
464− manipulating Docker images according to the
465− <link xlink:href="https://github.com/moby/moby/blob/master/image/spec/v1.2.md#docker-image-specification-v120">
466− Docker Image Specification v1.2.0 </link>. Docker itself is not used to
467− perform any of the operations done by these functions.
468− </para>
469−
470− <warning>
471− <para>
472− The <varname>dockerTools</varname> API is unstable and may be subject to
473− backwards-incompatible changes in the future.
474− </para>
475− </warning>
476−
477− <section xml:id="ssec-pkgs-dockerTools-buildImage">
478− <title>buildImage</title>
479−
480− <para>
481− This function is analogous to the <command>docker build</command> command,
482− in that can used to build a Docker-compatible repository tarball containing
483− a single image with one or multiple layers. As such, the result is suitable
484− for being loaded in Docker with <command>docker load</command>.
485− </para>
486−
487− <para>
488− The parameters of <varname>buildImage</varname> with relative example
489− values are described below:
490− </para>
491−
492− <example xml:id='ex-dockerTools-buildImage'>
493− <title>Docker build</title>
494−<programlisting>
495−buildImage {
496− name = "redis"; <co xml:id='ex-dockerTools-buildImage-1' />
497− tag = "latest"; <co xml:id='ex-dockerTools-buildImage-2' />
498−
499− fromImage = someBaseImage; <co xml:id='ex-dockerTools-buildImage-3' />
500− fromImageName = null; <co xml:id='ex-dockerTools-buildImage-4' />
501− fromImageTag = "latest"; <co xml:id='ex-dockerTools-buildImage-5' />
502−
503− contents = pkgs.redis; <co xml:id='ex-dockerTools-buildImage-6' />
504− runAsRoot = '' <co xml:id='ex-dockerTools-buildImage-runAsRoot' />
505− #!${stdenv.shell}
506− mkdir -p /data
507− '';
508−
509− config = { <co xml:id='ex-dockerTools-buildImage-8' />
510− Cmd = [ "/bin/redis-server" ];
511− WorkingDir = "/data";
512− Volumes = {
513− "/data" = {};
514− };
515− };
516−}
517−</programlisting>
518− </example>
519−
520− <para>
521− The above example will build a Docker image <literal>redis/latest</literal>
522− from the given base image. Loading and running this image in Docker results
523− in <literal>redis-server</literal> being started automatically.
524− </para>
525−
526− <calloutlist>
527− <callout arearefs='ex-dockerTools-buildImage-1'>
528− <para>
529− <varname>name</varname> specifies the name of the resulting image. This
530− is the only required argument for <varname>buildImage</varname>.
531− </para>
532− </callout>
533− <callout arearefs='ex-dockerTools-buildImage-2'>
534− <para>
535− <varname>tag</varname> specifies the tag of the resulting image. By
536− default it's <literal>null</literal>, which indicates that the nix output
537− hash will be used as tag.
538− </para>
539− </callout>
540− <callout arearefs='ex-dockerTools-buildImage-3'>
541− <para>
542− <varname>fromImage</varname> is the repository tarball containing the
543− base image. It must be a valid Docker image, such as exported by
544− <command>docker save</command>. By default it's <literal>null</literal>,
545− which can be seen as equivalent to <literal>FROM scratch</literal> of a
546− <filename>Dockerfile</filename>.
547− </para>
548− </callout>
549− <callout arearefs='ex-dockerTools-buildImage-4'>
550− <para>
551− <varname>fromImageName</varname> can be used to further specify the base
552− image within the repository, in case it contains multiple images. By
553− default it's <literal>null</literal>, in which case
554− <varname>buildImage</varname> will peek the first image available in the
555− repository.
556− </para>
557− </callout>
558− <callout arearefs='ex-dockerTools-buildImage-5'>
559− <para>
560− <varname>fromImageTag</varname> can be used to further specify the tag of
561− the base image within the repository, in case an image contains multiple
562− tags. By default it's <literal>null</literal>, in which case
563− <varname>buildImage</varname> will peek the first tag available for the
564− base image.
565− </para>
566− </callout>
567− <callout arearefs='ex-dockerTools-buildImage-6'>
568− <para>
569− <varname>contents</varname> is a derivation that will be copied in the
570− new layer of the resulting image. This can be similarly seen as
571− <command>ADD contents/ /</command> in a <filename>Dockerfile</filename>.
572− By default it's <literal>null</literal>.
573− </para>
574− </callout>
575− <callout arearefs='ex-dockerTools-buildImage-runAsRoot'>
576− <para>
577− <varname>runAsRoot</varname> is a bash script that will run as root in an
578− environment that overlays the existing layers of the base image with the
579− new resulting layer, including the previously copied
580− <varname>contents</varname> derivation. This can be similarly seen as
581− <command>RUN ...</command> in a <filename>Dockerfile</filename>.
582− <note>
583− <para>
584− Using this parameter requires the <literal>kvm</literal> device to be
585− available.
586− </para>
587− </note>
588− </para>
589− </callout>
590− <callout arearefs='ex-dockerTools-buildImage-8'>
591− <para>
592− <varname>config</varname> is used to specify the configuration of the
593− containers that will be started off the built image in Docker. The
594− available options are listed in the
595− <link xlink:href="https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions">
596− Docker Image Specification v1.2.0 </link>.
597− </para>
598− </callout>
599− </calloutlist>
600−
601− <para>
602− After the new layer has been created, its closure (to which
603− <varname>contents</varname>, <varname>config</varname> and
604− <varname>runAsRoot</varname> contribute) will be copied in the layer
605− itself. Only new dependencies that are not already in the existing layers
606− will be copied.
607− </para>
608−
609− <para>
610− At the end of the process, only one new single layer will be produced and
611− added to the resulting image.
612− </para>
613−
614− <para>
615− The resulting repository will only list the single image
616− <varname>image/tag</varname>. In the case of
617− <xref linkend='ex-dockerTools-buildImage'/> it would be
618− <varname>redis/latest</varname>.
619− </para>
620−
621− <para>
622− It is possible to inspect the arguments with which an image was built using
623− its <varname>buildArgs</varname> attribute.
624− </para>
625−
626− <note>
627− <para>
628− If you see errors similar to <literal>getProtocolByName: does not exist
629− (no such protocol name: tcp)</literal> you may need to add
630− <literal>pkgs.iana-etc</literal> to <varname>contents</varname>.
631− </para>
632− </note>
633−
634− <note>
635− <para>
636− If you see errors similar to <literal>Error_Protocol ("certificate has
637− unknown CA",True,UnknownCa)</literal> you may need to add
638− <literal>pkgs.cacert</literal> to <varname>contents</varname>.
639− </para>
640− </note>
641−
642− <example xml:id="example-pkgs-dockerTools-buildImage-creation-date">
643− <title>Impurely Defining a Docker Layer's Creation Date</title>
644− <para>
645− By default <function>buildImage</function> will use a static
646− date of one second past the UNIX Epoch. This allows
647− <function>buildImage</function> to produce binary reproducible
648− images. When listing images with <command>docker list
649− images</command>, the newly created images will be listed like
650− this:
651− </para>
652− <screen><![CDATA[
653−$ docker image list
654−REPOSITORY TAG IMAGE ID CREATED SIZE
655−hello latest 08c791c7846e 48 years ago 25.2MB
656−]]></screen>
657− <para>
658− You can break binary reproducibility but have a sorted,
659− meaningful <literal>CREATED</literal> column by setting
660− <literal>created</literal> to <literal>now</literal>.
661− </para>
662− <programlisting><![CDATA[
663−pkgs.dockerTools.buildImage {
664− name = "hello";
665− tag = "latest";
666− created = "now";
667− contents = pkgs.hello;
668−
669− config.Cmd = [ "/bin/hello" ];
670−}
671−]]></programlisting>
672− <para>
673− and now the Docker CLI will display a reasonable date and
674− sort the images as expected:
675− <screen><![CDATA[
676−$ docker image list
677−REPOSITORY TAG IMAGE ID CREATED SIZE
678−hello latest de2bf4786de6 About a minute ago 25.2MB
679−]]></screen>
680− however, the produced images will not be binary reproducible.
681− </para>
682− </example>
683− </section>
684−
685− <section xml:id="ssec-pkgs-dockerTools-buildLayeredImage">
686− <title>buildLayeredImage</title>
687−
688− <para>
689− Create a Docker image with many of the store paths being on their own layer
690− to improve sharing between images.
691− </para>
692−
693− <variablelist>
694− <varlistentry>
695− <term>
696− <varname>name</varname>
697− </term>
698− <listitem>
699− <para>
700− The name of the resulting image.
701− </para>
702− </listitem>
703− </varlistentry>
704− <varlistentry>
705− <term>
706− <varname>tag</varname> <emphasis>optional</emphasis>
707− </term>
708− <listitem>
709− <para>
710− Tag of the generated image.
711− </para>
712− <para>
713− <emphasis>Default:</emphasis> the output path's hash
714− </para>
715− </listitem>
716− </varlistentry>
717− <varlistentry>
718− <term>
719− <varname>contents</varname> <emphasis>optional</emphasis>
720− </term>
721− <listitem>
722− <para>
723− Top level paths in the container. Either a single derivation, or a list
724− of derivations.
725− </para>
726− <para>
727− <emphasis>Default:</emphasis> <literal>[]</literal>
728− </para>
729− </listitem>
730− </varlistentry>
731− <varlistentry>
732− <term>
733− <varname>config</varname> <emphasis>optional</emphasis>
734− </term>
735− <listitem>
736− <para>
737− Run-time configuration of the container. A full list of the options are
738− available at in the
739− <link xlink:href="https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions">
740− Docker Image Specification v1.2.0 </link>.
741− </para>
742− <para>
743− <emphasis>Default:</emphasis> <literal>{}</literal>
744− </para>
745− </listitem>
746− </varlistentry>
747− <varlistentry>
748− <term>
749− <varname>created</varname> <emphasis>optional</emphasis>
750− </term>
751− <listitem>
752− <para>
753− Date and time the layers were created. Follows the same
754− <literal>now</literal> exception supported by
755− <literal>buildImage</literal>.
756− </para>
757− <para>
758− <emphasis>Default:</emphasis> <literal>1970-01-01T00:00:01Z</literal>
759− </para>
760− </listitem>
761− </varlistentry>
762− <varlistentry>
763− <term>
764− <varname>maxLayers</varname> <emphasis>optional</emphasis>
765− </term>
766− <listitem>
767− <para>
768− Maximum number of layers to create.
769− </para>
770− <para>
771− <emphasis>Default:</emphasis> <literal>24</literal>
772− </para>
773− </listitem>
774− </varlistentry>
775− </variablelist>
776−
777− <section xml:id="dockerTools-buildLayeredImage-arg-contents">
778− <title>Behavior of <varname>contents</varname> in the final image</title>
779−
780− <para>
781− Each path directly listed in <varname>contents</varname> will have a
782− symlink in the root of the image.
783− </para>
784−
785− <para>
786− For example:
787−<programlisting><![CDATA[
788−pkgs.dockerTools.buildLayeredImage {
789− name = "hello";
790− contents = [ pkgs.hello ];
791−}
792−]]></programlisting>
793− will create symlinks for all the paths in the <literal>hello</literal>
794− package:
795−<screen><![CDATA[
796−/bin/hello -> /nix/store/h1zb1padqbbb7jicsvkmrym3r6snphxg-hello-2.10/bin/hello
797−/share/info/hello.info -> /nix/store/h1zb1padqbbb7jicsvkmrym3r6snphxg-hello-2.10/share/info/hello.info
798−/share/locale/bg/LC_MESSAGES/hello.mo -> /nix/store/h1zb1padqbbb7jicsvkmrym3r6snphxg-hello-2.10/share/locale/bg/LC_MESSAGES/hello.mo
799−]]></screen>
800− </para>
801− </section>
802−
803− <section xml:id="dockerTools-buildLayeredImage-arg-config">
804− <title>Automatic inclusion of <varname>config</varname> references</title>
805−
806− <para>
807− The closure of <varname>config</varname> is automatically included in the
808− closure of the final image.
809− </para>
810−
811− <para>
812− This allows you to make very simple Docker images with very little code.
813− This container will start up and run <command>hello</command>:
814−<programlisting><![CDATA[
815−pkgs.dockerTools.buildLayeredImage {
816− name = "hello";
817− config.Cmd = [ "${pkgs.hello}/bin/hello" ];
818−}
819−]]></programlisting>
820− </para>
821− </section>
822−
823− <section xml:id="dockerTools-buildLayeredImage-arg-maxLayers">
824− <title>Adjusting <varname>maxLayers</varname></title>
825−
826− <para>
827− Increasing the <varname>maxLayers</varname> increases the number of layers
828− which have a chance to be shared between different images.
829− </para>
830−
831− <para>
832− Modern Docker installations support up to 128 layers, however older
833− versions support as few as 42.
834− </para>
835−
836− <para>
837− If the produced image will not be extended by other Docker builds, it is
838− safe to set <varname>maxLayers</varname> to <literal>128</literal>.
839− However it will be impossible to extend the image further.
840− </para>
841−
842− <para>
843− The first (<literal>maxLayers-2</literal>) most "popular" paths will have
844− their own individual layers, then layer #<literal>maxLayers-1</literal>
845− will contain all the remaining "unpopular" paths, and finally layer
846− #<literal>maxLayers</literal> will contain the Image configuration.
847− </para>
848−
849− <para>
850− Docker's Layers are not inherently ordered, they are content-addressable
851− and are not explicitly layered until they are composed in to an Image.
852− </para>
853− </section>
854− </section>
855−
856− <section xml:id="ssec-pkgs-dockerTools-fetchFromRegistry">
857− <title>pullImage</title>
858−
859− <para>
860− This function is analogous to the <command>docker pull</command> command,
861− in that can be used to pull a Docker image from a Docker registry. By
862− default <link xlink:href="https://hub.docker.com/">Docker Hub</link> is
863− used to pull images.
864− </para>
865−
866− <para>
867− Its parameters are described in the example below:
868− </para>
869−
870− <example xml:id='ex-dockerTools-pullImage'>
871− <title>Docker pull</title>
872−<programlisting>
873−pullImage {
874− imageName = "nixos/nix"; <co xml:id='ex-dockerTools-pullImage-1' />
875− imageDigest = "sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b"; <co xml:id='ex-dockerTools-pullImage-2' />
876− finalImageTag = "1.11"; <co xml:id='ex-dockerTools-pullImage-3' />
877− sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8"; <co xml:id='ex-dockerTools-pullImage-4' />
878− os = "linux"; <co xml:id='ex-dockerTools-pullImage-5' />
879− arch = "x86_64"; <co xml:id='ex-dockerTools-pullImage-6' />
880−}
881−</programlisting>
882− </example>
883−
884− <calloutlist>
885− <callout arearefs='ex-dockerTools-pullImage-1'>
886− <para>
887− <varname>imageName</varname> specifies the name of the image to be
888− downloaded, which can also include the registry namespace (e.g.
889− <literal>nixos</literal>). This argument is required.
890− </para>
891− </callout>
892− <callout arearefs='ex-dockerTools-pullImage-2'>
893− <para>
894− <varname>imageDigest</varname> specifies the digest of the image to be
895− downloaded. Skopeo can be used to get the digest of an image, with its
896− <varname>inspect</varname> subcommand. Since a given
897− <varname>imageName</varname> may transparently refer to a manifest list
898− of images which support multiple architectures and/or operating systems,
899− supply the `--override-os` and `--override-arch` arguments to specify
900− exactly which image you want. By default it will match the OS and
901− architecture of the host the command is run on.
902−<programlisting>
903−$ nix-shell --packages skopeo jq --command "skopeo --override-os linux --override-arch x86_64 inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest'"
904−sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b
905−</programlisting>
906− This argument is required.
907− </para>
908− </callout>
909− <callout arearefs='ex-dockerTools-pullImage-3'>
910− <para>
911− <varname>finalImageTag</varname>, if specified, this is the tag of the
912− image to be created. Note it is never used to fetch the image since we
913− prefer to rely on the immutable digest ID. By default it's
914− <literal>latest</literal>.
915− </para>
916− </callout>
917− <callout arearefs='ex-dockerTools-pullImage-4'>
918− <para>
919− <varname>sha256</varname> is the checksum of the whole fetched image.
920− This argument is required.
921− </para>
922− </callout>
923− <callout arearefs='ex-dockerTools-pullImage-5'>
924− <para>
925− <varname>os</varname>, if specified, is the operating system of the
926− fetched image. By default it's <literal>linux</literal>.
927− </para>
928− </callout>
929− <callout arearefs='ex-dockerTools-pullImage-6'>
930− <para>
931− <varname>arch</varname>, if specified, is the cpu architecture of the
932− fetched image. By default it's <literal>x86_64</literal>.
933− </para>
934− </callout>
935− </calloutlist>
936− </section>
937−
938− <section xml:id="ssec-pkgs-dockerTools-exportImage">
939− <title>exportImage</title>
940−
941− <para>
942− This function is analogous to the <command>docker export</command> command,
943− in that can used to flatten a Docker image that contains multiple layers.
944− It is in fact the result of the merge of all the layers of the image. As
945− such, the result is suitable for being imported in Docker with
946− <command>docker import</command>.
947− </para>
948−
949− <note>
950− <para>
951− Using this function requires the <literal>kvm</literal> device to be
952− available.
953− </para>
954− </note>
955−
956− <para>
957− The parameters of <varname>exportImage</varname> are the following:
958− </para>
959−
960− <example xml:id='ex-dockerTools-exportImage'>
961− <title>Docker export</title>
962−<programlisting>
963−exportImage {
964− fromImage = someLayeredImage;
965− fromImageName = null;
966− fromImageTag = null;
967−
968− name = someLayeredImage.name;
969−}
970− </programlisting>
971− </example>
972−
973− <para>
974− The parameters relative to the base image have the same synopsis as
975− described in <xref linkend='ssec-pkgs-dockerTools-buildImage'/>, except
976− that <varname>fromImage</varname> is the only required argument in this
977− case.
978− </para>
979−
980− <para>
981− The <varname>name</varname> argument is the name of the derivation output,
982− which defaults to <varname>fromImage.name</varname>.
983− </para>
984− </section>
985−
986− <section xml:id="ssec-pkgs-dockerTools-shadowSetup">
987− <title>shadowSetup</title>
988−
989− <para>
990− This constant string is a helper for setting up the base files for managing
991− users and groups, only if such files don't exist already. It is suitable
992− for being used in a <varname>runAsRoot</varname>
993− <xref linkend='ex-dockerTools-buildImage-runAsRoot'/> script for cases like
994− in the example below:
995− </para>
996−
997− <example xml:id='ex-dockerTools-shadowSetup'>
998− <title>Shadow base files</title>
999−<programlisting>
1000−buildImage {
1001− name = "shadow-basic";
1002−
1003− runAsRoot = ''
1004− #!${stdenv.shell}
1005− ${shadowSetup}
1006− groupadd -r redis
1007− useradd -r -g redis redis
1008− mkdir /data
1009− chown redis:redis /data
1010− '';
1011−}
1012−</programlisting>
1013− </example>
1014−
1015− <para>
1016− Creating base files like <literal>/etc/passwd</literal> or
1017− <literal>/etc/login.defs</literal> are necessary for shadow-utils to
1018− manipulate users and groups.
1019− </para>
1020− </section>
1021− </section>
11+ <xi:include href="functions/overrides.xml" />
12+ <xi:include href="functions/generators.xml" />
13+ <xi:include href="functions/debug.xml" />
14+ <xi:include href="functions/fhs-environments.xml" />
15+ <xi:include href="functions/shell.xml" />
16+ <xi:include href="functions/dockertools.xml" />
102217</chapter>
doc/functions/debug.xmlnew file+21
@@ -0,0 +1,21 @@
1+<section xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xmlns:xi="http://www.w3.org/2001/XInclude"
4+ xml:id="sec-debug">
5+ <title>Debugging Nix Expressions</title>
6+
7+ <para>
8+ Nix is a unityped, dynamic language, this means every value can potentially
9+ appear anywhere. Since it is also non-strict, evaluation order and what
10+ ultimately is evaluated might surprise you. Therefore it is important to be
11+ able to debug nix expressions.
12+ </para>
13+
14+ <para>
15+ In the <literal>lib/debug.nix</literal> file you will find a number of
16+ functions that help (pretty-)printing values while evaluation is runnnig. You
17+ can even specify how deep these values should be printed recursively, and
18+ transform them on the fly. Please consult the docstrings in
19+ <literal>lib/debug.nix</literal> for usage information.
20+ </para>
21+</section>
doc/functions/dockertools.xmlnew file+564
@@ -0,0 +1,564 @@
1+<section xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xmlns:xi="http://www.w3.org/2001/XInclude"
4+ xml:id="sec-pkgs-dockerTools">
5+ <title>pkgs.dockerTools</title>
6+
7+ <para>
8+ <varname>pkgs.dockerTools</varname> is a set of functions for creating and
9+ manipulating Docker images according to the
10+ <link xlink:href="https://github.com/moby/moby/blob/master/image/spec/v1.2.md#docker-image-specification-v120">
11+ Docker Image Specification v1.2.0 </link>. Docker itself is not used to
12+ perform any of the operations done by these functions.
13+ </para>
14+
15+ <warning>
16+ <para>
17+ The <varname>dockerTools</varname> API is unstable and may be subject to
18+ backwards-incompatible changes in the future.
19+ </para>
20+ </warning>
21+
22+ <section xml:id="ssec-pkgs-dockerTools-buildImage">
23+ <title>buildImage</title>
24+
25+ <para>
26+ This function is analogous to the <command>docker build</command> command,
27+ in that can used to build a Docker-compatible repository tarball containing
28+ a single image with one or multiple layers. As such, the result is suitable
29+ for being loaded in Docker with <command>docker load</command>.
30+ </para>
31+
32+ <para>
33+ The parameters of <varname>buildImage</varname> with relative example values
34+ are described below:
35+ </para>
36+
37+ <example xml:id='ex-dockerTools-buildImage'>
38+ <title>Docker build</title>
39+<programlisting>
40+buildImage {
41+ name = "redis"; <co xml:id='ex-dockerTools-buildImage-1' />
42+ tag = "latest"; <co xml:id='ex-dockerTools-buildImage-2' />
43+
44+ fromImage = someBaseImage; <co xml:id='ex-dockerTools-buildImage-3' />
45+ fromImageName = null; <co xml:id='ex-dockerTools-buildImage-4' />
46+ fromImageTag = "latest"; <co xml:id='ex-dockerTools-buildImage-5' />
47+
48+ contents = pkgs.redis; <co xml:id='ex-dockerTools-buildImage-6' />
49+ runAsRoot = '' <co xml:id='ex-dockerTools-buildImage-runAsRoot' />
50+ #!${stdenv.shell}
51+ mkdir -p /data
52+ '';
53+
54+ config = { <co xml:id='ex-dockerTools-buildImage-8' />
55+ Cmd = [ "/bin/redis-server" ];
56+ WorkingDir = "/data";
57+ Volumes = {
58+ "/data" = {};
59+ };
60+ };
61+}
62+</programlisting>
63+ </example>
64+
65+ <para>
66+ The above example will build a Docker image <literal>redis/latest</literal>
67+ from the given base image. Loading and running this image in Docker results
68+ in <literal>redis-server</literal> being started automatically.
69+ </para>
70+
71+ <calloutlist>
72+ <callout arearefs='ex-dockerTools-buildImage-1'>
73+ <para>
74+ <varname>name</varname> specifies the name of the resulting image. This is
75+ the only required argument for <varname>buildImage</varname>.
76+ </para>
77+ </callout>
78+ <callout arearefs='ex-dockerTools-buildImage-2'>
79+ <para>
80+ <varname>tag</varname> specifies the tag of the resulting image. By
81+ default it's <literal>null</literal>, which indicates that the nix output
82+ hash will be used as tag.
83+ </para>
84+ </callout>
85+ <callout arearefs='ex-dockerTools-buildImage-3'>
86+ <para>
87+ <varname>fromImage</varname> is the repository tarball containing the base
88+ image. It must be a valid Docker image, such as exported by
89+ <command>docker save</command>. By default it's <literal>null</literal>,
90+ which can be seen as equivalent to <literal>FROM scratch</literal> of a
91+ <filename>Dockerfile</filename>.
92+ </para>
93+ </callout>
94+ <callout arearefs='ex-dockerTools-buildImage-4'>
95+ <para>
96+ <varname>fromImageName</varname> can be used to further specify the base
97+ image within the repository, in case it contains multiple images. By
98+ default it's <literal>null</literal>, in which case
99+ <varname>buildImage</varname> will peek the first image available in the
100+ repository.
101+ </para>
102+ </callout>
103+ <callout arearefs='ex-dockerTools-buildImage-5'>
104+ <para>
105+ <varname>fromImageTag</varname> can be used to further specify the tag of
106+ the base image within the repository, in case an image contains multiple
107+ tags. By default it's <literal>null</literal>, in which case
108+ <varname>buildImage</varname> will peek the first tag available for the
109+ base image.
110+ </para>
111+ </callout>
112+ <callout arearefs='ex-dockerTools-buildImage-6'>
113+ <para>
114+ <varname>contents</varname> is a derivation that will be copied in the new
115+ layer of the resulting image. This can be similarly seen as <command>ADD
116+ contents/ /</command> in a <filename>Dockerfile</filename>. By default
117+ it's <literal>null</literal>.
118+ </para>
119+ </callout>
120+ <callout arearefs='ex-dockerTools-buildImage-runAsRoot'>
121+ <para>
122+ <varname>runAsRoot</varname> is a bash script that will run as root in an
123+ environment that overlays the existing layers of the base image with the
124+ new resulting layer, including the previously copied
125+ <varname>contents</varname> derivation. This can be similarly seen as
126+ <command>RUN ...</command> in a <filename>Dockerfile</filename>.
127+ <note>
128+ <para>
129+ Using this parameter requires the <literal>kvm</literal> device to be
130+ available.
131+ </para>
132+ </note>
133+ </para>
134+ </callout>
135+ <callout arearefs='ex-dockerTools-buildImage-8'>
136+ <para>
137+ <varname>config</varname> is used to specify the configuration of the
138+ containers that will be started off the built image in Docker. The
139+ available options are listed in the
140+ <link xlink:href="https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions">
141+ Docker Image Specification v1.2.0 </link>.
142+ </para>
143+ </callout>
144+ </calloutlist>
145+
146+ <para>
147+ After the new layer has been created, its closure (to which
148+ <varname>contents</varname>, <varname>config</varname> and
149+ <varname>runAsRoot</varname> contribute) will be copied in the layer itself.
150+ Only new dependencies that are not already in the existing layers will be
151+ copied.
152+ </para>
153+
154+ <para>
155+ At the end of the process, only one new single layer will be produced and
156+ added to the resulting image.
157+ </para>
158+
159+ <para>
160+ The resulting repository will only list the single image
161+ <varname>image/tag</varname>. In the case of
162+ <xref linkend='ex-dockerTools-buildImage'/> it would be
163+ <varname>redis/latest</varname>.
164+ </para>
165+
166+ <para>
167+ It is possible to inspect the arguments with which an image was built using
168+ its <varname>buildArgs</varname> attribute.
169+ </para>
170+
171+ <note>
172+ <para>
173+ If you see errors similar to <literal>getProtocolByName: does not exist (no
174+ such protocol name: tcp)</literal> you may need to add
175+ <literal>pkgs.iana-etc</literal> to <varname>contents</varname>.
176+ </para>
177+ </note>
178+
179+ <note>
180+ <para>
181+ If you see errors similar to <literal>Error_Protocol ("certificate has
182+ unknown CA",True,UnknownCa)</literal> you may need to add
183+ <literal>pkgs.cacert</literal> to <varname>contents</varname>.
184+ </para>
185+ </note>
186+
187+ <example xml:id="example-pkgs-dockerTools-buildImage-creation-date">
188+ <title>Impurely Defining a Docker Layer's Creation Date</title>
189+ <para>
190+ By default <function>buildImage</function> will use a static date of one
191+ second past the UNIX Epoch. This allows <function>buildImage</function> to
192+ produce binary reproducible images. When listing images with
193+ <command>docker list images</command>, the newly created images will be
194+ listed like this:
195+ </para>
196+<screen><![CDATA[
197+$ docker image list
198+REPOSITORY TAG IMAGE ID CREATED SIZE
199+hello latest 08c791c7846e 48 years ago 25.2MB
200+]]></screen>
201+ <para>
202+ You can break binary reproducibility but have a sorted, meaningful
203+ <literal>CREATED</literal> column by setting <literal>created</literal> to
204+ <literal>now</literal>.
205+ </para>
206+<programlisting><![CDATA[
207+pkgs.dockerTools.buildImage {
208+ name = "hello";
209+ tag = "latest";
210+ created = "now";
211+ contents = pkgs.hello;
212+
213+ config.Cmd = [ "/bin/hello" ];
214+}
215+]]></programlisting>
216+ <para>
217+ and now the Docker CLI will display a reasonable date and sort the images
218+ as expected:
219+<screen><![CDATA[
220+$ docker image list
221+REPOSITORY TAG IMAGE ID CREATED SIZE
222+hello latest de2bf4786de6 About a minute ago 25.2MB
223+]]></screen>
224+ however, the produced images will not be binary reproducible.
225+ </para>
226+ </example>
227+ </section>
228+
229+ <section xml:id="ssec-pkgs-dockerTools-buildLayeredImage">
230+ <title>buildLayeredImage</title>
231+
232+ <para>
233+ Create a Docker image with many of the store paths being on their own layer
234+ to improve sharing between images.
235+ </para>
236+
237+ <variablelist>
238+ <varlistentry>
239+ <term>
240+ <varname>name</varname>
241+ </term>
242+ <listitem>
243+ <para>
244+ The name of the resulting image.
245+ </para>
246+ </listitem>
247+ </varlistentry>
248+ <varlistentry>
249+ <term>
250+ <varname>tag</varname> <emphasis>optional</emphasis>
251+ </term>
252+ <listitem>
253+ <para>
254+ Tag of the generated image.
255+ </para>
256+ <para>
257+ <emphasis>Default:</emphasis> the output path's hash
258+ </para>
259+ </listitem>
260+ </varlistentry>
261+ <varlistentry>
262+ <term>
263+ <varname>contents</varname> <emphasis>optional</emphasis>
264+ </term>
265+ <listitem>
266+ <para>
267+ Top level paths in the container. Either a single derivation, or a list
268+ of derivations.
269+ </para>
270+ <para>
271+ <emphasis>Default:</emphasis> <literal>[]</literal>
272+ </para>
273+ </listitem>
274+ </varlistentry>
275+ <varlistentry>
276+ <term>
277+ <varname>config</varname> <emphasis>optional</emphasis>
278+ </term>
279+ <listitem>
280+ <para>
281+ Run-time configuration of the container. A full list of the options are
282+ available at in the
283+ <link xlink:href="https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions">
284+ Docker Image Specification v1.2.0 </link>.
285+ </para>
286+ <para>
287+ <emphasis>Default:</emphasis> <literal>{}</literal>
288+ </para>
289+ </listitem>
290+ </varlistentry>
291+ <varlistentry>
292+ <term>
293+ <varname>created</varname> <emphasis>optional</emphasis>
294+ </term>
295+ <listitem>
296+ <para>
297+ Date and time the layers were created. Follows the same
298+ <literal>now</literal> exception supported by
299+ <literal>buildImage</literal>.
300+ </para>
301+ <para>
302+ <emphasis>Default:</emphasis> <literal>1970-01-01T00:00:01Z</literal>
303+ </para>
304+ </listitem>
305+ </varlistentry>
306+ <varlistentry>
307+ <term>
308+ <varname>maxLayers</varname> <emphasis>optional</emphasis>
309+ </term>
310+ <listitem>
311+ <para>
312+ Maximum number of layers to create.
313+ </para>
314+ <para>
315+ <emphasis>Default:</emphasis> <literal>24</literal>
316+ </para>
317+ </listitem>
318+ </varlistentry>
319+ </variablelist>
320+
321+ <section xml:id="dockerTools-buildLayeredImage-arg-contents">
322+ <title>Behavior of <varname>contents</varname> in the final image</title>
323+
324+ <para>
325+ Each path directly listed in <varname>contents</varname> will have a
326+ symlink in the root of the image.
327+ </para>
328+
329+ <para>
330+ For example:
331+<programlisting><![CDATA[
332+pkgs.dockerTools.buildLayeredImage {
333+ name = "hello";
334+ contents = [ pkgs.hello ];
335+}
336+]]></programlisting>
337+ will create symlinks for all the paths in the <literal>hello</literal>
338+ package:
339+<screen><![CDATA[
340+/bin/hello -> /nix/store/h1zb1padqbbb7jicsvkmrym3r6snphxg-hello-2.10/bin/hello
341+/share/info/hello.info -> /nix/store/h1zb1padqbbb7jicsvkmrym3r6snphxg-hello-2.10/share/info/hello.info
342+/share/locale/bg/LC_MESSAGES/hello.mo -> /nix/store/h1zb1padqbbb7jicsvkmrym3r6snphxg-hello-2.10/share/locale/bg/LC_MESSAGES/hello.mo
343+]]></screen>
344+ </para>
345+ </section>
346+
347+ <section xml:id="dockerTools-buildLayeredImage-arg-config">
348+ <title>Automatic inclusion of <varname>config</varname> references</title>
349+
350+ <para>
351+ The closure of <varname>config</varname> is automatically included in the
352+ closure of the final image.
353+ </para>
354+
355+ <para>
356+ This allows you to make very simple Docker images with very little code.
357+ This container will start up and run <command>hello</command>:
358+<programlisting><![CDATA[
359+pkgs.dockerTools.buildLayeredImage {
360+ name = "hello";
361+ config.Cmd = [ "${pkgs.hello}/bin/hello" ];
362+}
363+]]></programlisting>
364+ </para>
365+ </section>
366+
367+ <section xml:id="dockerTools-buildLayeredImage-arg-maxLayers">
368+ <title>Adjusting <varname>maxLayers</varname></title>
369+
370+ <para>
371+ Increasing the <varname>maxLayers</varname> increases the number of layers
372+ which have a chance to be shared between different images.
373+ </para>
374+
375+ <para>
376+ Modern Docker installations support up to 128 layers, however older
377+ versions support as few as 42.
378+ </para>
379+
380+ <para>
381+ If the produced image will not be extended by other Docker builds, it is
382+ safe to set <varname>maxLayers</varname> to <literal>128</literal>. However
383+ it will be impossible to extend the image further.
384+ </para>
385+
386+ <para>
387+ The first (<literal>maxLayers-2</literal>) most "popular" paths will have
388+ their own individual layers, then layer #<literal>maxLayers-1</literal>
389+ will contain all the remaining "unpopular" paths, and finally layer
390+ #<literal>maxLayers</literal> will contain the Image configuration.
391+ </para>
392+
393+ <para>
394+ Docker's Layers are not inherently ordered, they are content-addressable
395+ and are not explicitly layered until they are composed in to an Image.
396+ </para>
397+ </section>
398+ </section>
399+
400+ <section xml:id="ssec-pkgs-dockerTools-fetchFromRegistry">
401+ <title>pullImage</title>
402+
403+ <para>
404+ This function is analogous to the <command>docker pull</command> command, in
405+ that can be used to pull a Docker image from a Docker registry. By default
406+ <link xlink:href="https://hub.docker.com/">Docker Hub</link> is used to pull
407+ images.
408+ </para>
409+
410+ <para>
411+ Its parameters are described in the example below:
412+ </para>
413+
414+ <example xml:id='ex-dockerTools-pullImage'>
415+ <title>Docker pull</title>
416+<programlisting>
417+pullImage {
418+ imageName = "nixos/nix"; <co xml:id='ex-dockerTools-pullImage-1' />
419+ imageDigest = "sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b"; <co xml:id='ex-dockerTools-pullImage-2' />
420+ finalImageTag = "1.11"; <co xml:id='ex-dockerTools-pullImage-3' />
421+ sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8"; <co xml:id='ex-dockerTools-pullImage-4' />
422+ os = "linux"; <co xml:id='ex-dockerTools-pullImage-5' />
423+ arch = "x86_64"; <co xml:id='ex-dockerTools-pullImage-6' />
424+}
425+</programlisting>
426+ </example>
427+
428+ <calloutlist>
429+ <callout arearefs='ex-dockerTools-pullImage-1'>
430+ <para>
431+ <varname>imageName</varname> specifies the name of the image to be
432+ downloaded, which can also include the registry namespace (e.g.
433+ <literal>nixos</literal>). This argument is required.
434+ </para>
435+ </callout>
436+ <callout arearefs='ex-dockerTools-pullImage-2'>
437+ <para>
438+ <varname>imageDigest</varname> specifies the digest of the image to be
439+ downloaded. Skopeo can be used to get the digest of an image, with its
440+ <varname>inspect</varname> subcommand. Since a given
441+ <varname>imageName</varname> may transparently refer to a manifest list of
442+ images which support multiple architectures and/or operating systems,
443+ supply the `--override-os` and `--override-arch` arguments to specify
444+ exactly which image you want. By default it will match the OS and
445+ architecture of the host the command is run on.
446+<programlisting>
447+$ nix-shell --packages skopeo jq --command "skopeo --override-os linux --override-arch x86_64 inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest'"
448+sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b
449+</programlisting>
450+ This argument is required.
451+ </para>
452+ </callout>
453+ <callout arearefs='ex-dockerTools-pullImage-3'>
454+ <para>
455+ <varname>finalImageTag</varname>, if specified, this is the tag of the
456+ image to be created. Note it is never used to fetch the image since we
457+ prefer to rely on the immutable digest ID. By default it's
458+ <literal>latest</literal>.
459+ </para>
460+ </callout>
461+ <callout arearefs='ex-dockerTools-pullImage-4'>
462+ <para>
463+ <varname>sha256</varname> is the checksum of the whole fetched image. This
464+ argument is required.
465+ </para>
466+ </callout>
467+ <callout arearefs='ex-dockerTools-pullImage-5'>
468+ <para>
469+ <varname>os</varname>, if specified, is the operating system of the
470+ fetched image. By default it's <literal>linux</literal>.
471+ </para>
472+ </callout>
473+ <callout arearefs='ex-dockerTools-pullImage-6'>
474+ <para>
475+ <varname>arch</varname>, if specified, is the cpu architecture of the
476+ fetched image. By default it's <literal>x86_64</literal>.
477+ </para>
478+ </callout>
479+ </calloutlist>
480+ </section>
481+
482+ <section xml:id="ssec-pkgs-dockerTools-exportImage">
483+ <title>exportImage</title>
484+
485+ <para>
486+ This function is analogous to the <command>docker export</command> command,
487+ in that can used to flatten a Docker image that contains multiple layers. It
488+ is in fact the result of the merge of all the layers of the image. As such,
489+ the result is suitable for being imported in Docker with <command>docker
490+ import</command>.
491+ </para>
492+
493+ <note>
494+ <para>
495+ Using this function requires the <literal>kvm</literal> device to be
496+ available.
497+ </para>
498+ </note>
499+
500+ <para>
501+ The parameters of <varname>exportImage</varname> are the following:
502+ </para>
503+
504+ <example xml:id='ex-dockerTools-exportImage'>
505+ <title>Docker export</title>
506+<programlisting>
507+exportImage {
508+ fromImage = someLayeredImage;
509+ fromImageName = null;
510+ fromImageTag = null;
511+
512+ name = someLayeredImage.name;
513+}
514+ </programlisting>
515+ </example>
516+
517+ <para>
518+ The parameters relative to the base image have the same synopsis as
519+ described in <xref linkend='ssec-pkgs-dockerTools-buildImage'/>, except that
520+ <varname>fromImage</varname> is the only required argument in this case.
521+ </para>
522+
523+ <para>
524+ The <varname>name</varname> argument is the name of the derivation output,
525+ which defaults to <varname>fromImage.name</varname>.
526+ </para>
527+ </section>
528+
529+ <section xml:id="ssec-pkgs-dockerTools-shadowSetup">
530+ <title>shadowSetup</title>
531+
532+ <para>
533+ This constant string is a helper for setting up the base files for managing
534+ users and groups, only if such files don't exist already. It is suitable for
535+ being used in a <varname>runAsRoot</varname>
536+ <xref linkend='ex-dockerTools-buildImage-runAsRoot'/> script for cases like
537+ in the example below:
538+ </para>
539+
540+ <example xml:id='ex-dockerTools-shadowSetup'>
541+ <title>Shadow base files</title>
542+<programlisting>
543+buildImage {
544+ name = "shadow-basic";
545+
546+ runAsRoot = ''
547+ #!${stdenv.shell}
548+ ${shadowSetup}
549+ groupadd -r redis
550+ useradd -r -g redis redis
551+ mkdir /data
552+ chown redis:redis /data
553+ '';
554+}
555+</programlisting>
556+ </example>
557+
558+ <para>
559+ Creating base files like <literal>/etc/passwd</literal> or
560+ <literal>/etc/login.defs</literal> are necessary for shadow-utils to
561+ manipulate users and groups.
562+ </para>
563+ </section>
564+</section>
doc/functions/fhs-environments.xmlnew file+142
@@ -0,0 +1,142 @@
1+<section xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xmlns:xi="http://www.w3.org/2001/XInclude"
4+ xml:id="sec-fhs-environments">
5+ <title>buildFHSUserEnv</title>
6+
7+ <para>
8+ <function>buildFHSUserEnv</function> provides a way to build and run
9+ FHS-compatible lightweight sandboxes. It creates an isolated root with bound
10+ <filename>/nix/store</filename>, so its footprint in terms of disk space
11+ needed is quite small. This allows one to run software which is hard or
12+ unfeasible to patch for NixOS -- 3rd-party source trees with FHS assumptions,
13+ games distributed as tarballs, software with integrity checking and/or
14+ external self-updated binaries. It uses Linux namespaces feature to create
15+ temporary lightweight environments which are destroyed after all child
16+ processes exit, without root user rights requirement. Accepted arguments are:
17+ </para>
18+
19+ <variablelist>
20+ <varlistentry>
21+ <term>
22+ <literal>name</literal>
23+ </term>
24+ <listitem>
25+ <para>
26+ Environment name.
27+ </para>
28+ </listitem>
29+ </varlistentry>
30+ <varlistentry>
31+ <term>
32+ <literal>targetPkgs</literal>
33+ </term>
34+ <listitem>
35+ <para>
36+ Packages to be installed for the main host's architecture (i.e. x86_64 on
37+ x86_64 installations). Along with libraries binaries are also installed.
38+ </para>
39+ </listitem>
40+ </varlistentry>
41+ <varlistentry>
42+ <term>
43+ <literal>multiPkgs</literal>
44+ </term>
45+ <listitem>
46+ <para>
47+ Packages to be installed for all architectures supported by a host (i.e.
48+ i686 and x86_64 on x86_64 installations). Only libraries are installed by
49+ default.
50+ </para>
51+ </listitem>
52+ </varlistentry>
53+ <varlistentry>
54+ <term>
55+ <literal>extraBuildCommands</literal>
56+ </term>
57+ <listitem>
58+ <para>
59+ Additional commands to be executed for finalizing the directory structure.
60+ </para>
61+ </listitem>
62+ </varlistentry>
63+ <varlistentry>
64+ <term>
65+ <literal>extraBuildCommandsMulti</literal>
66+ </term>
67+ <listitem>
68+ <para>
69+ Like <literal>extraBuildCommands</literal>, but executed only on multilib
70+ architectures.
71+ </para>
72+ </listitem>
73+ </varlistentry>
74+ <varlistentry>
75+ <term>
76+ <literal>extraOutputsToInstall</literal>
77+ </term>
78+ <listitem>
79+ <para>
80+ Additional derivation outputs to be linked for both target and
81+ multi-architecture packages.
82+ </para>
83+ </listitem>
84+ </varlistentry>
85+ <varlistentry>
86+ <term>
87+ <literal>extraInstallCommands</literal>
88+ </term>
89+ <listitem>
90+ <para>
91+ Additional commands to be executed for finalizing the derivation with
92+ runner script.
93+ </para>
94+ </listitem>
95+ </varlistentry>
96+ <varlistentry>
97+ <term>
98+ <literal>runScript</literal>
99+ </term>
100+ <listitem>
101+ <para>
102+ A command that would be executed inside the sandbox and passed all the
103+ command line arguments. It defaults to <literal>bash</literal>.
104+ </para>
105+ </listitem>
106+ </varlistentry>
107+ </variablelist>
108+
109+ <para>
110+ One can create a simple environment using a <literal>shell.nix</literal> like
111+ that:
112+ </para>
113+
114+<programlisting><![CDATA[
115+{ pkgs ? import <nixpkgs> {} }:
116+
117+(pkgs.buildFHSUserEnv {
118+ name = "simple-x11-env";
119+ targetPkgs = pkgs: (with pkgs;
120+ [ udev
121+ alsaLib
122+ ]) ++ (with pkgs.xorg;
123+ [ libX11
124+ libXcursor
125+ libXrandr
126+ ]);
127+ multiPkgs = pkgs: (with pkgs;
128+ [ udev
129+ alsaLib
130+ ]);
131+ runScript = "bash";
132+}).env
133+]]></programlisting>
134+
135+ <para>
136+ Running <literal>nix-shell</literal> would then drop you into a shell with
137+ these libraries and binaries available. You can use this to run closed-source
138+ applications which expect FHS structure without hassles: simply change
139+ <literal>runScript</literal> to the application path, e.g.
140+ <filename>./bin/start.sh</filename> -- relative paths are supported.
141+ </para>
142+</section>
doc/functions/generators.xmlnew file+89
@@ -0,0 +1,89 @@
1+<section xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xmlns:xi="http://www.w3.org/2001/XInclude"
4+ xml:id="sec-generators">
5+ <title>Generators</title>
6+
7+ <para>
8+ Generators are functions that create file formats from nix data structures,
9+ e. g. for configuration files. There are generators available for:
10+ <literal>INI</literal>, <literal>JSON</literal> and <literal>YAML</literal>
11+ </para>
12+
13+ <para>
14+ All generators follow a similar call interface: <code>generatorName
15+ configFunctions data</code>, where <literal>configFunctions</literal> is an
16+ attrset of user-defined functions that format nested parts of the content.
17+ They each have common defaults, so often they do not need to be set manually.
18+ An example is <code>mkSectionName ? (name: libStr.escape [ "[" "]" ]
19+ name)</code> from the <literal>INI</literal> generator. It receives the name
20+ of a section and sanitizes it. The default <literal>mkSectionName</literal>
21+ escapes <literal>[</literal> and <literal>]</literal> with a backslash.
22+ </para>
23+
24+ <para>
25+ Generators can be fine-tuned to produce exactly the file format required by
26+ your application/service. One example is an INI-file format which uses
27+ <literal>: </literal> as separator, the strings
28+ <literal>"yes"</literal>/<literal>"no"</literal> as boolean values and
29+ requires all string values to be quoted:
30+ </para>
31+
32+<programlisting>
33+with lib;
34+let
35+ customToINI = generators.toINI {
36+ # specifies how to format a key/value pair
37+ mkKeyValue = generators.mkKeyValueDefault {
38+ # specifies the generated string for a subset of nix values
39+ mkValueString = v:
40+ if v == true then ''"yes"''
41+ else if v == false then ''"no"''
42+ else if isString v then ''"${v}"''
43+ # and delegats all other values to the default generator
44+ else generators.mkValueStringDefault {} v;
45+ } ":";
46+ };
47+
48+# the INI file can now be given as plain old nix values
49+in customToINI {
50+ main = {
51+ pushinfo = true;
52+ autopush = false;
53+ host = "localhost";
54+ port = 42;
55+ };
56+ mergetool = {
57+ merge = "diff3";
58+ };
59+}
60+</programlisting>
61+
62+ <para>
63+ This will produce the following INI file as nix string:
64+ </para>
65+
66+<programlisting>
67+[main]
68+autopush:"no"
69+host:"localhost"
70+port:42
71+pushinfo:"yes"
72+str\:ange:"very::strange"
73+
74+[mergetool]
75+merge:"diff3"
76+</programlisting>
77+
78+ <note>
79+ <para>
80+ Nix store paths can be converted to strings by enclosing a derivation
81+ attribute like so: <code>"${drv}"</code>.
82+ </para>
83+ </note>
84+
85+ <para>
86+ Detailed documentation for each generator can be found in
87+ <literal>lib/generators.nix</literal>.
88+ </para>
89+</section>
doc/functions/overrides.xmlnew file+203
@@ -0,0 +1,203 @@
1+<section xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xmlns:xi="http://www.w3.org/2001/XInclude"
4+ xml:id="sec-overrides">
5+ <title>Overriding</title>
6+
7+ <para>
8+ Sometimes one wants to override parts of <literal>nixpkgs</literal>, e.g.
9+ derivation attributes, the results of derivations or even the whole package
10+ set.
11+ </para>
12+
13+ <section xml:id="sec-pkg-override">
14+ <title>&lt;pkg&gt;.override</title>
15+
16+ <para>
17+ The function <varname>override</varname> is usually available for all the
18+ derivations in the nixpkgs expression (<varname>pkgs</varname>).
19+ </para>
20+
21+ <para>
22+ It is used to override the arguments passed to a function.
23+ </para>
24+
25+ <para>
26+ Example usages:
27+<programlisting>pkgs.foo.override { arg1 = val1; arg2 = val2; ... }</programlisting>
28+<programlisting>
29+import pkgs.path { overlays = [ (self: super: {
30+ foo = super.foo.override { barSupport = true ; };
31+ })]};
32+</programlisting>
33+<programlisting>
34+mypkg = pkgs.callPackage ./mypkg.nix {
35+ mydep = pkgs.mydep.override { ... };
36+ }
37+</programlisting>
38+ </para>
39+
40+ <para>
41+ In the first example, <varname>pkgs.foo</varname> is the result of a
42+ function call with some default arguments, usually a derivation. Using
43+ <varname>pkgs.foo.override</varname> will call the same function with the
44+ given new arguments.
45+ </para>
46+ </section>
47+
48+ <section xml:id="sec-pkg-overrideAttrs">
49+ <title>&lt;pkg&gt;.overrideAttrs</title>
50+
51+ <para>
52+ The function <varname>overrideAttrs</varname> allows overriding the
53+ attribute set passed to a <varname>stdenv.mkDerivation</varname> call,
54+ producing a new derivation based on the original one. This function is
55+ available on all derivations produced by the
56+ <varname>stdenv.mkDerivation</varname> function, which is most packages in
57+ the nixpkgs expression <varname>pkgs</varname>.
58+ </para>
59+
60+ <para>
61+ Example usage:
62+<programlisting>
63+helloWithDebug = pkgs.hello.overrideAttrs (oldAttrs: rec {
64+ separateDebugInfo = true;
65+});
66+</programlisting>
67+ </para>
68+
69+ <para>
70+ In the above example, the <varname>separateDebugInfo</varname> attribute is
71+ overridden to be true, thus building debug info for
72+ <varname>helloWithDebug</varname>, while all other attributes will be
73+ retained from the original <varname>hello</varname> package.
74+ </para>
75+
76+ <para>
77+ The argument <varname>oldAttrs</varname> is conventionally used to refer to
78+ the attr set originally passed to <varname>stdenv.mkDerivation</varname>.
79+ </para>
80+
81+ <note>
82+ <para>
83+ Note that <varname>separateDebugInfo</varname> is processed only by the
84+ <varname>stdenv.mkDerivation</varname> function, not the generated, raw Nix
85+ derivation. Thus, using <varname>overrideDerivation</varname> will not work
86+ in this case, as it overrides only the attributes of the final derivation.
87+ It is for this reason that <varname>overrideAttrs</varname> should be
88+ preferred in (almost) all cases to <varname>overrideDerivation</varname>,
89+ i.e. to allow using <varname>sdenv.mkDerivation</varname> to process input
90+ arguments, as well as the fact that it is easier to use (you can use the
91+ same attribute names you see in your Nix code, instead of the ones
92+ generated (e.g. <varname>buildInputs</varname> vs
93+ <varname>nativeBuildInputs</varname>, and involves less typing.
94+ </para>
95+ </note>
96+ </section>
97+
98+ <section xml:id="sec-pkg-overrideDerivation">
99+ <title>&lt;pkg&gt;.overrideDerivation</title>
100+
101+ <warning>
102+ <para>
103+ You should prefer <varname>overrideAttrs</varname> in almost all cases, see
104+ its documentation for the reasons why.
105+ <varname>overrideDerivation</varname> is not deprecated and will continue
106+ to work, but is less nice to use and does not have as many abilities as
107+ <varname>overrideAttrs</varname>.
108+ </para>
109+ </warning>
110+
111+ <warning>
112+ <para>
113+ Do not use this function in Nixpkgs as it evaluates a Derivation before
114+ modifying it, which breaks package abstraction and removes error-checking
115+ of function arguments. In addition, this evaluation-per-function
116+ application incurs a performance penalty, which can become a problem if
117+ many overrides are used. It is only intended for ad-hoc customisation, such
118+ as in <filename>~/.config/nixpkgs/config.nix</filename>.
119+ </para>
120+ </warning>
121+
122+ <para>
123+ The function <varname>overrideDerivation</varname> creates a new derivation
124+ based on an existing one by overriding the original's attributes with the
125+ attribute set produced by the specified function. This function is available
126+ on all derivations defined using the <varname>makeOverridable</varname>
127+ function. Most standard derivation-producing functions, such as
128+ <varname>stdenv.mkDerivation</varname>, are defined using this function,
129+ which means most packages in the nixpkgs expression,
130+ <varname>pkgs</varname>, have this function.
131+ </para>
132+
133+ <para>
134+ Example usage:
135+<programlisting>
136+mySed = pkgs.gnused.overrideDerivation (oldAttrs: {
137+ name = "sed-4.2.2-pre";
138+ src = fetchurl {
139+ url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
140+ sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k";
141+ };
142+ patches = [];
143+});
144+</programlisting>
145+ </para>
146+
147+ <para>
148+ In the above example, the <varname>name</varname>, <varname>src</varname>,
149+ and <varname>patches</varname> of the derivation will be overridden, while
150+ all other attributes will be retained from the original derivation.
151+ </para>
152+
153+ <para>
154+ The argument <varname>oldAttrs</varname> is used to refer to the attribute
155+ set of the original derivation.
156+ </para>
157+
158+ <note>
159+ <para>
160+ A package's attributes are evaluated *before* being modified by the
161+ <varname>overrideDerivation</varname> function. For example, the
162+ <varname>name</varname> attribute reference in <varname>url =
163+ "mirror://gnu/hello/${name}.tar.gz";</varname> is filled-in *before* the
164+ <varname>overrideDerivation</varname> function modifies the attribute set.
165+ This means that overriding the <varname>name</varname> attribute, in this
166+ example, *will not* change the value of the <varname>url</varname>
167+ attribute. Instead, we need to override both the <varname>name</varname>
168+ *and* <varname>url</varname> attributes.
169+ </para>
170+ </note>
171+ </section>
172+
173+ <section xml:id="sec-lib-makeOverridable">
174+ <title>lib.makeOverridable</title>
175+
176+ <para>
177+ The function <varname>lib.makeOverridable</varname> is used to make the
178+ result of a function easily customizable. This utility only makes sense for
179+ functions that accept an argument set and return an attribute set.
180+ </para>
181+
182+ <para>
183+ Example usage:
184+<programlisting>
185+f = { a, b }: { result = a+b; };
186+c = lib.makeOverridable f { a = 1; b = 2; };
187+</programlisting>
188+ </para>
189+
190+ <para>
191+ The variable <varname>c</varname> is the value of the <varname>f</varname>
192+ function applied with some default arguments. Hence the value of
193+ <varname>c.result</varname> is <literal>3</literal>, in this example.
194+ </para>
195+
196+ <para>
197+ The variable <varname>c</varname> however also has some additional
198+ functions, like <link linkend="sec-pkg-override">c.override</link> which can
199+ be used to override the default arguments. In this example the value of
200+ <varname>(c.override { a = 4; }).result</varname> is 6.
201+ </para>
202+ </section>
203+</section>
doc/functions/shell.xmlnew file+26
@@ -0,0 +1,26 @@
1+<section xmlns="http://docbook.org/ns/docbook"
2+ xmlns:xlink="http://www.w3.org/1999/xlink"
3+ xmlns:xi="http://www.w3.org/2001/XInclude"
4+ xml:id="sec-pkgs-mkShell">
5+ <title>pkgs.mkShell</title>
6+
7+ <para>
8+ <function>pkgs.mkShell</function> is a special kind of derivation that is
9+ only useful when using it combined with <command>nix-shell</command>. It will
10+ in fact fail to instantiate when invoked with <command>nix-build</command>.
11+ </para>
12+
13+ <section xml:id="sec-pkgs-mkShell-usage">
14+ <title>Usage</title>
15+
16+<programlisting><![CDATA[
17+{ pkgs ? import <nixpkgs> {} }:
18+pkgs.mkShell {
19+ # this will make all the build inputs from hello and gnutar
20+ # available to the shell environment
21+ inputsFrom = with pkgs; [ hello gnutar ];
22+ buildInputs = [ pkgs.gnumake ];
23+}
24+]]></programlisting>
25+ </section>
26+</section>
doc/package-notes.xml+46−28
@@ -668,8 +668,9 @@ overrides = self: super: rec {
668668 plugins = with availablePlugins; [ python perl ];
669669 }
670670}</programlisting>
671− If the <literal>configure</literal> function returns an attrset without the <literal>plugins</literal>
672− attribute, <literal>availablePlugins</literal> will be used automatically.
671+ If the <literal>configure</literal> function returns an attrset without the
672+ <literal>plugins</literal> attribute, <literal>availablePlugins</literal>
673+ will be used automatically.
673674 </para>
674675
675676 <para>
@@ -703,9 +704,11 @@ overrides = self: super: rec {
703704}; }
704705</programlisting>
705706 </para>
707+
706708 <para>
707− WeeChat allows to set defaults on startup using the <literal>--run-command</literal>.
708− The <literal>configure</literal> method can be used to pass commands to the program:
709+ WeeChat allows to set defaults on startup using the
710+ <literal>--run-command</literal>. The <literal>configure</literal> method
711+ can be used to pass commands to the program:
709712<programlisting>weechat.override {
710713 configure = { availablePlugins, ... }: {
711714 init = ''
@@ -714,12 +717,14 @@ overrides = self: super: rec {
714717 '';
715718 };
716719}</programlisting>
717− Further values can be added to the list of commands when running
718− <literal>weechat --run-command "your-commands"</literal>.
720+ Further values can be added to the list of commands when running
721+ <literal>weechat --run-command "your-commands"</literal>.
719722 </para>
723+
720724 <para>
721− Additionally it's possible to specify scripts to be loaded when starting <literal>weechat</literal>.
722− These will be loaded before the commands from <literal>init</literal>:
725+ Additionally it's possible to specify scripts to be loaded when starting
726+ <literal>weechat</literal>. These will be loaded before the commands from
727+ <literal>init</literal>:
723728<programlisting>weechat.override {
724729 configure = { availablePlugins, ... }: {
725730 scripts = with pkgs.weechatScripts; [
@@ -731,11 +736,13 @@ overrides = self: super: rec {
731736 };
732737}</programlisting>
733738 </para>
739+
734740 <para>
735− In <literal>nixpkgs</literal> there's a subpackage which contains derivations for
736− WeeChat scripts. Such derivations expect a <literal>passthru.scripts</literal> attribute
737− which contains a list of all scripts inside the store path. Furthermore all scripts
738− have to live in <literal>$out/share</literal>. An exemplary derivation looks like this:
741+ In <literal>nixpkgs</literal> there's a subpackage which contains
742+ derivations for WeeChat scripts. Such derivations expect a
743+ <literal>passthru.scripts</literal> attribute which contains a list of all
744+ scripts inside the store path. Furthermore all scripts have to live in
745+ <literal>$out/share</literal>. An exemplary derivation looks like this:
739746<programlisting>{ stdenv, fetchurl }:
740747
741748stdenv.mkDerivation {
@@ -814,20 +821,26 @@ citrix_receiver.override {
814821 <section xml:id="sec-ibus-typing-booster">
815822 <title>ibus-engines.typing-booster</title>
816823
817− <para>This package is an ibus-based completion method to speed up typing.</para>
824+ <para>
825+ This package is an ibus-based completion method to speed up typing.
826+ </para>
818827
819828 <section xml:id="sec-ibus-typing-booster-activate">
820829 <title>Activating the engine</title>
821830
822831 <para>
823− IBus needs to be configured accordingly to activate <literal>typing-booster</literal>. The configuration
824− depends on the desktop manager in use. For detailed instructions, please refer to the
825− <link xlink:href="https://mike-fabian.github.io/ibus-typing-booster/documentation.html">upstream docs</link>.
832+ IBus needs to be configured accordingly to activate
833+ <literal>typing-booster</literal>. The configuration depends on the desktop
834+ manager in use. For detailed instructions, please refer to the
835+ <link xlink:href="https://mike-fabian.github.io/ibus-typing-booster/documentation.html">upstream
836+ docs</link>.
826837 </para>
838+
827839 <para>
828− On NixOS you need to explicitly enable <literal>ibus</literal> with given engines
829− before customizing your desktop to use <literal>typing-booster</literal>. This can be achieved
830− using the <literal>ibus</literal> module:
840+ On NixOS you need to explicitly enable <literal>ibus</literal> with given
841+ engines before customizing your desktop to use
842+ <literal>typing-booster</literal>. This can be achieved using the
843+ <literal>ibus</literal> module:
831844<programlisting>{ pkgs, ... }: {
832845 i18n.inputMethod = {
833846 enabled = "ibus";
@@ -841,17 +854,20 @@ citrix_receiver.override {
841854 <title>Using custom hunspell dictionaries</title>
842855
843856 <para>
844− The IBus engine is based on <literal>hunspell</literal> to support completion in many languages.
845− By default the dictionaries <literal>de-de</literal>, <literal>en-us</literal>, <literal>es-es</literal>,
846− <literal>it-it</literal>, <literal>sv-se</literal> and <literal>sv-fi</literal>
847− are in use. To add another dictionary, the package can be overridden like this:
857+ The IBus engine is based on <literal>hunspell</literal> to support
858+ completion in many languages. By default the dictionaries
859+ <literal>de-de</literal>, <literal>en-us</literal>,
860+ <literal>es-es</literal>, <literal>it-it</literal>,
861+ <literal>sv-se</literal> and <literal>sv-fi</literal> are in use. To add
862+ another dictionary, the package can be overridden like this:
848863<programlisting>ibus-engines.typing-booster.override {
849864 langs = [ "de-at" "en-gb" ];
850865}</programlisting>
851866 </para>
867+
852868 <para>
853− <emphasis>Note: each language passed to <literal>langs</literal> must be an attribute name in
854− <literal>pkgs.hunspellDicts</literal>.</emphasis>
869+ <emphasis>Note: each language passed to <literal>langs</literal> must be an
870+ attribute name in <literal>pkgs.hunspellDicts</literal>.</emphasis>
855871 </para>
856872 </section>
857873
@@ -859,10 +875,12 @@ citrix_receiver.override {
859875 <title>Built-in emoji picker</title>
860876
861877 <para>
862− The <literal>ibus-engines.typing-booster</literal> package contains a program
863− named <literal>emoji-picker</literal>. To display all emojis correctly,
864− a special font such as <literal>noto-fonts-emoji</literal> is needed:
878+ The <literal>ibus-engines.typing-booster</literal> package contains a
879+ program named <literal>emoji-picker</literal>. To display all emojis
880+ correctly, a special font such as <literal>noto-fonts-emoji</literal> is
881+ needed:
865882 </para>
883+
866884 <para>
867885 On NixOS it can be installed using the following expression:
868886<programlisting>{ pkgs, ... }: {
doc/shell.section.mddeleted−22
@@ -1,22 +0,0 @@
1−---
2−title: pkgs.mkShell
3−author: zimbatm
4−date: 2017-10-30
5−---
6−
7−# mkShell
8−
9−pkgs.mkShell is a special kind of derivation that is only useful when using
10−it combined with nix-shell. It will in fact fail to instantiate when invoked
11−with nix-build.
12−
13−## Usage
14−
15−```nix
16−{ pkgs ? import <nixpkgs> {} }:
17−pkgs.mkShell {
18− # this will make all the build inputs from hello and gnutar available to the shell environment
19− inputsFrom = with pkgs; [ hello gnutar ];
20− buildInputs = [ pkgs.gnumake ];
21−}
22−```