forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdenv.xml
1672 lines (1330 loc) · 58.7 KB
/
stdenv.xml
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<chapter xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xml:id="chap-stdenv">
<title>The Standard Environment</title>
<para>The standard build environment in the Nix Packages collection
provides an environment for building Unix packages that does a lot of
common build tasks automatically. In fact, for Unix packages that use
the standard <literal>./configure; make; make install</literal> build
interface, you don’t need to write a build script at all; the standard
environment does everything automatically. If
<literal>stdenv</literal> doesn’t do what you need automatically, you
can easily customise or override the various build phases.</para>
<section xml:id="sec-using-stdenv"><title>Using
<literal>stdenv</literal></title>
<para>To build a package with the standard environment, you use the
function <varname>stdenv.mkDerivation</varname>, instead of the
primitive built-in function <varname>derivation</varname>, e.g.
<programlisting>
stdenv.mkDerivation {
name = "libfoo-1.2.3";
src = fetchurl {
url = http://example.org/libfoo-1.2.3.tar.bz2;
sha256 = "0x2g1jqygyr5wiwg4ma1nd7w4ydpy82z9gkcv8vh2v8dn3y58v5m";
};
}</programlisting>
(<varname>stdenv</varname> needs to be in scope, so if you write this
in a separate Nix expression from
<filename>pkgs/all-packages.nix</filename>, you need to pass it as a
function argument.) Specifying a <varname>name</varname> and a
<varname>src</varname> is the absolute minimum you need to do. Many
packages have dependencies that are not provided in the standard
environment. It’s usually sufficient to specify those dependencies in
the <varname>buildInputs</varname> attribute:
<programlisting>
stdenv.mkDerivation {
name = "libfoo-1.2.3";
...
buildInputs = [libbar perl ncurses];
}</programlisting>
This attribute ensures that the <filename>bin</filename>
subdirectories of these packages appear in the <envar>PATH</envar>
environment variable during the build, that their
<filename>include</filename> subdirectories are searched by the C
compiler, and so on. (See <xref linkend="ssec-setup-hooks"/> for
details.)</para>
<para>Often it is necessary to override or modify some aspect of the
build. To make this easier, the standard environment breaks the
package build into a number of <emphasis>phases</emphasis>, all of
which can be overridden or modified individually: unpacking the
sources, applying patches, configuring, building, and installing.
(There are some others; see <xref linkend="sec-stdenv-phases"/>.)
For instance, a package that doesn’t supply a makefile but instead has
to be compiled “manually” could be handled like this:
<programlisting>
stdenv.mkDerivation {
name = "fnord-4.5";
...
buildPhase = ''
gcc foo.c -o foo
'';
installPhase = ''
mkdir -p $out/bin
cp foo $out/bin
'';
}</programlisting>
(Note the use of <literal>''</literal>-style string literals, which
are very convenient for large multi-line script fragments because they
don’t need escaping of <literal>"</literal> and <literal>\</literal>,
and because indentation is intelligently removed.)</para>
<para>There are many other attributes to customise the build. These
are listed in <xref linkend="ssec-stdenv-attributes"/>.</para>
<para>While the standard environment provides a generic builder, you
can still supply your own build script:
<programlisting>
stdenv.mkDerivation {
name = "libfoo-1.2.3";
...
builder = ./builder.sh;
}</programlisting>
where the builder can do anything it wants, but typically starts with
<programlisting>
source $stdenv/setup
</programlisting>
to let <literal>stdenv</literal> set up the environment (e.g., process
the <varname>buildInputs</varname>). If you want, you can still use
<literal>stdenv</literal>’s generic builder:
<programlisting>
source $stdenv/setup
buildPhase() {
echo "... this is my custom build phase ..."
gcc foo.c -o foo
}
installPhase() {
mkdir -p $out/bin
cp foo $out/bin
}
genericBuild
</programlisting>
</para>
</section>
<section xml:id="sec-tools-of-stdenv"><title>Tools provided by
<literal>stdenv</literal></title>
<para>The standard environment provides the following packages:
<itemizedlist>
<listitem><para>The GNU C Compiler, configured with C and C++
support.</para></listitem>
<listitem><para>GNU coreutils (contains a few dozen standard Unix
commands).</para></listitem>
<listitem><para>GNU findutils (contains
<command>find</command>).</para></listitem>
<listitem><para>GNU diffutils (contains <command>diff</command>,
<command>cmp</command>).</para></listitem>
<listitem><para>GNU <command>sed</command>.</para></listitem>
<listitem><para>GNU <command>grep</command>.</para></listitem>
<listitem><para>GNU <command>awk</command>.</para></listitem>
<listitem><para>GNU <command>tar</command>.</para></listitem>
<listitem><para><command>gzip</command>, <command>bzip2</command>
and <command>xz</command>.</para></listitem>
<listitem><para>GNU Make. It has been patched to provide
<quote>nested</quote> output that can be fed into the
<command>nix-log2xml</command> command and
<command>log2html</command> stylesheet to create a structured,
readable output of the build steps performed by
Make.</para></listitem>
<listitem><para>Bash. This is the shell used for all builders in
the Nix Packages collection. Not using <command>/bin/sh</command>
removes a large source of portability problems.</para></listitem>
<listitem><para>The <command>patch</command>
command.</para></listitem>
</itemizedlist>
</para>
<para>On Linux, <literal>stdenv</literal> also includes the
<command>patchelf</command> utility.</para>
</section>
<section xml:id="ssec-stdenv-attributes"><title>Attributes</title>
<variablelist>
<title>Variables affecting <literal>stdenv</literal>
initialisation</title>
<varlistentry>
<term><varname>NIX_DEBUG</varname></term>
<listitem><para>If set, <literal>stdenv</literal> will print some
debug information during the build. In particular, the
<command>gcc</command> and <command>ld</command> wrapper scripts
will print out the complete command line passed to the wrapped
tools.</para></listitem>
</varlistentry>
</variablelist>
<variablelist>
<title>Variables specifying dependencies</title>
<varlistentry>
<term><varname>nativeBuildInputs</varname></term>
<listitem><para>
A list of dependencies used by the new derivation at <emphasis>build</emphasis>-time.
I.e. these dependencies should not make it into the package's runtime-closure, though this is currently not checked.
For each dependency <replaceable>dir</replaceable>, the directory <filename><replaceable>dir</replaceable>/bin</filename>, if it exists, is added to the <envar>PATH</envar> environment variable.
Other environment variables are also set up via a pluggable mechanism.
For instance, if <varname>buildInputs</varname> contains Perl, then the <filename>lib/site_perl</filename> subdirectory of each input is added to the <envar>PERL5LIB</envar> environment variable.
See <xref linkend="ssec-setup-hooks"/> for details.
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>buildInputs</varname></term>
<listitem><para>
A list of dependencies used by the new derivation at <emphasis>run</emphasis>-time.
Currently, the build-time environment is modified in the exact same way as with <varname>nativeBuildInputs</varname>.
This is problematic in that when cross-compiling, foreign executables can clobber native ones on the <envar>PATH</envar>.
Even more confusing is static-linking.
A statically-linked library should be listed here because ultimately that generated machine code will be used at run-time, even though a derivation containing the object files or static archives will only be used at build-time.
A less confusing solution to this would be nice.
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>propagatedNativeBuildInputs</varname></term>
<listitem><para>
Like <varname>nativeBuildInputs</varname>, but these dependencies are <emphasis>propagated</emphasis>:
that is, the dependencies listed here are added to the <varname>nativeBuildInputs</varname> of any package that uses <emphasis>this</emphasis> package as a dependency.
So if package Y has <literal>propagatedBuildInputs = [X]</literal>, and package Z has <literal>buildInputs = [Y]</literal>, then package X will appear in Z’s build environment automatically.
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>propagatedBuildInputs</varname></term>
<listitem><para>
Like <varname>buildInputs</varname>, but propagated just like <varname>propagatedNativeBuildInputs</varname>.
This inherits <varname>buildInputs</varname>'s flaws of clobbering native executables when cross-compiling and being confusing for static linking.
</para></listitem>
</varlistentry>
</variablelist>
<variablelist>
<title>Variables affecting build properties</title>
<varlistentry>
<term><varname>enableParallelBuilding</varname></term>
<listitem><para>If set, <literal>stdenv</literal> will pass specific
flags to <literal>make</literal> and other build tools to enable
parallel building with up to <literal>build-cores</literal>
workers.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preferLocalBuild</varname></term>
<listitem><para>If set, specifies that the package is so lightweight
in terms of build operations (e.g. write a text file from a Nix string
to the store) that there's no need to look for it in binary caches --
it's faster to just build it locally. It also tells Hydra and other
facilities that this package doesn't need to be exported in binary
caches (noone would use it, after all).</para></listitem>
</varlistentry>
</variablelist>
<variablelist>
<title>Special variables</title>
<varlistentry>
<term><varname>passthru</varname></term>
<listitem><para>This is an attribute set which can be filled with arbitrary
values. For example:
<programlisting>
passthru = {
foo = "bar";
baz = {
value1 = 4;
value2 = 5;
};
}
</programlisting>
</para>
<para>Values inside it are not passed to the builder, so you can change
them without triggering a rebuild. However, they can be accessed outside of a
derivation directly, as if they were set inside a derivation itself, e.g.
<literal>hello.baz.value1</literal>. We don't specify any usage or
schema of <literal>passthru</literal> - it is meant for values that would be
useful outside the derivation in other parts of a Nix expression (e.g. in other
derivations). An example would be to convey some specific dependency of your
derivation which contains a program with plugins support. Later, others who
make derivations with plugins can use passed-through dependency to ensure that
their plugin would be binary-compatible with built program.</para></listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="sec-stdenv-phases"><title>Phases</title>
<para>The generic builder has a number of <emphasis>phases</emphasis>.
Package builds are split into phases to make it easier to override
specific parts of the build (e.g., unpacking the sources or installing
the binaries). Furthermore, it allows a nicer presentation of build
logs in the Nix build farm.</para>
<para>Each phase can be overridden in its entirety either by setting
the environment variable
<varname><replaceable>name</replaceable>Phase</varname> to a string
containing some shell commands to be executed, or by redefining the
shell function
<varname><replaceable>name</replaceable>Phase</varname>. The former
is convenient to override a phase from the derivation, while the
latter is convenient from a build script.</para>
<section xml:id="ssec-controlling-phases"><title>Controlling
phases</title>
<para>There are a number of variables that control what phases are
executed and in what order:
<variablelist>
<title>Variables affecting phase control</title>
<varlistentry>
<term><varname>phases</varname></term>
<listitem>
<para>Specifies the phases. You can change the order in which
phases are executed, or add new phases, by setting this
variable. If it’s not set, the default value is used, which is
<literal>$prePhases unpackPhase patchPhase $preConfigurePhases
configurePhase $preBuildPhases buildPhase checkPhase
$preInstallPhases installPhase fixupPhase $preDistPhases
distPhase $postPhases</literal>.
</para>
<para>Usually, if you just want to add a few phases, it’s more
convenient to set one of the variables below (such as
<varname>preInstallPhases</varname>), as you then don’t specify
all the normal phases.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>prePhases</varname></term>
<listitem>
<para>Additional phases executed before any of the default phases.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>preConfigurePhases</varname></term>
<listitem>
<para>Additional phases executed just before the configure phase.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>preBuildPhases</varname></term>
<listitem>
<para>Additional phases executed just before the build phase.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>preInstallPhases</varname></term>
<listitem>
<para>Additional phases executed just before the install phase.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>preFixupPhases</varname></term>
<listitem>
<para>Additional phases executed just before the fixup phase.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>preDistPhases</varname></term>
<listitem>
<para>Additional phases executed just before the distribution phase.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>postPhases</varname></term>
<listitem>
<para>Additional phases executed after any of the default
phases.</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</section>
<section xml:id="ssec-unpack-phase"><title>The unpack phase</title>
<para>The unpack phase is responsible for unpacking the source code of
the package. The default implementation of
<function>unpackPhase</function> unpacks the source files listed in
the <envar>src</envar> environment variable to the current directory.
It supports the following files by default:
<variablelist>
<varlistentry>
<term>Tar files</term>
<listitem><para>These can optionally be compressed using
<command>gzip</command> (<filename>.tar.gz</filename>,
<filename>.tgz</filename> or <filename>.tar.Z</filename>),
<command>bzip2</command> (<filename>.tar.bz2</filename> or
<filename>.tbz2</filename>) or <command>xz</command>
(<filename>.tar.xz</filename> or
<filename>.tar.lzma</filename>).</para></listitem>
</varlistentry>
<varlistentry>
<term>Zip files</term>
<listitem><para>Zip files are unpacked using
<command>unzip</command>. However, <command>unzip</command> is
not in the standard environment, so you should add it to
<varname>buildInputs</varname> yourself.</para></listitem>
</varlistentry>
<varlistentry>
<term>Directories in the Nix store</term>
<listitem><para>These are simply copied to the current directory.
The hash part of the file name is stripped,
e.g. <filename>/nix/store/1wydxgby13cz...-my-sources</filename>
would be copied to
<filename>my-sources</filename>.</para></listitem>
</varlistentry>
</variablelist>
Additional file types can be supported by setting the
<varname>unpackCmd</varname> variable (see below).</para>
<para></para>
<variablelist>
<title>Variables controlling the unpack phase</title>
<varlistentry>
<term><varname>srcs</varname> / <varname>src</varname></term>
<listitem><para>The list of source files or directories to be
unpacked or copied. One of these must be set.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>sourceRoot</varname></term>
<listitem><para>After running <function>unpackPhase</function>,
the generic builder changes the current directory to the directory
created by unpacking the sources. If there are multiple source
directories, you should set <varname>sourceRoot</varname> to the
name of the intended directory.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>setSourceRoot</varname></term>
<listitem><para>Alternatively to setting
<varname>sourceRoot</varname>, you can set
<varname>setSourceRoot</varname> to a shell command to be
evaluated by the unpack phase after the sources have been
unpacked. This command must set
<varname>sourceRoot</varname>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preUnpack</varname></term>
<listitem><para>Hook executed at the start of the unpack
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postUnpack</varname></term>
<listitem><para>Hook executed at the end of the unpack
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontMakeSourcesWritable</varname></term>
<listitem><para>If set to <literal>1</literal>, the unpacked
sources are <emphasis>not</emphasis> made
writable. By default, they are made writable to prevent problems
with read-only sources. For example, copied store directories
would be read-only without this.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>unpackCmd</varname></term>
<listitem><para>The unpack phase evaluates the string
<literal>$unpackCmd</literal> for any unrecognised file. The path
to the current source file is contained in the
<varname>curSrc</varname> variable.</para></listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="ssec-patch-phase"><title>The patch phase</title>
<para>The patch phase applies the list of patches defined in the
<varname>patches</varname> variable.</para>
<variablelist>
<title>Variables controlling the patch phase</title>
<varlistentry>
<term><varname>patches</varname></term>
<listitem><para>The list of patches. They must be in the format
accepted by the <command>patch</command> command, and may
optionally be compressed using <command>gzip</command>
(<filename>.gz</filename>), <command>bzip2</command>
(<filename>.bz2</filename>) or <command>xz</command>
(<filename>.xz</filename>).</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>patchFlags</varname></term>
<listitem><para>Flags to be passed to <command>patch</command>.
If not set, the argument <option>-p1</option> is used, which
causes the leading directory component to be stripped from the
file names in each patch.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>prePatch</varname></term>
<listitem><para>Hook executed at the start of the patch
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postPatch</varname></term>
<listitem><para>Hook executed at the end of the patch
phase.</para></listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="ssec-configure-phase"><title>The configure phase</title>
<para>The configure phase prepares the source tree for building. The
default <function>configurePhase</function> runs
<filename>./configure</filename> (typically an Autoconf-generated
script) if it exists.</para>
<variablelist>
<title>Variables controlling the configure phase</title>
<varlistentry>
<term><varname>configureScript</varname></term>
<listitem><para>The name of the configure script. It defaults to
<filename>./configure</filename> if it exists; otherwise, the
configure phase is skipped. This can actually be a command (like
<literal>perl ./Configure.pl</literal>).</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>configureFlags</varname></term>
<listitem><para>A list of strings passed as additional arguments to the
configure script.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>configureFlagsArray</varname></term>
<listitem><para>A shell array containing additional arguments
passed to the configure script. You must use this instead of
<varname>configureFlags</varname> if the arguments contain
spaces.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontAddPrefix</varname></term>
<listitem><para>By default, the flag
<literal>--prefix=$prefix</literal> is added to the configure
flags. If this is undesirable, set this variable to
true.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>prefix</varname></term>
<listitem><para>The prefix under which the package must be
installed, passed via the <option>--prefix</option> option to the
configure script. It defaults to
<option>$out</option>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontAddDisableDepTrack</varname></term>
<listitem><para>By default, the flag
<literal>--disable-dependency-tracking</literal> is added to the
configure flags to speed up Automake-based builds. If this is
undesirable, set this variable to true.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontFixLibtool</varname></term>
<listitem><para>By default, the configure phase applies some
special hackery to all files called <filename>ltmain.sh</filename>
before running the configure script in order to improve the purity
of Libtool-based packages<footnote><para>It clears the
<varname>sys_lib_<replaceable>*</replaceable>search_path</varname>
variables in the Libtool script to prevent Libtool from using
libraries in <filename>/usr/lib</filename> and
such.</para></footnote>. If this is undesirable, set this
variable to true.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontDisableStatic</varname></term>
<listitem><para>By default, when the configure script has
<option>--enable-static</option>, the option
<option>--disable-static</option> is added to the configure flags.</para>
<para>If this is undesirable, set this variable to
true.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preConfigure</varname></term>
<listitem><para>Hook executed at the start of the configure
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postConfigure</varname></term>
<listitem><para>Hook executed at the end of the configure
phase.</para></listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="build-phase"><title>The build phase</title>
<para>The build phase is responsible for actually building the package
(e.g. compiling it). The default <function>buildPhase</function>
simply calls <command>make</command> if a file named
<filename>Makefile</filename>, <filename>makefile</filename> or
<filename>GNUmakefile</filename> exists in the current directory (or
the <varname>makefile</varname> is explicitly set); otherwise it does
nothing.</para>
<variablelist>
<title>Variables controlling the build phase</title>
<varlistentry>
<term><varname>dontBuild</varname></term>
<listitem><para>Set to true to skip the build phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>makefile</varname></term>
<listitem><para>The file name of the Makefile.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>makeFlags</varname></term>
<listitem><para>A list of strings passed as additional flags to
<command>make</command>. These flags are also used by the default
install and check phase. For setting make flags specific to the
build phase, use <varname>buildFlags</varname> (see
below).</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>makeFlagsArray</varname></term>
<listitem><para>A shell array containing additional arguments
passed to <command>make</command>. You must use this instead of
<varname>makeFlags</varname> if the arguments contain
spaces, e.g.
<programlisting>
makeFlagsArray=(CFLAGS="-O0 -g" LDFLAGS="-lfoo -lbar")
</programlisting>
Note that shell arrays cannot be passed through environment
variables, so you cannot set <varname>makeFlagsArray</varname> in
a derivation attribute (because those are passed through
environment variables): you have to define them in shell
code.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>buildFlags</varname> / <varname>buildFlagsArray</varname></term>
<listitem><para>A list of strings passed as additional flags to
<command>make</command>. Like <varname>makeFlags</varname> and
<varname>makeFlagsArray</varname>, but only used by the build
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preBuild</varname></term>
<listitem><para>Hook executed at the start of the build
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postBuild</varname></term>
<listitem><para>Hook executed at the end of the build
phase.</para></listitem>
</varlistentry>
</variablelist>
<para>
You can set flags for <command>make</command> through the
<varname>makeFlags</varname> variable.</para>
<para>Before and after running <command>make</command>, the hooks
<varname>preBuild</varname> and <varname>postBuild</varname> are
called, respectively.</para>
</section>
<section xml:id="ssec-check-phase"><title>The check phase</title>
<para>The check phase checks whether the package was built correctly
by running its test suite. The default
<function>checkPhase</function> calls <command>make check</command>,
but only if the <varname>doCheck</varname> variable is enabled.</para>
<variablelist>
<title>Variables controlling the check phase</title>
<varlistentry>
<term><varname>doCheck</varname></term>
<listitem><para>If set to a non-empty string, the check phase is
executed, otherwise it is skipped (default). Thus you should set
<programlisting>
doCheck = true;</programlisting>
in the derivation to enable checks.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>makeFlags</varname> /
<varname>makeFlagsArray</varname> /
<varname>makefile</varname></term>
<listitem><para>See the build phase for details.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>checkTarget</varname></term>
<listitem><para>The make target that runs the tests. Defaults to
<literal>check</literal>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>checkFlags</varname> / <varname>checkFlagsArray</varname></term>
<listitem><para>A list of strings passed as additional flags to
<command>make</command>. Like <varname>makeFlags</varname> and
<varname>makeFlagsArray</varname>, but only used by the check
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preCheck</varname></term>
<listitem><para>Hook executed at the start of the check
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postCheck</varname></term>
<listitem><para>Hook executed at the end of the check
phase.</para></listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="ssec-install-phase"><title>The install phase</title>
<para>The install phase is responsible for installing the package in
the Nix store under <envar>out</envar>. The default
<function>installPhase</function> creates the directory
<literal>$out</literal> and calls <command>make
install</command>.</para>
<variablelist>
<title>Variables controlling the install phase</title>
<varlistentry>
<term><varname>makeFlags</varname> /
<varname>makeFlagsArray</varname> /
<varname>makefile</varname></term>
<listitem><para>See the build phase for details.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>installTargets</varname></term>
<listitem><para>The make targets that perform the installation.
Defaults to <literal>install</literal>. Example:
<programlisting>
installTargets = "install-bin install-doc";</programlisting>
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>installFlags</varname> / <varname>installFlagsArray</varname></term>
<listitem><para>A list of strings passed as additional flags to
<command>make</command>. Like <varname>makeFlags</varname> and
<varname>makeFlagsArray</varname>, but only used by the install
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preInstall</varname></term>
<listitem><para>Hook executed at the start of the install
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postInstall</varname></term>
<listitem><para>Hook executed at the end of the install
phase.</para></listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="ssec-fixup-phase"><title>The fixup phase</title>
<para>The fixup phase performs some (Nix-specific) post-processing
actions on the files installed under <filename>$out</filename> by the
install phase. The default <function>fixupPhase</function> does the
following:
<itemizedlist>
<listitem><para>It moves the <filename>man/</filename>,
<filename>doc/</filename> and <filename>info/</filename>
subdirectories of <envar>$out</envar> to
<filename>share/</filename>.</para></listitem>
<listitem><para>It strips libraries and executables of debug
information.</para></listitem>
<listitem><para>On Linux, it applies the <command>patchelf</command>
command to ELF executables and libraries to remove unused
directories from the <literal>RPATH</literal> in order to prevent
unnecessary runtime dependencies.</para></listitem>
<listitem><para>It rewrites the interpreter paths of shell scripts
to paths found in <envar>PATH</envar>. E.g.,
<filename>/usr/bin/perl</filename> will be rewritten to
<filename>/nix/store/<replaceable>some-perl</replaceable>/bin/perl</filename>
found in <envar>PATH</envar>.</para></listitem>
</itemizedlist>
</para>
<variablelist>
<title>Variables controlling the fixup phase</title>
<varlistentry>
<term><varname>dontStrip</varname></term>
<listitem><para>If set, libraries and executables are not
stripped. By default, they are.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontMoveSbin</varname></term>
<listitem><para>If set, files in <filename>$out/sbin</filename> are not moved
to <filename>$out/bin</filename>. By default, they are.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>stripAllList</varname></term>
<listitem><para>List of directories to search for libraries and
executables from which <emphasis>all</emphasis> symbols should be
stripped. By default, it’s empty. Stripping all symbols is
risky, since it may remove not just debug symbols but also ELF
information necessary for normal execution.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>stripAllFlags</varname></term>
<listitem><para>Flags passed to the <command>strip</command>
command applied to the files in the directories listed in
<varname>stripAllList</varname>. Defaults to <option>-s</option>
(i.e. <option>--strip-all</option>).</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>stripDebugList</varname></term>
<listitem><para>List of directories to search for libraries and
executables from which only debugging-related symbols should be
stripped. It defaults to <literal>lib bin
sbin</literal>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>stripDebugFlags</varname></term>
<listitem><para>Flags passed to the <command>strip</command>
command applied to the files in the directories listed in
<varname>stripDebugList</varname>. Defaults to
<option>-S</option>
(i.e. <option>--strip-debug</option>).</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontPatchELF</varname></term>
<listitem><para>If set, the <command>patchelf</command> command is
not used to remove unnecessary <literal>RPATH</literal> entries.
Only applies to Linux.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>dontPatchShebangs</varname></term>
<listitem><para>If set, scripts starting with
<literal>#!</literal> do not have their interpreter paths
rewritten to paths in the Nix store.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>forceShare</varname></term>
<listitem><para>The list of directories that must be moved from
<filename>$out</filename> to <filename>$out/share</filename>.
Defaults to <literal>man doc info</literal>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>setupHook</varname></term>
<listitem><para>A package can export a <link
linkend="ssec-setup-hooks">setup hook</link> by setting this
variable. The setup hook, if defined, is copied to
<filename>$out/nix-support/setup-hook</filename>. Environment
variables are then substituted in it using <function
linkend="fun-substituteAll">substituteAll</function>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>preFixup</varname></term>
<listitem><para>Hook executed at the start of the fixup
phase.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>postFixup</varname></term>
<listitem><para>Hook executed at the end of the fixup
phase.</para></listitem>
</varlistentry>
<varlistentry xml:id="stdenv-separateDebugInfo">
<term><varname>separateDebugInfo</varname></term>
<listitem><para>If set to <literal>true</literal>, the standard
environment will enable debug information in C/C++ builds. After
installation, the debug information will be separated from the
executables and stored in the output named
<literal>debug</literal>. (This output is enabled automatically;
you don’t need to set the <varname>outputs</varname> attribute
explicitly.) To be precise, the debug information is stored in
<filename><replaceable>debug</replaceable>/lib/debug/.build-id/<replaceable>XX</replaceable>/<replaceable>YYYY…</replaceable></filename>,
where <replaceable>XXYYYY…</replaceable> is the <replaceable>build
ID</replaceable> of the binary — a SHA-1 hash of the contents of
the binary. Debuggers like GDB use the build ID to look up the
separated debug information.</para>
<para>For example, with GDB, you can add
<programlisting>
set debug-file-directory ~/.nix-profile/lib/debug
</programlisting>
to <filename>~/.gdbinit</filename>. GDB will then be able to find
debug information installed via <literal>nix-env