aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/manual.xmli
blob: 241eef2cc799e731752daa9de14a5fe01399b7c6 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
<?xml version="1.0"?>
<book xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0">

  <info>
    <title>Nix Package Manager Guide</title>
    <subtitle>Version 3.0</subtitle>

    <author>
      <personname>
        <firstname>Eelco</firstname>
        <surname>Dolstra</surname>
      </personname>
      <contrib>Author</contrib>
    </author>

    <copyright>
      <year>2004-2018</year>
      <holder>Eelco Dolstra</holder>
    </copyright>

  </info>

  <!--
  <preface>
    <title>Preface</title>
    <para>This manual describes how to set up and use the Nix package
    manager.</para>
  </preface>
  -->

  <part xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-introduction" xml:base="introduction/introduction.xml">

<title>Introduction</title>

<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-about-nix">

<title>About Nix</title>

<para>Nix is a <emphasis>purely functional package manager</emphasis>.
This means that it treats packages like values in purely functional
programming languages such as Haskell &#x2014; they are built by functions
that don&#x2019;t have side-effects, and they never change after they have
been built.  Nix stores packages in the <emphasis>Nix
store</emphasis>, usually the directory
<filename>/nix/store</filename>, where each package has its own unique
subdirectory such as

<programlisting>
/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-33.1/
</programlisting>

where <literal>b6gvzjyb2pg0&#x2026;</literal> is a unique identifier for the
package that captures all its dependencies (it&#x2019;s a cryptographic hash
of the package&#x2019;s build dependency graph).  This enables many powerful
features.</para>


<simplesect><title>Multiple versions</title>

<para>You can have multiple versions or variants of a package
installed at the same time.  This is especially important when
different applications have dependencies on different versions of the
same package &#x2014; it prevents the &#x201C;DLL hell&#x201D;.  Because of the hashing
scheme, different versions of a package end up in different paths in
the Nix store, so they don&#x2019;t interfere with each other.</para>

<para>An important consequence is that operations like upgrading or
uninstalling an application cannot break other applications, since
these operations never &#x201C;destructively&#x201D; update or delete files that are
used by other packages.</para>

</simplesect>


<simplesect><title>Complete dependencies</title>

<para>Nix helps you make sure that package dependency specifications
are complete.  In general, when you&#x2019;re making a package for a package
management system like RPM, you have to specify for each package what
its dependencies are, but there are no guarantees that this
specification is complete.  If you forget a dependency, then the
package will build and work correctly on <emphasis>your</emphasis>
machine if you have the dependency installed, but not on the end
user's machine if it's not there.</para>

<para>Since Nix on the other hand doesn&#x2019;t install packages in &#x201C;global&#x201D;
locations like <filename>/usr/bin</filename> but in package-specific
directories, the risk of incomplete dependencies is greatly reduced.
This is because tools such as compilers don&#x2019;t search in per-packages
directories such as
<filename>/nix/store/5lbfaxb722zp&#x2026;-openssl-0.9.8d/include</filename>,
so if a package builds correctly on your system, this is because you
specified the dependency explicitly. This takes care of the build-time
dependencies.</para>

<para>Once a package is built, runtime dependencies are found by
scanning binaries for the hash parts of Nix store paths (such as
<literal>r8vvq9kq&#x2026;</literal>).  This sounds risky, but it works
extremely well.</para>

</simplesect>


<simplesect><title>Multi-user support</title>

<para>Nix has multi-user support.  This means that non-privileged
users can securely install software.  Each user can have a different
<emphasis>profile</emphasis>, a set of packages in the Nix store that
appear in the user&#x2019;s <envar>PATH</envar>.  If a user installs a
package that another user has already installed previously, the
package won&#x2019;t be built or downloaded a second time.  At the same time,
it is not possible for one user to inject a Trojan horse into a
package that might be used by another user.</para>

</simplesect>


<simplesect><title>Atomic upgrades and rollbacks</title>

<para>Since package management operations never overwrite packages in
the Nix store but just add new versions in different paths, they are
<emphasis>atomic</emphasis>.  So during a package upgrade, there is no
time window in which the package has some files from the old version
and some files from the new version &#x2014; which would be bad because a
program might well crash if it&#x2019;s started during that period.</para>

<para>And since packages aren&#x2019;t overwritten, the old versions are still
there after an upgrade.  This means that you can <emphasis>roll
back</emphasis> to the old version:</para>

<screen>
$ nix-env --upgrade <replaceable>some-packages</replaceable>
$ nix-env --rollback
</screen>

</simplesect>


<simplesect><title>Garbage collection</title>

<para>When you uninstall a package like this&#x2026;

<screen>
$ nix-env --uninstall firefox
</screen>

the package isn&#x2019;t deleted from the system right away (after all, you
might want to do a rollback, or it might be in the profiles of other
users).  Instead, unused packages can be deleted safely by running the
<emphasis>garbage collector</emphasis>:

<screen>
$ nix-collect-garbage
</screen>

This deletes all packages that aren&#x2019;t in use by any user profile or by
a currently running program.</para>

</simplesect>


<simplesect><title>Functional package language</title>

<para>Packages are built from <emphasis>Nix expressions</emphasis>,
which is a simple functional language.  A Nix expression describes
everything that goes into a package build action (a &#x201C;derivation&#x201D;):
other packages, sources, the build script, environment variables for
the build script, etc.  Nix tries very hard to ensure that Nix
expressions are <emphasis>deterministic</emphasis>: building a Nix
expression twice should yield the same result.</para>

<para>Because it&#x2019;s a functional language, it&#x2019;s easy to support
building variants of a package: turn the Nix expression into a
function and call it any number of times with the appropriate
arguments.  Due to the hashing scheme, variants don&#x2019;t conflict with
each other in the Nix store.</para>

</simplesect>


<simplesect><title>Transparent source/binary deployment</title>

<para>Nix expressions generally describe how to build a package from
source, so an installation action like

<screen>
$ nix-env --install firefox
</screen>

<emphasis>could</emphasis> cause quite a bit of build activity, as not
only Firefox but also all its dependencies (all the way up to the C
library and the compiler) would have to built, at least if they are
not already in the Nix store.  This is a <emphasis>source deployment
model</emphasis>.  For most users, building from source is not very
pleasant as it takes far too long.  However, Nix can automatically
skip building from source and instead use a <emphasis>binary
cache</emphasis>, a web server that provides pre-built binaries. For
instance, when asked to build
<literal>/nix/store/b6gvzjyb2pg0&#x2026;-firefox-33.1</literal> from source,
Nix would first check if the file
<uri>https://cache.nixos.org/b6gvzjyb2pg0&#x2026;.narinfo</uri> exists, and
if so, fetch the pre-built binary referenced from there; otherwise, it
would fall back to building from source.</para>

</simplesect>


<!--
<simplesect><title>Binary patching</title>

<para>In addition to downloading binaries automatically if they’re
available, Nix can download binary deltas that patch an existing
package in the Nix store into a new version.  This speeds up
upgrades.</para>

</simplesect>
-->


<simplesect><title>Nix Packages collection</title>

<para>We provide a large set of Nix expressions containing hundreds of
existing Unix packages, the <emphasis>Nix Packages
collection</emphasis> (Nixpkgs).</para>

</simplesect>


<simplesect><title>Managing build environments</title>

<para>Nix is extremely useful for developers as it makes it easy to
automatically set up the build environment for a package. Given a
Nix expression that describes the dependencies of your package, the
command <command>nix-shell</command> will build or download those
dependencies if they&#x2019;re not already in your Nix store, and then start
a Bash shell in which all necessary environment variables (such as
compiler search paths) are set.</para>

<para>For example, the following command gets all dependencies of the
Pan newsreader, as described by <link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix">its
Nix expression</link>:</para>

<screen>
$ nix-shell '&lt;nixpkgs&gt;' -A pan
</screen>

<para>You&#x2019;re then dropped into a shell where you can edit, build and test
the package:</para>

<screen>
[nix-shell]$ tar xf $src
[nix-shell]$ cd pan-*
[nix-shell]$ ./configure
[nix-shell]$ make
[nix-shell]$ ./pan/gui/pan
</screen>

<!--
<para>Since Nix packages are reproducible and have complete dependency
specifications, Nix makes an excellent basis for <a
href="[%root%]hydra">a continuous build system</a>.</para>
-->

</simplesect>


<simplesect><title>Portability</title>

<para>Nix runs on Linux and macOS.</para>

</simplesect>


<simplesect><title>NixOS</title>

<para>NixOS is a Linux distribution based on Nix.  It uses Nix not
just for package management but also to manage the system
configuration (e.g., to build configuration files in
<filename>/etc</filename>).  This means, among other things, that it
is easy to roll back the entire configuration of the system to an
earlier state.  Also, users can install software without root
privileges.  For more information and downloads, see the <link xlink:href="http://nixos.org/">NixOS homepage</link>.</para>

</simplesect>


<simplesect><title>License</title>

<para>Nix is released under the terms of the <link xlink:href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">GNU
LGPLv2.1 or (at your option) any later version</link>.</para>

</simplesect>


</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-quick-start">

<title>Quick Start</title>

<para>This chapter is for impatient people who don't like reading
documentation.  For more in-depth information you are kindly referred
to subsequent chapters.</para>

<procedure>

<step><para>Install single-user Nix by running the following:

<screen>
$ bash &lt;(curl -L https://nixos.org/nix/install)
</screen>

This will install Nix in <filename>/nix</filename>. The install script
will create <filename>/nix</filename> using <command>sudo</command>,
so make sure you have sufficient rights.  (For other installation
methods, see <xref linkend="chap-installation"/>.)</para></step>

<step><para>See what installable packages are currently available
in the channel:

<screen>
$ nix-env -qa
docbook-xml-4.3
docbook-xml-4.5
firefox-33.0.2
hello-2.9
libxslt-1.1.28
<replaceable>...</replaceable></screen>

</para></step>

<step><para>Install some packages from the channel:

<screen>
$ nix-env -i hello</screen>

This should download pre-built packages; it should not build them
locally (if it does, something went wrong).</para></step>

<step><para>Test that they work:

<screen>
$ which hello
/home/eelco/.nix-profile/bin/hello
$ hello
Hello, world!
</screen>

</para></step>

<step><para>Uninstall a package:

<screen>
$ nix-env -e hello</screen>

</para></step>

<step><para>You can also test a package without installing it:

<screen>
$ nix-shell -p hello
</screen>

This builds or downloads GNU Hello and its dependencies, then drops
you into a Bash shell where the <command>hello</command> command is
present, all without affecting your normal environment:

<screen>
[nix-shell:~]$ hello
Hello, world!

[nix-shell:~]$ exit

$ hello
hello: command not found
</screen>

</para></step>

<step><para>To keep up-to-date with the channel, do:

<screen>
$ nix-channel --update nixpkgs
$ nix-env -u '*'</screen>

The latter command will upgrade each installed package for which there
is a &#x201C;newer&#x201D; version (as determined by comparing the version
numbers).</para></step>

<step><para>If you're unhappy with the result of a
<command>nix-env</command> action (e.g., an upgraded package turned
out not to work properly), you can go back:

<screen>
$ nix-env --rollback</screen>

</para></step>

<step><para>You should periodically run the Nix garbage collector
to get rid of unused packages, since uninstalls or upgrades don't
actually delete them:

<screen>
$ nix-collect-garbage -d</screen>

<!--
The first command deletes old “generations” of your profile (making
rollbacks impossible, but also making the packages in those old
generations available for garbage collection), while the second
command actually deletes them.-->

</para></step>

</procedure>

</chapter>

</part>
  <part xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-installation" xml:base="installation/installation.xml">

<title>Installation</title>

<partintro>
<para>This section describes how to install and configure Nix for first-time use.</para>
</partintro>

<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-supported-platforms">

<title>Supported Platforms</title>

<para>Nix is currently supported on the following platforms:

<itemizedlist>

  <listitem><para>Linux (i686, x86_64, aarch64).</para></listitem>

  <listitem><para>macOS (x86_64).</para></listitem>

  <!--
  <listitem><para>FreeBSD (only tested on Intel).</para></listitem>
  -->

  <!--
  <listitem><para>Windows through <link
  xlink:href="http://www.cygwin.com/">Cygwin</link>.</para>

  <warning><para>On Cygwin, Nix <emphasis>must</emphasis> be installed
  on an NTFS partition.  It will not work correctly on a FAT
  partition.</para></warning>

  </listitem>
  -->

</itemizedlist>

</para>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-installing-binary">

<title>Installing a Binary Distribution</title>

<para>
  If you are using Linux or macOS versions up to 10.14 (Mojave), the
  easiest way to install Nix is to run the following command:
</para>

<screen>
  $ sh &lt;(curl -L https://nixos.org/nix/install)
</screen>

<para>
  If you're using macOS 10.15 (Catalina) or newer, consult
  <link linkend="sect-macos-installation">the macOS installation instructions</link>
  before installing.
</para>

<para>
  As of Nix 2.1.0, the Nix installer will always default to creating a
  single-user installation, however opting in to the multi-user
  installation is highly recommended.
  <!-- TODO: this explains *neither* why the default version is
  single-user, nor why we'd recommend multi-user over the default.
  True prospective users don't have much basis for evaluating this.
  What's it to me? Who should pick which? Why? What if I pick wrong?
  -->
</para>

<section xml:id="sect-single-user-installation">
  <title>Single User Installation</title>

  <para>
    To explicitly select a single-user installation on your system:

    <screen>
  sh &lt;(curl -L https://nixos.org/nix/install) --no-daemon
</screen>
  </para>

<para>
This will perform a single-user installation of Nix, meaning that
<filename>/nix</filename> is owned by the invoking user.  You should
run this under your usual user account, <emphasis>not</emphasis> as
root.  The script will invoke <command>sudo</command> to create
<filename>/nix</filename> if it doesn&#x2019;t already exist.  If you don&#x2019;t
have <command>sudo</command>, you should manually create
<filename>/nix</filename> first as root, e.g.:

<screen>
$ mkdir /nix
$ chown alice /nix
</screen>

The install script will modify the first writable file from amongst
<filename>.bash_profile</filename>, <filename>.bash_login</filename>
and <filename>.profile</filename> to source
<filename>~/.nix-profile/etc/profile.d/nix.sh</filename>. You can set
the <envar>NIX_INSTALLER_NO_MODIFY_PROFILE</envar> environment
variable before executing the install script to disable this
behaviour.
</para>


<para>You can uninstall Nix simply by running:

<screen>
$ rm -rf /nix
</screen>

</para>
</section>

<section xml:id="sect-multi-user-installation">
  <title>Multi User Installation</title>
  <para>
    The multi-user Nix installation creates system users, and a system
    service for the Nix daemon.
  </para>

  <itemizedlist>
    <title>Supported Systems</title>

    <listitem>
      <para>Linux running systemd, with SELinux disabled</para>
    </listitem>
    <listitem><para>macOS</para></listitem>
  </itemizedlist>

  <para>
    You can instruct the installer to perform a multi-user
    installation on your system:
  </para>

  <screen>sh &lt;(curl -L https://nixos.org/nix/install) --daemon</screen>

  <para>
    The multi-user installation of Nix will create build users between
    the user IDs 30001 and 30032, and a group with the group ID 30000.

    You should run this under your usual user account,
    <emphasis>not</emphasis> as root. The script will invoke
    <command>sudo</command> as needed.
  </para>

  <note><para>
    If you need Nix to use a different group ID or user ID set, you
    will have to download the tarball manually and <link linkend="sect-nix-install-binary-tarball">edit the install
    script</link>.
  </para></note>

  <para>
    The installer will modify <filename>/etc/bashrc</filename>, and
    <filename>/etc/zshrc</filename> if they exist. The installer will
    first back up these files with a
    <literal>.backup-before-nix</literal> extension. The installer
    will also create <filename>/etc/profile.d/nix.sh</filename>.
  </para>

  <para>You can uninstall Nix with the following commands:

<screen>
sudo rm -rf /etc/profile/nix.sh /etc/nix /nix ~root/.nix-profile ~root/.nix-defexpr ~root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels

# If you are on Linux with systemd, you will need to run:
sudo systemctl stop nix-daemon.socket
sudo systemctl stop nix-daemon.service
sudo systemctl disable nix-daemon.socket
sudo systemctl disable nix-daemon.service
sudo systemctl daemon-reload

# If you are on macOS, you will need to run:
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
</screen>

    There may also be references to Nix in
    <filename>/etc/profile</filename>,
    <filename>/etc/bashrc</filename>, and
    <filename>/etc/zshrc</filename> which you may remove.
  </para>

</section>

<section xml:id="sect-macos-installation">
  <title>macOS Installation</title>

  <para>
    Starting with macOS 10.15 (Catalina), the root filesystem is read-only.
    This means <filename>/nix</filename> can no longer live on your system
    volume, and that you'll need a workaround to install Nix.
  </para>

  <para>
    The recommended approach, which creates an unencrypted APFS volume
    for your Nix store and a "synthetic" empty directory to mount it
    over at <filename>/nix</filename>, is least likely to impair Nix
    or your system.
  </para>

  <note><para>
    With all separate-volume approaches, it's possible something on
    your system (particularly daemons/services and restored apps) may
    need access to your Nix store before the volume is mounted. Adding
    additional encryption makes this more likely.
  </para></note>

  <para>
    If you're using a recent Mac with a
    <link xlink:href="https://www.apple.com/euro/mac/shared/docs/Apple_T2_Security_Chip_Overview.pdf">T2 chip</link>,
    your drive will still be encrypted at rest (in which case "unencrypted"
    is a bit of a misnomer). To use this approach, just install Nix with:
  </para>

  <screen>$ sh &lt;(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume</screen>

  <para>
    If you don't like the sound of this, you'll want to weigh the
    other approaches and tradeoffs detailed in this section.
  </para>

  <note>
    <title>Eventual solutions?</title>
    <para>
      All of the known workarounds have drawbacks, but we hope
      better solutions will be available in the future. Some that
      we have our eye on are:
    </para>
    <orderedlist>
      <listitem>
        <para>
          A true firmlink would enable the Nix store to live on the
          primary data volume without the build problems caused by
          the symlink approach. End users cannot currently
          create true firmlinks.
        </para>
      </listitem>
      <listitem>
        <para>
          If the Nix store volume shared FileVault encryption
          with the primary data volume (probably by using the same
          volume group and role), FileVault encryption could be
          easily supported by the installer without requiring
          manual setup by each user.
        </para>
      </listitem>
    </orderedlist>
  </note>

  <section xml:id="sect-macos-installation-change-store-prefix">
    <title>Change the Nix store path prefix</title>
    <para>
      Changing the default prefix for the Nix store is a simple
      approach which enables you to leave it on your root volume,
      where it can take full advantage of FileVault encryption if
      enabled. Unfortunately, this approach also opts your device out
      of some benefits that are enabled by using the same prefix
      across systems:

      <itemizedlist>
        <listitem>
          <para>
            Your system won't be able to take advantage of the binary
            cache (unless someone is able to stand up and support
            duplicate caching infrastructure), which means you'll
            spend more time waiting for builds.
          </para>
        </listitem>
        <listitem>
          <para>
            It's harder to build and deploy packages to Linux systems.
          </para>
        </listitem>
        <!-- TODO: may be more here -->
      </itemizedlist>

      <!-- TODO: Yes, but how?! -->

      It would also possible (and often requested) to just apply this
      change ecosystem-wide, but it's an intrusive process that has
      side effects we want to avoid for now.
      <!-- magnificent hand-wavy gesture -->
    </para>
    <para>
    </para>
  </section>

  <section xml:id="sect-macos-installation-encrypted-volume">
    <title>Use a separate encrypted volume</title>
    <para>
      If you like, you can also add encryption to the recommended
      approach taken by the installer. You can do this by pre-creating
      an encrypted volume before you run the installer--or you can
      run the installer and encrypt the volume it creates later.
      <!-- TODO: see later note about whether this needs both add-encryption and from-scratch directions -->
    </para>
    <para>
      In either case, adding encryption to a second volume isn't quite
      as simple as enabling FileVault for your boot volume. Before you
      dive in, there are a few things to weigh:
    </para>
    <orderedlist>
      <listitem>
        <para>
          The additional volume won't be encrypted with your existing
          FileVault key, so you'll need another mechanism to decrypt
          the volume.
        </para>
      </listitem>
      <listitem>
        <para>
          You can store the password in Keychain to automatically
          decrypt the volume on boot--but it'll have to wait on Keychain
          and may not mount before your GUI apps restore. If any of
          your launchd agents or apps depend on Nix-installed software
          (for example, if you use a Nix-installed login shell), the
          restore may fail or break.
        </para>
        <para>
          On a case-by-case basis, you may be able to work around this
          problem by using <command>wait4path</command> to block
          execution until your executable is available.
        </para>
        <para>
          It's also possible to decrypt and mount the volume earlier
          with a login hook--but this mechanism appears to be
          deprecated and its future is unclear.
        </para>
      </listitem>
      <listitem>
        <para>
          You can hard-code the password in the clear, so that your
          store volume can be decrypted before Keychain is available.
        </para>
      </listitem>
    </orderedlist>
    <para>
      If you are comfortable navigating these tradeoffs, you can encrypt the volume with
      something along the lines of:
      <!-- TODO:
      I don't know if this also needs from-scratch instructions?
      can we just recommend use-the-installer-and-then-encrypt?
      -->
    </para>
    <!--
    TODO: it looks like this option can be encryptVolume|encrypt|enableFileVault

    It may be more clear to use encryptVolume, here? FileVault seems
    heavily associated with the boot-volume behavior; I worry
    a little that it can mislead here, especially as it gets
    copied around minus doc context...?
    -->
    <screen>alice$ diskutil apfs enableFileVault /nix -user disk</screen>

    <!-- TODO: and then go into detail on the mount/decrypt approaches? -->
  </section>

  <section xml:id="sect-macos-installation-symlink">
    <!--
    Maybe a good razor is: if we'd hate having to support someone who
    installed Nix this way, it shouldn't even be detailed?
    -->
    <title>Symlink the Nix store to a custom location</title>
    <para>
      Another simple approach is using <filename>/etc/synthetic.conf</filename>
      to symlink the Nix store to the data volume. This option also
      enables your store to share any configured FileVault encryption.
      Unfortunately, builds that resolve the symlink may leak the
      canonical path or even fail.
    </para>
    <para>
      Because of these downsides, we can't recommend this approach.
    </para>
    <!-- Leaving out instructions for this one. -->
  </section>

  <section xml:id="sect-macos-installation-recommended-notes">
    <title>Notes on the recommended approach</title>
    <para>
      This section goes into a little more detail on the recommended
      approach. You don't need to understand it to run the installer,
      but it can serve as a helpful reference if you run into trouble.
    </para>
    <orderedlist>
      <listitem>
        <para>
          In order to compose user-writable locations into the new
          read-only system root, Apple introduced a new concept called
          <literal>firmlinks</literal>, which it describes as a
          "bi-directional wormhole" between two filesystems. You can
          see the current firmlinks in <filename>/usr/share/firmlinks</filename>.
          Unfortunately, firmlinks aren't (currently?) user-configurable.
        </para>

        <para>
          For special cases like NFS mount points or package manager roots,
          <link xlink:href="https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man5/synthetic.conf.5.html">synthetic.conf(5)</link>
          supports limited user-controlled file-creation (of symlinks,
          and synthetic empty directories) at <filename>/</filename>.
          To create a synthetic empty directory for mounting at <filename>/nix</filename>,
          add the following line to <filename>/etc/synthetic.conf</filename>
          (create it if necessary):
        </para>

        <screen>nix</screen>
      </listitem>

      <listitem>
        <para>
          This configuration is applied at boot time, but you can use
          <command>apfs.util</command> to trigger creation (not deletion)
          of new entries without a reboot:
        </para>

        <screen>alice$ /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B</screen>
      </listitem>

      <listitem>
        <para>
          Create the new APFS volume with diskutil:
        </para>

        <screen>alice$ sudo diskutil apfs addVolume diskX APFS 'Nix Store' -mountpoint /nix</screen>
      </listitem>

      <listitem>
        <para>
          Using <command>vifs</command>, add the new mount to
          <filename>/etc/fstab</filename>. If it doesn't already have
          other entries, it should look something like:
        </para>

<screen>
#
# Warning - this file should only be modified with vifs(8)
#
# Failure to do so is unsupported and may be destructive.
#
LABEL=Nix\040Store /nix apfs rw,nobrowse
</screen>

        <para>
          The nobrowse setting will keep Spotlight from indexing this
          volume, and keep it from showing up on your desktop.
        </para>
      </listitem>
    </orderedlist>
  </section>

</section>

<section xml:id="sect-nix-install-pinned-version-url">
  <title>Installing a pinned Nix version from a URL</title>

  <para>
    NixOS.org hosts version-specific installation URLs for all Nix
    versions since 1.11.16, at
    <literal>https://releases.nixos.org/nix/nix-<replaceable>version</replaceable>/install</literal>.
  </para>

  <para>
    These install scripts can be used the same as the main
  NixOS.org installation script:

  <screen>
  sh &lt;(curl -L https://nixos.org/nix/install)
</screen>
  </para>

  <para>
    In the same directory of the install script are sha256 sums, and
    gpg signature files.
  </para>
</section>

<section xml:id="sect-nix-install-binary-tarball">
  <title>Installing from a binary tarball</title>

  <para>
    You can also download a binary tarball that contains Nix and all
    its dependencies.  (This is what the install script at
    <uri>https://nixos.org/nix/install</uri> does automatically.)  You
    should unpack it somewhere (e.g. in <filename>/tmp</filename>),
    and then run the script named <command>install</command> inside
    the binary tarball:


<screen>
alice$ cd /tmp
alice$ tar xfj nix-1.8-x86_64-darwin.tar.bz2
alice$ cd nix-1.8-x86_64-darwin
alice$ ./install
</screen>
  </para>

  <para>
    If you need to edit the multi-user installation script to use
    different group ID or a different user ID range, modify the
    variables set in the file named
    <filename>install-multi-user</filename>.
  </para>
</section>
</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-installing-source">

<title>Installing Nix from Source</title>

<para>If no binary package is available, you can download and compile
a source distribution.</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-prerequisites-source">

<title>Prerequisites</title>

<itemizedlist>

  <listitem><para>GNU Autoconf
  (<link xlink:href="https://www.gnu.org/software/autoconf/"/>)
  and the autoconf-archive macro collection
  (<link xlink:href="https://www.gnu.org/software/autoconf-archive/"/>).
  These are only needed to run the bootstrap script, and are not necessary
  if your source distribution came with a pre-built
  <literal>./configure</literal> script.</para></listitem>

  <listitem><para>GNU Make.</para></listitem>
  
  <listitem><para>Bash Shell. The <literal>./configure</literal> script
  relies on bashisms, so Bash is required.</para></listitem>

  <listitem><para>A version of GCC or Clang that supports C++17.</para></listitem>

  <listitem><para><command>pkg-config</command> to locate
  dependencies.  If your distribution does not provide it, you can get
  it from <link xlink:href="http://www.freedesktop.org/wiki/Software/pkg-config"/>.</para></listitem>

  <listitem><para>The OpenSSL library to calculate cryptographic hashes.
  If your distribution does not provide it, you can get it from <link xlink:href="https://www.openssl.org"/>.</para></listitem>

  <listitem><para>The <literal>libbrotlienc</literal> and
  <literal>libbrotlidec</literal> libraries to provide implementation
  of the Brotli compression algorithm. They are available for download
  from the official repository <link xlink:href="https://github.com/google/brotli"/>.</para></listitem>

  <listitem><para>The bzip2 compressor program and the
  <literal>libbz2</literal> library.  Thus you must have bzip2
  installed, including development headers and libraries.  If your
  distribution does not provide these, you can obtain bzip2 from <link xlink:href="https://web.archive.org/web/20180624184756/http://www.bzip.org/"/>.</para></listitem>

  <listitem><para><literal>liblzma</literal>, which is provided by
  XZ Utils. If your distribution does not provide this, you can
  get it from <link xlink:href="https://tukaani.org/xz/"/>.</para></listitem>
  
  <listitem><para>cURL and its library. If your distribution does not
  provide it, you can get it from <link xlink:href="https://curl.haxx.se/"/>.</para></listitem>
      
  <listitem><para>The SQLite embedded database library, version 3.6.19
  or higher.  If your distribution does not provide it, please install
  it from <link xlink:href="http://www.sqlite.org/"/>.</para></listitem>

  <listitem><para>The <link xlink:href="http://www.hboehm.info/gc/">Boehm
  garbage collector</link> to reduce the evaluator&#x2019;s memory
  consumption (optional).  To enable it, install
  <literal>pkgconfig</literal> and the Boehm garbage collector, and
  pass the flag <option>--enable-gc</option> to
  <command>configure</command>.</para></listitem>

  <listitem><para>The <literal>boost</literal> library of version
  1.66.0 or higher. It can be obtained from the official web site
  <link xlink:href="https://www.boost.org/"/>.</para></listitem>

  <listitem><para>The <literal>editline</literal> library of version
  1.14.0 or higher. It can be obtained from the its repository
  <link xlink:href="https://github.com/troglobit/editline"/>.</para></listitem>

  <listitem><para>The <command>xmllint</command> and
  <command>xsltproc</command> programs to build this manual and the
  man-pages.  These are part of the <literal>libxml2</literal> and
  <literal>libxslt</literal> packages, respectively.  You also need
  the <link xlink:href="http://docbook.sourceforge.net/projects/xsl/">DocBook
  XSL stylesheets</link> and optionally the <link xlink:href="http://www.docbook.org/schemas/5x"> DocBook 5.0 RELAX NG
  schemas</link>.  Note that these are only required if you modify the
  manual sources or when you are building from the Git
  repository.</para></listitem>

  <listitem><para>Recent versions of Bison and Flex to build the
  parser.  (This is because Nix needs GLR support in Bison and
  reentrancy support in Flex.)  For Bison, you need version 2.6, which
  can be obtained from the <link xlink:href="ftp://alpha.gnu.org/pub/gnu/bison">GNU FTP
  server</link>.  For Flex, you need version 2.5.35, which is
  available on <link xlink:href="http://lex.sourceforge.net/">SourceForge</link>.
  Slightly older versions may also work, but ancient versions like the
  ubiquitous 2.5.4a won't.  Note that these are only required if you
  modify the parser or when you are building from the Git
  repository.</para></listitem>

  <listitem><para>The <literal>libseccomp</literal> is used to provide
  syscall filtering on Linux. This is an optional dependency and can
  be disabled passing a <option>--disable-seccomp-sandboxing</option>
  option to the <command>configure</command> script (Not recommended
  unless your system doesn't support
  <literal>libseccomp</literal>). To get the library, visit <link xlink:href="https://github.com/seccomp/libseccomp"/>.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-obtaining-source">

<title>Obtaining a Source Distribution</title>

<para>The source tarball of the most recent stable release can be
downloaded from the <link xlink:href="http://nixos.org/nix/download.html">Nix homepage</link>.
You can also grab the <link xlink:href="http://hydra.nixos.org/job/nix/master/release/latest-finished#tabs-constituents">most
recent development release</link>.</para>

<para>Alternatively, the most recent sources of Nix can be obtained
from its <link xlink:href="https://github.com/NixOS/nix">Git
repository</link>.  For example, the following command will check out
the latest revision into a directory called
<filename>nix</filename>:</para>

<screen>
$ git clone https://github.com/NixOS/nix</screen>

<para>Likewise, specific releases can be obtained from the <link xlink:href="https://github.com/NixOS/nix/tags">tags</link> of the
repository.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-building-source">

<title>Building Nix from Source</title>

<para>After unpacking or checking out the Nix sources, issue the
following commands:

<screen>
$ ./configure <replaceable>options...</replaceable>
$ make
$ make install</screen>

Nix requires GNU Make so you may need to invoke
<command>gmake</command> instead.</para>

<para>When building from the Git repository, these should be preceded
by the command:

<screen>
$ ./bootstrap.sh</screen>

</para>

<para>The installation path can be specified by passing the
<option>--prefix=<replaceable>prefix</replaceable></option> to
<command>configure</command>.  The default installation directory is
<filename>/usr/local</filename>.  You can change this to any location
you like.  You must have write permission to the
<replaceable>prefix</replaceable> path.</para>

<para>Nix keeps its <emphasis>store</emphasis> (the place where
packages are stored) in <filename>/nix/store</filename> by default.
This can be changed using
<option>--with-store-dir=<replaceable>path</replaceable></option>.</para>

<warning><para>It is best <emphasis>not</emphasis> to change the Nix
store from its default, since doing so makes it impossible to use
pre-built binaries from the standard Nixpkgs channels &#x2014; that is, all
packages will need to be built from source.</para></warning>

<para>Nix keeps state (such as its database and log files) in
<filename>/nix/var</filename> by default.  This can be changed using
<option>--localstatedir=<replaceable>path</replaceable></option>.</para>

</section>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-nix-security">

<title>Security</title>

<para>Nix has two basic security models.  First, it can be used in
&#x201C;single-user mode&#x201D;, which is similar to what most other package
management tools do: there is a single user (typically <systemitem class="username">root</systemitem>) who performs all package
management operations.  All other users can then use the installed
packages, but they cannot perform package management operations
themselves.</para>

<para>Alternatively, you can configure Nix in &#x201C;multi-user mode&#x201D;.  In
this model, all users can perform package management operations &#x2014; for
instance, every user can install software without requiring root
privileges.  Nix ensures that this is secure.  For instance, it&#x2019;s not
possible for one user to overwrite a package used by another user with
a Trojan horse.</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-single-user">

<title>Single-User Mode</title>

<para>In single-user mode, all Nix operations that access the database
in <filename><replaceable>prefix</replaceable>/var/nix/db</filename>
or modify the Nix store in
<filename><replaceable>prefix</replaceable>/store</filename> must be
performed under the user ID that owns those directories.  This is
typically <systemitem class="username">root</systemitem>.  (If you
install from RPM packages, that&#x2019;s in fact the default ownership.)
However, on single-user machines, it is often convenient to
<command>chown</command> those directories to your normal user account
so that you don&#x2019;t have to <command>su</command> to <systemitem class="username">root</systemitem> all the time.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-multi-user">

<title>Multi-User Mode</title>

<para>To allow a Nix store to be shared safely among multiple users,
it is important that users are not able to run builders that modify
the Nix store or database in arbitrary ways, or that interfere with
builds started by other users.  If they could do so, they could
install a Trojan horse in some package and compromise the accounts of
other users.</para>

<para>To prevent this, the Nix store and database are owned by some
privileged user (usually <literal>root</literal>) and builders are
executed under special user accounts (usually named
<literal>nixbld1</literal>, <literal>nixbld2</literal>, etc.).  When a
unprivileged user runs a Nix command, actions that operate on the Nix
store (such as builds) are forwarded to a <emphasis>Nix
daemon</emphasis> running under the owner of the Nix store/database
that performs the operation.</para>

<note><para>Multi-user mode has one important limitation: only
<systemitem class="username">root</systemitem> and a set of trusted
users specified in <filename>nix.conf</filename> can specify arbitrary
binary caches. So while unprivileged users may install packages from
arbitrary Nix expressions, they may not get pre-built
binaries.</para></note>


<simplesect>

<title>Setting up the build users</title>

<para>The <emphasis>build users</emphasis> are the special UIDs under
which builds are performed.  They should all be members of the
<emphasis>build users group</emphasis> <literal>nixbld</literal>.
This group should have no other members.  The build users should not
be members of any other group. On Linux, you can create the group and
users as follows:

<screen>
$ groupadd -r nixbld
$ for n in $(seq 1 10); do useradd -c "Nix build user $n" \
    -d /var/empty -g nixbld -G nixbld -M -N -r -s "$(which nologin)" \
    nixbld$n; done
</screen>

This creates 10 build users. There can never be more concurrent builds
than the number of build users, so you may want to increase this if
you expect to do many builds at the same time.</para>

</simplesect>


<simplesect>

<title>Running the daemon</title>

<para>The <link linkend="sec-nix-daemon">Nix daemon</link> should be
started as follows (as <literal>root</literal>):

<screen>
$ nix-daemon</screen>

You&#x2019;ll want to put that line somewhere in your system&#x2019;s boot
scripts.</para>

<para>To let unprivileged users use the daemon, they should set the
<link linkend="envar-remote"><envar>NIX_REMOTE</envar> environment
variable</link> to <literal>daemon</literal>.  So you should put a
line like

<programlisting>
export NIX_REMOTE=daemon</programlisting>

into the users&#x2019; login scripts.</para>

</simplesect>


<simplesect>

<title>Restricting access</title>

<para>To limit which users can perform Nix operations, you can use the
permissions on the directory
<filename>/nix/var/nix/daemon-socket</filename>.  For instance, if you
want to restrict the use of Nix to the members of a group called
<literal>nix-users</literal>, do

<screen>
$ chgrp nix-users /nix/var/nix/daemon-socket
$ chmod ug=rwx,o= /nix/var/nix/daemon-socket
</screen>

This way, users who are not in the <literal>nix-users</literal> group
cannot connect to the Unix domain socket
<filename>/nix/var/nix/daemon-socket/socket</filename>, so they cannot
perform Nix operations.</para>

</simplesect>


</section>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-env-variables">

<title>Environment Variables</title>

<para>To use Nix, some environment variables should be set.  In
particular, <envar>PATH</envar> should contain the directories
<filename><replaceable>prefix</replaceable>/bin</filename> and
<filename>~/.nix-profile/bin</filename>.  The first directory contains
the Nix tools themselves, while <filename>~/.nix-profile</filename> is
a symbolic link to the current <emphasis>user environment</emphasis>
(an automatically generated package consisting of symlinks to
installed packages).  The simplest way to set the required environment
variables is to include the file
<filename><replaceable>prefix</replaceable>/etc/profile.d/nix.sh</filename>
in your <filename>~/.profile</filename> (or similar), like this:</para>

<screen>
source <replaceable>prefix</replaceable>/etc/profile.d/nix.sh</screen>

<section xml:id="sec-nix-ssl-cert-file">

<title><envar>NIX_SSL_CERT_FILE</envar></title>

<para>If you need to specify a custom certificate bundle to account
for an HTTPS-intercepting man in the middle proxy, you must specify
the path to the certificate bundle in the environment variable
<envar>NIX_SSL_CERT_FILE</envar>.</para>


<para>If you don't specify a <envar>NIX_SSL_CERT_FILE</envar>
manually, Nix will install and use its own certificate
bundle.</para>

<procedure>
  <step><para>Set the environment variable and install Nix</para>
    <screen>
$ export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt
$ sh &lt;(curl -L https://nixos.org/nix/install)
</screen></step>

  <step><para>In the shell profile and rc files (for example,
  <filename>/etc/bashrc</filename>, <filename>/etc/zshrc</filename>),
  add the following line:</para>
<programlisting>
export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt
</programlisting>
</step>
</procedure>

<note><para>You must not add the export and then do the install, as
the Nix installer will detect the presense of Nix configuration, and
abort.</para></note>

<section xml:id="sec-nix-ssl-cert-file-with-nix-daemon-and-macos">
<title><envar>NIX_SSL_CERT_FILE</envar> with macOS and the Nix daemon</title>

<para>On macOS you must specify the environment variable for the Nix
daemon service, then restart it:</para>

<screen>
$ sudo launchctl setenv NIX_SSL_CERT_FILE /etc/ssl/my-certificate-bundle.crt
$ sudo launchctl kickstart -k system/org.nixos.nix-daemon
</screen>
</section>

<section xml:id="sec-installer-proxy-settings">

<title>Proxy Environment Variables</title>

<para>The Nix installer has special handling for these proxy-related
environment variables:
<varname>http_proxy</varname>, <varname>https_proxy</varname>,
<varname>ftp_proxy</varname>, <varname>no_proxy</varname>,
<varname>HTTP_PROXY</varname>, <varname>HTTPS_PROXY</varname>,
<varname>FTP_PROXY</varname>, <varname>NO_PROXY</varname>.
</para>
<para>If any of these variables are set when running the Nix installer,
then the installer will create an override file at
<filename>/etc/systemd/system/nix-daemon.service.d/override.conf</filename>
so <command>nix-daemon</command> will use them.
</para>
</section>

</section>
</chapter>

<!-- TODO: should be updated
<section><title>Upgrading Nix through Nix</title>

<para>You can install the latest stable version of Nix through Nix
itself by subscribing to the channel <link
xlink:href="http://nixos.org/releases/nix/channels/nix-stable" />,
or the latest unstable version by subscribing to the channel <link
xlink:href="http://nixos.org/releases/nix/channels/nix-unstable" />.
You can also do a <link linkend="sec-one-click">one-click
installation</link> by clicking on the package links at <link
xlink:href="http://nixos.org/releases/full-index-nix.html" />.</para>

</section>
-->

</part>
  <chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-upgrading-nix" xml:base="installation/upgrading.xml">

  <title>Upgrading Nix</title>

  <para>
    Multi-user Nix users on macOS can upgrade Nix by running:
    <command>sudo -i sh -c 'nix-channel --update &amp;&amp;
    nix-env -iA nixpkgs.nix &amp;&amp;
    launchctl remove org.nixos.nix-daemon &amp;&amp;
    launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist'</command>
  </para>


  <para>
    Single-user installations of Nix should run this:
    <command>nix-channel --update; nix-env -iA nixpkgs.nix nixpkgs.cacert</command>
  </para>
      
  <para>
    Multi-user Nix users on Linux should run this with sudo:
    <command>nix-channel --update; nix-env -iA nixpkgs.nix nixpkgs.cacert; systemctl daemon-reload; systemctl restart nix-daemon</command>
  </para>
</chapter>
  <part xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-package-management" xml:base="packages/package-management.xml">

<title>Package Management</title>

<partintro>
<para>This chapter discusses how to do package management with Nix,
i.e., how to obtain, install, upgrade, and erase packages.  This is
the &#x201C;user&#x2019;s&#x201D; perspective of the Nix system &#x2014; people
who want to <emphasis>create</emphasis> packages should consult
<xref linkend="chap-writing-nix-expressions"/>.</para>
</partintro>

<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-basic-package-mgmt">

<title>Basic Package Management</title>

<para>The main command for package management is <link linkend="sec-nix-env"><command>nix-env</command></link>.  You can use
it to install, upgrade, and erase packages, and to query what
packages are installed or are available for installation.</para>

<para>In Nix, different users can have different &#x201C;views&#x201D;
on the set of installed applications.  That is, there might be lots of
applications present on the system (possibly in many different
versions), but users can have a specific selection of those active &#x2014;
where &#x201C;active&#x201D; just means that it appears in a directory
in the user&#x2019;s <envar>PATH</envar>.  Such a view on the set of
installed applications is called a <emphasis>user
environment</emphasis>, which is just a directory tree consisting of
symlinks to the files of the active applications.  </para>

<para>Components are installed from a set of <emphasis>Nix
expressions</emphasis> that tell Nix how to build those packages,
including, if necessary, their dependencies.  There is a collection of
Nix expressions called the Nixpkgs package collection that contains
packages ranging from basic development stuff such as GCC and Glibc,
to end-user applications like Mozilla Firefox.  (Nix is however not
tied to the Nixpkgs package collection; you could write your own Nix
expressions based on Nixpkgs, or completely new ones.)</para>

<para>You can manually download the latest version of Nixpkgs from
<link xlink:href="http://nixos.org/nixpkgs/download.html"/>. However,
it&#x2019;s much more convenient to use the Nixpkgs
<emphasis>channel</emphasis>, since it makes it easy to stay up to
date with new versions of Nixpkgs. (Channels are described in more
detail in <xref linkend="sec-channels"/>.) Nixpkgs is automatically
added to your list of &#x201C;subscribed&#x201D; channels when you install
Nix. If this is not the case for some reason, you can add it as
follows:

<screen>
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
</screen>

</para>

<note><para>On NixOS, you&#x2019;re automatically subscribed to a NixOS
channel corresponding to your NixOS major release
(e.g. <uri>http://nixos.org/channels/nixos-14.12</uri>). A NixOS
channel is identical to the Nixpkgs channel, except that it contains
only Linux binaries and is updated only if a set of regression tests
succeed.</para></note>

<para>You can view the set of available packages in Nixpkgs:

<screen>
$ nix-env -qa
aterm-2.2
bash-3.0
binutils-2.15
bison-1.875d
blackdown-1.4.2
bzip2-1.0.2
&#x2026;</screen>

The flag <option>-q</option> specifies a query operation, and
<option>-a</option> means that you want to show the &#x201C;available&#x201D; (i.e.,
installable) packages, as opposed to the installed packages. If you
downloaded Nixpkgs yourself, or if you checked it out from GitHub,
then you need to pass the path to your Nixpkgs tree using the
<option>-f</option> flag:

<screen>
$ nix-env -qaf <replaceable>/path/to/nixpkgs</replaceable>
</screen>

where <replaceable>/path/to/nixpkgs</replaceable> is where you&#x2019;ve
unpacked or checked out Nixpkgs.</para>

<para>You can select specific packages by name:

<screen>
$ nix-env -qa firefox
firefox-34.0.5
firefox-with-plugins-34.0.5
</screen>

and using regular expressions:

<screen>
$ nix-env -qa 'firefox.*'
</screen>

</para>

<para>It is also possible to see the <emphasis>status</emphasis> of
available packages, i.e., whether they are installed into the user
environment and/or present in the system:

<screen>
$ nix-env -qas
&#x2026;
-PS bash-3.0
--S binutils-2.15
IPS bison-1.875d
&#x2026;</screen>

The first character (<literal>I</literal>) indicates whether the
package is installed in your current user environment.  The second
(<literal>P</literal>) indicates whether it is present on your system
(in which case installing it into your user environment would be a
very quick operation).  The last one (<literal>S</literal>) indicates
whether there is a so-called <emphasis>substitute</emphasis> for the
package, which is Nix&#x2019;s mechanism for doing binary deployment.  It
just means that Nix knows that it can fetch a pre-built package from
somewhere (typically a network server) instead of building it
locally.</para>

<para>You can install a package using <literal>nix-env -i</literal>.
For instance,

<screen>
$ nix-env -i subversion</screen>

will install the package called <literal>subversion</literal> (which
is, of course, the <link xlink:href="http://subversion.tigris.org/">Subversion version
management system</link>).</para>

<note><para>When you ask Nix to install a package, it will first try
to get it in pre-compiled form from a <emphasis>binary
cache</emphasis>. By default, Nix will use the binary cache
<uri>https://cache.nixos.org</uri>; it contains binaries for most
packages in Nixpkgs. Only if no binary is available in the binary
cache, Nix will build the package from source. So if <literal>nix-env
-i subversion</literal> results in Nix building stuff from source,
then either the package is not built for your platform by the Nixpkgs
build servers, or your version of Nixpkgs is too old or too new. For
instance, if you have a very recent checkout of Nixpkgs, then the
Nixpkgs build servers may not have had a chance to build everything
and upload the resulting binaries to
<uri>https://cache.nixos.org</uri>. The Nixpkgs channel is only
updated after all binaries have been uploaded to the cache, so if you
stick to the Nixpkgs channel (rather than using a Git checkout of the
Nixpkgs tree), you will get binaries for most packages.</para></note>

<para>Naturally, packages can also be uninstalled:

<screen>
$ nix-env -e subversion</screen>

</para>

<para>Upgrading to a new version is just as easy.  If you have a new
release of Nix Packages, you can do:

<screen>
$ nix-env -u subversion</screen>

This will <emphasis>only</emphasis> upgrade Subversion if there is a
&#x201C;newer&#x201D; version in the new set of Nix expressions, as
defined by some pretty arbitrary rules regarding ordering of version
numbers (which generally do what you&#x2019;d expect of them).  To just
unconditionally replace Subversion with whatever version is in the Nix
expressions, use <parameter>-i</parameter> instead of
<parameter>-u</parameter>; <parameter>-i</parameter> will remove
whatever version is already installed.</para>

<para>You can also upgrade all packages for which there are newer
versions:

<screen>
$ nix-env -u</screen>

</para>

<para>Sometimes it&#x2019;s useful to be able to ask what
<command>nix-env</command> would do, without actually doing it.  For
instance, to find out what packages would be upgraded by
<literal>nix-env -u</literal>, you can do

<screen>
$ nix-env -u --dry-run
(dry run; not doing anything)
upgrading `libxslt-1.1.0' to `libxslt-1.1.10'
upgrading `graphviz-1.10' to `graphviz-1.12'
upgrading `coreutils-5.0' to `coreutils-5.2.1'</screen>

</para>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-profiles">

<title>Profiles</title>

<para>Profiles and user environments are Nix&#x2019;s mechanism for
implementing the ability to allow different users to have different
configurations, and to do atomic upgrades and rollbacks.  To
understand how they work, it&#x2019;s useful to know a bit about how Nix
works.  In Nix, packages are stored in unique locations in the
<emphasis>Nix store</emphasis> (typically,
<filename>/nix/store</filename>).  For instance, a particular version
of the Subversion package might be stored in a directory
<filename>/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3/</filename>,
while another version might be stored in
<filename>/nix/store/5mq2jcn36ldlmh93yj1n8s9c95pj7c5s-subversion-1.1.2</filename>.
The long strings prefixed to the directory names are cryptographic
hashes<footnote><para>160-bit truncations of SHA-256 hashes encoded in
a base-32 notation, to be precise.</para></footnote> of
<emphasis>all</emphasis> inputs involved in building the package &#x2014;
sources, dependencies, compiler flags, and so on.  So if two
packages differ in any way, they end up in different locations in
the file system, so they don&#x2019;t interfere with each other.  <xref linkend="fig-user-environments"/> shows a part of a typical Nix
store.</para>

<figure xml:id="fig-user-environments"><title>User environments</title>
  <mediaobject>
    <imageobject>
      <imagedata fileref="../figures/user-environments.png" format="PNG"/>
    </imageobject>
  </mediaobject>
</figure>

<para>Of course, you wouldn&#x2019;t want to type

<screen>
$ /nix/store/dpmvp969yhdq...-subversion-1.1.3/bin/svn</screen>

every time you want to run Subversion.  Of course we could set up the
<envar>PATH</envar> environment variable to include the
<filename>bin</filename> directory of every package we want to use,
but this is not very convenient since changing <envar>PATH</envar>
doesn&#x2019;t take effect for already existing processes.  The solution Nix
uses is to create directory trees of symlinks to
<emphasis>activated</emphasis> packages.  These are called
<emphasis>user environments</emphasis> and they are packages
themselves (though automatically generated by
<command>nix-env</command>), so they too reside in the Nix store.  For
instance, in <xref linkend="fig-user-environments"/> the user
environment <filename>/nix/store/0c1p5z4kda11...-user-env</filename>
contains a symlink to just Subversion 1.1.2 (arrows in the figure
indicate symlinks).  This would be what we would obtain if we had done

<screen>
$ nix-env -i subversion</screen>

on a set of Nix expressions that contained Subversion 1.1.2.</para>

<para>This doesn&#x2019;t in itself solve the problem, of course; you
wouldn&#x2019;t want to type
<filename>/nix/store/0c1p5z4kda11...-user-env/bin/svn</filename>
either.  That&#x2019;s why there are symlinks outside of the store that point
to the user environments in the store; for instance, the symlinks
<filename>default-42-link</filename> and
<filename>default-43-link</filename> in the example.  These are called
<emphasis>generations</emphasis> since every time you perform a
<command>nix-env</command> operation, a new user environment is
generated based on the current one.  For instance, generation 43 was
created from generation 42 when we did

<screen>
$ nix-env -i subversion firefox</screen>

on a set of Nix expressions that contained Firefox and a new version
of Subversion.</para>

<para>Generations are grouped together into
<emphasis>profiles</emphasis> so that different users don&#x2019;t interfere
with each other if they don&#x2019;t want to.  For example:

<screen>
$ ls -l /nix/var/nix/profiles/
...
lrwxrwxrwx  1 eelco ... default-42-link -&gt; /nix/store/0c1p5z4kda11...-user-env
lrwxrwxrwx  1 eelco ... default-43-link -&gt; /nix/store/3aw2pdyx2jfc...-user-env
lrwxrwxrwx  1 eelco ... default -&gt; default-43-link</screen>

This shows a profile called <filename>default</filename>.  The file
<filename>default</filename> itself is actually a symlink that points
to the current generation.  When we do a <command>nix-env</command>
operation, a new user environment and generation link are created
based on the current one, and finally the <filename>default</filename>
symlink is made to point at the new generation.  This last step is
atomic on Unix, which explains how we can do atomic upgrades.  (Note
that the building/installing of new packages doesn&#x2019;t interfere in
any way with old packages, since they are stored in different
locations in the Nix store.)</para>

<para>If you find that you want to undo a <command>nix-env</command>
operation, you can just do

<screen>
$ nix-env --rollback</screen>

which will just make the current generation link point at the previous
link.  E.g., <filename>default</filename> would be made to point at
<filename>default-42-link</filename>.  You can also switch to a
specific generation:

<screen>
$ nix-env --switch-generation 43</screen>

which in this example would roll forward to generation 43 again.  You
can also see all available generations:

<screen>
$ nix-env --list-generations</screen></para>

<para>You generally wouldn&#x2019;t have
<filename>/nix/var/nix/profiles/<replaceable>some-profile</replaceable>/bin</filename>
in your <envar>PATH</envar>.  Rather, there is a symlink
<filename>~/.nix-profile</filename> that points to your current
profile.  This means that you should put
<filename>~/.nix-profile/bin</filename> in your <envar>PATH</envar>
(and indeed, that&#x2019;s what the initialisation script
<filename>/nix/etc/profile.d/nix.sh</filename> does).  This makes it
easier to switch to a different profile.  You can do that using the
command <command>nix-env --switch-profile</command>:

<screen>
$ nix-env --switch-profile /nix/var/nix/profiles/my-profile

$ nix-env --switch-profile /nix/var/nix/profiles/default</screen>

These commands switch to the <filename>my-profile</filename> and
default profile, respectively.  If the profile doesn&#x2019;t exist, it will
be created automatically.  You should be careful about storing a
profile in another location than the <filename>profiles</filename>
directory, since otherwise it might not be used as a root of the
garbage collector (see <xref linkend="sec-garbage-collection"/>).</para>

<para>All <command>nix-env</command> operations work on the profile
pointed to by <command>~/.nix-profile</command>, but you can override
this using the <option>--profile</option> option (abbreviation
<option>-p</option>):

<screen>
$ nix-env -p /nix/var/nix/profiles/other-profile -i subversion</screen>

This will <emphasis>not</emphasis> change the
<command>~/.nix-profile</command> symlink.</para>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-garbage-collection">

<title>Garbage Collection</title>

<para><command>nix-env</command> operations such as upgrades
(<option>-u</option>) and uninstall (<option>-e</option>) never
actually delete packages from the system.  All they do (as shown
above) is to create a new user environment that no longer contains
symlinks to the &#x201C;deleted&#x201D; packages.</para>

<para>Of course, since disk space is not infinite, unused packages
should be removed at some point.  You can do this by running the Nix
garbage collector.  It will remove from the Nix store any package
not used (directly or indirectly) by any generation of any
profile.</para>

<para>Note however that as long as old generations reference a
package, it will not be deleted.  After all, we wouldn&#x2019;t be able to
do a rollback otherwise.  So in order for garbage collection to be
effective, you should also delete (some) old generations.  Of course,
this should only be done if you are certain that you will not need to
roll back.</para>

<para>To delete all old (non-current) generations of your current
profile:

<screen>
$ nix-env --delete-generations old</screen>

Instead of <literal>old</literal> you can also specify a list of
generations, e.g.,

<screen>
$ nix-env --delete-generations 10 11 14</screen>

To delete all generations older than a specified number of days
(except the current generation), use the <literal>d</literal>
suffix. For example,

<screen>
$ nix-env --delete-generations 14d</screen>

deletes all generations older than two weeks.</para>

<para>After removing appropriate old generations you can run the
garbage collector as follows:

<screen>
$ nix-store --gc</screen>

The behaviour of the gargage collector is affected by the 
<literal>keep-derivations</literal> (default: true) and <literal>keep-outputs</literal>
(default: false) options in the Nix configuration file. The defaults will ensure
that all derivations that are build-time dependencies of garbage collector roots
will be kept and that all output paths that are runtime dependencies
will be kept as well. All other derivations or paths will be collected. 
(This is usually what you want, but while you are developing
it may make sense to keep outputs to ensure that rebuild times are quick.)

If you are feeling uncertain, you can also first view what files would
be deleted:

<screen>
$ nix-store --gc --print-dead</screen>

Likewise, the option <option>--print-live</option> will show the paths
that <emphasis>won&#x2019;t</emphasis> be deleted.</para>

<para>There is also a convenient little utility
<command>nix-collect-garbage</command>, which when invoked with the
<option>-d</option> (<option>--delete-old</option>) switch deletes all
old generations of all profiles in
<filename>/nix/var/nix/profiles</filename>.  So

<screen>
$ nix-collect-garbage -d</screen>

is a quick and easy way to clean up your system.</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-gc-roots">

<title>Garbage Collector Roots</title>

<para>The roots of the garbage collector are all store paths to which
there are symlinks in the directory
<filename><replaceable>prefix</replaceable>/nix/var/nix/gcroots</filename>.
For instance, the following command makes the path
<filename>/nix/store/d718ef...-foo</filename> a root of the collector:

<screen>
$ ln -s /nix/store/d718ef...-foo /nix/var/nix/gcroots/bar</screen>
	
That is, after this command, the garbage collector will not remove
<filename>/nix/store/d718ef...-foo</filename> or any of its
dependencies.</para>

<para>Subdirectories of
<filename><replaceable>prefix</replaceable>/nix/var/nix/gcroots</filename>
are also searched for symlinks.  Symlinks to non-store paths are
followed and searched for roots, but symlinks to non-store paths
<emphasis>inside</emphasis> the paths reached in that way are not
followed to prevent infinite recursion.</para>

</section>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-channels">

<title>Channels</title>

<para>If you want to stay up to date with a set of packages, it&#x2019;s not
very convenient to manually download the latest set of Nix expressions
for those packages and upgrade using <command>nix-env</command>.
Fortunately, there&#x2019;s a better way: <emphasis>Nix
channels</emphasis>.</para>

<para>A Nix channel is just a URL that points to a place that contains
a set of Nix expressions and a manifest.  Using the command <link linkend="sec-nix-channel"><command>nix-channel</command></link> you
can automatically stay up to date with whatever is available at that
URL.</para>
      
<para>To see the list of official NixOS channels, visit <link xlink:href="https://nixos.org/channels"/>.</para>

<para>You can &#x201C;subscribe&#x201D; to a channel using
<command>nix-channel --add</command>, e.g.,

<screen>
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable</screen>

subscribes you to a channel that always contains that latest version
of the Nix Packages collection.  (Subscribing really just means that
the URL is added to the file <filename>~/.nix-channels</filename>,
where it is read by subsequent calls to <command>nix-channel
--update</command>.) You can &#x201C;unsubscribe&#x201D; using <command>nix-channel
--remove</command>:

<screen>
$ nix-channel --remove nixpkgs
</screen>
</para>

<para>To obtain the latest Nix expressions available in a channel, do

<screen>
$ nix-channel --update</screen>

This downloads and unpacks the Nix expressions in every channel
(downloaded from <literal><replaceable>url</replaceable>/nixexprs.tar.bz2</literal>).
It also makes the union of each channel&#x2019;s Nix expressions available by
default to <command>nix-env</command> operations (via the symlink
<filename>~/.nix-defexpr/channels</filename>).  Consequently, you can
then say

<screen>
$ nix-env -u</screen>

to upgrade all packages in your profile to the latest versions
available in the subscribed channels.</para>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-sharing-packages">

<title>Sharing Packages Between Machines</title>

<para>Sometimes you want to copy a package from one machine to
another.  Or, you want to install some packages and you know that
another machine already has some or all of those packages or their
dependencies.  In that case there are mechanisms to quickly copy
packages between machines.</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-binary-cache-substituter">

<title>Serving a Nix store via HTTP</title>

<para>You can easily share the Nix store of a machine via HTTP. This
allows other machines to fetch store paths from that machine to speed
up installations. It uses the same <emphasis>binary cache</emphasis>
mechanism that Nix usually uses to fetch pre-built binaries from
<uri>https://cache.nixos.org</uri>.</para>

<para>The daemon that handles binary cache requests via HTTP,
<command>nix-serve</command>, is not part of the Nix distribution, but
you can install it from Nixpkgs:

<screen>
$ nix-env -i nix-serve
</screen>

You can then start the server, listening for HTTP connections on
whatever port you like:

<screen>
$ nix-serve -p 8080
</screen>

To check whether it works, try the following on the client:

<screen>
$ curl http://avalon:8080/nix-cache-info
</screen>

which should print something like:

<screen>
StoreDir: /nix/store
WantMassQuery: 1
Priority: 30
</screen>

</para>

<para>On the client side, you can tell Nix to use your binary cache
using <option>--option extra-binary-caches</option>, e.g.:

<screen>
$ nix-env -i firefox --option extra-binary-caches http://avalon:8080/
</screen>

The option <option>extra-binary-caches</option> tells Nix to use this
binary cache in addition to your default caches, such as
<uri>https://cache.nixos.org</uri>. Thus, for any path in the closure
of Firefox, Nix will first check if the path is available on the
server <literal>avalon</literal> or another binary caches. If not, it
will fall back to building from source.</para>

<para>You can also tell Nix to always use your binary cache by adding
a line to the <filename linkend="sec-conf-file">nix.conf</filename>
configuration file like this:

<programlisting>
binary-caches = http://avalon:8080/ https://cache.nixos.org/
</programlisting>

</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-copy-closure">

<title>Copying Closures Via SSH</title>

<para>The command <command linkend="sec-nix-copy-closure">nix-copy-closure</command> copies a Nix
store path along with all its dependencies to or from another machine
via the SSH protocol.  It doesn&#x2019;t copy store paths that are already
present on the target machine.  For example, the following command
copies Firefox with all its dependencies:

<screen>
$ nix-copy-closure --to alice@itchy.example.org $(type -p firefox)</screen>

See <xref linkend="sec-nix-copy-closure"/> for details.</para>

<para>With <command linkend="refsec-nix-store-export">nix-store
--export</command> and <command linkend="refsec-nix-store-import">nix-store --import</command> you can
write the closure of a store path (that is, the path and all its
dependencies) to a file, and then unpack that file into another Nix
store.  For example,

<screen>
$ nix-store --export $(nix-store -qR $(type -p firefox)) &gt; firefox.closure</screen>

writes the closure of Firefox to a file.  You can then copy this file
to another machine and install the closure:

<screen>
$ nix-store --import &lt; firefox.closure</screen>

Any store paths in the closure that are already present in the target
store are ignored.  It is also possible to pipe the export into
another command, e.g. to copy and install a closure directly to/on
another machine:

<screen>
$ nix-store --export $(nix-store -qR $(type -p firefox)) | bzip2 | \
    ssh alice@itchy.example.org "bunzip2 | nix-store --import"</screen>

However, <command>nix-copy-closure</command> is generally more
efficient because it only copies paths that are not already present in
the target Nix store.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-ssh-substituter">

<title>Serving a Nix store via SSH</title>

<para>You can tell Nix to automatically fetch needed binaries from a
remote Nix store via SSH. For example, the following installs Firefox,
automatically fetching any store paths in Firefox&#x2019;s closure if they
are available on the server <literal>avalon</literal>:

<screen>
$ nix-env -i firefox --substituters ssh://alice@avalon
</screen>

This works similar to the binary cache substituter that Nix usually
uses, only using SSH instead of HTTP: if a store path
<literal>P</literal> is needed, Nix will first check if it&#x2019;s available
in the Nix store on <literal>avalon</literal>. If not, it will fall
back to using the binary cache substituter, and then to building from
source.</para>

<note><para>The SSH substituter currently does not allow you to enter
an SSH passphrase interactively. Therefore, you should use
<command>ssh-add</command> to load the decrypted private key into
<command>ssh-agent</command>.</para></note>

<para>You can also copy the closure of some store path, without
installing it into your profile, e.g.

<screen>
$ nix-store -r /nix/store/m85bxg&#x2026;-firefox-34.0.5 --substituters ssh://alice@avalon
</screen>

This is essentially equivalent to doing

<screen>
$ nix-copy-closure --from alice@avalon /nix/store/m85bxg&#x2026;-firefox-34.0.5
</screen>

</para>

<para>You can use SSH&#x2019;s <emphasis>forced command</emphasis> feature to
set up a restricted user account for SSH substituter access, allowing
read-only access to the local Nix store, but nothing more. For
example, add the following lines to <filename>sshd_config</filename>
to restrict the user <literal>nix-ssh</literal>:

<programlisting>
Match User nix-ssh
  AllowAgentForwarding no
  AllowTcpForwarding no
  PermitTTY no
  PermitTunnel no
  X11Forwarding no
  ForceCommand nix-store --serve
Match All
</programlisting>

On NixOS, you can accomplish the same by adding the following to your
<filename>configuration.nix</filename>:

<programlisting>
nix.sshServe.enable = true;
nix.sshServe.keys = [ "ssh-dss AAAAB3NzaC1k... bob@example.org" ];
</programlisting>

where the latter line lists the public keys of users that are allowed
to connect.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-s3-substituter">

<title>Serving a Nix store via AWS S3 or S3-compatible Service</title>

<para>Nix has built-in support for storing and fetching store paths
from Amazon S3 and S3 compatible services. This uses the same
<emphasis>binary</emphasis> cache mechanism that Nix usually uses to
fetch prebuilt binaries from <uri>cache.nixos.org</uri>.</para>

<para>The following options can be specified as URL parameters to
the S3 URL:</para>

<variablelist>
  <varlistentry><term><literal>profile</literal></term>
  <listitem>
    <para>
      The name of the AWS configuration profile to use. By default
      Nix will use the <literal>default</literal> profile.
    </para>
  </listitem>
  </varlistentry>

  <varlistentry><term><literal>region</literal></term>
  <listitem>
    <para>
      The region of the S3 bucket. <literal>us&#x2013;east-1</literal> by
      default.
    </para>

    <para>
      If your bucket is not in <literal>us&#x2013;east-1</literal>, you
      should always explicitly specify the region parameter.
    </para>
  </listitem>
  </varlistentry>

  <varlistentry><term><literal>endpoint</literal></term>
  <listitem>
    <para>
      The URL to your S3-compatible service, for when not using
      Amazon S3. Do not specify this value if you're using Amazon
      S3.
    </para>
    <note><para>This endpoint must support HTTPS and will use
    path-based addressing instead of virtual host based
    addressing.</para></note>
  </listitem>
  </varlistentry>

  <varlistentry><term><literal>scheme</literal></term>
  <listitem>
    <para>
      The scheme used for S3 requests, <literal>https</literal>
      (default) or <literal>http</literal>.  This option allows you to
      disable HTTPS for binary caches which don't support it.
    </para>
    <note><para>HTTPS should be used if the cache might contain
    sensitive information.</para></note>
  </listitem>
  </varlistentry>
</variablelist>

<para>In this example we will use the bucket named
<literal>example-nix-cache</literal>.</para>

<section xml:id="ssec-s3-substituter-anonymous-reads">
  <title>Anonymous Reads to your S3-compatible binary cache</title>

  <para>If your binary cache is publicly accessible and does not
  require authentication, the simplest and easiest way to use Nix with
  your S3 compatible binary cache is to use the HTTP URL for that
  cache.</para>

  <para>For AWS S3 the binary cache URL for example bucket will be
  exactly <uri>https://example-nix-cache.s3.amazonaws.com</uri> or
  <uri>s3://example-nix-cache</uri>. For S3 compatible binary caches,
  consult that cache's documentation.</para>

  <para>Your bucket will need the following bucket policy:</para>

  <programlisting><![CDATA[
{
    "Id": "DirectReads",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowDirectReads",
            "Action": [
                "s3:GetObject",
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::example-nix-cache",
                "arn:aws:s3:::example-nix-cache/*"
            ],
            "Principal": "*"
        }
    ]
}
]]></programlisting>
</section>

<section xml:id="ssec-s3-substituter-authenticated-reads">
  <title>Authenticated Reads to your S3 binary cache</title>

  <para>For AWS S3 the binary cache URL for example bucket will be
  exactly <uri>s3://example-nix-cache</uri>.</para>

  <para>Nix will use the <link xlink:href="https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/credentials.html">default
  credential provider chain</link> for authenticating requests to
  Amazon S3.</para>

  <para>Nix supports authenticated reads from Amazon S3 and S3
  compatible binary caches.</para>

  <para>Your bucket will need a bucket policy allowing the desired
  users to perform the <literal>s3:GetObject</literal> and
  <literal>s3:GetBucketLocation</literal> action on all objects in the
  bucket. The anonymous policy in <xref linkend="ssec-s3-substituter-anonymous-reads"/> can be updated to
  have a restricted <literal>Principal</literal> to support
  this.</para>
</section>


<section xml:id="ssec-s3-substituter-authenticated-writes">
  <title>Authenticated Writes to your S3-compatible binary cache</title>

  <para>Nix support fully supports writing to Amazon S3 and S3
  compatible buckets. The binary cache URL for our example bucket will
  be <uri>s3://example-nix-cache</uri>.</para>

  <para>Nix will use the <link xlink:href="https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/credentials.html">default
  credential provider chain</link> for authenticating requests to
  Amazon S3.</para>

  <para>Your account will need the following IAM policy to
  upload to the cache:</para>

  <programlisting><![CDATA[
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UploadToCache",
      "Effect": "Allow",
      "Action": [
        "s3:AbortMultipartUpload",
        "s3:GetBucketLocation",
        "s3:GetObject",
        "s3:ListBucket",
        "s3:ListBucketMultipartUploads",
        "s3:ListMultipartUploadParts",
        "s3:PutObject"
      ],
      "Resource": [
        "arn:aws:s3:::example-nix-cache",
        "arn:aws:s3:::example-nix-cache/*"
      ]
    }
  ]
}
]]></programlisting>


  <example><title>Uploading with a specific credential profile for Amazon S3</title>
    <para><command>nix copy --to 's3://example-nix-cache?profile=cache-upload&amp;region=eu-west-2' nixpkgs.hello</command></para>
  </example>

  <example><title>Uploading to an S3-Compatible Binary Cache</title>
    <para><command>nix copy --to 's3://example-nix-cache?profile=cache-upload&amp;scheme=https&amp;endpoint=minio.example.com' nixpkgs.hello</command></para>
  </example>
</section>
</section>

</chapter>

</part>
  <part xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-writing-nix-expressions" xml:base="expressions/writing-nix-expressions.xml">

<title>Writing Nix Expressions</title>

<partintro>
<para>This chapter shows you how to write Nix expressions, which 
instruct Nix how to build packages.  It starts with a
simple example (a Nix expression for GNU Hello), and then moves
on to a more in-depth look at the Nix expression language.</para>

<note><para>This chapter is mostly about the Nix expression language.
For more extensive information on adding packages to the Nix Packages
collection (such as functions in the standard environment and coding
conventions), please consult <link xlink:href="http://nixos.org/nixpkgs/manual/">its
manual</link>.</para></note>
</partintro>

<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-simple-expression">

<title>A Simple Nix Expression</title>

<para>This section shows how to add and test the <link xlink:href="http://www.gnu.org/software/hello/hello.html">GNU Hello
package</link> to the Nix Packages collection.  Hello is a program
that prints out the text <quote>Hello, world!</quote>.</para>

<para>To add a package to the Nix Packages collection, you generally
need to do three things:

<orderedlist>

  <listitem><para>Write a Nix expression for the package.  This is a
  file that describes all the inputs involved in building the package,
  such as dependencies, sources, and so on.</para></listitem>

  <listitem><para>Write a <emphasis>builder</emphasis>.  This is a
  shell script<footnote><para>In fact, it can be written in any
  language, but typically it's a <command>bash</command> shell
  script.</para></footnote> that actually builds the package from
  the inputs.</para></listitem>

  <listitem><para>Add the package to the file
  <filename>pkgs/top-level/all-packages.nix</filename>.  The Nix
  expression written in the first step is a
  <emphasis>function</emphasis>; it requires other packages in order
  to build it.  In this step you put it all together, i.e., you call
  the function with the right arguments to build the actual
  package.</para></listitem>

</orderedlist>

</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-expression-syntax">

<title>Expression Syntax</title>

<example xml:id="ex-hello-nix"><title>Nix expression for GNU Hello
(<filename>default.nix</filename>)</title>
<programlisting>
{ stdenv, fetchurl, perl }: <co xml:id="ex-hello-nix-co-1"/>

stdenv.mkDerivation { <co xml:id="ex-hello-nix-co-2"/>
  name = "hello-2.1.1"; <co xml:id="ex-hello-nix-co-3"/>
  builder = ./builder.sh; <co xml:id="ex-hello-nix-co-4"/>
  src = fetchurl { <co xml:id="ex-hello-nix-co-5"/>
    url = "ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz";
    sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
  };
  inherit perl; <co xml:id="ex-hello-nix-co-6"/>
}</programlisting>
</example>

<para><xref linkend="ex-hello-nix"/> shows a Nix expression for GNU
Hello.  It's actually already in the Nix Packages collection in
<filename>pkgs/applications/misc/hello/ex-1/default.nix</filename>.
It is customary to place each package in a separate directory and call
the single Nix expression in that directory
<filename>default.nix</filename>.  The file has the following elements
(referenced from the figure by number):

<calloutlist>

  <callout arearefs="ex-hello-nix-co-1">

    <para>This states that the expression is a
    <emphasis>function</emphasis> that expects to be called with three
    arguments: <varname>stdenv</varname>, <varname>fetchurl</varname>,
    and <varname>perl</varname>.  They are needed to build Hello, but
    we don't know how to build them here; that's why they are function
    arguments.  <varname>stdenv</varname> is a package that is used
    by almost all Nix Packages packages; it provides a
    <quote>standard</quote> environment consisting of the things you
    would expect in a basic Unix environment: a C/C++ compiler (GCC,
    to be precise), the Bash shell, fundamental Unix tools such as
    <command>cp</command>, <command>grep</command>,
    <command>tar</command>, etc.  <varname>fetchurl</varname> is a
    function that downloads files.  <varname>perl</varname> is the
    Perl interpreter.</para>

    <para>Nix functions generally have the form <literal>{ x, y, ...,
    z }: e</literal> where <varname>x</varname>, <varname>y</varname>,
    etc. are the names of the expected arguments, and where
    <replaceable>e</replaceable> is the body of the function.  So
    here, the entire remainder of the file is the body of the
    function; when given the required arguments, the body should
    describe how to build an instance of the Hello package.</para>

  </callout>

  <callout arearefs="ex-hello-nix-co-2">

    <para>So we have to build a package.  Building something from
    other stuff is called a <emphasis>derivation</emphasis> in Nix (as
    opposed to sources, which are built by humans instead of
    computers).  We perform a derivation by calling
    <varname>stdenv.mkDerivation</varname>.
    <varname>mkDerivation</varname> is a function provided by
    <varname>stdenv</varname> that builds a package from a set of
    <emphasis>attributes</emphasis>.  A set is just a list of
    key/value pairs where each key is a string and each value is an
    arbitrary Nix expression.  They take the general form <literal>{
    <replaceable>name1</replaceable> =
    <replaceable>expr1</replaceable>; <replaceable>...</replaceable>
    <replaceable>nameN</replaceable> =
    <replaceable>exprN</replaceable>; }</literal>.</para>

  </callout>

  <callout arearefs="ex-hello-nix-co-3">

    <para>The attribute <varname>name</varname> specifies the symbolic
    name and version of the package.  Nix doesn't really care about
    these things, but they are used by for instance <command>nix-env
    -q</command> to show a <quote>human-readable</quote> name for
    packages.  This attribute is required by
    <varname>mkDerivation</varname>.</para>

  </callout>

  <callout arearefs="ex-hello-nix-co-4">

    <para>The attribute <varname>builder</varname> specifies the
    builder.  This attribute can sometimes be omitted, in which case
    <varname>mkDerivation</varname> will fill in a default builder
    (which does a <literal>configure; make; make install</literal>, in
    essence).  Hello is sufficiently simple that the default builder
    would suffice, but in this case, we will show an actual builder
    for educational purposes.  The value
    <command>./builder.sh</command> refers to the shell script shown
    in <xref linkend="ex-hello-builder"/>, discussed below.</para>

  </callout>

  <callout arearefs="ex-hello-nix-co-5">

    <para>The builder has to know what the sources of the package
    are.  Here, the attribute <varname>src</varname> is bound to the
    result of a call to the <command>fetchurl</command> function.
    Given a URL and a SHA-256 hash of the expected contents of the file
    at that URL, this function builds a derivation that downloads the
    file and checks its hash.  So the sources are a dependency that
    like all other dependencies is built before Hello itself is
    built.</para>

    <para>Instead of <varname>src</varname> any other name could have
    been used, and in fact there can be any number of sources (bound
    to different attributes).  However, <varname>src</varname> is
    customary, and it's also expected by the default builder (which we
    don't use in this example).</para>

  </callout>

  <callout arearefs="ex-hello-nix-co-6">

    <para>Since the derivation requires Perl, we have to pass the
    value of the <varname>perl</varname> function argument to the
    builder.  All attributes in the set are actually passed as
    environment variables to the builder, so declaring an attribute

    <programlisting>
perl = perl;</programlisting>

    will do the trick: it binds an attribute <varname>perl</varname>
    to the function argument which also happens to be called
    <varname>perl</varname>.  However, it looks a bit silly, so there
    is a shorter syntax.  The <literal>inherit</literal> keyword
    causes the specified attributes to be bound to whatever variables
    with the same name happen to be in scope.</para>

  </callout>

</calloutlist>

</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-build-script">

<title>Build Script</title>

<example xml:id="ex-hello-builder"><title>Build script for GNU Hello
(<filename>builder.sh</filename>)</title>
<programlisting>
source $stdenv/setup <co xml:id="ex-hello-builder-co-1"/>

PATH=$perl/bin:$PATH <co xml:id="ex-hello-builder-co-2"/>

tar xvfz $src <co xml:id="ex-hello-builder-co-3"/>
cd hello-*
./configure --prefix=$out <co xml:id="ex-hello-builder-co-4"/>
make <co xml:id="ex-hello-builder-co-5"/>
make install</programlisting>
</example>

<para><xref linkend="ex-hello-builder"/> shows the builder referenced
from Hello's Nix expression (stored in
<filename>pkgs/applications/misc/hello/ex-1/builder.sh</filename>).
The builder can actually be made a lot shorter by using the
<emphasis>generic builder</emphasis> functions provided by
<varname>stdenv</varname>, but here we write out the build steps to
elucidate what a builder does.  It performs the following
steps:</para>

<calloutlist>

  <callout arearefs="ex-hello-builder-co-1">

    <para>When Nix runs a builder, it initially completely clears the
    environment (except for the attributes declared in the
    derivation).  For instance, the <envar>PATH</envar> variable is
    empty<footnote><para>Actually, it's initialised to
    <filename>/path-not-set</filename> to prevent Bash from setting it
    to a default value.</para></footnote>.  This is done to prevent
    undeclared inputs from being used in the build process.  If for
    example the <envar>PATH</envar> contained
    <filename>/usr/bin</filename>, then you might accidentally use
    <filename>/usr/bin/gcc</filename>.</para>

    <para>So the first step is to set up the environment.  This is
    done by calling the <filename>setup</filename> script of the
    standard environment.  The environment variable
    <envar>stdenv</envar> points to the location of the standard
    environment being used.  (It wasn't specified explicitly as an
    attribute in <xref linkend="ex-hello-nix"/>, but
    <varname>mkDerivation</varname> adds it automatically.)</para>

  </callout>

  <callout arearefs="ex-hello-builder-co-2">

    <para>Since Hello needs Perl, we have to make sure that Perl is in
    the <envar>PATH</envar>.  The <envar>perl</envar> environment
    variable points to the location of the Perl package (since it
    was passed in as an attribute to the derivation), so
    <filename><replaceable>$perl</replaceable>/bin</filename> is the
    directory containing the Perl interpreter.</para>

  </callout>

  <callout arearefs="ex-hello-builder-co-3">

    <para>Now we have to unpack the sources.  The
    <varname>src</varname> attribute was bound to the result of
    fetching the Hello source tarball from the network, so the
    <envar>src</envar> environment variable points to the location in
    the Nix store to which the tarball was downloaded.  After
    unpacking, we <command>cd</command> to the resulting source
    directory.</para>

    <para>The whole build is performed in a temporary directory
    created in <varname>/tmp</varname>, by the way.  This directory is
    removed after the builder finishes, so there is no need to clean
    up the sources afterwards.  Also, the temporary directory is
    always newly created, so you don't have to worry about files from
    previous builds interfering with the current build.</para>

  </callout>

  <callout arearefs="ex-hello-builder-co-4">

    <para>GNU Hello is a typical Autoconf-based package, so we first
    have to run its <filename>configure</filename> script.  In Nix
    every package is stored in a separate location in the Nix store,
    for instance
    <filename>/nix/store/9a54ba97fb71b65fda531012d0443ce2-hello-2.1.1</filename>.
    Nix computes this path by cryptographically hashing all attributes
    of the derivation.  The path is passed to the builder through the
    <envar>out</envar> environment variable.  So here we give
    <filename>configure</filename> the parameter
    <literal>--prefix=$out</literal> to cause Hello to be installed in
    the expected location.</para>

  </callout>

  <callout arearefs="ex-hello-builder-co-5">

    <para>Finally we build Hello (<literal>make</literal>) and install
    it into the location specified by <envar>out</envar>
    (<literal>make install</literal>).</para>

  </callout>

</calloutlist>

<para>If you are wondering about the absence of error checking on the
result of various commands called in the builder: this is because the
shell script is evaluated with Bash's <option>-e</option> option,
which causes the script to be aborted if any command fails without an
error check.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-arguments">

<title>Arguments and Variables</title>

<example xml:id="ex-hello-composition">

<title>Composing GNU Hello
(<filename>all-packages.nix</filename>)</title>
<programlisting>
...

rec { <co xml:id="ex-hello-composition-co-1"/>

  hello = import ../applications/misc/hello/ex-1 <co xml:id="ex-hello-composition-co-2"/> { <co xml:id="ex-hello-composition-co-3"/>
    inherit fetchurl stdenv perl;
  };

  perl = import ../development/interpreters/perl { <co xml:id="ex-hello-composition-co-4"/>
    inherit fetchurl stdenv;
  };

  fetchurl = import ../build-support/fetchurl {
    inherit stdenv; ...
  };

  stdenv = ...;

}
</programlisting>
</example>

<para>The Nix expression in <xref linkend="ex-hello-nix"/> is a
function; it is missing some arguments that have to be filled in
somewhere.  In the Nix Packages collection this is done in the file
<filename>pkgs/top-level/all-packages.nix</filename>, where all
Nix expressions for packages are imported and called with the
appropriate arguments.  <xref linkend="ex-hello-composition"/> shows
some fragments of
<filename>all-packages.nix</filename>.</para>

<calloutlist>

  <callout arearefs="ex-hello-composition-co-1">

    <para>This file defines a set of attributes, all of which are
    concrete derivations (i.e., not functions).  In fact, we define a
    <emphasis>mutually recursive</emphasis> set of attributes.  That
    is, the attributes can refer to each other.  This is precisely
    what we want since we want to <quote>plug</quote> the
    various packages into each other.</para>

  </callout>

  <callout arearefs="ex-hello-composition-co-2">

    <para>Here we <emphasis>import</emphasis> the Nix expression for
    GNU Hello.  The import operation just loads and returns the
    specified Nix expression. In fact, we could just have put the
    contents of <xref linkend="ex-hello-nix"/> in
    <filename>all-packages.nix</filename> at this point.  That
    would be completely equivalent, but it would make the file rather
    bulky.</para>

    <para>Note that we refer to
    <filename>../applications/misc/hello/ex-1</filename>, not
    <filename>../applications/misc/hello/ex-1/default.nix</filename>.
    When you try to import a directory, Nix automatically appends
    <filename>/default.nix</filename> to the file name.</para>

  </callout>

  <callout arearefs="ex-hello-composition-co-3">

    <para>This is where the actual composition takes place.  Here we
    <emphasis>call</emphasis> the function imported from
    <filename>../applications/misc/hello/ex-1</filename> with a set
    containing the things that the function expects, namely
    <varname>fetchurl</varname>, <varname>stdenv</varname>, and
    <varname>perl</varname>.  We use inherit again to use the
    attributes defined in the surrounding scope (we could also have
    written <literal>fetchurl = fetchurl;</literal>, etc.).</para>

    <para>The result of this function call is an actual derivation
    that can be built by Nix (since when we fill in the arguments of
    the function, what we get is its body, which is the call to
    <varname>stdenv.mkDerivation</varname> in <xref linkend="ex-hello-nix"/>).</para>

    <note><para>Nixpkgs has a convenience function
    <function>callPackage</function> that imports and calls a
    function, filling in any missing arguments by passing the
    corresponding attribute from the Nixpkgs set, like this:

<programlisting>
hello = callPackage ../applications/misc/hello/ex-1 { };
</programlisting>

    If necessary, you can set or override arguments:

<programlisting>
hello = callPackage ../applications/misc/hello/ex-1 { stdenv = myStdenv; };
</programlisting>

    </para></note>

  </callout>

  <callout arearefs="ex-hello-composition-co-4">

    <para>Likewise, we have to instantiate Perl,
    <varname>fetchurl</varname>, and the standard environment.</para>

  </callout>

</calloutlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-building-simple">

<title>Building and Testing</title>

<para>You can now try to build Hello.  Of course, you could do
<literal>nix-env -i hello</literal>, but you may not want to install a
possibly broken package just yet.  The best way to test the package is by
using the command <command linkend="sec-nix-build">nix-build</command>,
which builds a Nix expression and creates a symlink named
<filename>result</filename> in the current directory:

<screen>
$ nix-build -A hello
building path `/nix/store/632d2b22514d...-hello-2.1.1'
hello-2.1.1/
hello-2.1.1/intl/
hello-2.1.1/intl/ChangeLog
<replaceable>...</replaceable>

$ ls -l result
lrwxrwxrwx ... 2006-09-29 10:43 result -&gt; /nix/store/632d2b22514d...-hello-2.1.1

$ ./result/bin/hello
Hello, world!</screen>

The <link linkend="opt-attr"><option>-A</option></link> option selects
the <literal>hello</literal> attribute.  This is faster than using the
symbolic package name specified by the <literal>name</literal>
attribute (which also happens to be <literal>hello</literal>) and is
unambiguous (there can be multiple packages with the symbolic name
<literal>hello</literal>, but there can be only one attribute in a set
named <literal>hello</literal>).</para>

<para><command>nix-build</command> registers the
<filename>./result</filename> symlink as a garbage collection root, so
unless and until you delete the <filename>./result</filename> symlink,
the output of the build will be safely kept on your system.  You can
use <command>nix-build</command>&#x2019;s <option linkend="opt-out-link">-o</option> switch to give the symlink another
name.</para>

<para>Nix has transactional semantics.  Once a build finishes
successfully, Nix makes a note of this in its database: it registers
that the path denoted by <envar>out</envar> is now
<quote>valid</quote>.  If you try to build the derivation again, Nix
will see that the path is already valid and finish immediately.  If a
build fails, either because it returns a non-zero exit code, because
Nix or the builder are killed, or because the machine crashes, then
the output paths will not be registered as valid.  If you try to build
the derivation again, Nix will remove the output paths if they exist
(e.g., because the builder died half-way through <literal>make
install</literal>) and try again.  Note that there is no
<quote>negative caching</quote>: Nix doesn't remember that a build
failed, and so a failed build can always be repeated.  This is because
Nix cannot distinguish between permanent failures (e.g., a compiler
error due to a syntax error in the source) and transient failures
(e.g., a disk full condition).</para>

<para>Nix also performs locking.  If you run multiple Nix builds
simultaneously, and they try to build the same derivation, the first
Nix instance that gets there will perform the build, while the others
block (or perform other derivations if available) until the build
finishes:

<screen>
$ nix-build -A hello
waiting for lock on `/nix/store/0h5b7hp8d4hqfrw8igvx97x1xawrjnac-hello-2.1.1x'</screen>

So it is always safe to run multiple instances of Nix in parallel
(which isn&#x2019;t the case with, say, <command>make</command>).</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-generic-builder">

<title>Generic Builder Syntax</title>

<para>Recall from <xref linkend="ex-hello-builder"/> that the builder
looked something like this:

<programlisting>
PATH=$perl/bin:$PATH
tar xvfz $src
cd hello-*
./configure --prefix=$out
make
make install</programlisting>

The builders for almost all Unix packages look like this &#x2014; set up some
environment variables, unpack the sources, configure, build, and
install.  For this reason the standard environment provides some Bash
functions that automate the build process.  A builder using the
generic build facilities in shown in <xref linkend="ex-hello-builder2"/>.</para>

<example xml:id="ex-hello-builder2"><title>Build script using the generic
build functions</title>
<programlisting>
buildInputs="$perl" <co xml:id="ex-hello-builder2-co-1"/>

source $stdenv/setup <co xml:id="ex-hello-builder2-co-2"/>

genericBuild <co xml:id="ex-hello-builder2-co-3"/></programlisting>
</example>

<calloutlist>

  <callout arearefs="ex-hello-builder2-co-1">

    <para>The <envar>buildInputs</envar> variable tells
    <filename>setup</filename> to use the indicated packages as
    <quote>inputs</quote>.  This means that if a package provides a
    <filename>bin</filename> subdirectory, it's added to
    <envar>PATH</envar>; if it has a <filename>include</filename>
    subdirectory, it's added to GCC's header search path; and so
    on.<footnote><para>How does it work? <filename>setup</filename>
    tries to source the file
    <filename><replaceable>pkg</replaceable>/nix-support/setup-hook</filename>
    of all dependencies.  These &#x201C;setup hooks&#x201D; can then set up whatever
    environment variables they want; for instance, the setup hook for
    Perl sets the <envar>PERL5LIB</envar> environment variable to
    contain the <filename>lib/site_perl</filename> directories of all
    inputs.</para></footnote>
    </para>

  </callout>

  <callout arearefs="ex-hello-builder2-co-2">

    <para>The function <function>genericBuild</function> is defined in
    the file <literal>$stdenv/setup</literal>.</para>

  </callout>

  <callout arearefs="ex-hello-builder2-co-3">

    <para>The final step calls the shell function
    <function>genericBuild</function>, which performs the steps that
    were done explicitly in <xref linkend="ex-hello-builder"/>.  The
    generic builder is smart enough to figure out whether to unpack
    the sources using <command>gzip</command>,
    <command>bzip2</command>, etc.  It can be customised in many ways;
    see the Nixpkgs manual for details.</para>

  </callout>

</calloutlist>

<para>Discerning readers will note that the
<envar>buildInputs</envar> could just as well have been set in the Nix
expression, like this:

<programlisting>
  buildInputs = [ perl ];</programlisting>

The <varname>perl</varname> attribute can then be removed, and the
builder becomes even shorter:

<programlisting>
source $stdenv/setup
genericBuild</programlisting>

In fact, <varname>mkDerivation</varname> provides a default builder
that looks exactly like that, so it is actually possible to omit the
builder for Hello entirely.</para>

</section>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-expression-language">

<title>Nix Expression Language</title>

<para>The Nix expression language is a pure, lazy, functional
language.  Purity means that operations in the language don't have
side-effects (for instance, there is no variable assignment).
Laziness means that arguments to functions are evaluated only when
they are needed.  Functional means that functions are
<quote>normal</quote> values that can be passed around and manipulated
in interesting ways.  The language is not a full-featured, general
purpose language.  Its main job is to describe packages,
compositions of packages, and the variability within
packages.</para>

<para>This section presents the various features of the
language.</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-values">

<title>Values</title>


<simplesect><title>Simple Values</title>

<para>Nix has the following basic data types:

<itemizedlist>

  <listitem>

    <para><emphasis>Strings</emphasis> can be written in three
    ways.</para>

    <para>The most common way is to enclose the string between double
    quotes, e.g., <literal>"foo bar"</literal>.  Strings can span
    multiple lines.  The special characters <literal>"</literal> and
    <literal>\</literal> and the character sequence
    <literal>${</literal> must be escaped by prefixing them with a
    backslash (<literal>\</literal>).  Newlines, carriage returns and
    tabs can be written as <literal>\n</literal>,
    <literal>\r</literal> and <literal>\t</literal>,
    respectively.</para>

    <para>You can include the result of an expression into a string by
    enclosing it in
    <literal>${<replaceable>...</replaceable>}</literal>, a feature
    known as <emphasis>antiquotation</emphasis>.  The enclosed
    expression must evaluate to something that can be coerced into a
    string (meaning that it must be a string, a path, or a
    derivation).  For instance, rather than writing

<programlisting>
"--with-freetype2-library=" + freetype + "/lib"</programlisting>

    (where <varname>freetype</varname> is a derivation), you can
    instead write the more natural

<programlisting>
"--with-freetype2-library=${freetype}/lib"</programlisting>

    The latter is automatically translated to the former.  A more
    complicated example (from the Nix expression for <link xlink:href="http://www.trolltech.com/products/qt">Qt</link>):

<programlisting>
configureFlags = "
  -system-zlib -system-libpng -system-libjpeg
  ${if openglSupport then "-dlopen-opengl
    -L${mesa}/lib -I${mesa}/include
    -L${libXmu}/lib -I${libXmu}/include" else ""}
  ${if threadSupport then "-thread" else "-no-thread"}
";</programlisting>

    Note that Nix expressions and strings can be arbitrarily nested;
    in this case the outer string contains various antiquotations that
    themselves contain strings (e.g., <literal>"-thread"</literal>),
    some of which in turn contain expressions (e.g.,
    <literal>${mesa}</literal>).</para>

    <para>The second way to write string literals is as an
    <emphasis>indented string</emphasis>, which is enclosed between
    pairs of <emphasis>double single-quotes</emphasis>, like so:

<programlisting>
''
  This is the first line.
  This is the second line.
    This is the third line.
''</programlisting>

    This kind of string literal intelligently strips indentation from
    the start of each line.  To be precise, it strips from each line a
    number of spaces equal to the minimal indentation of the string as
    a whole (disregarding the indentation of empty lines).  For
    instance, the first and second line are indented two space, while
    the third line is indented four spaces.  Thus, two spaces are
    stripped from each line, so the resulting string is

<programlisting>
"This is the first line.\nThis is the second line.\n  This is the third line.\n"</programlisting>

    </para>

    <para>Note that the whitespace and newline following the opening
    <literal>''</literal> is ignored if there is no non-whitespace
    text on the initial line.</para>

    <para>Antiquotation
    (<literal>${<replaceable>expr</replaceable>}</literal>) is
    supported in indented strings.</para>

    <para>Since <literal>${</literal> and <literal>''</literal> have
    special meaning in indented strings, you need a way to quote them.
    <literal>$</literal> can be escaped by prefixing it with
    <literal>''</literal> (that is, two single quotes), i.e.,
    <literal>''$</literal>. <literal>''</literal> can be escaped by
    prefixing it with <literal>'</literal>, i.e.,
    <literal>'''</literal>. <literal>$</literal> removes any special meaning
    from the following <literal>$</literal>. Linefeed, carriage-return and tab
    characters can be written as <literal>''\n</literal>,
    <literal>''\r</literal>, <literal>''\t</literal>, and <literal>''\</literal>
    escapes any other character.

    </para>

    <para>Indented strings are primarily useful in that they allow
    multi-line string literals to follow the indentation of the
    enclosing Nix expression, and that less escaping is typically
    necessary for strings representing languages such as shell scripts
    and configuration files because <literal>''</literal> is much less
    common than <literal>"</literal>.  Example:

<programlisting>
stdenv.mkDerivation {
  <replaceable>...</replaceable>
  postInstall =
    ''
      mkdir $out/bin $out/etc
      cp foo $out/bin
      echo "Hello World" &gt; $out/etc/foo.conf
      ${if enableBar then "cp bar $out/bin" else ""}
    '';
  <replaceable>...</replaceable>
}
</programlisting>

    </para>

    <para>Finally, as a convenience, <emphasis>URIs</emphasis> as
    defined in appendix B of <link xlink:href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</link>
    can be written <emphasis>as is</emphasis>, without quotes.  For
    instance, the string
    <literal>"http://example.org/foo.tar.bz2"</literal>
    can also be written as
    <literal>http://example.org/foo.tar.bz2</literal>.</para>

  </listitem>

  <listitem><para>Numbers, which can be <emphasis>integers</emphasis> (like
  <literal>123</literal>) or <emphasis>floating point</emphasis> (like
  <literal>123.43</literal> or <literal>.27e13</literal>).</para>

  <para>Numbers are type-compatible: pure integer operations will always
  return integers, whereas any operation involving at least one floating point
  number will have a floating point number as a result.</para></listitem>

  <listitem><para><emphasis>Paths</emphasis>, e.g.,
  <filename>/bin/sh</filename> or <filename>./builder.sh</filename>.
  A path must contain at least one slash to be recognised as such; for
  instance, <filename>builder.sh</filename> is not a
  path<footnote><para>It's parsed as an expression that selects the
  attribute <varname>sh</varname> from the variable
  <varname>builder</varname>.</para></footnote>.  If the file name is
  relative, i.e., if it does not begin with a slash, it is made
  absolute at parse time relative to the directory of the Nix
  expression that contained it.  For instance, if a Nix expression in
  <filename>/foo/bar/bla.nix</filename> refers to
  <filename>../xyzzy/fnord.nix</filename>, the absolute path is
  <filename>/foo/xyzzy/fnord.nix</filename>.</para>

  <para>If the first component of a path is a <literal>~</literal>,
  it is interpreted as if the rest of the path were relative to the
  user's home directory. e.g. <filename>~/foo</filename> would be
  equivalent to <filename>/home/edolstra/foo</filename> for a user
  whose home directory is <filename>/home/edolstra</filename>.
  </para>

  <para>Paths can also be specified between angle brackets, e.g.
  <literal>&lt;nixpkgs&gt;</literal>. This means that the directories
  listed in the environment variable
  <envar linkend="env-NIX_PATH">NIX_PATH</envar> will be searched
  for the given file or directory name.
  </para>

  </listitem>

  <listitem><para><emphasis>Booleans</emphasis> with values
  <literal>true</literal> and
  <literal>false</literal>.</para></listitem>

  <listitem><para>The null value, denoted as
  <literal>null</literal>.</para></listitem>

</itemizedlist>

</para>

</simplesect>


<simplesect><title>Lists</title>

<para>Lists are formed by enclosing a whitespace-separated list of
values between square brackets.  For example,

<programlisting>
[ 123 ./foo.nix "abc" (f { x = y; }) ]</programlisting>

defines a list of four elements, the last being the result of a call
to the function <varname>f</varname>.  Note that function calls have
to be enclosed in parentheses.  If they had been omitted, e.g.,

<programlisting>
[ 123 ./foo.nix "abc" f { x = y; } ]</programlisting>

the result would be a list of five elements, the fourth one being a
function and the fifth being a set.</para>

<para>Note that lists are only lazy in values, and they are strict in length.
</para>

</simplesect>


<simplesect><title>Sets</title>

<para>Sets are really the core of the language, since ultimately the
Nix language is all about creating derivations, which are really just
sets of attributes to be passed to build scripts.</para>

<para>Sets are just a list of name/value pairs (called
<emphasis>attributes</emphasis>) enclosed in curly brackets, where
each value is an arbitrary expression terminated by a semicolon.  For
example:

<programlisting>
{ x = 123;
  text = "Hello";
  y = f { bla = 456; };
}</programlisting>

This defines a set with attributes named <varname>x</varname>,
<varname>text</varname>, <varname>y</varname>.  The order of the
attributes is irrelevant.  An attribute name may only occur
once.</para>

<para>Attributes can be selected from a set using the
<literal>.</literal> operator.  For instance,

<programlisting>
{ a = "Foo"; b = "Bar"; }.a</programlisting>

evaluates to <literal>"Foo"</literal>.  It is possible to provide a
default value in an attribute selection using the
<literal>or</literal> keyword.  For example,

<programlisting>
{ a = "Foo"; b = "Bar"; }.c or "Xyzzy"</programlisting>

will evaluate to <literal>"Xyzzy"</literal> because there is no
<varname>c</varname> attribute in the set.</para>

<para>You can use arbitrary double-quoted strings as attribute
names:

<programlisting>
{ "foo ${bar}" = 123; "nix-1.0" = 456; }."foo ${bar}"
</programlisting>

This will evaluate to <literal>123</literal> (Assuming
<literal>bar</literal> is antiquotable). In the case where an
attribute name is just a single antiquotation, the quotes can be
dropped:

<programlisting>
{ foo = 123; }.${bar} or 456 </programlisting>

This will evaluate to <literal>123</literal> if
<literal>bar</literal> evaluates to <literal>"foo"</literal> when
coerced to a string and <literal>456</literal> otherwise (again
assuming <literal>bar</literal> is antiquotable).</para>

<para>In the special case where an attribute name inside of a set declaration
evaluates to <literal>null</literal> (which is normally an error, as
<literal>null</literal> is not antiquotable), that attribute is simply not
added to the set:

<programlisting>
{ ${if foo then "bar" else null} = true; }</programlisting>

This will evaluate to <literal>{}</literal> if <literal>foo</literal>
evaluates to <literal>false</literal>.</para>

<para>A set that has a <literal>__functor</literal> attribute whose value
is callable (i.e. is itself a function or a set with a
<literal>__functor</literal> attribute whose value is callable) can be
applied as if it were a function, with the set itself passed in first
, e.g.,

<programlisting>
let add = { __functor = self: x: x + self.x; };
    inc = add // { x = 1; };
in inc 1
</programlisting>

evaluates to <literal>2</literal>. This can be used to attach metadata to a
function without the caller needing to treat it specially, or to implement
a form of object-oriented programming, for example.

</para>

</simplesect>


</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-constructs">

<title>Language Constructs</title>

<simplesect><title>Recursive sets</title>

<para>Recursive sets are just normal sets, but the attributes can
refer to each other.  For example,

<programlisting>
rec {
  x = y;
  y = 123;
}.x
</programlisting>

evaluates to <literal>123</literal>.  Note that without
<literal>rec</literal> the binding <literal>x = y;</literal> would
refer to the variable <varname>y</varname> in the surrounding scope,
if one exists, and would be invalid if no such variable exists.  That
is, in a normal (non-recursive) set, attributes are not added to the
lexical scope; in a recursive set, they are.</para>

<para>Recursive sets of course introduce the danger of infinite
recursion.  For example,

<programlisting>
rec {
  x = y;
  y = x;
}.x</programlisting>

does not terminate<footnote><para>Actually, Nix detects infinite
recursion in this case and aborts (<quote>infinite recursion
encountered</quote>).</para></footnote>.</para>

</simplesect>


<simplesect xml:id="sect-let-expressions"><title>Let-expressions</title>

<para>A let-expression allows you to define local variables for an
expression.  For instance,

<programlisting>
let
  x = "foo";
  y = "bar";
in x + y</programlisting>

evaluates to <literal>"foobar"</literal>.

</para>

</simplesect>


<simplesect><title>Inheriting attributes</title>

<para>When defining a set or in a let-expression it is often convenient to copy variables
from the surrounding lexical scope (e.g., when you want to propagate
attributes).  This can be shortened using the
<literal>inherit</literal> keyword.  For instance,

<programlisting>
let x = 123; in
{ inherit x;
  y = 456;
}</programlisting>

is equivalent to

<programlisting>
let x = 123; in
{ x = x;
  y = 456;
}</programlisting>

and both evaluate to <literal>{ x = 123; y = 456; }</literal>. (Note that
this works because <varname>x</varname> is added to the lexical scope
by the <literal>let</literal> construct.)  It is also possible to
inherit attributes from another set.  For instance, in this fragment
from <filename>all-packages.nix</filename>,

<programlisting>
  graphviz = (import ../tools/graphics/graphviz) {
    inherit fetchurl stdenv libpng libjpeg expat x11 yacc;
    inherit (xlibs) libXaw;
  };

  xlibs = {
    libX11 = ...;
    libXaw = ...;
    ...
  }

  libpng = ...;
  libjpg = ...;
  ...</programlisting>

the set used in the function call to the function defined in
<filename>../tools/graphics/graphviz</filename> inherits a number of
variables from the surrounding scope (<varname>fetchurl</varname>
... <varname>yacc</varname>), but also inherits
<varname>libXaw</varname> (the X Athena Widgets) from the
<varname>xlibs</varname> (X11 client-side libraries) set.</para>

<para>
Summarizing the fragment

<programlisting>
...
inherit x y z;
inherit (src-set) a b c;
...</programlisting>

is equivalent to

<programlisting>
...
x = x; y = y; z = z;
a = src-set.a; b = src-set.b; c = src-set.c;
...</programlisting>

when used while defining local variables in a let-expression or
while defining a set.</para>

</simplesect>


<simplesect xml:id="ss-functions"><title>Functions</title>

<para>Functions have the following form:

<programlisting>
<replaceable>pattern</replaceable>: <replaceable>body</replaceable></programlisting>

The pattern specifies what the argument of the function must look
like, and binds variables in the body to (parts of) the
argument.  There are three kinds of patterns:</para>

<itemizedlist>


  <listitem><para>If a pattern is a single identifier, then the
  function matches any argument.  Example:

  <programlisting>
let negate = x: !x;
    concat = x: y: x + y;
in if negate true then concat "foo" "bar" else ""</programlisting>

  Note that <function>concat</function> is a function that takes one
  argument and returns a function that takes another argument.  This
  allows partial parameterisation (i.e., only filling some of the
  arguments of a function); e.g.,

  <programlisting>
map (concat "foo") [ "bar" "bla" "abc" ]</programlisting>

  evaluates to <literal>[ "foobar" "foobla"
  "fooabc" ]</literal>.</para></listitem>


  <listitem><para>A <emphasis>set pattern</emphasis> of the form
  <literal>{ name1, name2, &#x2026;, nameN }</literal> matches a set
  containing the listed attributes, and binds the values of those
  attributes to variables in the function body.  For example, the
  function

<programlisting>
{ x, y, z }: z + y + x</programlisting>

  can only be called with a set containing exactly the attributes
  <varname>x</varname>, <varname>y</varname> and
  <varname>z</varname>.  No other attributes are allowed.  If you want
  to allow additional arguments, you can use an ellipsis
  (<literal>...</literal>):

<programlisting>
{ x, y, z, ... }: z + y + x</programlisting>

  This works on any set that contains at least the three named
  attributes.</para>

  <para>It is possible to provide <emphasis>default values</emphasis>
  for attributes, in which case they are allowed to be missing.  A
  default value is specified by writing
  <literal><replaceable>name</replaceable> ?
  <replaceable>e</replaceable></literal>, where
  <replaceable>e</replaceable> is an arbitrary expression.  For example,

<programlisting>
{ x, y ? "foo", z ? "bar" }: z + y + x</programlisting>

  specifies a function that only requires an attribute named
  <varname>x</varname>, but optionally accepts <varname>y</varname>
  and <varname>z</varname>.</para></listitem>


  <listitem><para>An <literal>@</literal>-pattern provides a means of referring
  to the whole value being matched:

<programlisting> args@{ x, y, z, ... }: z + y + x + args.a</programlisting>

but can also be written as:

<programlisting> { x, y, z, ... } @ args: z + y + x + args.a</programlisting>

  Here <varname>args</varname> is bound to the entire argument, which
  is further matched against the pattern <literal>{ x, y, z,
  ... }</literal>. <literal>@</literal>-pattern makes mainly sense with an 
  ellipsis(<literal>...</literal>) as you can access attribute names as 
  <literal>a</literal>, using <literal>args.a</literal>, which was given as an
  additional attribute to the function.
  </para>

  <warning>
   <para>
    The <literal>args@</literal> expression is bound to the argument passed to the function which
    means that attributes with defaults that aren't explicitly specified in the function call
    won't cause an evaluation error, but won't exist in <literal>args</literal>.
   </para>
   <para>
    For instance
<programlisting>
let
  function = args@{ a ? 23, ... }: args;
in
 function {}
</programlisting>
    will evaluate to an empty attribute set.
   </para>
  </warning></listitem>

</itemizedlist>

<para>Note that functions do not have names.  If you want to give them
a name, you can bind them to an attribute, e.g.,

<programlisting>
let concat = { x, y }: x + y;
in concat { x = "foo"; y = "bar"; }</programlisting>

</para>

</simplesect>


<simplesect><title>Conditionals</title>

<para>Conditionals look like this:

<programlisting>
if <replaceable>e1</replaceable> then <replaceable>e2</replaceable> else <replaceable>e3</replaceable></programlisting>

where <replaceable>e1</replaceable> is an expression that should
evaluate to a Boolean value (<literal>true</literal> or
<literal>false</literal>).</para>

</simplesect>


<simplesect><title>Assertions</title>

<para>Assertions are generally used to check that certain requirements
on or between features and dependencies hold.  They look like this:

<programlisting>
assert <replaceable>e1</replaceable>; <replaceable>e2</replaceable></programlisting>

where <replaceable>e1</replaceable> is an expression that should
evaluate to a Boolean value.  If it evaluates to
<literal>true</literal>, <replaceable>e2</replaceable> is returned;
otherwise expression evaluation is aborted and a backtrace is printed.</para>

<example xml:id="ex-subversion-nix"><title>Nix expression for Subversion</title>
<programlisting>
{ localServer ? false
, httpServer ? false
, sslSupport ? false
, pythonBindings ? false
, javaSwigBindings ? false
, javahlBindings ? false
, stdenv, fetchurl
, openssl ? null, httpd ? null, db4 ? null, expat, swig ? null, j2sdk ? null
}:

assert localServer -&gt; db4 != null; <co xml:id="ex-subversion-nix-co-1"/>
assert httpServer -&gt; httpd != null &amp;&amp; httpd.expat == expat; <co xml:id="ex-subversion-nix-co-2"/>
assert sslSupport -&gt; openssl != null &amp;&amp; (httpServer -&gt; httpd.openssl == openssl); <co xml:id="ex-subversion-nix-co-3"/>
assert pythonBindings -&gt; swig != null &amp;&amp; swig.pythonSupport;
assert javaSwigBindings -&gt; swig != null &amp;&amp; swig.javaSupport;
assert javahlBindings -&gt; j2sdk != null;

stdenv.mkDerivation {
  name = "subversion-1.1.1";
  ...
  openssl = if sslSupport then openssl else null; <co xml:id="ex-subversion-nix-co-4"/>
  ...
}</programlisting>
</example>

<para><xref linkend="ex-subversion-nix"/> show how assertions are
used in the Nix expression for Subversion.</para>

<calloutlist>

  <callout arearefs="ex-subversion-nix-co-1">
    <para>This assertion states that if Subversion is to have support
    for local repositories, then Berkeley DB is needed.  So if the
    Subversion function is called with the
    <varname>localServer</varname> argument set to
    <literal>true</literal> but the <varname>db4</varname> argument
    set to <literal>null</literal>, then the evaluation fails.</para>
  </callout>

  <callout arearefs="ex-subversion-nix-co-2">
    <para>This is a more subtle condition: if Subversion is built with
    Apache (<literal>httpServer</literal>) support, then the Expat
    library (an XML library) used by Subversion should be same as the
    one used by Apache.  This is because in this configuration
    Subversion code ends up being linked with Apache code, and if the
    Expat libraries do not match, a build- or runtime link error or
    incompatibility might occur.</para>
  </callout>

  <callout arearefs="ex-subversion-nix-co-3">
    <para>This assertion says that in order for Subversion to have SSL
    support (so that it can access <literal>https</literal> URLs), an
    OpenSSL library must be passed.  Additionally, it says that
    <emphasis>if</emphasis> Apache support is enabled, then Apache's
    OpenSSL should match Subversion's.  (Note that if Apache support
    is not enabled, we don't care about Apache's OpenSSL.)</para>
  </callout>

  <callout arearefs="ex-subversion-nix-co-4">
    <para>The conditional here is not really related to assertions,
    but is worth pointing out: it ensures that if SSL support is
    disabled, then the Subversion derivation is not dependent on
    OpenSSL, even if a non-<literal>null</literal> value was passed.
    This prevents an unnecessary rebuild of Subversion if OpenSSL
    changes.</para>
  </callout>

</calloutlist>

</simplesect>



<simplesect><title>With-expressions</title>

<para>A <emphasis>with-expression</emphasis>,

<programlisting>
with <replaceable>e1</replaceable>; <replaceable>e2</replaceable></programlisting>

introduces the set <replaceable>e1</replaceable> into the lexical
scope of the expression <replaceable>e2</replaceable>.  For instance,

<programlisting>
let as = { x = "foo"; y = "bar"; };
in with as; x + y</programlisting>

evaluates to <literal>"foobar"</literal> since the
<literal>with</literal> adds the <varname>x</varname> and
<varname>y</varname> attributes of <varname>as</varname> to the
lexical scope in the expression <literal>x + y</literal>.  The most
common use of <literal>with</literal> is in conjunction with the
<function>import</function> function.  E.g.,

<programlisting>
with (import ./definitions.nix); ...</programlisting>

makes all attributes defined in the file
<filename>definitions.nix</filename> available as if they were defined
locally in a <literal>let</literal>-expression.</para>

<para>The bindings introduced by <literal>with</literal> do not shadow bindings
introduced by other means, e.g.

<programlisting>
let a = 3; in with { a = 1; }; let a = 4; in with { a = 2; }; ...</programlisting>

establishes the same scope as

<programlisting>
let a = 1; in let a = 2; in let a = 3; in let a = 4; in ...</programlisting>

</para>

</simplesect>


<simplesect><title>Comments</title>

<para>Comments can be single-line, started with a <literal>#</literal>
character, or inline/multi-line, enclosed within <literal>/*
... */</literal>.</para>

</simplesect>


</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-language-operators">

<title>Operators</title>

<para><xref linkend="table-operators"/> lists the operators in the
Nix expression language, in order of precedence (from strongest to
weakest binding).</para>

<table xml:id="table-operators">
  <title>Operators</title>
  <tgroup cols="3">
    <thead>
      <row>
        <entry>Name</entry>
        <entry>Syntax</entry>
        <entry>Associativity</entry>
        <entry>Description</entry>
        <entry>Precedence</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry>Select</entry>
        <entry><replaceable>e</replaceable> <literal>.</literal>
        <replaceable>attrpath</replaceable>
        [ <literal>or</literal> <replaceable>def</replaceable> ]
        </entry>
        <entry>none</entry>
        <entry>Select attribute denoted by the attribute path
        <replaceable>attrpath</replaceable> from set
        <replaceable>e</replaceable>.  (An attribute path is a
        dot-separated list of attribute names.)  If the attribute
        doesn&#x2019;t exist, return <replaceable>def</replaceable> if
        provided, otherwise abort evaluation.</entry>
        <entry>1</entry>
      </row>
      <row>
        <entry>Application</entry>
        <entry><replaceable>e1</replaceable> <replaceable>e2</replaceable></entry>
        <entry>left</entry>
        <entry>Call function <replaceable>e1</replaceable> with
        argument <replaceable>e2</replaceable>.</entry>
        <entry>2</entry>
      </row>
      <row>
        <entry>Arithmetic Negation</entry>
        <entry><literal>-</literal> <replaceable>e</replaceable></entry>
        <entry>none</entry>
        <entry>Arithmetic negation.</entry>
        <entry>3</entry>
      </row>
      <row>
        <entry>Has Attribute</entry>
        <entry><replaceable>e</replaceable> <literal>?</literal>
        <replaceable>attrpath</replaceable></entry>
        <entry>none</entry>
        <entry>Test whether set <replaceable>e</replaceable> contains
        the attribute denoted by <replaceable>attrpath</replaceable>;
        return <literal>true</literal> or
        <literal>false</literal>.</entry>
        <entry>4</entry>
      </row>
      <row>
        <entry>List Concatenation</entry>
        <entry><replaceable>e1</replaceable> <literal>++</literal> <replaceable>e2</replaceable></entry>
        <entry>right</entry>
        <entry>List concatenation.</entry>
        <entry>5</entry>
      </row>
      <row>
        <entry>Multiplication</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>*</literal> <replaceable>e2</replaceable>,
        </entry>
        <entry>left</entry>
        <entry>Arithmetic multiplication.</entry>
        <entry>6</entry>
      </row>
      <row>
        <entry>Division</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>/</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>left</entry>
        <entry>Arithmetic division.</entry>
        <entry>6</entry>
      </row>
      <row>
        <entry>Addition</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>+</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>left</entry>
        <entry>Arithmetic addition.</entry>
        <entry>7</entry>
      </row>
      <row>
        <entry>Subtraction</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>-</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>left</entry>
        <entry>Arithmetic subtraction.</entry>
        <entry>7</entry>
      </row>
      <row>
        <entry>String Concatenation</entry>
        <entry>
          <replaceable>string1</replaceable> <literal>+</literal> <replaceable>string2</replaceable>
        </entry>
        <entry>left</entry>
        <entry>String concatenation.</entry>
        <entry>7</entry>
      </row>
      <row>
        <entry>Not</entry>
        <entry><literal>!</literal> <replaceable>e</replaceable></entry>
        <entry>none</entry>
        <entry>Boolean negation.</entry>
        <entry>8</entry>
      </row>
      <row>
        <entry>Update</entry>
        <entry><replaceable>e1</replaceable> <literal>//</literal>
        <replaceable>e2</replaceable></entry>
        <entry>right</entry>
        <entry>Return a set consisting of the attributes in
        <replaceable>e1</replaceable> and
        <replaceable>e2</replaceable> (with the latter taking
        precedence over the former in case of equally named
        attributes).</entry>
        <entry>9</entry>
      </row>
      <row>
        <entry>Less Than</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>&lt;</literal> <replaceable>e2</replaceable>,
        </entry>
        <entry>none</entry>
        <entry>Arithmetic comparison.</entry>
        <entry>10</entry>
      </row>
      <row>
        <entry>Less Than or Equal To</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>&lt;=</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>none</entry>
        <entry>Arithmetic comparison.</entry>
        <entry>10</entry>
      </row>
      <row>
        <entry>Greater Than</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>&gt;</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>none</entry>
        <entry>Arithmetic comparison.</entry>
        <entry>10</entry>
      </row>
      <row>
        <entry>Greater Than or Equal To</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>&gt;=</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>none</entry>
        <entry>Arithmetic comparison.</entry>
        <entry>10</entry>
      </row>
      <row>
        <entry>Equality</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>==</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>none</entry>
        <entry>Equality.</entry>
        <entry>11</entry>
      </row>
      <row>
        <entry>Inequality</entry>
        <entry>
          <replaceable>e1</replaceable> <literal>!=</literal> <replaceable>e2</replaceable>
        </entry>
        <entry>none</entry>
        <entry>Inequality.</entry>
        <entry>11</entry>
      </row>
      <row>
        <entry>Logical AND</entry>
        <entry><replaceable>e1</replaceable> <literal>&amp;&amp;</literal>
        <replaceable>e2</replaceable></entry>
        <entry>left</entry>
        <entry>Logical AND.</entry>
        <entry>12</entry>
      </row>
      <row>
        <entry>Logical OR</entry>
        <entry><replaceable>e1</replaceable> <literal>||</literal>
        <replaceable>e2</replaceable></entry>
        <entry>left</entry>
        <entry>Logical OR.</entry>
        <entry>13</entry>
      </row>
      <row>
        <entry>Logical Implication</entry>
        <entry><replaceable>e1</replaceable> <literal>-&gt;</literal>
        <replaceable>e2</replaceable></entry>
        <entry>none</entry>
        <entry>Logical implication (equivalent to
        <literal>!<replaceable>e1</replaceable> ||
        <replaceable>e2</replaceable></literal>).</entry>
        <entry>14</entry>
      </row>
    </tbody>
  </tgroup>
</table>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-derivation">

<title>Derivations</title>

<para>The most important built-in function is
<function>derivation</function>, which is used to describe a single
derivation (a build action).  It takes as input a set, the attributes
of which specify the inputs of the build.</para>

<itemizedlist>

  <listitem xml:id="attr-system"><para>There must be an attribute named
  <varname>system</varname> whose value must be a string specifying a
  Nix platform identifier, such as <literal>"i686-linux"</literal> or
  <literal>"x86_64-darwin"</literal><footnote><para>To figure out
  your platform identifier, look at the line <quote>Checking for the
  canonical Nix system name</quote> in the output of Nix's
  <filename>configure</filename> script.</para></footnote> The build
  can only be performed on a machine and operating system matching the
  platform identifier.  (Nix can automatically forward builds for
  other platforms by forwarding them to other machines; see <xref linkend="chap-distributed-builds"/>.)</para></listitem>

  <listitem><para>There must be an attribute named
  <varname>name</varname> whose value must be a string.  This is used
  as a symbolic name for the package by <command>nix-env</command>,
  and it is appended to the output paths of the
  derivation.</para></listitem>

  <listitem><para>There must be an attribute named
  <varname>builder</varname> that identifies the program that is
  executed to perform the build.  It can be either a derivation or a
  source (a local file reference, e.g.,
  <filename>./builder.sh</filename>).</para></listitem>

  <listitem><para>Every attribute is passed as an environment variable
  to the builder.  Attribute values are translated to environment
  variables as follows:

    <itemizedlist>

      <listitem><para>Strings and numbers are just passed
      verbatim.</para></listitem>

      <listitem><para>A <emphasis>path</emphasis> (e.g.,
      <filename>../foo/sources.tar</filename>) causes the referenced
      file to be copied to the store; its location in the store is put
      in the environment variable.  The idea is that all sources
      should reside in the Nix store, since all inputs to a derivation
      should reside in the Nix store.</para></listitem>

      <listitem><para>A <emphasis>derivation</emphasis> causes that
      derivation to be built prior to the present derivation; its
      default output path is put in the environment
      variable.</para></listitem>

      <listitem><para>Lists of the previous types are also allowed.
      They are simply concatenated, separated by
      spaces.</para></listitem>

      <listitem><para><literal>true</literal> is passed as the string
      <literal>1</literal>, <literal>false</literal> and
      <literal>null</literal> are passed as an empty string.
      </para></listitem>
    </itemizedlist>

  </para></listitem>

  <listitem><para>The optional attribute <varname>args</varname>
  specifies command-line arguments to be passed to the builder.  It
  should be a list.</para></listitem>

  <listitem><para>The optional attribute <varname>outputs</varname>
  specifies a list of symbolic outputs of the derivation.  By default,
  a derivation produces a single output path, denoted as
  <literal>out</literal>.  However, derivations can produce multiple
  output paths.  This is useful because it allows outputs to be
  downloaded or garbage-collected separately.  For instance, imagine a
  library package that provides a dynamic library, header files, and
  documentation.  A program that links against the library doesn&#x2019;t
  need the header files and documentation at runtime, and it doesn&#x2019;t
  need the documentation at build time.  Thus, the library package
  could specify:
<programlisting>
outputs = [ "lib" "headers" "doc" ];
</programlisting>
  This will cause Nix to pass environment variables
  <literal>lib</literal>, <literal>headers</literal> and
  <literal>doc</literal> to the builder containing the intended store
  paths of each output.  The builder would typically do something like
<programlisting>
./configure --libdir=$lib/lib --includedir=$headers/include --docdir=$doc/share/doc
</programlisting>
  for an Autoconf-style package.  You can refer to each output of a
  derivation by selecting it as an attribute, e.g.
<programlisting>
buildInputs = [ pkg.lib pkg.headers ];
</programlisting>
  The first element of <varname>outputs</varname> determines the
  <emphasis>default output</emphasis>.  Thus, you could also write
<programlisting>
buildInputs = [ pkg pkg.headers ];
</programlisting>
  since <literal>pkg</literal> is equivalent to
  <literal>pkg.lib</literal>.</para></listitem>

</itemizedlist>

<para>The function <function>mkDerivation</function> in the Nixpkgs
standard environment is a wrapper around
<function>derivation</function> that adds a default value for
<varname>system</varname> and always uses Bash as the builder, to
which the supplied builder is passed as a command-line argument.  See
the Nixpkgs manual for details.</para>

<para>The builder is executed as follows:

<itemizedlist>

  <listitem><para>A temporary directory is created under the directory
  specified by <envar>TMPDIR</envar> (default
  <filename>/tmp</filename>) where the build will take place.  The
  current directory is changed to this directory.</para></listitem>

  <listitem><para>The environment is cleared and set to the derivation
  attributes, as specified above.</para></listitem>

  <listitem><para>In addition, the following variables are set:

  <itemizedlist>

    <listitem><para><envar>NIX_BUILD_TOP</envar> contains the path of
    the temporary directory for this build.</para></listitem>

    <listitem><para>Also, <envar>TMPDIR</envar>,
    <envar>TEMPDIR</envar>, <envar>TMP</envar>, <envar>TEMP</envar>
    are set to point to the temporary directory.  This is to prevent
    the builder from accidentally writing temporary files anywhere
    else.  Doing so might cause interference by other
    processes.</para></listitem>

    <listitem><para><envar>PATH</envar> is set to
    <filename>/path-not-set</filename> to prevent shells from
    initialising it to their built-in default value.</para></listitem>

    <listitem><para><envar>HOME</envar> is set to
    <filename>/homeless-shelter</filename> to prevent programs from
    using <filename>/etc/passwd</filename> or the like to find the
    user's home directory, which could cause impurity.  Usually, when
    <envar>HOME</envar> is set, it is used as the location of the home
    directory, even if it points to a non-existent
    path.</para></listitem>

    <listitem><para><envar>NIX_STORE</envar> is set to the path of the
    top-level Nix store directory (typically,
    <filename>/nix/store</filename>).</para></listitem>

    <listitem><para>For each output declared in
    <varname>outputs</varname>, the corresponding environment variable
    is set to point to the intended path in the Nix store for that
    output.  Each output path is a concatenation of the cryptographic
    hash of all build inputs, the <varname>name</varname> attribute
    and the output name.  (The output name is omitted if it&#x2019;s
    <literal>out</literal>.)</para></listitem>

  </itemizedlist>

  </para></listitem>

  <listitem><para>If an output path already exists, it is removed.
  Also, locks are acquired to prevent multiple Nix instances from
  performing the same build at the same time.</para></listitem>

  <listitem><para>A log of the combined standard output and error is
  written to <filename>/nix/var/log/nix</filename>.</para></listitem>

  <listitem><para>The builder is executed with the arguments specified
  by the attribute <varname>args</varname>.  If it exits with exit
  code 0, it is considered to have succeeded.</para></listitem>

  <listitem><para>The temporary directory is removed (unless the
  <option>-K</option> option was specified).</para></listitem>

  <listitem><para>If the build was successful, Nix scans each output
  path for references to input paths by looking for the hash parts of
  the input paths.  Since these are potential runtime dependencies,
  Nix registers them as dependencies of the output
  paths.</para></listitem>

  <listitem><para>After the build, Nix sets the last-modified
  timestamp on all files in the build result to 1 (00:00:01 1/1/1970
  UTC), sets the group to the default group, and sets the mode of the
  file to 0444 or 0555 (i.e., read-only, with execute permission
  enabled if the file was originally executable).  Note that possible
  <literal>setuid</literal> and <literal>setgid</literal> bits are
  cleared.  Setuid and setgid programs are not currently supported by
  Nix.  This is because the Nix archives used in deployment have no
  concept of ownership information, and because it makes the build
  result dependent on the user performing the build.</para></listitem>

</itemizedlist>

</para>

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-advanced-attributes">

<title>Advanced Attributes</title>

<para>Derivations can declare some infrequently used optional
attributes.</para>

<variablelist>

  <varlistentry xml:id="adv-attr-allowedReferences"><term><varname>allowedReferences</varname></term>

    <listitem><para>The optional attribute
    <varname>allowedReferences</varname> specifies a list of legal
    references (dependencies) of the output of the builder.  For
    example,

<programlisting>
allowedReferences = [];
</programlisting>

    enforces that the output of a derivation cannot have any runtime
    dependencies on its inputs.  To allow an output to have a runtime
    dependency on itself, use <literal>"out"</literal> as a list item.
    This is used in NixOS to check that generated files such as
    initial ramdisks for booting Linux don&#x2019;t have accidental
    dependencies on other paths in the Nix store.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-allowedRequisites"><term><varname>allowedRequisites</varname></term>

    <listitem><para>This attribute is similar to
    <varname>allowedReferences</varname>, but it specifies the legal
    requisites of the whole closure, so all the dependencies
    recursively.  For example,

<programlisting>
allowedRequisites = [ foobar ];
</programlisting>

    enforces that the output of a derivation cannot have any other
    runtime dependency than <varname>foobar</varname>, and in addition
    it enforces that <varname>foobar</varname> itself doesn't
    introduce any other dependency itself.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="adv-attr-disallowedReferences"><term><varname>disallowedReferences</varname></term>

    <listitem><para>The optional attribute
    <varname>disallowedReferences</varname> specifies a list of illegal
    references (dependencies) of the output of the builder.  For
    example,

<programlisting>
disallowedReferences = [ foo ];
</programlisting>

    enforces that the output of a derivation cannot have a direct runtime
    dependencies on the derivation <varname>foo</varname>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-disallowedRequisites"><term><varname>disallowedRequisites</varname></term>

    <listitem><para>This attribute is similar to
    <varname>disallowedReferences</varname>, but it specifies illegal
    requisites for the whole closure, so all the dependencies
    recursively.  For example,

<programlisting>
disallowedRequisites = [ foobar ];
</programlisting>

    enforces that the output of a derivation cannot have any
    runtime dependency on <varname>foobar</varname> or any other derivation
    depending recursively on <varname>foobar</varname>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-exportReferencesGraph"><term><varname>exportReferencesGraph</varname></term>

    <listitem><para>This attribute allows builders access to the
    references graph of their inputs.  The attribute is a list of
    inputs in the Nix store whose references graph the builder needs
    to know.  The value of this attribute should be a list of pairs
    <literal>[ <replaceable>name1</replaceable>
    <replaceable>path1</replaceable> <replaceable>name2</replaceable>
    <replaceable>path2</replaceable> <replaceable>...</replaceable>
    ]</literal>.  The references graph of each
    <replaceable>pathN</replaceable> will be stored in a text file
    <replaceable>nameN</replaceable> in the temporary build directory.
    The text files have the format used by <command>nix-store
    --register-validity</command> (with the deriver fields left
    empty).  For example, when the following derivation is built:

<programlisting>
derivation {
  ...
  exportReferencesGraph = [ "libfoo-graph" libfoo ];
};
</programlisting>

    the references graph of <literal>libfoo</literal> is placed in the
    file <filename>libfoo-graph</filename> in the temporary build
    directory.</para>

    <para><varname>exportReferencesGraph</varname> is useful for
    builders that want to do something with the closure of a store
    path.  Examples include the builders in NixOS that generate the
    initial ramdisk for booting Linux (a <command>cpio</command>
    archive containing the closure of the boot script) and the
    ISO-9660 image for the installation CD (which is populated with a
    Nix store containing the closure of a bootable NixOS
    configuration).</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-impureEnvVars"><term><varname>impureEnvVars</varname></term>

    <listitem><para>This attribute allows you to specify a list of
    environment variables that should be passed from the environment
    of the calling user to the builder.  Usually, the environment is
    cleared completely when the builder is executed, but with this
    attribute you can allow specific environment variables to be
    passed unmodified.  For example, <function>fetchurl</function> in
    Nixpkgs has the line

<programlisting>
impureEnvVars = [ "http_proxy" "https_proxy" <replaceable>...</replaceable> ];
</programlisting>

    to make it use the proxy server configuration specified by the
    user in the environment variables <envar>http_proxy</envar> and
    friends.</para>

    <para>This attribute is only allowed in <link linkend="fixed-output-drvs">fixed-output derivations</link>, where
    impurities such as these are okay since (the hash of) the output
    is known in advance.  It is ignored for all other
    derivations.</para>

    <warning><para><varname>impureEnvVars</varname> implementation takes
    environment variables from the current builder process. When a daemon is
    building its environmental variables are used. Without the daemon, the
    environmental variables come from the environment of the
    <command>nix-build</command>.</para></warning></listitem>

  </varlistentry>


  <varlistentry xml:id="fixed-output-drvs">
    <term xml:id="adv-attr-outputHash"><varname>outputHash</varname></term>
    <term xml:id="adv-attr-outputHashAlgo"><varname>outputHashAlgo</varname></term>
    <term xml:id="adv-attr-outputHashMode"><varname>outputHashMode</varname></term>

    <listitem><para>These attributes declare that the derivation is a
    so-called <emphasis>fixed-output derivation</emphasis>, which
    means that a cryptographic hash of the output is already known in
    advance.  When the build of a fixed-output derivation finishes,
    Nix computes the cryptographic hash of the output and compares it
    to the hash declared with these attributes.  If there is a
    mismatch, the build fails.</para>

    <para>The rationale for fixed-output derivations is derivations
    such as those produced by the <function>fetchurl</function>
    function.  This function downloads a file from a given URL.  To
    ensure that the downloaded file has not been modified, the caller
    must also specify a cryptographic hash of the file.  For example,

<programlisting>
fetchurl {
  url = "http://ftp.gnu.org/pub/gnu/hello/hello-2.1.1.tar.gz";
  sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
}
</programlisting>

    It sometimes happens that the URL of the file changes, e.g.,
    because servers are reorganised or no longer available.  We then
    must update the call to <function>fetchurl</function>, e.g.,

<programlisting>
fetchurl {
  url = "ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz";
  sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
}
</programlisting>

    If a <function>fetchurl</function> derivation was treated like a
    normal derivation, the output paths of the derivation and
    <emphasis>all derivations depending on it</emphasis> would change.
    For instance, if we were to change the URL of the Glibc source
    distribution in Nixpkgs (a package on which almost all other
    packages depend) massive rebuilds would be needed.  This is
    unfortunate for a change which we know cannot have a real effect
    as it propagates upwards through the dependency graph.</para>

    <para>For fixed-output derivations, on the other hand, the name of
    the output path only depends on the <varname>outputHash*</varname>
    and <varname>name</varname> attributes, while all other attributes
    are ignored for the purpose of computing the output path.  (The
    <varname>name</varname> attribute is included because it is part
    of the path.)</para>

    <para>As an example, here is the (simplified) Nix expression for
    <varname>fetchurl</varname>:

<programlisting>
{ stdenv, curl }: # The <command>curl</command> program is used for downloading.

{ url, sha256 }:

stdenv.mkDerivation {
  name = baseNameOf (toString url);
  builder = ./builder.sh;
  buildInputs = [ curl ];

  # This is a fixed-output derivation; the output must be a regular
  # file with SHA256 hash <varname>sha256</varname>.
  outputHashMode = "flat";
  outputHashAlgo = "sha256";
  outputHash = sha256;

  inherit url;
}
</programlisting>

    </para>

    <para>The <varname>outputHashAlgo</varname> attribute specifies
    the hash algorithm used to compute the hash.  It can currently be
    <literal>"sha1"</literal>, <literal>"sha256"</literal> or
    <literal>"sha512"</literal>.</para>

    <para>The <varname>outputHashMode</varname> attribute determines
    how the hash is computed.  It must be one of the following two
    values:

    <variablelist>

      <varlistentry><term><literal>"flat"</literal></term>

        <listitem><para>The output must be a non-executable regular
        file.  If it isn&#x2019;t, the build fails.  The hash is simply
        computed over the contents of that file (so it&#x2019;s equal to what
        Unix commands like <command>sha256sum</command> or
        <command>sha1sum</command> produce).</para>

        <para>This is the default.</para></listitem>

      </varlistentry>

      <varlistentry><term><literal>"recursive"</literal></term>

        <listitem><para>The hash is computed over the NAR archive dump
        of the output (i.e., the result of <link linkend="refsec-nix-store-dump"><command>nix-store
        --dump</command></link>).  In this case, the output can be
        anything, including a directory tree.</para></listitem>

      </varlistentry>

    </variablelist>

    </para>

    <para>The <varname>outputHash</varname> attribute, finally, must
    be a string containing the hash in either hexadecimal or base-32
    notation.  (See the <link linkend="sec-nix-hash"><command>nix-hash</command> command</link>
    for information about converting to and from base-32
    notation.)</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-passAsFile"><term><varname>passAsFile</varname></term>

    <listitem><para>A list of names of attributes that should be
    passed via files rather than environment variables.  For example,
    if you have

    <programlisting>
passAsFile = ["big"];
big = "a very long string";
    </programlisting>

    then when the builder runs, the environment variable
    <envar>bigPath</envar> will contain the absolute path to a
    temporary file containing <literal>a very long
    string</literal>. That is, for any attribute
    <replaceable>x</replaceable> listed in
    <varname>passAsFile</varname>, Nix will pass an environment
    variable <envar><replaceable>x</replaceable>Path</envar> holding
    the path of the file containing the value of attribute
    <replaceable>x</replaceable>. This is useful when you need to pass
    large strings to a builder, since most operating systems impose a
    limit on the size of the environment (typically, a few hundred
    kilobyte).</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-preferLocalBuild"><term><varname>preferLocalBuild</varname></term>

    <listitem><para>If this attribute is set to
    <literal>true</literal> and <link linkend="chap-distributed-builds">distributed building is
    enabled</link>, then, if possible, the derivaton will be built
    locally instead of forwarded to a remote machine.  This is
    appropriate for trivial builders where the cost of doing a
    download or remote build would exceed the cost of building
    locally.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="adv-attr-allowSubstitutes"><term><varname>allowSubstitutes</varname></term>

    <listitem>
    <para>If this attribute is set to
    <literal>false</literal>, then Nix will always build this
    derivation; it will not try to substitute its outputs. This is
    useful for very trivial derivations (such as
    <function>writeText</function> in Nixpkgs) that are cheaper to
    build than to substitute from a binary cache.</para>

    <note><para>You need to have a builder configured which satisfies
    the derivation&#x2019;s <literal>system</literal> attribute, since the
    derivation cannot be substituted. Thus it is usually a good idea
    to align <literal>system</literal> with
    <literal>builtins.currentSystem</literal> when setting
    <literal>allowSubstitutes</literal> to <literal>false</literal>.
    For most trivial derivations this should be the case.
    </para></note>
    </listitem>

  </varlistentry>


</variablelist>

</section>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-builtins">

<title>Built-in Functions</title>

<para>This section lists the functions and constants built into the
Nix expression evaluator.  (The built-in function
<function>derivation</function> is discussed above.)  Some built-ins,
such as <function>derivation</function>, are always in scope of every
Nix expression; you can just access them right away.  But to prevent
polluting the namespace too much, most built-ins are not in scope.
Instead, you can access them through the <varname>builtins</varname>
built-in value, which is a set that contains all built-in functions
and values.  For instance, <function>derivation</function> is also
available as <function>builtins.derivation</function>.</para>


<variablelist>


  <varlistentry xml:id="builtin-abort">
    <term><function>abort</function> <replaceable>s</replaceable></term>
    <term><function>builtins.abort</function> <replaceable>s</replaceable></term>

    <listitem><para>Abort Nix expression evaluation, print error
    message <replaceable>s</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-add">
    <term><function>builtins.add</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable>
    </term>

    <listitem><para>Return the sum of the numbers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-all">
    <term><function>builtins.all</function>
    <replaceable>pred</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Return <literal>true</literal> if the function
    <replaceable>pred</replaceable> returns <literal>true</literal>
    for all elements of <replaceable>list</replaceable>,
    and <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-any">
    <term><function>builtins.any</function>
    <replaceable>pred</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Return <literal>true</literal> if the function
    <replaceable>pred</replaceable> returns <literal>true</literal>
    for at least one element of <replaceable>list</replaceable>,
    and <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-attrNames">
    <term><function>builtins.attrNames</function>
    <replaceable>set</replaceable></term>

    <listitem><para>Return the names of the attributes in the set
    <replaceable>set</replaceable> in an alphabetically sorted list.  For instance,
    <literal>builtins.attrNames { y = 1; x = "foo"; }</literal>
    evaluates to <literal>[ "x" "y" ]</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-attrValues">
    <term><function>builtins.attrValues</function>
    <replaceable>set</replaceable></term>

    <listitem><para>Return the values of the attributes in the set
    <replaceable>set</replaceable> in the order corresponding to the
    sorted attribute names.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-baseNameOf">
    <term><function>baseNameOf</function> <replaceable>s</replaceable></term>

    <listitem><para>Return the <emphasis>base name</emphasis> of the
    string <replaceable>s</replaceable>, that is, everything following
    the final slash in the string.  This is similar to the GNU
    <command>basename</command> command.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-bitAnd">
    <term><function>builtins.bitAnd</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return the bitwise AND of the integers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-bitOr">
    <term><function>builtins.bitOr</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return the bitwise OR of the integers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-bitXor">
    <term><function>builtins.bitXor</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return the bitwise XOR of the integers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-builtins">
    <term><varname>builtins</varname></term>

    <listitem><para>The set <varname>builtins</varname> contains all
    the built-in functions and values.  You can use
    <varname>builtins</varname> to test for the availability of
    features in the Nix installation, e.g.,

<programlisting>
if builtins ? getEnv then builtins.getEnv "PATH" else ""</programlisting>

    This allows a Nix expression to fall back gracefully on older Nix
    installations that don&#x2019;t have the desired built-in
    function.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-compareVersions">
    <term><function>builtins.compareVersions</function>
    <replaceable>s1</replaceable> <replaceable>s2</replaceable></term>

    <listitem><para>Compare two strings representing versions and
    return <literal>-1</literal> if version
    <replaceable>s1</replaceable> is older than version
    <replaceable>s2</replaceable>, <literal>0</literal> if they are
    the same, and <literal>1</literal> if
    <replaceable>s1</replaceable> is newer than
    <replaceable>s2</replaceable>.  The version comparison algorithm
    is the same as the one used by <link linkend="ssec-version-comparisons"><command>nix-env
    -u</command></link>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-concatLists">
    <term><function>builtins.concatLists</function>
    <replaceable>lists</replaceable></term>

    <listitem><para>Concatenate a list of lists into a single
    list.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-concatStringsSep">
    <term><function>builtins.concatStringsSep</function>
    <replaceable>separator</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Concatenate a list of strings with a separator
    between each element, e.g. <literal>concatStringsSep "/"
    ["usr" "local" "bin"] == "usr/local/bin"</literal></para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-currentSystem">
    <term><varname>builtins.currentSystem</varname></term>

    <listitem><para>The built-in value <varname>currentSystem</varname>
    evaluates to the Nix platform identifier for the Nix installation
    on which the expression is being evaluated, such as
    <literal>"i686-linux"</literal> or
    <literal>"x86_64-darwin"</literal>.</para></listitem>

  </varlistentry>


  <!--
  <varlistentry><term><function>currentTime</function></term>

    <listitem><para>The built-in value <varname>currentTime</varname>
    returns the current system time in seconds since 00:00:00 1/1/1970
    UTC.  Due to the evaluation model of Nix expressions
    (<emphasis>maximal laziness</emphasis>), it always yields the same
    value within an execution of Nix.</para></listitem>

  </varlistentry>
  -->


  <!--
  <varlistentry><term><function>dependencyClosure</function></term>

    <listitem><para>TODO</para></listitem>

  </varlistentry>
  -->


  <varlistentry xml:id="builtin-deepSeq">
    <term><function>builtins.deepSeq</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>This is like <literal>seq
    <replaceable>e1</replaceable>
    <replaceable>e2</replaceable></literal>, except that
    <replaceable>e1</replaceable> is evaluated
    <emphasis>deeply</emphasis>: if it&#x2019;s a list or set, its elements
    or attributes are also evaluated recursively.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-derivation">
    <term><function>derivation</function>
    <replaceable>attrs</replaceable></term>
    <term><function>builtins.derivation</function>
    <replaceable>attrs</replaceable></term>

    <listitem><para><function>derivation</function> is described in
    <xref linkend="ssec-derivation"/>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-dirOf">
    <term><function>dirOf</function> <replaceable>s</replaceable></term>
    <term><function>builtins.dirOf</function> <replaceable>s</replaceable></term>

    <listitem><para>Return the directory part of the string
    <replaceable>s</replaceable>, that is, everything before the final
    slash in the string.  This is similar to the GNU
    <command>dirname</command> command.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-div">
    <term><function>builtins.div</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return the quotient of the numbers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-elem">
    <term><function>builtins.elem</function>
    <replaceable>x</replaceable> <replaceable>xs</replaceable></term>

    <listitem><para>Return <literal>true</literal> if a value equal to
    <replaceable>x</replaceable> occurs in the list
    <replaceable>xs</replaceable>, and <literal>false</literal>
    otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-elemAt">
    <term><function>builtins.elemAt</function>
    <replaceable>xs</replaceable> <replaceable>n</replaceable></term>

    <listitem><para>Return element <replaceable>n</replaceable> from
    the list <replaceable>xs</replaceable>.  Elements are counted
    starting from 0.  A fatal error occurs if the index is out of
    bounds.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-fetchurl">
    <term><function>builtins.fetchurl</function>
    <replaceable>url</replaceable></term>

    <listitem><para>Download the specified URL and return the path of
    the downloaded file. This function is not available if <link linkend="conf-restrict-eval">restricted evaluation mode</link> is
    enabled.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-fetchTarball">
    <term><function>fetchTarball</function>
    <replaceable>url</replaceable></term>
    <term><function>builtins.fetchTarball</function>
    <replaceable>url</replaceable></term>

    <listitem><para>Download the specified URL, unpack it and return
    the path of the unpacked tree. The file must be a tape archive
    (<filename>.tar</filename>) compressed with
    <literal>gzip</literal>, <literal>bzip2</literal> or
    <literal>xz</literal>. The top-level path component of the files
    in the tarball is removed, so it is best if the tarball contains a
    single directory at top level. The typical use of the function is
    to obtain external Nix expression dependencies, such as a
    particular version of Nixpkgs, e.g.

<programlisting>
with import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-14.12.tar.gz) {};

stdenv.mkDerivation { &#x2026; }
</programlisting>
    </para>

    <para>The fetched tarball is cached for a certain amount of time
    (1 hour by default) in <filename>~/.cache/nix/tarballs/</filename>.
    You can change the cache timeout either on the command line with
    <option>--option tarball-ttl <replaceable>number of seconds</replaceable></option> or
    in the Nix configuration file with this option:
    <literal><xref linkend="conf-tarball-ttl"/> <replaceable>number of seconds to cache</replaceable></literal>.
    </para>

    <para>Note that when obtaining the hash with <varname>nix-prefetch-url
    </varname> the option <varname>--unpack</varname> is required.
    </para>

    <para>This function can also verify the contents against a hash.
    In that case, the function takes a set instead of a URL. The set
    requires the attribute <varname>url</varname> and the attribute
    <varname>sha256</varname>, e.g.

<programlisting>
with import (fetchTarball {
  url = "https://github.com/NixOS/nixpkgs/archive/nixos-14.12.tar.gz";
  sha256 = "1jppksrfvbk5ypiqdz4cddxdl8z6zyzdb2srq8fcffr327ld5jj2";
}) {};

stdenv.mkDerivation { &#x2026; }
</programlisting>

    </para>

    <para>This function is not available if <link linkend="conf-restrict-eval">restricted evaluation mode</link> is
    enabled.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-fetchGit">
    <term>
      <function>builtins.fetchGit</function>
      <replaceable>args</replaceable>
    </term>

    <listitem>
      <para>
        Fetch a path from git. <replaceable>args</replaceable> can be
        a URL, in which case the HEAD of the repo at that URL is
        fetched. Otherwise, it can be an attribute with the following
        attributes (all except <varname>url</varname> optional):
      </para>

      <variablelist>
        <varlistentry>
          <term>url</term>
          <listitem>
            <para>
              The URL of the repo.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>name</term>
          <listitem>
            <para>
              The name of the directory the repo should be exported to
              in the store. Defaults to the basename of the URL.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>rev</term>
          <listitem>
            <para>
              The git revision to fetch. Defaults to the tip of
              <varname>ref</varname>.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>ref</term>
          <listitem>
            <para>
              The git ref to look for the requested revision under.
              This is often a branch or tag name. Defaults to
              <literal>HEAD</literal>.
            </para>

            <para>
              By default, the <varname>ref</varname> value is prefixed
              with <literal>refs/heads/</literal>. As of Nix 2.3.0
              Nix will not prefix <literal>refs/heads/</literal> if
              <varname>ref</varname> starts with <literal>refs/</literal>.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>submodules</term>
          <listitem>
            <para>
              A Boolean parameter that specifies whether submodules
              should be checked out. Defaults to
              <literal>false</literal>.
            </para>
          </listitem>
        </varlistentry>
      </variablelist>

      <example>
        <title>Fetching a private repository over SSH</title>
        <programlisting>builtins.fetchGit {
  url = "git@github.com:my-secret/repository.git";
  ref = "master";
  rev = "adab8b916a45068c044658c4158d81878f9ed1c3";
}</programlisting>
      </example>

      <example>
        <title>Fetching an arbitrary ref</title>
        <programlisting>builtins.fetchGit {
  url = "https://github.com/NixOS/nix.git";
  ref = "refs/heads/0.5-release";
}</programlisting>
      </example>

      <example>
        <title>Fetching a repository's specific commit on an arbitrary branch</title>
        <para>
          If the revision you're looking for is in the default branch
          of the git repository you don't strictly need to specify
          the branch name in the <varname>ref</varname> attribute.
        </para>
        <para>
          However, if the revision you're looking for is in a future
          branch for the non-default branch you will need to specify
          the the <varname>ref</varname> attribute as well.
        </para>
        <programlisting>builtins.fetchGit {
  url = "https://github.com/nixos/nix.git";
  rev = "841fcbd04755c7a2865c51c1e2d3b045976b7452";
  ref = "1.11-maintenance";
}</programlisting>
        <note>
          <para>
            It is nice to always specify the branch which a revision
            belongs to. Without the branch being specified, the
            fetcher might fail if the default branch changes.
            Additionally, it can be confusing to try a commit from a
            non-default branch and see the fetch fail. If the branch
            is specified the fault is much more obvious.
          </para>
        </note>
      </example>

      <example>
        <title>Fetching a repository's specific commit on the default branch</title>
        <para>
          If the revision you're looking for is in the default branch
          of the git repository you may omit the
          <varname>ref</varname> attribute.
        </para>
        <programlisting>builtins.fetchGit {
  url = "https://github.com/nixos/nix.git";
  rev = "841fcbd04755c7a2865c51c1e2d3b045976b7452";
}</programlisting>
      </example>

      <example>
        <title>Fetching a tag</title>
        <programlisting>builtins.fetchGit {
  url = "https://github.com/nixos/nix.git";
  ref = "refs/tags/1.9";
}</programlisting>
      </example>

      <example>
        <title>Fetching the latest version of a remote branch</title>
        <para>
          <function>builtins.fetchGit</function> can behave impurely
           fetch the latest version of a remote branch.
        </para>
        <note><para>Nix will refetch the branch in accordance to
        <xref linkend="conf-tarball-ttl"/>.</para></note>
        <note><para>This behavior is disabled in
        <emphasis>Pure evaluation mode</emphasis>.</para></note>
        <programlisting>builtins.fetchGit {
  url = "ssh://git@github.com/nixos/nix.git";
  ref = "master";
}</programlisting>
      </example>
    </listitem>
  </varlistentry>


  <varlistentry><term><function>builtins.filter</function>
  <replaceable>f</replaceable> <replaceable>xs</replaceable></term>

    <listitem><para>Return a list consisting of the elements of
    <replaceable>xs</replaceable> for which the function
    <replaceable>f</replaceable> returns
    <literal>true</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-filterSource">
    <term><function>builtins.filterSource</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem>

      <para>This function allows you to copy sources into the Nix
      store while filtering certain files.  For instance, suppose that
      you want to use the directory <filename>source-dir</filename> as
      an input to a Nix expression, e.g.

<programlisting>
stdenv.mkDerivation {
  ...
  src = ./source-dir;
}
</programlisting>

      However, if <filename>source-dir</filename> is a Subversion
      working copy, then all those annoying <filename>.svn</filename>
      subdirectories will also be copied to the store.  Worse, the
      contents of those directories may change a lot, causing lots of
      spurious rebuilds.  With <function>filterSource</function> you
      can filter out the <filename>.svn</filename> directories:

<programlisting>
  src = builtins.filterSource
    (path: type: type != "directory" || baseNameOf path != ".svn")
    ./source-dir;
</programlisting>

      </para>

      <para>Thus, the first argument <replaceable>e1</replaceable>
      must be a predicate function that is called for each regular
      file, directory or symlink in the source tree
      <replaceable>e2</replaceable>.  If the function returns
      <literal>true</literal>, the file is copied to the Nix store,
      otherwise it is omitted.  The function is called with two
      arguments.  The first is the full path of the file.  The second
      is a string that identifies the type of the file, which is
      either <literal>"regular"</literal>,
      <literal>"directory"</literal>, <literal>"symlink"</literal> or
      <literal>"unknown"</literal> (for other kinds of files such as
      device nodes or fifos &#x2014; but note that those cannot be copied to
      the Nix store, so if the predicate returns
      <literal>true</literal> for them, the copy will fail). If you
      exclude a directory, the entire corresponding subtree of
      <replaceable>e2</replaceable> will be excluded.</para>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-foldl-prime">
    <term><function>builtins.foldl&#x2019;</function>
    <replaceable>op</replaceable> <replaceable>nul</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Reduce a list by applying a binary operator, from
    left to right, e.g. <literal>foldl&#x2019; op nul [x0 x1 x2 ...] = op (op
    (op nul x0) x1) x2) ...</literal>. The operator is applied
    strictly, i.e., its arguments are evaluated first. For example,
    <literal>foldl&#x2019; (x: y: x + y) 0 [1 2 3]</literal> evaluates to
    6.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-functionArgs">
    <term><function>builtins.functionArgs</function>
    <replaceable>f</replaceable></term>

    <listitem><para>
    Return a set containing the names of the formal arguments expected
    by the function <replaceable>f</replaceable>.
    The value of each attribute is a Boolean denoting whether the corresponding
    argument has a default value.  For instance,
    <literal>functionArgs ({ x, y ? 123}: ...)  =  { x = false; y = true; }</literal>.
    </para>

    <para>"Formal argument" here refers to the attributes pattern-matched by
    the function.  Plain lambdas are not included, e.g.
    <literal>functionArgs (x: ...)  =  { }</literal>.
    </para></listitem>
  </varlistentry>


  <varlistentry xml:id="builtin-fromJSON">
    <term><function>builtins.fromJSON</function> <replaceable>e</replaceable></term>

    <listitem><para>Convert a JSON string to a Nix
    value. For example,

<programlisting>
builtins.fromJSON ''{"x": [1, 2, 3], "y": null}''
</programlisting>

    returns the value <literal>{ x = [ 1 2 3 ]; y = null;
    }</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-genList">
    <term><function>builtins.genList</function>
    <replaceable>generator</replaceable> <replaceable>length</replaceable></term>

    <listitem><para>Generate list of size
    <replaceable>length</replaceable>, with each element
    <replaceable>i</replaceable> equal to the value returned by
    <replaceable>generator</replaceable> <literal>i</literal>. For
    example,

<programlisting>
builtins.genList (x: x * x) 5
</programlisting>

    returns the list <literal>[ 0 1 4 9 16 ]</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-getAttr">
    <term><function>builtins.getAttr</function>
    <replaceable>s</replaceable> <replaceable>set</replaceable></term>

    <listitem><para><function>getAttr</function> returns the attribute
    named <replaceable>s</replaceable> from
    <replaceable>set</replaceable>.  Evaluation aborts if the
    attribute doesn&#x2019;t exist.  This is a dynamic version of the
    <literal>.</literal> operator, since <replaceable>s</replaceable>
    is an expression rather than an identifier.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-getEnv">
    <term><function>builtins.getEnv</function>
    <replaceable>s</replaceable></term>

    <listitem><para><function>getEnv</function> returns the value of
    the environment variable <replaceable>s</replaceable>, or an empty
    string if the variable doesn&#x2019;t exist.  This function should be
    used with care, as it can introduce all sorts of nasty environment
    dependencies in your Nix expression.</para>

    <para><function>getEnv</function> is used in Nix Packages to
    locate the file <filename>~/.nixpkgs/config.nix</filename>, which
    contains user-local settings for Nix Packages.  (That is, it does
    a <literal>getEnv "HOME"</literal> to locate the user&#x2019;s home
    directory.)</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-hasAttr">
    <term><function>builtins.hasAttr</function>
    <replaceable>s</replaceable> <replaceable>set</replaceable></term>

    <listitem><para><function>hasAttr</function> returns
    <literal>true</literal> if <replaceable>set</replaceable> has an
    attribute named <replaceable>s</replaceable>, and
    <literal>false</literal> otherwise.  This is a dynamic version of
    the <literal>?</literal>  operator, since
    <replaceable>s</replaceable> is an expression rather than an
    identifier.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-hashString">
    <term><function>builtins.hashString</function>
    <replaceable>type</replaceable> <replaceable>s</replaceable></term>

    <listitem><para>Return a base-16 representation of the
    cryptographic hash of string <replaceable>s</replaceable>.  The
    hash algorithm specified by <replaceable>type</replaceable> must
    be one of <literal>"md5"</literal>, <literal>"sha1"</literal>,
    <literal>"sha256"</literal> or <literal>"sha512"</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-hashFile">
    <term><function>builtins.hashFile</function>
    <replaceable>type</replaceable> <replaceable>p</replaceable></term>

    <listitem><para>Return a base-16 representation of the
    cryptographic hash of the file at path <replaceable>p</replaceable>.  The
    hash algorithm specified by <replaceable>type</replaceable> must
    be one of <literal>"md5"</literal>, <literal>"sha1"</literal>,
    <literal>"sha256"</literal> or <literal>"sha512"</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-head">
    <term><function>builtins.head</function>
    <replaceable>list</replaceable></term>

    <listitem><para>Return the first element of a list; abort
    evaluation if the argument isn&#x2019;t a list or is an empty list.  You
    can test whether a list is empty by comparing it with
    <literal>[]</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-import">
    <term><function>import</function>
    <replaceable>path</replaceable></term>
    <term><function>builtins.import</function>
    <replaceable>path</replaceable></term>

    <listitem><para>Load, parse and return the Nix expression in the
    file <replaceable>path</replaceable>.  If <replaceable>path
    </replaceable> is a directory, the file <filename>default.nix
    </filename> in that directory is loaded.  Evaluation aborts if the
    file doesn&#x2019;t exist or contains an incorrect Nix expression.
    <function>import</function> implements Nix&#x2019;s module system: you
    can put any Nix expression (such as a set or a function) in a
    separate file, and use it from Nix expressions in other
    files.</para>

    <note><para>Unlike some languages, <function>import</function> is a regular
    function in Nix. Paths using the angle bracket syntax (e.g., <function>
    import</function> <replaceable>&lt;foo&gt;</replaceable>) are normal path
    values (see <xref linkend="ssec-values"/>).</para></note>

    <para>A Nix expression loaded by <function>import</function> must
    not contain any <emphasis>free variables</emphasis> (identifiers
    that are not defined in the Nix expression itself and are not
    built-in).  Therefore, it cannot refer to variables that are in
    scope at the call site.  For instance, if you have a calling
    expression

<programlisting>
rec {
  x = 123;
  y = import ./foo.nix;
}</programlisting>

    then the following <filename>foo.nix</filename> will give an
    error:

<programlisting>
x + 456</programlisting>

    since <varname>x</varname> is not in scope in
    <filename>foo.nix</filename>.  If you want <varname>x</varname>
    to be available in <filename>foo.nix</filename>, you should pass
    it as a function argument:

<programlisting>
rec {
  x = 123;
  y = import ./foo.nix x;
}</programlisting>

    and

<programlisting>
x: x + 456</programlisting>

    (The function argument doesn&#x2019;t have to be called
    <varname>x</varname> in <filename>foo.nix</filename>; any name
    would work.)</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-intersectAttrs">
    <term><function>builtins.intersectAttrs</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return a set consisting of the attributes in the
    set <replaceable>e2</replaceable> that also exist in the set
    <replaceable>e1</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isAttrs">
    <term><function>builtins.isAttrs</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a set, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isList">
    <term><function>builtins.isList</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a list, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isFunction"><term><function>builtins.isFunction</function>
  <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a function, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isString">
    <term><function>builtins.isString</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a string, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isInt">
    <term><function>builtins.isInt</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to an int, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isFloat">
    <term><function>builtins.isFloat</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a float, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-isBool">
    <term><function>builtins.isBool</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a bool, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>

  <varlistentry><term><function>builtins.isPath</function>
  <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to a path, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-isNull">
    <term><function>isNull</function>
    <replaceable>e</replaceable></term>
    <term><function>builtins.isNull</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return <literal>true</literal> if
    <replaceable>e</replaceable> evaluates to <literal>null</literal>,
    and <literal>false</literal> otherwise.</para>

    <warning><para>This function is <emphasis>deprecated</emphasis>;
    just write <literal>e == null</literal> instead.</para></warning>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-length">
    <term><function>builtins.length</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return the length of the list
    <replaceable>e</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-lessThan">
    <term><function>builtins.lessThan</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return <literal>true</literal> if the number
    <replaceable>e1</replaceable> is less than the number
    <replaceable>e2</replaceable>, and <literal>false</literal>
    otherwise.  Evaluation aborts if either
    <replaceable>e1</replaceable> or <replaceable>e2</replaceable>
    does not evaluate to a number.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-listToAttrs">
    <term><function>builtins.listToAttrs</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Construct a set from a list specifying the names
    and values of each attribute.  Each element of the list should be
    a set consisting of a string-valued attribute
    <varname>name</varname> specifying the name of the attribute, and
    an attribute <varname>value</varname> specifying its value.
    Example:

<programlisting>
builtins.listToAttrs
  [ { name = "foo"; value = 123; }
    { name = "bar"; value = 456; }
  ]
</programlisting>

    evaluates to

<programlisting>
{ foo = 123; bar = 456; }
</programlisting>

    </para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-map">
    <term><function>map</function>
    <replaceable>f</replaceable> <replaceable>list</replaceable></term>
    <term><function>builtins.map</function>
    <replaceable>f</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Apply the function <replaceable>f</replaceable> to
    each element in the list <replaceable>list</replaceable>.  For
    example,

<programlisting>
map (x: "foo" + x) [ "bar" "bla" "abc" ]</programlisting>

    evaluates to <literal>[ "foobar" "foobla" "fooabc"
    ]</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-match">
    <term><function>builtins.match</function>
    <replaceable>regex</replaceable> <replaceable>str</replaceable></term>

    <listitem><para>Returns a list if the <link xlink:href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04">extended
    POSIX regular expression</link> <replaceable>regex</replaceable>
    matches <replaceable>str</replaceable> precisely, otherwise returns
    <literal>null</literal>.  Each item in the list is a regex group.

<programlisting>
builtins.match "ab" "abc"
</programlisting>

Evaluates to <literal>null</literal>.

<programlisting>
builtins.match "abc" "abc"
</programlisting>

Evaluates to <literal>[ ]</literal>.

<programlisting>
builtins.match "a(b)(c)" "abc"
</programlisting>

Evaluates to <literal>[ "b" "c" ]</literal>.

<programlisting>
builtins.match "[[:space:]]+([[:upper:]]+)[[:space:]]+" "  FOO   "
</programlisting>

Evaluates to <literal>[ "foo" ]</literal>.

    </para></listitem>
  </varlistentry>

  <varlistentry xml:id="builtin-mul">
    <term><function>builtins.mul</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return the product of the numbers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-parseDrvName">
    <term><function>builtins.parseDrvName</function>
    <replaceable>s</replaceable></term>

    <listitem><para>Split the string <replaceable>s</replaceable> into
    a package name and version.  The package name is everything up to
    but not including the first dash followed by a digit, and the
    version is everything following that dash.  The result is returned
    in a set <literal>{ name, version }</literal>.  Thus,
    <literal>builtins.parseDrvName "nix-0.12pre12876"</literal>
    returns <literal>{ name = "nix"; version = "0.12pre12876";
    }</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-path">
    <term>
      <function>builtins.path</function>
      <replaceable>args</replaceable>
    </term>

    <listitem>
      <para>
        An enrichment of the built-in path type, based on the attributes
        present in <replaceable>args</replaceable>. All are optional
        except <varname>path</varname>:
      </para>

      <variablelist>
        <varlistentry>
          <term>path</term>
          <listitem>
            <para>The underlying path.</para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>name</term>
          <listitem>
            <para>
              The name of the path when added to the store. This can
              used to reference paths that have nix-illegal characters
              in their names, like <literal>@</literal>.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>filter</term>
          <listitem>
            <para>
              A function of the type expected by
              <link linkend="builtin-filterSource">builtins.filterSource</link>,
              with the same semantics.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>recursive</term>
          <listitem>
            <para>
              When <literal>false</literal>, when
              <varname>path</varname> is added to the store it is with a
              flat hash, rather than a hash of the NAR serialization of
              the file. Thus, <varname>path</varname> must refer to a
              regular file, not a directory. This allows similar
              behavior to <literal>fetchurl</literal>. Defaults to
              <literal>true</literal>.
            </para>
          </listitem>
        </varlistentry>
        <varlistentry>
          <term>sha256</term>
          <listitem>
            <para>
              When provided, this is the expected hash of the file at
              the path. Evaluation will fail if the hash is incorrect,
              and providing a hash allows
              <literal>builtins.path</literal> to be used even when the
              <literal>pure-eval</literal> nix config option is on.
            </para>
          </listitem>
        </varlistentry>
      </variablelist>
    </listitem>
  </varlistentry>

  <varlistentry xml:id="builtin-pathExists">
    <term><function>builtins.pathExists</function>
    <replaceable>path</replaceable></term>

    <listitem><para>Return <literal>true</literal> if the path
    <replaceable>path</replaceable> exists at evaluation time, and
    <literal>false</literal> otherwise.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-placeholder">
    <term><function>builtins.placeholder</function>
    <replaceable>output</replaceable></term>

    <listitem><para>Return a placeholder string for the specified
    <replaceable>output</replaceable> that will be substituted by the
    corresponding output path at build time. Typical outputs would be
    <literal>"out"</literal>, <literal>"bin"</literal> or
    <literal>"dev"</literal>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="builtin-readDir">
    <term><function>builtins.readDir</function>
    <replaceable>path</replaceable></term>

    <listitem><para>Return the contents of the directory
    <replaceable>path</replaceable> as a set mapping directory entries
    to the corresponding file type. For instance, if directory
    <filename>A</filename> contains a regular file
    <filename>B</filename> and another directory
    <filename>C</filename>, then <literal>builtins.readDir
    ./A</literal> will return the set

<programlisting>
{ B = "regular"; C = "directory"; }</programlisting>

    The possible values for the file type are
    <literal>"regular"</literal>, <literal>"directory"</literal>,
    <literal>"symlink"</literal> and
    <literal>"unknown"</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-readFile">
    <term><function>builtins.readFile</function>
    <replaceable>path</replaceable></term>

    <listitem><para>Return the contents of the file
    <replaceable>path</replaceable> as a string.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-removeAttrs">
    <term><function>removeAttrs</function>
    <replaceable>set</replaceable> <replaceable>list</replaceable></term>
    <term><function>builtins.removeAttrs</function>
    <replaceable>set</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Remove the attributes listed in
    <replaceable>list</replaceable> from
    <replaceable>set</replaceable>.  The attributes don&#x2019;t have to
    exist in <replaceable>set</replaceable>. For instance,

<programlisting>
removeAttrs { x = 1; y = 2; z = 3; } [ "a" "x" "z" ]</programlisting>

    evaluates to <literal>{ y = 2; }</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-replaceStrings">
    <term><function>builtins.replaceStrings</function>
    <replaceable>from</replaceable> <replaceable>to</replaceable> <replaceable>s</replaceable></term>

    <listitem><para>Given string <replaceable>s</replaceable>, replace
    every occurrence of the strings in <replaceable>from</replaceable>
    with the corresponding string in
    <replaceable>to</replaceable>. For example,

<programlisting>
builtins.replaceStrings ["oo" "a"] ["a" "i"] "foobar"
</programlisting>

    evaluates to <literal>"fabir"</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-seq">
    <term><function>builtins.seq</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Evaluate <replaceable>e1</replaceable>, then
    evaluate and return <replaceable>e2</replaceable>. This ensures
    that a computation is strict in the value of
    <replaceable>e1</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-sort">
    <term><function>builtins.sort</function>
    <replaceable>comparator</replaceable> <replaceable>list</replaceable></term>

    <listitem><para>Return <replaceable>list</replaceable> in sorted
    order. It repeatedly calls the function
    <replaceable>comparator</replaceable> with two elements. The
    comparator should return <literal>true</literal> if the first
    element is less than the second, and <literal>false</literal>
    otherwise. For example,

<programlisting>
builtins.sort builtins.lessThan [ 483 249 526 147 42 77 ]
</programlisting>

    produces the list <literal>[ 42 77 147 249 483 526
    ]</literal>.</para>

    <para>This is a stable sort: it preserves the relative order of
    elements deemed equal by the comparator.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-split">
    <term><function>builtins.split</function>
    <replaceable>regex</replaceable> <replaceable>str</replaceable></term>

    <listitem><para>Returns a list composed of non matched strings interleaved
    with the lists of the <link xlink:href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04">extended
    POSIX regular expression</link> <replaceable>regex</replaceable> matches
    of <replaceable>str</replaceable>. Each item in the lists of matched
    sequences is a regex group.

<programlisting>
builtins.split "(a)b" "abc"
</programlisting>

Evaluates to <literal>[ "" [ "a" ] "c" ]</literal>.

<programlisting>
builtins.split "([ac])" "abc"
</programlisting>

Evaluates to <literal>[ "" [ "a" ] "b" [ "c" ] "" ]</literal>.

<programlisting>
builtins.split "(a)|(c)" "abc"
</programlisting>

Evaluates to <literal>[ "" [ "a" null ] "b" [ null "c" ] "" ]</literal>.

<programlisting>
builtins.split "([[:upper:]]+)" "  FOO   "
</programlisting>

Evaluates to <literal>[ "  " [ "FOO" ] "   " ]</literal>.

    </para></listitem>
  </varlistentry>


  <varlistentry xml:id="builtin-splitVersion">
    <term><function>builtins.splitVersion</function>
    <replaceable>s</replaceable></term>

    <listitem><para>Split a string representing a version into its
    components, by the same version splitting logic underlying the
    version comparison in <link linkend="ssec-version-comparisons">
    <command>nix-env -u</command></link>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-stringLength">
    <term><function>builtins.stringLength</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return the length of the string
    <replaceable>e</replaceable>.  If <replaceable>e</replaceable> is
    not a string, evaluation is aborted.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-sub">
    <term><function>builtins.sub</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Return the difference between the numbers
    <replaceable>e1</replaceable> and
    <replaceable>e2</replaceable>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-substring">
    <term><function>builtins.substring</function>
    <replaceable>start</replaceable> <replaceable>len</replaceable>
    <replaceable>s</replaceable></term>

    <listitem><para>Return the substring of
    <replaceable>s</replaceable> from character position
    <replaceable>start</replaceable> (zero-based) up to but not
    including <replaceable>start + len</replaceable>.  If
    <replaceable>start</replaceable> is greater than the length of the
    string, an empty string is returned, and if <replaceable>start +
    len</replaceable> lies beyond the end of the string, only the
    substring up to the end of the string is returned.
    <replaceable>start</replaceable> must be
    non-negative. For example,

<programlisting>
builtins.substring 0 3 "nixos"
</programlisting>

   evaluates to <literal>"nix"</literal>.
   </para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-tail">
    <term><function>builtins.tail</function>
    <replaceable>list</replaceable></term>

    <listitem><para>Return the second to last elements of a list;
    abort evaluation if the argument isn&#x2019;t a list or is an empty
    list.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-throw">
    <term><function>throw</function>
    <replaceable>s</replaceable></term>
    <term><function>builtins.throw</function>
    <replaceable>s</replaceable></term>

    <listitem><para>Throw an error message
    <replaceable>s</replaceable>.  This usually aborts Nix expression
    evaluation, but in <command>nix-env -qa</command> and other
    commands that try to evaluate a set of derivations to get
    information about those derivations, a derivation that throws an
    error is silently skipped (which is not the case for
    <function>abort</function>).</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-toFile">
    <term><function>builtins.toFile</function>
    <replaceable>name</replaceable>
    <replaceable>s</replaceable></term>

    <listitem><para>Store the string <replaceable>s</replaceable> in a
    file in the Nix store and return its path.  The file has suffix
    <replaceable>name</replaceable>.  This file can be used as an
    input to derivations.  One application is to write builders
    &#x201C;inline&#x201D;.  For instance, the following Nix expression combines
    <xref linkend="ex-hello-nix"/> and <xref linkend="ex-hello-builder"/> into one file:

<programlisting>
{ stdenv, fetchurl, perl }:

stdenv.mkDerivation {
  name = "hello-2.1.1";

  builder = builtins.toFile "builder.sh" "
    source $stdenv/setup

    PATH=$perl/bin:$PATH

    tar xvfz $src
    cd hello-*
    ./configure --prefix=$out
    make
    make install
  ";

  src = fetchurl {
    url = "http://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz";
    sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
  };
  inherit perl;
}</programlisting>

    </para>

    <para>It is even possible for one file to refer to another, e.g.,

<programlisting>
  builder = let
    configFile = builtins.toFile "foo.conf" "
      # This is some dummy configuration file.
      <replaceable>...</replaceable>
    ";
  in builtins.toFile "builder.sh" "
    source $stdenv/setup
    <replaceable>...</replaceable>
    cp ${configFile} $out/etc/foo.conf
  ";</programlisting>

    Note that <literal>${configFile}</literal> is an antiquotation
    (see <xref linkend="ssec-values"/>), so the result of the
    expression <literal>configFile</literal> (i.e., a path like
    <filename>/nix/store/m7p7jfny445k...-foo.conf</filename>) will be
    spliced into the resulting string.</para>

    <para>It is however <emphasis>not</emphasis> allowed to have files
    mutually referring to each other, like so:

<programlisting>
let
  foo = builtins.toFile "foo" "...${bar}...";
  bar = builtins.toFile "bar" "...${foo}...";
in foo</programlisting>

    This is not allowed because it would cause a cyclic dependency in
    the computation of the cryptographic hashes for
    <varname>foo</varname> and <varname>bar</varname>.</para>
    <para>It is also not possible to reference the result of a derivation.
    If you are using Nixpkgs, the <literal>writeTextFile</literal> function is able to
    do that.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-toJSON">
    <term><function>builtins.toJSON</function> <replaceable>e</replaceable></term>

    <listitem><para>Return a string containing a JSON representation
    of <replaceable>e</replaceable>.  Strings, integers, floats, booleans,
    nulls and lists are mapped to their JSON equivalents.  Sets
    (except derivations) are represented as objects.  Derivations are
    translated to a JSON string containing the derivation&#x2019;s output
    path.  Paths are copied to the store and represented as a JSON
    string of the resulting store path.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-toPath">
    <term><function>builtins.toPath</function> <replaceable>s</replaceable></term>

    <listitem><para> DEPRECATED. Use <literal>/. + "/path"</literal>
    to convert a string into an absolute path. For relative paths,
    use <literal>./. + "/path"</literal>.
    </para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-toString">
    <term><function>toString</function> <replaceable>e</replaceable></term>
    <term><function>builtins.toString</function> <replaceable>e</replaceable></term>

    <listitem><para>Convert the expression
    <replaceable>e</replaceable> to a string.
    <replaceable>e</replaceable> can be:</para>
    <itemizedlist>
      <listitem><para>A string (in which case the string is returned unmodified).</para></listitem>
      <listitem><para>A path (e.g., <literal>toString /foo/bar</literal> yields <literal>"/foo/bar"</literal>.</para></listitem>
      <listitem><para>A set containing <literal>{ __toString = self: ...; }</literal>.</para></listitem>
      <listitem><para>An integer.</para></listitem>
      <listitem><para>A list, in which case the string representations of its elements are joined with spaces.</para></listitem>
      <listitem><para>A Boolean (<literal>false</literal> yields <literal>""</literal>, <literal>true</literal> yields <literal>"1"</literal>).</para></listitem>
      <listitem><para><literal>null</literal>, which yields the empty string.</para></listitem>
    </itemizedlist>
    </listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-toXML">
    <term><function>builtins.toXML</function> <replaceable>e</replaceable></term>

    <listitem><para>Return a string containing an XML representation
    of <replaceable>e</replaceable>.  The main application for
    <function>toXML</function> is to communicate information with the
    builder in a more structured format than plain environment
    variables.</para>

    <!-- TODO: more formally describe the schema of the XML
    representation -->

    <para><xref linkend="ex-toxml"/> shows an example where this is
    the case.  The builder is supposed to generate the configuration
    file for a <link xlink:href="http://jetty.mortbay.org/">Jetty
    servlet container</link>.  A servlet container contains a number
    of servlets (<filename>*.war</filename> files) each exported under
    a specific URI prefix.  So the servlet configuration is a list of
    sets containing the <varname>path</varname> and
    <varname>war</varname> of the servlet (<xref linkend="ex-toxml-co-servlets"/>).  This kind of information is
    difficult to communicate with the normal method of passing
    information through an environment variable, which just
    concatenates everything together into a string (which might just
    work in this case, but wouldn&#x2019;t work if fields are optional or
    contain lists themselves).  Instead the Nix expression is
    converted to an XML representation with
    <function>toXML</function>, which is unambiguous and can easily be
    processed with the appropriate tools.  For instance, in the
    example an XSLT stylesheet (<xref linkend="ex-toxml-co-stylesheet"/>) is applied to it (<xref linkend="ex-toxml-co-apply"/>) to
    generate the XML configuration file for the Jetty server.  The XML
    representation produced from <xref linkend="ex-toxml-co-servlets"/> by <function>toXML</function> is shown in <xref linkend="ex-toxml-result"/>.</para>

    <para>Note that <xref linkend="ex-toxml"/> uses the <function linkend="builtin-toFile">toFile</function> built-in to write the
    builder and the stylesheet &#x201C;inline&#x201D; in the Nix expression.  The
    path of the stylesheet is spliced into the builder at
    <literal>xsltproc ${stylesheet}
    <replaceable>...</replaceable></literal>.</para>

    <example xml:id="ex-toxml"><title>Passing information to a builder
    using <function>toXML</function></title>

<programlisting><![CDATA[
{ stdenv, fetchurl, libxslt, jira, uberwiki }:

stdenv.mkDerivation (rec {
  name = "web-server";

  buildInputs = [ libxslt ];

  builder = builtins.toFile "builder.sh" "
    source $stdenv/setup
    mkdir $out
    echo "$servlets" | xsltproc ${stylesheet} - > $out/server-conf.xml]]> <co xml:id="ex-toxml-co-apply"/> <![CDATA[
  ";

  stylesheet = builtins.toFile "stylesheet.xsl"]]> <co xml:id="ex-toxml-co-stylesheet"/> <![CDATA[
   "<?xml version='1.0' encoding='UTF-8'?>
    <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
      <xsl:template match='/'>
        <Configure>
          <xsl:for-each select='/expr/list/attrs'>
            <Call name='addWebApplication'>
              <Arg><xsl:value-of select=\"attr[@name = 'path']/string/@value\" /></Arg>
              <Arg><xsl:value-of select=\"attr[@name = 'war']/path/@value\" /></Arg>
            </Call>
          </xsl:for-each>
        </Configure>
      </xsl:template>
    </xsl:stylesheet>
  ";

  servlets = builtins.toXML []]> <co xml:id="ex-toxml-co-servlets"/> <![CDATA[
    { path = "/bugtracker"; war = jira + "/lib/atlassian-jira.war"; }
    { path = "/wiki"; war = uberwiki + "/uberwiki.war"; }
  ];
})]]></programlisting>

    </example>

    <example xml:id="ex-toxml-result"><title>XML representation produced by
    <function>toXML</function></title>

<programlisting><![CDATA[<?xml version='1.0' encoding='utf-8'?>
<expr>
  <list>
    <attrs>
      <attr name="path">
        <string value="/bugtracker" />
      </attr>
      <attr name="war">
        <path value="/nix/store/d1jh9pasa7k2...-jira/lib/atlassian-jira.war" />
      </attr>
    </attrs>
    <attrs>
      <attr name="path">
        <string value="/wiki" />
      </attr>
      <attr name="war">
        <path value="/nix/store/y6423b1yi4sx...-uberwiki/uberwiki.war" />
      </attr>
    </attrs>
  </list>
</expr>]]></programlisting>

    </example>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-trace">
    <term><function>builtins.trace</function>
    <replaceable>e1</replaceable> <replaceable>e2</replaceable></term>

    <listitem><para>Evaluate <replaceable>e1</replaceable> and print its
    abstract syntax representation on standard error.  Then return
    <replaceable>e2</replaceable>.  This function is useful for
    debugging.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="builtin-tryEval">
    <term><function>builtins.tryEval</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Try to shallowly evaluate <replaceable>e</replaceable>.
    Return a set containing the attributes <literal>success</literal>
    (<literal>true</literal> if <replaceable>e</replaceable> evaluated
    successfully, <literal>false</literal> if an error was thrown) and
    <literal>value</literal>, equalling <replaceable>e</replaceable>
    if successful and <literal>false</literal> otherwise. Note that this
    doesn't evaluate <replaceable>e</replaceable> deeply, so
    <literal>let e = { x = throw ""; }; in (builtins.tryEval e).success
    </literal> will be <literal>true</literal>. Using <literal>builtins.deepSeq
    </literal> one can get the expected result: <literal>let e = { x = throw "";
    }; in (builtins.tryEval (builtins.deepSeq e e)).success</literal> will be
    <literal>false</literal>.
    </para></listitem>

  </varlistentry>


  <varlistentry xml:id="builtin-typeOf">
    <term><function>builtins.typeOf</function>
    <replaceable>e</replaceable></term>

    <listitem><para>Return a string representing the type of the value
    <replaceable>e</replaceable>, namely <literal>"int"</literal>,
    <literal>"bool"</literal>, <literal>"string"</literal>,
    <literal>"path"</literal>, <literal>"null"</literal>,
    <literal>"set"</literal>, <literal>"list"</literal>,
    <literal>"lambda"</literal> or
    <literal>"float"</literal>.</para></listitem>

  </varlistentry>


</variablelist>


</section>


</chapter>

</part>
  <part xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="part-advanced-topics" version="5.0" xml:base="advanced-topics/advanced-topics.xml">

<title>Advanced Topics</title>

<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-distributed-builds">

<title>Remote Builds</title>

<para>Nix supports remote builds, where a local Nix installation can
forward Nix builds to other machines.  This allows multiple builds to
be performed in parallel and allows Nix to perform multi-platform
builds in a semi-transparent way.  For instance, if you perform a
build for a <literal>x86_64-darwin</literal> on an
<literal>i686-linux</literal> machine, Nix can automatically forward
the build to a <literal>x86_64-darwin</literal> machine, if
available.</para>

<para>To forward a build to a remote machine, it&#x2019;s required that the
remote machine is accessible via SSH and that it has Nix
installed. You can test whether connecting to the remote Nix instance
works, e.g.

<screen>
$ nix ping-store --store ssh://mac
</screen>

will try to connect to the machine named <literal>mac</literal>. It is
possible to specify an SSH identity file as part of the remote store
URI, e.g.

<screen>
$ nix ping-store --store ssh://mac?ssh-key=/home/alice/my-key
</screen>

Since builds should be non-interactive, the key should not have a
passphrase. Alternatively, you can load identities ahead of time into
<command>ssh-agent</command> or <command>gpg-agent</command>.</para>

<para>If you get the error

<screen>
bash: nix-store: command not found
error: cannot connect to 'mac'
</screen>

then you need to ensure that the <envar>PATH</envar> of
non-interactive login shells contains Nix.</para>

<warning><para>If you are building via the Nix daemon, it is the Nix
daemon user account (that is, <literal>root</literal>) that should
have SSH access to the remote machine. If you can&#x2019;t or don&#x2019;t want to
configure <literal>root</literal> to be able to access to remote
machine, you can use a private Nix store instead by passing
e.g. <literal>--store ~/my-nix</literal>.</para></warning>

<para>The list of remote machines can be specified on the command line
or in the Nix configuration file. The former is convenient for
testing. For example, the following command allows you to build a
derivation for <literal>x86_64-darwin</literal> on a Linux machine:

<screen>
$ uname
Linux

$ nix build \
  '(with import &lt;nixpkgs&gt; { system = "x86_64-darwin"; }; runCommand "foo" {} "uname &gt; $out")' \
  --builders 'ssh://mac x86_64-darwin'
[1/0/1 built, 0.0 MiB DL] building foo on ssh://mac

$ cat ./result
Darwin
</screen>

It is possible to specify multiple builders separated by a semicolon
or a newline, e.g.

<screen>
  --builders 'ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd'
</screen>
</para>

<para>Each machine specification consists of the following elements,
separated by spaces. Only the first element is required.
To leave a field at its default, set it to <literal>-</literal>.

<orderedlist>

  <listitem><para>The URI of the remote store in the format
  <literal>ssh://[<replaceable>username</replaceable>@]<replaceable>hostname</replaceable></literal>,
  e.g. <literal>ssh://nix@mac</literal> or
  <literal>ssh://mac</literal>. For backward compatibility,
  <literal>ssh://</literal> may be omitted. The hostname may be an
  alias defined in your
  <filename>~/.ssh/config</filename>.</para></listitem>

  <listitem><para>A comma-separated list of Nix platform type
  identifiers, such as <literal>x86_64-darwin</literal>.  It is
  possible for a machine to support multiple platform types, e.g.,
  <literal>i686-linux,x86_64-linux</literal>. If omitted, this
  defaults to the local platform type.</para></listitem>

  <listitem><para>The SSH identity file to be used to log in to the
  remote machine. If omitted, SSH will use its regular
  identities.</para></listitem>

  <listitem><para>The maximum number of builds that Nix will execute
  in parallel on the machine.  Typically this should be equal to the
  number of CPU cores.  For instance, the machine
  <literal>itchy</literal> in the example will execute up to 8 builds
  in parallel.</para></listitem>

  <listitem><para>The &#x201C;speed factor&#x201D;, indicating the relative speed of
  the machine.  If there are multiple machines of the right type, Nix
  will prefer the fastest, taking load into account.</para></listitem>

  <listitem><para>A comma-separated list of <emphasis>supported
  features</emphasis>.  If a derivation has the
  <varname>requiredSystemFeatures</varname> attribute, then Nix will
  only perform the derivation on a machine that has the specified
  features.  For instance, the attribute

<programlisting>
requiredSystemFeatures = [ "kvm" ];
</programlisting>

  will cause the build to be performed on a machine that has the
  <literal>kvm</literal> feature.</para></listitem>

  <listitem><para>A comma-separated list of <emphasis>mandatory
  features</emphasis>.  A machine will only be used to build a
  derivation if all of the machine&#x2019;s mandatory features appear in the
  derivation&#x2019;s <varname>requiredSystemFeatures</varname>
  attribute..</para></listitem>

</orderedlist>

For example, the machine specification

<programlisting>
nix@scratchy.labs.cs.uu.nl  i686-linux      /home/nix/.ssh/id_scratchy_auto        8 1 kvm
nix@itchy.labs.cs.uu.nl     i686-linux      /home/nix/.ssh/id_scratchy_auto        8 2
nix@poochie.labs.cs.uu.nl   i686-linux      /home/nix/.ssh/id_scratchy_auto        1 2 kvm benchmark
</programlisting>

specifies several machines that can perform
<literal>i686-linux</literal> builds. However,
<literal>poochie</literal> will only do builds that have the attribute

<programlisting>
requiredSystemFeatures = [ "benchmark" ];
</programlisting>

or

<programlisting>
requiredSystemFeatures = [ "benchmark" "kvm" ];
</programlisting>

<literal>itchy</literal> cannot do builds that require
<literal>kvm</literal>, but <literal>scratchy</literal> does support
such builds. For regular builds, <literal>itchy</literal> will be
preferred over <literal>scratchy</literal> because it has a higher
speed factor.</para>

<para>Remote builders can also be configured in
<filename>nix.conf</filename>, e.g.

<programlisting>
builders = ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd
</programlisting>

Finally, remote builders can be configured in a separate configuration
file included in <option>builders</option> via the syntax
<literal>@<replaceable>file</replaceable></literal>. For example,

<programlisting>
builders = @/etc/nix/machines
</programlisting>

causes the list of machines in <filename>/etc/nix/machines</filename>
to be included. (This is the default.)</para>

<para>If you want the builders to use caches, you likely want to set
the option <link linkend="conf-builders-use-substitutes"><literal>builders-use-substitutes</literal></link>
in your local <filename>nix.conf</filename>.</para>

<para>To build only on remote builders and disable building on the local machine,
you can use the option <option>--max-jobs 0</option>.</para>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="chap-tuning-cores-and-jobs">

<title>Tuning Cores and Jobs</title>

<para>Nix has two relevant settings with regards to how your CPU cores
will be utilized: <xref linkend="conf-cores"/> and
<xref linkend="conf-max-jobs"/>. This chapter will talk about what
they are, how they interact, and their configuration trade-offs.</para>

<variablelist>
  <varlistentry>
    <term><xref linkend="conf-max-jobs"/></term>
    <listitem><para>
      Dictates how many separate derivations will be built at the same
      time. If you set this to zero, the local machine will do no
      builds. Nix will still substitute from binary caches, and build
      remotely if remote builders are configured.
    </para></listitem>
  </varlistentry>
  <varlistentry>
    <term><xref linkend="conf-cores"/></term>
    <listitem><para>
      Suggests how many cores each derivation should use. Similar to
      <command>make -j</command>.
    </para></listitem>
  </varlistentry>
</variablelist>

<para>The <xref linkend="conf-cores"/> setting determines the value of
<envar>NIX_BUILD_CORES</envar>. <envar>NIX_BUILD_CORES</envar> is equal
to <xref linkend="conf-cores"/>, unless <xref linkend="conf-cores"/>
equals <literal>0</literal>, in which case <envar>NIX_BUILD_CORES</envar>
will be the total number of cores in the system.</para>

<para>The maximum number of consumed cores is a simple multiplication,
<xref linkend="conf-max-jobs"/> * <envar>NIX_BUILD_CORES</envar>.</para>

<para>The balance on how to set these two independent variables depends
upon each builder's workload and hardware. Here are a few example
scenarios on a machine with 24 cores:</para>

<table>
  <caption>Balancing 24 Build Cores</caption>
  <thead>
    <tr>
      <th><xref linkend="conf-max-jobs"/></th>
      <th><xref linkend="conf-cores"/></th>
      <th><envar>NIX_BUILD_CORES</envar></th>
      <th>Maximum Processes</th>
      <th>Result</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>24</td>
      <td>24</td>
      <td>24</td>
      <td>
        One derivation will be built at a time, each one can use 24
        cores. Undersold if a job can&#x2019;t use 24 cores.
      </td>
    </tr>

    <tr>
      <td>4</td>
      <td>6</td>
      <td>6</td>
      <td>24</td>
      <td>
        Four derivations will be built at once, each given access to
        six cores.
      </td>
    </tr>
    <tr>
      <td>12</td>
      <td>6</td>
      <td>6</td>
      <td>72</td>
      <td>
        12 derivations will be built at once, each given access to six
        cores. This configuration is over-sold. If all 12 derivations
        being built simultaneously try to use all six cores, the
        machine's performance will be degraded due to extensive context
        switching between the 12 builds.
      </td>
    </tr>
    <tr>
      <td>24</td>
      <td>1</td>
      <td>1</td>
      <td>24</td>
      <td>
        24 derivations can build at the same time, each using a single
        core. Never oversold, but derivations which require many cores
        will be very slow to compile.
      </td>
    </tr>
    <tr>
      <td>24</td>
      <td>0</td>
      <td>24</td>
      <td>576</td>
      <td>
        24 derivations can build at the same time, each using all the
        available cores of the machine. Very likely to be oversold,
        and very likely to suffer context switches.
      </td>
    </tr>
  </tbody>
</table>

<para>It is up to the derivations' build script to respect
host's requested cores-per-build by following the value of the
<envar>NIX_BUILD_CORES</envar> environment variable.</para>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chap-diff-hook" version="5.0">

<title>Verifying Build Reproducibility with <option linkend="conf-diff-hook">diff-hook</option></title>

<subtitle>Check build reproducibility by running builds multiple times
and comparing their results.</subtitle>

<para>Specify a program with Nix's <xref linkend="conf-diff-hook"/> to
compare build results when two builds produce different results. Note:
this hook is only executed if the results are not the same, this hook
is not used for determining if the results are the same.</para>

<para>For purposes of demonstration, we'll use the following Nix file,
<filename>deterministic.nix</filename> for testing:</para>

<programlisting>
let
  inherit (import &lt;nixpkgs&gt; {}) runCommand;
in {
  stable = runCommand "stable" {} ''
    touch $out
  '';

  unstable = runCommand "unstable" {} ''
    echo $RANDOM &gt; $out
  '';
}
</programlisting>

<para>Additionally, <filename>nix.conf</filename> contains:

<programlisting>
diff-hook = /etc/nix/my-diff-hook
run-diff-hook = true
</programlisting>

where <filename>/etc/nix/my-diff-hook</filename> is an executable
file containing:

<programlisting>
#!/bin/sh
exec &gt;&amp;2
echo "For derivation $3:"
/run/current-system/sw/bin/diff -r "$1" "$2"
</programlisting>

</para>

<para>The diff hook is executed by the same user and group who ran the
build. However, the diff hook does not have write access to the store
path just built.</para>

<section>
  <title>
    Spot-Checking Build Determinism
  </title>

  <para>
    Verify a path which already exists in the Nix store by passing
    <option>--check</option> to the build command.
  </para>

  <para>If the build passes and is deterministic, Nix will exit with a
  status code of 0:</para>

  <screen>
$ nix-build ./deterministic.nix -A stable
this derivation will be built:
  /nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv
building '/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv'...
/nix/store/yyxlzw3vqaas7wfp04g0b1xg51f2czgq-stable

$ nix-build ./deterministic.nix -A stable --check
checking outputs of '/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv'...
/nix/store/yyxlzw3vqaas7wfp04g0b1xg51f2czgq-stable
</screen>

  <para>If the build is not deterministic, Nix will exit with a status
  code of 1:</para>

  <screen>
$ nix-build ./deterministic.nix -A unstable
this derivation will be built:
  /nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv
building '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'...
/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable

$ nix-build ./deterministic.nix -A unstable --check
checking outputs of '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'...
error: derivation '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv' may not be deterministic: output '/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable' differs
</screen>

<para>In the Nix daemon's log, we will now see:
<screen>
For derivation /nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv:
1c1
&lt; 8108
---
&gt; 30204
</screen>
</para>

  <para>Using <option>--check</option> with <option>--keep-failed</option>
  will cause Nix to keep the second build's output in a special,
  <literal>.check</literal> path:</para>

  <screen>
$ nix-build ./deterministic.nix -A unstable --check --keep-failed
checking outputs of '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'...
note: keeping build directory '/tmp/nix-build-unstable.drv-0'
error: derivation '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv' may not be deterministic: output '/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable' differs from '/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable.check'
</screen>

  <para>In particular, notice the
  <literal>/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable.check</literal>
  output. Nix has copied the build results to that directory where you
  can examine it.</para>

  <note xml:id="check-dirs-are-unregistered">
    <title><literal>.check</literal> paths are not registered store paths</title>

    <para>Check paths are not protected against garbage collection,
    and this path will be deleted on the next garbage collection.</para>

    <para>The path is guaranteed to be alive for the duration of
    <xref linkend="conf-diff-hook"/>'s execution, but may be deleted
    any time after.</para>

    <para>If the comparison is performed as part of automated tooling,
    please use the diff-hook or author your tooling to handle the case
    where the build was not deterministic and also a check path does
    not exist.</para>
  </note>

  <para>
    <option>--check</option> is only usable if the derivation has
    been built on the system already. If the derivation has not been
    built Nix will fail with the error:
    <screen>
error: some outputs of '/nix/store/hzi1h60z2qf0nb85iwnpvrai3j2w7rr6-unstable.drv' are not valid, so checking is not possible
</screen>

    Run the build without <option>--check</option>, and then try with
    <option>--check</option> again.
  </para>
</section>

<section>
  <title>
    Automatic and Optionally Enforced Determinism Verification
  </title>

  <para>
    Automatically verify every build at build time by executing the
    build multiple times.
  </para>

  <para>
    Setting <xref linkend="conf-repeat"/> and
    <xref linkend="conf-enforce-determinism"/> in your
    <filename>nix.conf</filename> permits the automated verification
    of every build Nix performs.
  </para>

  <para>
    The following configuration will run each build three times, and
    will require the build to be deterministic:

    <programlisting>
enforce-determinism = true
repeat = 2
</programlisting>
  </para>

  <para>
    Setting <xref linkend="conf-enforce-determinism"/> to false as in
    the following configuration will run the build multiple times,
    execute the build hook, but will allow the build to succeed even
    if it does not build reproducibly:

    <programlisting>
enforce-determinism = false
repeat = 1
</programlisting>
  </para>

  <para>
    An example output of this configuration:
    <screen>
$ nix-build ./test.nix -A unstable
this derivation will be built:
  /nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv
building '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' (round 1/2)...
building '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' (round 2/2)...
output '/nix/store/6xg356v9gl03hpbbg8gws77n19qanh02-unstable' of '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' differs from '/nix/store/6xg356v9gl03hpbbg8gws77n19qanh02-unstable.check' from previous round
/nix/store/6xg356v9gl03hpbbg8gws77n19qanh02-unstable
</screen>
  </para>
</section>
</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="chap-post-build-hook" version="5.0">

<title>Using the <option linkend="conf-post-build-hook">post-build-hook</option></title>
<subtitle>Uploading to an S3-compatible binary cache after each build</subtitle>


<section xml:id="chap-post-build-hook-caveats">
  <title>Implementation Caveats</title>
  <para>Here we use the post-build hook to upload to a binary cache.
  This is a simple and working example, but it is not suitable for all
  use cases.</para>

  <para>The post build hook program runs after each executed build,
  and blocks the build loop. The build loop exits if the hook program
  fails.</para>

  <para>Concretely, this implementation will make Nix slow or unusable
  when the internet is slow or unreliable.</para>

  <para>A more advanced implementation might pass the store paths to a
  user-supplied daemon or queue for processing the store paths outside
  of the build loop.</para>
</section>

<section>
  <title>Prerequisites</title>

  <para>
    This tutorial assumes you have configured an S3-compatible binary cache
    according to the instructions at
    <xref linkend="ssec-s3-substituter-authenticated-writes"/>, and
    that the <literal>root</literal> user's default AWS profile can
    upload to the bucket.
  </para>
</section>

<section>
  <title>Set up a Signing Key</title>
  <para>Use <command>nix-store --generate-binary-cache-key</command> to
  create our public and private signing keys. We will sign paths
  with the private key, and distribute the public key for verifying
  the authenticity of the paths.</para>

  <screen>
# nix-store --generate-binary-cache-key example-nix-cache-1 /etc/nix/key.private /etc/nix/key.public
# cat /etc/nix/key.public
example-nix-cache-1:1/cKDz3QCCOmwcztD2eV6Coggp6rqc9DGjWv7C0G+rM=
</screen>

<para>Then, add the public key and the cache URL to your
<filename>nix.conf</filename>'s <xref linkend="conf-trusted-public-keys"/>
and <xref linkend="conf-substituters"/> like:</para>

<programlisting>
substituters = https://cache.nixos.org/ s3://example-nix-cache
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= example-nix-cache-1:1/cKDz3QCCOmwcztD2eV6Coggp6rqc9DGjWv7C0G+rM=
</programlisting>

<para>We will restart the Nix daemon in a later step.</para>
</section>

<section>
  <title>Implementing the build hook</title>
  <para>Write the following script to
  <filename>/etc/nix/upload-to-cache.sh</filename>:
  </para>

  <programlisting>
#!/bin/sh

set -eu
set -f # disable globbing
export IFS=' '

echo "Signing paths" $OUT_PATHS
nix sign-paths --key-file /etc/nix/key.private $OUT_PATHS
echo "Uploading paths" $OUT_PATHS
exec nix copy --to 's3://example-nix-cache' $OUT_PATHS
</programlisting>

  <note>
    <title>Should <literal>$OUT_PATHS</literal> be quoted?</title>
    <para>
      The <literal>$OUT_PATHS</literal> variable is a space-separated
      list of Nix store paths. In this case, we expect and want the
      shell to perform word splitting to make each output path its
      own argument to <command>nix sign-paths</command>. Nix guarantees
      the paths will not contain any spaces, however a store path
      might contain glob characters. The <command>set -f</command>
      disables globbing in the shell.
    </para>
  </note>
  <para>
    Then make sure the hook program is executable by the <literal>root</literal> user:
    <screen>
# chmod +x /etc/nix/upload-to-cache.sh
</screen></para>
</section>

<section>
  <title>Updating Nix Configuration</title>

  <para>Edit <filename>/etc/nix/nix.conf</filename> to run our hook,
  by adding the following configuration snippet at the end:</para>

  <programlisting>
post-build-hook = /etc/nix/upload-to-cache.sh
</programlisting>

<para>Then, restart the <command>nix-daemon</command>.</para>
</section>

<section>
  <title>Testing</title>

  <para>Build any derivation, for example:</para>

  <screen>
$ nix-build -E '(import &lt;nixpkgs&gt; {}).writeText "example" (builtins.toString builtins.currentTime)'
this derivation will be built:
  /nix/store/s4pnfbkalzy5qz57qs6yybna8wylkig6-example.drv
building '/nix/store/s4pnfbkalzy5qz57qs6yybna8wylkig6-example.drv'...
running post-build-hook '/home/grahamc/projects/github.com/NixOS/nix/post-hook.sh'...
post-build-hook: Signing paths /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
post-build-hook: Uploading paths /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
/nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
</screen>

  <para>Then delete the path from the store, and try substituting it from the binary cache:</para>
  <screen>
$ rm ./result
$ nix-store --delete /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
</screen>

<para>Now, copy the path back from the cache:</para>
<screen>
$ nix-store --realise /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
copying path '/nix/store/m8bmqwrch6l3h8s0k3d673xpmipcdpsa-example from 's3://example-nix-cache'...
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/m8bmqwrch6l3h8s0k3d673xpmipcdpsa-example
</screen>
</section>
<section>
  <title>Conclusion</title>
  <para>
    We now have a Nix installation configured to automatically sign and
    upload every local build to a remote binary cache.
  </para>

  <para>
    Before deploying this to production, be sure to consider the
    implementation caveats in <xref linkend="chap-post-build-hook-caveats"/>.
  </para>
</section>
</chapter>

</part>
  <part xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="part-command-ref" xml:base="command-ref/command-ref.xml">

<title>Command Reference</title>

<partintro>
<para>This section lists commands and options that you can use when you
work with Nix.</para>
</partintro>

<chapter xmlns="http://docbook.org/ns/docbook" xml:id="sec-common-options">

<title>Common Options</title>


<para>Most Nix commands accept the following command-line options:</para>

<variablelist xml:id="opt-common">

<varlistentry><term><option>--help</option></term>

  <listitem><para>Prints out a summary of the command syntax and
  exits.</para></listitem>

</varlistentry>


<varlistentry><term><option>--version</option></term>

  <listitem><para>Prints out the Nix version number on standard output
  and exits.</para></listitem>
</varlistentry>


<varlistentry><term><option>--verbose</option> / <option>-v</option></term>

  <listitem>

  <para>Increases the level of verbosity of diagnostic messages
  printed on standard error.  For each Nix operation, the information
  printed on standard output is well-defined; any diagnostic
  information is printed on standard error, never on standard
  output.</para>

  <para>This option may be specified repeatedly.  Currently, the
  following verbosity levels exist:</para>

  <variablelist>

    <varlistentry><term>0</term>
    <listitem><para>&#x201C;Errors only&#x201D;: only print messages
    explaining why the Nix invocation failed.</para></listitem>
    </varlistentry>

    <varlistentry><term>1</term>
    <listitem><para>&#x201C;Informational&#x201D;: print
    <emphasis>useful</emphasis> messages about what Nix is doing.
    This is the default.</para></listitem>
    </varlistentry>

    <varlistentry><term>2</term>
    <listitem><para>&#x201C;Talkative&#x201D;: print more informational
    messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>3</term>
    <listitem><para>&#x201C;Chatty&#x201D;: print even more
    informational messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>4</term>
    <listitem><para>&#x201C;Debug&#x201D;: print debug
    information.</para></listitem>
    </varlistentry>

    <varlistentry><term>5</term>
    <listitem><para>&#x201C;Vomit&#x201D;: print vast amounts of debug
    information.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry>


<varlistentry><term><option>--quiet</option></term>

  <listitem>

  <para>Decreases the level of verbosity of diagnostic messages
  printed on standard error.  This is the inverse option to
  <option>-v</option> / <option>--verbose</option>.
  </para>

  <para>This option may be specified repeatedly.  See the previous
  verbosity levels list.</para>

  </listitem>

</varlistentry>


<varlistentry xml:id="opt-log-format"><term><option>--log-format</option> <replaceable>format</replaceable></term>

  <listitem>

  <para>This option can be used to change the output of the log format, with
  <replaceable>format</replaceable> being one of:</para>

  <variablelist>

    <varlistentry><term>raw</term>
    <listitem><para>This is the raw format, as outputted by nix-build.</para></listitem>
    </varlistentry>

    <varlistentry><term>internal-json</term>
    <listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar</term>
    <listitem><para>Only display a progress bar during the builds.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar-with-logs</term>
    <listitem><para>Display the raw logs, with the progress bar at the bottom.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry>

<varlistentry><term><option>--no-build-output</option> / <option>-Q</option></term>

  <listitem><para>By default, output written by builders to standard
  output and standard error is echoed to the Nix command's standard
  error.  This option suppresses this behaviour.  Note that the
  builder's standard output and error are always written to a log file
  in
  <filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.</para></listitem>

</varlistentry>


<varlistentry xml:id="opt-max-jobs"><term><option>--max-jobs</option> / <option>-j</option>
<replaceable>number</replaceable></term>

  <listitem>

  <para>Sets the maximum number of build jobs that Nix will
  perform in parallel to the specified number.  Specify
  <literal>auto</literal> to use the number of CPUs in the system.
  The default is specified by the <link linkend="conf-max-jobs"><literal>max-jobs</literal></link>
  configuration setting, which itself defaults to
  <literal>1</literal>.  A higher value is useful on SMP systems or to
  exploit I/O latency.</para>

  <para> Setting it to <literal>0</literal> disallows building on the local
  machine, which is useful when you want builds to happen only on remote
  builders.</para>

  </listitem>

</varlistentry>


<varlistentry xml:id="opt-cores"><term><option>--cores</option></term>

  <listitem><para>Sets the value of the <envar>NIX_BUILD_CORES</envar>
  environment variable in the invocation of builders.  Builders can
  use this variable at their discretion to control the maximum amount
  of parallelism.  For instance, in Nixpkgs, if the derivation
  attribute <varname>enableParallelBuilding</varname> is set to
  <literal>true</literal>, the builder passes the
  <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
  It defaults to the value of the <link linkend="conf-cores"><literal>cores</literal></link>
  configuration setting, if set, or <literal>1</literal> otherwise.
  The value <literal>0</literal> means that the builder should use all
  available CPU cores in the system.</para></listitem>

</varlistentry>


<varlistentry xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can go without producing any data on standard output or standard
  error.  The default is specified by the <link linkend="conf-max-silent-time"><literal>max-silent-time</literal></link>
  configuration setting.  <literal>0</literal> means no
  time-out.</para></listitem>

</varlistentry>

<varlistentry xml:id="opt-timeout"><term><option>--timeout</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can run.  The default is specified by the <link linkend="conf-timeout"><literal>timeout</literal></link>
  configuration setting.  <literal>0</literal> means no
  timeout.</para></listitem>

</varlistentry>

<varlistentry><term><option>--keep-going</option> / <option>-k</option></term>

  <listitem><para>Keep going in case of failed builds, to the
  greatest extent possible.  That is, if building an input of some
  derivation fails, Nix will still build the other inputs, but not the
  derivation itself.  Without this option, Nix stops if any build
  fails (except for builds of substitutes), possibly killing builds in
  progress (in case of parallel or distributed builds).</para></listitem>

</varlistentry>


<varlistentry><term><option>--keep-failed</option> / <option>-K</option></term>

  <listitem><para>Specifies that in case of a build failure, the
  temporary directory (usually in <filename>/tmp</filename>) in which
  the build takes place should not be deleted.  The path of the build
  directory is printed as an informational message.
    </para>
  </listitem>
</varlistentry>


<varlistentry><term><option>--fallback</option></term>

  <listitem>

  <para>Whenever Nix attempts to build a derivation for which
  substitutes are known for each output path, but realising the output
  paths through the substitutes fails, fall back on building the
  derivation.</para>

  <para>The most common scenario in which this is useful is when we
  have registered substitutes in order to perform binary distribution
  from, say, a network repository.  If the repository is down, the
  realisation of the derivation will fail.  When this option is
  specified, Nix will build the derivation instead.  Thus,
  installation from binaries falls back on installation from source.
  This option is not the default since it is generally not desirable
  for a transient failure in obtaining the substitutes to lead to a
  full build from source (with the related consumption of
  resources).</para>

  </listitem>

</varlistentry>

<varlistentry><term><option>--no-build-hook</option></term>

  <listitem>

  <para>Disables the build hook mechanism.  This allows to ignore remote
  builders if they are setup on the machine.</para>

  <para>It's useful in cases where the bandwidth between the client and the
  remote builder is too low.  In that case it can take more time to upload the
  sources to the remote builder and fetch back the result than to do the
  computation locally.</para>

  </listitem>

</varlistentry>



<varlistentry><term><option>--readonly-mode</option></term>

  <listitem><para>When this option is used, no attempt is made to open
  the Nix database.  Most Nix operations do need database access, so
  those operations will fail.</para></listitem>

</varlistentry>


<varlistentry><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is accepted by
  <command>nix-env</command>, <command>nix-instantiate</command>,
  <command>nix-shell</command> and <command>nix-build</command>.
  When evaluating Nix expressions, the expression evaluator will
  automatically try to call functions that
  it encounters.  It can automatically call functions for which every
  argument has a <link linkend="ss-functions">default value</link>
  (e.g., <literal>{ <replaceable>argName</replaceable> ?
  <replaceable>defaultValue</replaceable> }:
  <replaceable>...</replaceable></literal>).  With
  <option>--arg</option>, you can also call functions that have
  arguments without a default value (or override a default value).
  That is, if the evaluator encounters a function with an argument
  named <replaceable>name</replaceable>, it will call it with value
  <replaceable>value</replaceable>.</para>

  <para>For instance, the top-level <literal>default.nix</literal> in
  Nixpkgs is actually a function:

<programlisting>
{ # The system (e.g., `i686-linux') for which to build the packages.
  system ? builtins.currentSystem
  <replaceable>...</replaceable>
}: <replaceable>...</replaceable></programlisting>

  So if you call this Nix expression (e.g., when you do
  <literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
  the function will be called automatically using the value <link linkend="builtin-currentSystem"><literal>builtins.currentSystem</literal></link>
  for the <literal>system</literal> argument.  You can override this
  using <option>--arg</option>, e.g., <literal>nix-env -i
  <replaceable>pkgname</replaceable> --arg system
  \"i686-freebsd\"</literal>.  (Note that since the argument is a Nix
  string literal, you have to escape the quotes.)</para></listitem>

</varlistentry>


<varlistentry><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is like <option>--arg</option>, only the
  value is not a Nix expression but a string.  So instead of
  <literal>--arg system \"i686-linux\"</literal> (the outer quotes are
  to keep the shell happy) you can say <literal>--argstr system
  i686-linux</literal>.</para></listitem>

</varlistentry>


<varlistentry xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
<replaceable>attrPath</replaceable></term>

  <listitem><para>Select an attribute from the top-level Nix
  expression being evaluated.  (<command>nix-env</command>,
  <command>nix-instantiate</command>, <command>nix-build</command> and
  <command>nix-shell</command> only.)  The <emphasis>attribute
  path</emphasis> <replaceable>attrPath</replaceable> is a sequence of
  attribute names separated by dots.  For instance, given a top-level
  Nix expression <replaceable>e</replaceable>, the attribute path
  <literal>xorg.xorgserver</literal> would cause the expression
  <literal><replaceable>e</replaceable>.xorg.xorgserver</literal> to
  be used.  See <link linkend="refsec-nix-env-install-examples"><command>nix-env
  --install</command></link> for some concrete examples.</para>

  <para>In addition to attribute names, you can also specify array
  indices.  For instance, the attribute path
  <literal>foo.3.bar</literal> selects the <literal>bar</literal>
  attribute of the fourth element of the array in the
  <literal>foo</literal> attribute of the top-level
  expression.</para></listitem>

</varlistentry>


<varlistentry><term><option>--expr</option> / <option>-E</option></term>

  <listitem><para>Interpret the command line arguments as a list of
  Nix expressions to be parsed and evaluated, rather than as a list
  of file names of Nix expressions.
  (<command>nix-instantiate</command>, <command>nix-build</command>
  and <command>nix-shell</command> only.)</para>

  <para>For <command>nix-shell</command>, this option is commonly used
  to give you a shell in which you can build the packages returned
  by the expression. If you want to get a shell which contain the
  <emphasis>built</emphasis> packages ready for use, give your
  expression to the <command>nix-shell -p</command> convenience flag
  instead.</para></listitem>

</varlistentry>


<varlistentry xml:id="opt-I"><term><option>-I</option> <replaceable>path</replaceable></term>

  <listitem><para>Add a path to the Nix expression search path.  This
  option may be given multiple times.  See the <envar linkend="env-NIX_PATH">NIX_PATH</envar> environment variable for
  information on the semantics of the Nix search path.  Paths added
  through <option>-I</option> take precedence over
  <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry>


<varlistentry><term><option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>Set the Nix configuration option
  <replaceable>name</replaceable> to <replaceable>value</replaceable>.
  This overrides settings in the Nix configuration file (see
  <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para></listitem>

</varlistentry>


<varlistentry><term><option>--repair</option></term>

  <listitem><para>Fix corrupted or missing store paths by
  redownloading or rebuilding them.  Note that this is slow because it
  requires computing a cryptographic hash of the contents of every
  path in the closure of the build.  Also note the warning under
  <command>nix-store --repair-path</command>.</para></listitem>

</varlistentry>


</variablelist>


</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-common-env">

<title>Common Environment Variables</title>


<para>Most Nix commands interpret the following environment variables:</para>

<variablelist xml:id="env-common">

<varlistentry><term><envar>IN_NIX_SHELL</envar></term>

  <listitem><para>Indicator that tells if the current environment was set up by
  <command>nix-shell</command>.  Since Nix 2.0 the values are
  <literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>

</varlistentry>

<varlistentry xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>

  <listitem>

    <para>A colon-separated list of directories used to look up Nix
    expressions enclosed in angle brackets (i.e.,
    <literal>&lt;<replaceable>path</replaceable>&gt;</literal>).  For
    instance, the value

    <screen>
/home/eelco/Dev:/etc/nixos</screen>

    will cause Nix to look for paths relative to
    <filename>/home/eelco/Dev</filename> and
    <filename>/etc/nixos</filename>, in this order.  It is also
    possible to match paths against a prefix.  For example, the value

    <screen>
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>

    will cause Nix to search for
    <literal>&lt;nixpkgs/<replaceable>path</replaceable>&gt;</literal> in
    <filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
    and
    <filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>

    <para>If a path in the Nix search path starts with
    <literal>http://</literal> or <literal>https://</literal>, it is
    interpreted as the URL of a tarball that will be downloaded and
    unpacked to a temporary location. The tarball must consist of a
    single top-level directory. For example, setting
    <envar>NIX_PATH</envar> to

    <screen>
nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-15.09.tar.gz</screen>

    tells Nix to download the latest revision in the Nixpkgs/NixOS
    15.09 channel.</para>

    <para>A following shorthand can be used to refer to the official channels:

    <screen>nixpkgs=channel:nixos-15.09</screen>
    </para>

    <para>The search path can be extended using the <option linkend="opt-I">-I</option> option, which takes precedence over
    <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>

  <listitem>

  <para>Normally, the Nix store directory (typically
  <filename>/nix/store</filename>) is not allowed to contain any
  symlink components.  This is to prevent &#x201C;impure&#x201D; builds.  Builders
  sometimes &#x201C;canonicalise&#x201D; paths by resolving all symlink components.
  Thus, builds on different machines (with
  <filename>/nix/store</filename> resolving to different locations)
  could yield different results.  This is generally not a problem,
  except when builds are deployed to machines where
  <filename>/nix/store</filename> resolves differently.  If you are
  sure that you&#x2019;re not going to do that, you can set
  <envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>

  <para>Note that if you&#x2019;re symlinking the Nix store so that you can
  put it on another file system than the root file system, on Linux
  you&#x2019;re better off using <literal>bind</literal> mount points, e.g.,

  <screen>
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix</screen>

  Consult the <citerefentry><refentrytitle>mount</refentrytitle>
  <manvolnum>8</manvolnum></citerefentry> manual page for details.</para>

  </listitem>

</varlistentry>


<varlistentry><term><envar>NIX_STORE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix store (default
  <filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_DATA_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix static data
  directory (default
  <filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_LOG_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix log directory
  (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_STATE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix state directory
  (default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_CONF_DIR</envar></term>

  <listitem><para>Overrides the location of the system Nix configuration
  directory (default
  <filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>

</varlistentry>

<varlistentry><term><envar>NIX_USER_CONF_FILES</envar></term>

  <listitem><para>Overrides the location of the user Nix configuration files
  to load from (defaults to the XDG spec locations). The variable is treated
  as a list separated by the <literal>:</literal> token.</para></listitem>

</varlistentry>

<varlistentry><term><envar>TMPDIR</envar></term>

  <listitem><para>Use the specified directory to store temporary
  files.  In particular, this includes temporary build directories;
  these can take up substantial amounts of disk space.  The default is
  <filename>/tmp</filename>.</para></listitem>

</varlistentry>


<varlistentry xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>

  <listitem><para>This variable should be set to
  <literal>daemon</literal> if you want to use the Nix daemon to
  execute Nix operations. This is necessary in <link linkend="ssec-multi-user">multi-user Nix installations</link>.
  If the Nix daemon's Unix socket is at some non-standard path,
  this variable should be set to <literal>unix://path/to/socket</literal>.
  Otherwise, it should be left unset.</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_SHOW_STATS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print some
  evaluation statistics, such as the number of values
  allocated.</para></listitem>

</varlistentry>


<varlistentry><term><envar>NIX_COUNT_CALLS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print how
  often functions were called during Nix expression evaluation.  This
  is useful for profiling your Nix expressions.</para></listitem>

</varlistentry>


<varlistentry><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>

  <listitem><para>If Nix has been configured to use the Boehm garbage
  collector, this variable sets the initial size of the heap in bytes.
  It defaults to 384 MiB.  Setting it to a low value reduces memory
  consumption, but will increase runtime due to the overhead of
  garbage collection.</para></listitem>

</varlistentry>


</variablelist>


</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-main-commands">

<title>Main Commands</title>

<para>This section lists commands and options that you can use when you
work with Nix.</para>

<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-env">

<refmeta>
  <refentrytitle>nix-env</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-env</refname>
  <refpurpose>manipulate or query Nix user environments</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-env</command>
    <arg xmlns="http://docbook.org/ns/docbook"><option>--help</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--version</option></arg><arg xmlns="http://docbook.org/ns/docbook" rep="repeat">
  <group choice="req">
    <arg choice="plain"><option>--verbose</option></arg>
    <arg choice="plain"><option>-v</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <arg choice="plain"><option>--quiet</option></arg>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--log-format</option>
  <replaceable>format</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--no-build-output</option></arg>
    <arg choice="plain"><option>-Q</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="req">
    <arg choice="plain"><option>--max-jobs</option></arg>
    <arg choice="plain"><option>-j</option></arg>
  </group>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--cores</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--max-silent-time</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--timeout</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--keep-going</option></arg>
    <arg choice="plain"><option>-k</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--keep-failed</option></arg>
    <arg choice="plain"><option>-K</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook"><option>--fallback</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--readonly-mode</option></arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>-I</option>
  <replaceable>path</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--option</option>
  <replaceable>name</replaceable>
  <replaceable>value</replaceable>
</arg><sbr xmlns="http://docbook.org/ns/docbook"/>
    <arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg>
      <group choice="req">
        <arg choice="plain"><option>--file</option></arg>
        <arg choice="plain"><option>-f</option></arg>
      </group>
      <replaceable>path</replaceable>
    </arg>
    <arg>
      <group choice="req">
        <arg choice="plain"><option>--profile</option></arg>
        <arg choice="plain"><option>-p</option></arg>
      </group>
      <replaceable>path</replaceable>
    </arg>
    <arg>
      <arg choice="plain"><option>--system-filter</option></arg>
      <replaceable>system</replaceable>
    </arg>
    <arg><option>--dry-run</option></arg>
    <arg choice="plain"><replaceable>operation</replaceable></arg>
    <arg rep="repeat"><replaceable>options</replaceable></arg>
    <arg rep="repeat"><replaceable>arguments</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para>The command <command>nix-env</command> is used to manipulate Nix
user environments.  User environments are sets of software packages
available to a user at some point in time.  In other words, they are a
synthesised view of the programs available in the Nix store.  There
may be many user environments: different users can have different
environments, and individual users can switch between different
environments.</para>

<para><command>nix-env</command> takes exactly one
<emphasis>operation</emphasis> flag which indicates the subcommand to
be performed.  These are documented below.</para>

</refsection>



<!--######################################################################-->

<refsection><title>Selectors</title>

<para>Several commands, such as <command>nix-env -q</command> and
<command>nix-env -i</command>, take a list of arguments that specify
the packages on which to operate. These are extended regular
expressions that must match the entire name of the package. (For
details on regular expressions, see
<citerefentry><refentrytitle>regex</refentrytitle><manvolnum>7</manvolnum></citerefentry>.)
The match is case-sensitive. The regular expression can optionally be
followed by a dash and a version number; if omitted, any version of
the package will match.  Here are some examples:

<variablelist>

  <varlistentry>
    <term><literal>firefox</literal></term>
    <listitem><para>Matches the package name
    <literal>firefox</literal> and any version.</para></listitem>
  </varlistentry>

  <varlistentry>
    <term><literal>firefox-32.0</literal></term>
    <listitem><para>Matches the package name
    <literal>firefox</literal> and version
    <literal>32.0</literal>.</para></listitem>
  </varlistentry>

  <varlistentry>
    <term><literal>gtk\\+</literal></term>
    <listitem><para>Matches the package name
    <literal>gtk+</literal>. The <literal>+</literal> character must
    be escaped using a backslash to prevent it from being interpreted
    as a quantifier, and the backslash must be escaped in turn with
    another backslash to ensure that the shell passes it
    on.</para></listitem>
  </varlistentry>

  <varlistentry>
    <term><literal>.\*</literal></term>
    <listitem><para>Matches any package name. This is the default for
    most commands.</para></listitem>
  </varlistentry>

  <varlistentry>
    <term><literal>'.*zip.*'</literal></term>
    <listitem><para>Matches any package name containing the string
    <literal>zip</literal>. Note the dots: <literal>'*zip*'</literal>
    does not work, because in a regular expression, the character
    <literal>*</literal> is interpreted as a
    quantifier.</para></listitem>
  </varlistentry>

  <varlistentry>
    <term><literal>'.*(firefox|chromium).*'</literal></term>
    <listitem><para>Matches any package name containing the strings
    <literal>firefox</literal> or
    <literal>chromium</literal>.</para></listitem>
  </varlistentry>

</variablelist>

</para>

</refsection>



<!--######################################################################-->

<refsection><title>Common options</title>

<para>This section lists the options that are common to all
operations.  These options are allowed for every subcommand, though
they may not always have an effect.  <phrase condition="manual">See
also <xref linkend="sec-common-options"/>.</phrase></para>

<variablelist>

  <varlistentry><term><option>--file</option> / <option>-f</option> <replaceable>path</replaceable></term>

    <listitem><para>Specifies the Nix expression (designated below as
    the <emphasis>active Nix expression</emphasis>) used by the
    <option>--install</option>, <option>--upgrade</option>, and
    <option>--query --available</option> operations to obtain
    derivations.  The default is
    <filename>~/.nix-defexpr</filename>.</para>

    <para>If the argument starts with <literal>http://</literal> or
    <literal>https://</literal>, it is interpreted as the URL of a
    tarball that will be downloaded and unpacked to a temporary
    location. The tarball must include a single top-level directory
    containing at least a file named <filename>default.nix</filename>.</para>

    </listitem>

  </varlistentry>

  <varlistentry><term><option>--profile</option> / <option>-p</option> <replaceable>path</replaceable></term>

    <listitem><para>Specifies the profile to be used by those
    operations that operate on a profile (designated below as the
    <emphasis>active profile</emphasis>).  A profile is a sequence of
    user environments called <emphasis>generations</emphasis>, one of
    which is the <emphasis>current
    generation</emphasis>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--dry-run</option></term>

    <listitem><para>For the <option>--install</option>,
    <option>--upgrade</option>, <option>--uninstall</option>,
    <option>--switch-generation</option>,
    <option>--delete-generations</option> and
    <option>--rollback</option> operations, this flag will cause
    <command>nix-env</command> to print what
    <emphasis>would</emphasis> be done if this flag had not been
    specified, without actually doing it.</para>

    <para><option>--dry-run</option> also prints out which paths will
    be <link linkend="gloss-substitute">substituted</link> (i.e.,
    downloaded) and which paths will be built from source (because no
    substitute is available).</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--system-filter</option> <replaceable>system</replaceable></term>

    <listitem><para>By default, operations such as <option>--query
    --available</option> show derivations matching any platform.  This
    option allows you to use derivations for the specified platform
    <replaceable>system</replaceable>.</para></listitem>

  </varlistentry>

</variablelist>

<variablelist condition="manpage">
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--help</option></term>

  <listitem><para>Prints out a summary of the command syntax and
  exits.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--version</option></term>

  <listitem><para>Prints out the Nix version number on standard output
  and exits.</para></listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--verbose</option> / <option>-v</option></term>

  <listitem>

  <para>Increases the level of verbosity of diagnostic messages
  printed on standard error.  For each Nix operation, the information
  printed on standard output is well-defined; any diagnostic
  information is printed on standard error, never on standard
  output.</para>

  <para>This option may be specified repeatedly.  Currently, the
  following verbosity levels exist:</para>

  <variablelist>

    <varlistentry><term>0</term>
    <listitem><para>&#x201C;Errors only&#x201D;: only print messages
    explaining why the Nix invocation failed.</para></listitem>
    </varlistentry>

    <varlistentry><term>1</term>
    <listitem><para>&#x201C;Informational&#x201D;: print
    <emphasis>useful</emphasis> messages about what Nix is doing.
    This is the default.</para></listitem>
    </varlistentry>

    <varlistentry><term>2</term>
    <listitem><para>&#x201C;Talkative&#x201D;: print more informational
    messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>3</term>
    <listitem><para>&#x201C;Chatty&#x201D;: print even more
    informational messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>4</term>
    <listitem><para>&#x201C;Debug&#x201D;: print debug
    information.</para></listitem>
    </varlistentry>

    <varlistentry><term>5</term>
    <listitem><para>&#x201C;Vomit&#x201D;: print vast amounts of debug
    information.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--quiet</option></term>

  <listitem>

  <para>Decreases the level of verbosity of diagnostic messages
  printed on standard error.  This is the inverse option to
  <option>-v</option> / <option>--verbose</option>.
  </para>

  <para>This option may be specified repeatedly.  See the previous
  verbosity levels list.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-log-format"><term><option>--log-format</option> <replaceable>format</replaceable></term>

  <listitem>

  <para>This option can be used to change the output of the log format, with
  <replaceable>format</replaceable> being one of:</para>

  <variablelist>

    <varlistentry><term>raw</term>
    <listitem><para>This is the raw format, as outputted by nix-build.</para></listitem>
    </varlistentry>

    <varlistentry><term>internal-json</term>
    <listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar</term>
    <listitem><para>Only display a progress bar during the builds.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar-with-logs</term>
    <listitem><para>Display the raw logs, with the progress bar at the bottom.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-output</option> / <option>-Q</option></term>

  <listitem><para>By default, output written by builders to standard
  output and standard error is echoed to the Nix command's standard
  error.  This option suppresses this behaviour.  Note that the
  builder's standard output and error are always written to a log file
  in
  <filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-jobs"><term><option>--max-jobs</option> / <option>-j</option>
<replaceable>number</replaceable></term>

  <listitem>

  <para>Sets the maximum number of build jobs that Nix will
  perform in parallel to the specified number.  Specify
  <literal>auto</literal> to use the number of CPUs in the system.
  The default is specified by the <link linkend="conf-max-jobs"><literal>max-jobs</literal></link>
  configuration setting, which itself defaults to
  <literal>1</literal>.  A higher value is useful on SMP systems or to
  exploit I/O latency.</para>

  <para> Setting it to <literal>0</literal> disallows building on the local
  machine, which is useful when you want builds to happen only on remote
  builders.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-cores"><term><option>--cores</option></term>

  <listitem><para>Sets the value of the <envar>NIX_BUILD_CORES</envar>
  environment variable in the invocation of builders.  Builders can
  use this variable at their discretion to control the maximum amount
  of parallelism.  For instance, in Nixpkgs, if the derivation
  attribute <varname>enableParallelBuilding</varname> is set to
  <literal>true</literal>, the builder passes the
  <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
  It defaults to the value of the <link linkend="conf-cores"><literal>cores</literal></link>
  configuration setting, if set, or <literal>1</literal> otherwise.
  The value <literal>0</literal> means that the builder should use all
  available CPU cores in the system.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can go without producing any data on standard output or standard
  error.  The default is specified by the <link linkend="conf-max-silent-time"><literal>max-silent-time</literal></link>
  configuration setting.  <literal>0</literal> means no
  time-out.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-timeout"><term><option>--timeout</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can run.  The default is specified by the <link linkend="conf-timeout"><literal>timeout</literal></link>
  configuration setting.  <literal>0</literal> means no
  timeout.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-going</option> / <option>-k</option></term>

  <listitem><para>Keep going in case of failed builds, to the
  greatest extent possible.  That is, if building an input of some
  derivation fails, Nix will still build the other inputs, but not the
  derivation itself.  Without this option, Nix stops if any build
  fails (except for builds of substitutes), possibly killing builds in
  progress (in case of parallel or distributed builds).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-failed</option> / <option>-K</option></term>

  <listitem><para>Specifies that in case of a build failure, the
  temporary directory (usually in <filename>/tmp</filename>) in which
  the build takes place should not be deleted.  The path of the build
  directory is printed as an informational message.
    </para>
  </listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--fallback</option></term>

  <listitem>

  <para>Whenever Nix attempts to build a derivation for which
  substitutes are known for each output path, but realising the output
  paths through the substitutes fails, fall back on building the
  derivation.</para>

  <para>The most common scenario in which this is useful is when we
  have registered substitutes in order to perform binary distribution
  from, say, a network repository.  If the repository is down, the
  realisation of the derivation will fail.  When this option is
  specified, Nix will build the derivation instead.  Thus,
  installation from binaries falls back on installation from source.
  This option is not the default since it is generally not desirable
  for a transient failure in obtaining the substitutes to lead to a
  full build from source (with the related consumption of
  resources).</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-hook</option></term>

  <listitem>

  <para>Disables the build hook mechanism.  This allows to ignore remote
  builders if they are setup on the machine.</para>

  <para>It's useful in cases where the bandwidth between the client and the
  remote builder is too low.  In that case it can take more time to upload the
  sources to the remote builder and fetch back the result than to do the
  computation locally.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--readonly-mode</option></term>

  <listitem><para>When this option is used, no attempt is made to open
  the Nix database.  Most Nix operations do need database access, so
  those operations will fail.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is accepted by
  <command>nix-env</command>, <command>nix-instantiate</command>,
  <command>nix-shell</command> and <command>nix-build</command>.
  When evaluating Nix expressions, the expression evaluator will
  automatically try to call functions that
  it encounters.  It can automatically call functions for which every
  argument has a <link linkend="ss-functions">default value</link>
  (e.g., <literal>{ <replaceable>argName</replaceable> ?
  <replaceable>defaultValue</replaceable> }:
  <replaceable>...</replaceable></literal>).  With
  <option>--arg</option>, you can also call functions that have
  arguments without a default value (or override a default value).
  That is, if the evaluator encounters a function with an argument
  named <replaceable>name</replaceable>, it will call it with value
  <replaceable>value</replaceable>.</para>

  <para>For instance, the top-level <literal>default.nix</literal> in
  Nixpkgs is actually a function:

<programlisting>
{ # The system (e.g., `i686-linux') for which to build the packages.
  system ? builtins.currentSystem
  <replaceable>...</replaceable>
}: <replaceable>...</replaceable></programlisting>

  So if you call this Nix expression (e.g., when you do
  <literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
  the function will be called automatically using the value <link linkend="builtin-currentSystem"><literal>builtins.currentSystem</literal></link>
  for the <literal>system</literal> argument.  You can override this
  using <option>--arg</option>, e.g., <literal>nix-env -i
  <replaceable>pkgname</replaceable> --arg system
  \"i686-freebsd\"</literal>.  (Note that since the argument is a Nix
  string literal, you have to escape the quotes.)</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is like <option>--arg</option>, only the
  value is not a Nix expression but a string.  So instead of
  <literal>--arg system \"i686-linux\"</literal> (the outer quotes are
  to keep the shell happy) you can say <literal>--argstr system
  i686-linux</literal>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
<replaceable>attrPath</replaceable></term>

  <listitem><para>Select an attribute from the top-level Nix
  expression being evaluated.  (<command>nix-env</command>,
  <command>nix-instantiate</command>, <command>nix-build</command> and
  <command>nix-shell</command> only.)  The <emphasis>attribute
  path</emphasis> <replaceable>attrPath</replaceable> is a sequence of
  attribute names separated by dots.  For instance, given a top-level
  Nix expression <replaceable>e</replaceable>, the attribute path
  <literal>xorg.xorgserver</literal> would cause the expression
  <literal><replaceable>e</replaceable>.xorg.xorgserver</literal> to
  be used.  See <link linkend="refsec-nix-env-install-examples"><command>nix-env
  --install</command></link> for some concrete examples.</para>

  <para>In addition to attribute names, you can also specify array
  indices.  For instance, the attribute path
  <literal>foo.3.bar</literal> selects the <literal>bar</literal>
  attribute of the fourth element of the array in the
  <literal>foo</literal> attribute of the top-level
  expression.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--expr</option> / <option>-E</option></term>

  <listitem><para>Interpret the command line arguments as a list of
  Nix expressions to be parsed and evaluated, rather than as a list
  of file names of Nix expressions.
  (<command>nix-instantiate</command>, <command>nix-build</command>
  and <command>nix-shell</command> only.)</para>

  <para>For <command>nix-shell</command>, this option is commonly used
  to give you a shell in which you can build the packages returned
  by the expression. If you want to get a shell which contain the
  <emphasis>built</emphasis> packages ready for use, give your
  expression to the <command>nix-shell -p</command> convenience flag
  instead.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-I"><term><option>-I</option> <replaceable>path</replaceable></term>

  <listitem><para>Add a path to the Nix expression search path.  This
  option may be given multiple times.  See the <envar linkend="env-NIX_PATH">NIX_PATH</envar> environment variable for
  information on the semantics of the Nix search path.  Paths added
  through <option>-I</option> take precedence over
  <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>Set the Nix configuration option
  <replaceable>name</replaceable> to <replaceable>value</replaceable>.
  This overrides settings in the Nix configuration file (see
  <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--repair</option></term>

  <listitem><para>Fix corrupted or missing store paths by
  redownloading or rebuilding them.  Note that this is slow because it
  requires computing a cryptographic hash of the contents of every
  path in the closure of the build.  Also note the warning under
  <command>nix-store --repair-path</command>.</para></listitem>

</varlistentry>
</variablelist>

</refsection>



<!--######################################################################-->

<refsection><title>Files</title>

<variablelist>

  <varlistentry><term><filename>~/.nix-defexpr</filename></term>

    <listitem><para>The source for the default Nix
    expressions used by the <option>--install</option>,
    <option>--upgrade</option>, and <option>--query
    --available</option> operations to obtain derivations. The
    <option>--file</option> option may be used to override this
    default.</para>

    <para>If <filename>~/.nix-defexpr</filename> is a file,
    it is loaded as a Nix expression. If the expression
    is a set, it is used as the default Nix expression.
    If the expression is a function, an empty set is passed
    as argument and the return value is used as
    the default Nix expression.</para>

    <para>If <filename>~/.nix-defexpr</filename> is a directory
    containing a <filename>default.nix</filename> file, that file
    is loaded as in the above paragraph.</para>

    <para>If <filename>~/.nix-defexpr</filename> is a directory without
    a <filename>default.nix</filename> file, then its contents
    (both files and subdirectories) are loaded as Nix expressions.
    The expressions are combined into a single set, each expression
    under an attribute with the same name as the original file
    or subdirectory.
    </para>

    <para>For example, if <filename>~/.nix-defexpr</filename> contains
    two files, <filename>foo.nix</filename> and <filename>bar.nix</filename>,
    then the default Nix expression will essentially be

<programlisting>
{
  foo = import ~/.nix-defexpr/foo.nix;
  bar = import ~/.nix-defexpr/bar.nix;
}</programlisting>

    </para>

    <para>The file <filename>manifest.nix</filename> is always ignored.
    Subdirectories without a <filename>default.nix</filename> file
    are traversed recursively in search of more Nix expressions,
    but the names of these intermediate directories are not
    added to the attribute paths of the default Nix expression.</para>

    <para>The command <command>nix-channel</command> places symlinks
    to the downloaded Nix expressions from each subscribed channel in
    this directory.</para>
    </listitem>

  </varlistentry>

  <varlistentry><term><filename>~/.nix-profile</filename></term>

    <listitem><para>A symbolic link to the user's current profile.  By
    default, this symlink points to
    <filename><replaceable>prefix</replaceable>/var/nix/profiles/default</filename>.
    The <envar>PATH</envar> environment variable should include
    <filename>~/.nix-profile/bin</filename> for the user environment
    to be visible to the user.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-env-install"><title>Operation <option>--install</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <group choice="req">
    <arg choice="plain"><option>--install</option></arg>
    <arg choice="plain"><option>-i</option></arg>
  </group>
  <arg xmlns="http://docbook.org/ns/docbook">
    <group choice="req">
      <arg choice="plain"><option>--prebuilt-only</option></arg>
      <arg choice="plain"><option>-b</option></arg>
    </group>
  </arg><arg xmlns="http://docbook.org/ns/docbook">
    <group choice="req">
      <arg choice="plain"><option>--attr</option></arg>
      <arg choice="plain"><option>-A</option></arg>
    </group>
  </arg><arg xmlns="http://docbook.org/ns/docbook"><option>--from-expression</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>-E</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--from-profile</option> <replaceable>path</replaceable></arg>
  <group choice="opt">
    <arg choice="plain"><option>--preserve-installed</option></arg>
    <arg choice="plain"><option>-P</option></arg>
  </group>
  <group choice="opt">
    <arg choice="plain"><option>--remove-all</option></arg>
    <arg choice="plain"><option>-r</option></arg>
  </group>
  <arg choice="plain" rep="repeat"><replaceable>args</replaceable></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>The install operation creates a new user environment, based on
the current generation of the active profile, to which a set of store
paths described by <replaceable>args</replaceable> is added.  The
arguments <replaceable>args</replaceable> map to store paths in a
number of possible ways:

<itemizedlist>

  <listitem><para>By default, <replaceable>args</replaceable> is a set
  of derivation names denoting derivations in the active Nix
  expression.  These are realised, and the resulting output paths are
  installed.  Currently installed derivations with a name equal to the
  name of a derivation being added are removed unless the option
  <option>--preserve-installed</option> is
  specified.</para>

  <para>If there are multiple derivations matching a name in
  <replaceable>args</replaceable> that have the same name (e.g.,
  <literal>gcc-3.3.6</literal> and <literal>gcc-4.1.1</literal>), then
  the derivation with the highest <emphasis>priority</emphasis> is
  used.  A derivation can define a priority by declaring the
  <varname>meta.priority</varname> attribute.  This attribute should
  be a number, with a higher value denoting a lower priority.  The
  default priority is <literal>0</literal>.</para>

  <para>If there are multiple matching derivations with the same
  priority, then the derivation with the highest version will be
  installed.</para>

  <para>You can force the installation of multiple derivations with
  the same name by being specific about the versions.  For instance,
  <literal>nix-env -i gcc-3.3.6 gcc-4.1.1</literal> will install both
  version of GCC (and will probably cause a user environment
  conflict!).</para></listitem>

  <listitem><para>If <link linkend="opt-attr"><option>--attr</option></link>
  (<option>-A</option>) is specified, the arguments are
  <emphasis>attribute paths</emphasis> that select attributes from the
  top-level Nix expression.  This is faster than using derivation
  names and unambiguous.  To find out the attribute paths of available
  packages, use <literal>nix-env -qaP</literal>.</para></listitem>

  <listitem><para>If <option>--from-profile</option>
  <replaceable>path</replaceable> is given,
  <replaceable>args</replaceable> is a set of names denoting installed
  store paths in the profile <replaceable>path</replaceable>.  This is
  an easy way to copy user environment elements from one profile to
  another.</para></listitem>

  <listitem><para>If <option>--from-expression</option> is given,
  <replaceable>args</replaceable> are Nix <link linkend="ss-functions">functions</link> that are called with the
  active Nix expression as their single argument.  The derivations
  returned by those function calls are installed.  This allows
  derivations to be specified in an unambiguous way, which is necessary
  if there are multiple derivations with the same
  name.</para></listitem>

  <listitem><para>If <replaceable>args</replaceable> are store
  derivations, then these are <link linkend="rsec-nix-store-realise">realised</link>, and the resulting
  output paths are installed.</para></listitem>

  <listitem><para>If <replaceable>args</replaceable> are store paths
  that are not store derivations, then these are <link linkend="rsec-nix-store-realise">realised</link> and
  installed.</para></listitem>

  <listitem><para>By default all outputs are installed for each derivation.
  That can be reduced by setting <literal>meta.outputsToInstall</literal>.
  </para></listitem> <!-- TODO: link nixpkgs docs on the ability to override those. -->

</itemizedlist>

</para>

</refsection>


<refsection><title>Flags</title>

<variablelist>

  <varlistentry><term><option>--prebuilt-only</option> / <option>-b</option></term>

    <listitem><para>Use only derivations for which a substitute is
    registered, i.e., there is a pre-built binary available that can
    be downloaded in lieu of building the derivation.  Thus, no
    packages will be built from source.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--preserve-installed</option></term>
    <term><option>-P</option></term>

    <listitem><para>Do not remove derivations with a name matching one
    of the derivations being installed.  Usually, trying to have two
    versions of the same package installed in the same generation of a
    profile will lead to an error in building the generation, due to
    file name clashes between the two versions.  However, this is not
    the case for all packages.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--remove-all</option></term>
    <term><option>-r</option></term>

    <listitem><para>Remove all previously installed packages first.
    This is equivalent to running <literal>nix-env -e '.*'</literal>
    first, except that everything happens in a single
    transaction.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection xml:id="refsec-nix-env-install-examples"><title>Examples</title>

<para>To install a specific version of <command>gcc</command> from the
active Nix expression:

<screen>
$ nix-env --install gcc-3.3.2
installing `gcc-3.3.2'
uninstalling `gcc-3.1'</screen>

Note the previously installed version is removed, since
<option>--preserve-installed</option> was not specified.</para>

<para>To install an arbitrary version:

<screen>
$ nix-env --install gcc
installing `gcc-3.3.2'</screen>

</para>

<para>To install using a specific attribute:

<screen>
$ nix-env -i -A gcc40mips
$ nix-env -i -A xorg.xorgserver</screen>

</para>

<para>To install all derivations in the Nix expression <filename>foo.nix</filename>:

<screen>
$ nix-env -f ~/foo.nix -i '.*'</screen>

</para>

<para>To copy the store path with symbolic name <literal>gcc</literal>
from another profile:

<screen>
$ nix-env -i --from-profile /nix/var/nix/profiles/foo gcc</screen>

</para>

<para>To install a specific store derivation (typically created by
<command>nix-instantiate</command>):

<screen>
$ nix-env -i /nix/store/fibjb1bfbpm5mrsxc4mh2d8n37sxh91i-gcc-3.4.3.drv</screen>

</para>

<para>To install a specific output path:

<screen>
$ nix-env -i /nix/store/y3cgx0xj1p4iv9x0pnnmdhr8iyg741vk-gcc-3.4.3</screen>

</para>

<para>To install from a Nix expression specified on the command-line:

<screen>
$ nix-env -f ./foo.nix -i -E \
    'f: (f {system = "i686-linux";}).subversionWithJava'</screen>

I.e., this evaluates to <literal>(f: (f {system =
"i686-linux";}).subversionWithJava) (import ./foo.nix)</literal>, thus
selecting the <literal>subversionWithJava</literal> attribute from the
set returned by calling the function defined in
<filename>./foo.nix</filename>.</para>

<para>A dry-run tells you which paths will be downloaded or built from
source:

<screen>
$ nix-env -f '&lt;nixpkgs&gt;' -iA hello --dry-run
(dry run; not doing anything)
installing &#x2018;hello-2.10&#x2019;
this path will be fetched (0.04 MiB download, 0.19 MiB unpacked):
  /nix/store/wkhdf9jinag5750mqlax6z2zbwhqb76n-hello-2.10
  <replaceable>...</replaceable></screen>

</para>

<para>To install Firefox from the latest revision in the Nixpkgs/NixOS
14.12 channel:

<screen>
$ nix-env -f https://github.com/NixOS/nixpkgs/archive/nixos-14.12.tar.gz -iA firefox
</screen>

</para>

</refsection>

</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-env-upgrade"><title>Operation <option>--upgrade</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <group choice="req">
    <arg choice="plain"><option>--upgrade</option></arg>
    <arg choice="plain"><option>-u</option></arg>
  </group>
  <arg xmlns="http://docbook.org/ns/docbook">
    <group choice="req">
      <arg choice="plain"><option>--prebuilt-only</option></arg>
      <arg choice="plain"><option>-b</option></arg>
    </group>
  </arg><arg xmlns="http://docbook.org/ns/docbook">
    <group choice="req">
      <arg choice="plain"><option>--attr</option></arg>
      <arg choice="plain"><option>-A</option></arg>
    </group>
  </arg><arg xmlns="http://docbook.org/ns/docbook"><option>--from-expression</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>-E</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--from-profile</option> <replaceable>path</replaceable></arg>
  <group choice="opt">
    <arg choice="plain"><option>--lt</option></arg>
    <arg choice="plain"><option>--leq</option></arg>
    <arg choice="plain"><option>--eq</option></arg>
    <arg choice="plain"><option>--always</option></arg>
  </group>
  <arg choice="plain" rep="repeat"><replaceable>args</replaceable></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>The upgrade operation creates a new user environment, based on
the current generation of the active profile, in which all store paths
are replaced for which there are newer versions in the set of paths
described by <replaceable>args</replaceable>.  Paths for which there
are no newer versions are left untouched; this is not an error.  It is
also not an error if an element of <replaceable>args</replaceable>
matches no installed derivations.</para>

<para>For a description of how <replaceable>args</replaceable> is
mapped to a set of store paths, see <link linkend="rsec-nix-env-install"><option>--install</option></link>.  If
<replaceable>args</replaceable> describes multiple store paths with
the same symbolic name, only the one with the highest version is
installed.</para>

</refsection>

<refsection><title>Flags</title>

<variablelist>

  <varlistentry><term><option>--lt</option></term>

    <listitem><para>Only upgrade a derivation to newer versions.  This
    is the default.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--leq</option></term>

    <listitem><para>In addition to upgrading to newer versions, also
    &#x201C;upgrade&#x201D; to derivations that have the same version.  Version are
    not a unique identification of a derivation, so there may be many
    derivations that have the same version.  This flag may be useful
    to force &#x201C;synchronisation&#x201D; between the installed and available
    derivations.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--eq</option></term>

    <listitem><para><emphasis>Only</emphasis> &#x201C;upgrade&#x201D; to derivations
    that have the same version.  This may not seem very useful, but it
    actually is, e.g., when there is a new release of Nixpkgs and you
    want to replace installed applications with the same versions
    built against newer dependencies (to reduce the number of
    dependencies floating around on your system).</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--always</option></term>

    <listitem><para>In addition to upgrading to newer versions, also
    &#x201C;upgrade&#x201D; to derivations that have the same or a lower version.
    I.e., derivations may actually be downgraded depending on what is
    available in the active Nix expression.</para></listitem>

  </varlistentry>

</variablelist>

<para>For the other flags, see <option linkend="rsec-nix-env-install">--install</option>.</para>

</refsection>

<refsection><title>Examples</title>

<screen>
$ nix-env --upgrade gcc
upgrading `gcc-3.3.1' to `gcc-3.4'

$ nix-env -u gcc-3.3.2 --always <lineannotation>(switch to a specific version)</lineannotation>
upgrading `gcc-3.4' to `gcc-3.3.2'

$ nix-env --upgrade pan
<lineannotation>(no upgrades available, so nothing happens)</lineannotation>

$ nix-env -u <lineannotation>(try to upgrade everything)</lineannotation>
upgrading `hello-2.1.2' to `hello-2.1.3'
upgrading `mozilla-1.2' to `mozilla-1.4'</screen>

</refsection>

<refsection xml:id="ssec-version-comparisons"><title>Versions</title>

<para>The upgrade operation determines whether a derivation
<varname>y</varname> is an upgrade of a derivation
<varname>x</varname> by looking at their respective
<literal>name</literal> attributes.  The names (e.g.,
<literal>gcc-3.3.1</literal> are split into two parts: the package
name (<literal>gcc</literal>), and the version
(<literal>3.3.1</literal>).  The version part starts after the first
dash not followed by a letter.  <varname>x</varname> is considered an
upgrade of <varname>y</varname> if their package names match, and the
version of <varname>y</varname> is higher that that of
<varname>x</varname>.</para>

<para>The versions are compared by splitting them into contiguous
components of numbers and letters.  E.g., <literal>3.3.1pre5</literal>
is split into <literal>[3, 3, 1, "pre", 5]</literal>.  These lists are
then compared lexicographically (from left to right).  Corresponding
components <varname>a</varname> and <varname>b</varname> are compared
as follows.  If they are both numbers, integer comparison is used.  If
<varname>a</varname> is an empty string and <varname>b</varname> is a
number, <varname>a</varname> is considered less than
<varname>b</varname>.  The special string component
<literal>pre</literal> (for <emphasis>pre-release</emphasis>) is
considered to be less than other components.  String components are
considered less than number components.  Otherwise, they are compared
lexicographically (i.e., using case-sensitive string comparison).</para>

<para>This is illustrated by the following examples:

<screen>
1.0 &lt; 2.3
2.1 &lt; 2.3
2.3 = 2.3
2.5 &gt; 2.3
3.1 &gt; 2.3
2.3.1 &gt; 2.3
2.3.1 &gt; 2.3a
2.3pre1 &lt; 2.3
2.3pre3 &lt; 2.3pre12
2.3a &lt; 2.3c
2.3pre1 &lt; 2.3c
2.3pre1 &lt; 2.3q</screen>

</para>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--uninstall</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <group choice="req">
    <arg choice="plain"><option>--uninstall</option></arg>
    <arg choice="plain"><option>-e</option></arg>
  </group>
  <arg choice="plain" rep="repeat"><replaceable>drvnames</replaceable></arg>
</cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The uninstall operation creates a new user environment, based on
the current generation of the active profile, from which the store
paths designated by the symbolic names
<replaceable>names</replaceable> are removed.</para>

</refsection>

<refsection><title>Examples</title>

<screen>
$ nix-env --uninstall gcc
$ nix-env -e '.*' <lineannotation>(remove everything)</lineannotation></screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-env-set"><title>Operation <option>--set</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <arg choice="plain"><option>--set</option></arg>
  <arg choice="plain"><replaceable>drvname</replaceable></arg>
</cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The <option>--set</option> operation modifies the current generation of a
profile so that it contains exactly the specified derivation, and nothing else.
</para>

</refsection>

<refsection><title>Examples</title>

<para>
The following updates a profile such that its current generation will contain
just Firefox:

<screen>
$ nix-env -p /nix/var/nix/profiles/browser --set firefox</screen>

</para>

</refsection>

</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-env-set-flag"><title>Operation <option>--set-flag</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <arg choice="plain"><option>--set-flag</option></arg>
  <arg choice="plain"><replaceable>name</replaceable></arg>
  <arg choice="plain"><replaceable>value</replaceable></arg>
  <arg choice="plain" rep="repeat"><replaceable>drvnames</replaceable></arg>
</cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The <option>--set-flag</option> operation allows meta attributes
of installed packages to be modified.  There are several attributes
that can be usefully modified, because they affect the behaviour of
<command>nix-env</command> or the user environment build
script:

<itemizedlist>

  <listitem><para><varname>priority</varname> can be changed to
  resolve filename clashes.  The user environment build script uses
  the <varname>meta.priority</varname> attribute of derivations to
  resolve filename collisions between packages.  Lower priority values
  denote a higher priority.  For instance, the GCC wrapper package and
  the Binutils package in Nixpkgs both have a file
  <filename>bin/ld</filename>, so previously if you tried to install
  both you would get a collision.  Now, on the other hand, the GCC
  wrapper declares a higher priority than Binutils, so the former&#x2019;s
  <filename>bin/ld</filename> is symlinked in the user
  environment.</para></listitem>

  <listitem><para><varname>keep</varname> can be set to
  <literal>true</literal> to prevent the package from being upgraded
  or replaced.  This is useful if you want to hang on to an older
  version of a package.</para></listitem>

  <listitem><para><varname>active</varname> can be set to
  <literal>false</literal> to &#x201C;disable&#x201D; the package.  That is, no
  symlinks will be generated to the files of the package, but it
  remains part of the profile (so it won&#x2019;t be garbage-collected).  It
  can be set back to <literal>true</literal> to re-enable the
  package.</para></listitem>

</itemizedlist>

</para>

</refsection>

<refsection><title>Examples</title>

<para>To prevent the currently installed Firefox from being upgraded:

<screen>
$ nix-env --set-flag keep true firefox</screen>

After this, <command>nix-env -u</command> will ignore Firefox.</para>

<para>To disable the currently installed Firefox, then install a new
Firefox while the old remains part of the profile:

<screen>
$ nix-env -q
firefox-2.0.0.9 <lineannotation>(the current one)</lineannotation>

$ nix-env --preserve-installed -i firefox-2.0.0.11
installing `firefox-2.0.0.11'
building path(s) `/nix/store/myy0y59q3ig70dgq37jqwg1j0rsapzsl-user-environment'
collision between `/nix/store/<replaceable>...</replaceable>-firefox-2.0.0.11/bin/firefox'
  and `/nix/store/<replaceable>...</replaceable>-firefox-2.0.0.9/bin/firefox'.
<lineannotation>(i.e., can&#x2019;t have two active at the same time)</lineannotation>

$ nix-env --set-flag active false firefox
setting flag on `firefox-2.0.0.9'

$ nix-env --preserve-installed -i firefox-2.0.0.11
installing `firefox-2.0.0.11'

$ nix-env -q
firefox-2.0.0.11 <lineannotation>(the enabled one)</lineannotation>
firefox-2.0.0.9 <lineannotation>(the disabled one)</lineannotation></screen>

</para>

<para>To make files from <literal>binutils</literal> take precedence
over files from <literal>gcc</literal>:

<screen>
$ nix-env --set-flag priority 5 binutils
$ nix-env --set-flag priority 10 gcc</screen>

</para>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--query</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <group choice="req">
    <arg choice="plain"><option>--query</option></arg>
    <arg choice="plain"><option>-q</option></arg>
  </group>
  <group choice="opt">
    <arg choice="plain"><option>--installed</option></arg>
    <arg choice="plain"><option>--available</option></arg>
    <arg choice="plain"><option>-a</option></arg>
  </group>

  <sbr/>

  <arg>
    <group choice="req">
      <arg choice="plain"><option>--status</option></arg>
      <arg choice="plain"><option>-s</option></arg>
    </group>
  </arg>
  <arg>
    <group choice="req">
      <arg choice="plain"><option>--attr-path</option></arg>
      <arg choice="plain"><option>-P</option></arg>
    </group>
  </arg>
  <arg><option>--no-name</option></arg>
  <arg>
    <group choice="req">
      <arg choice="plain"><option>--compare-versions</option></arg>
      <arg choice="plain"><option>-c</option></arg>
    </group>
  </arg>
  <arg><option>--system</option></arg>
  <arg><option>--drv-path</option></arg>
  <arg><option>--out-path</option></arg>
  <arg><option>--description</option></arg>
  <arg><option>--meta</option></arg>

  <sbr/>

  <arg><option>--xml</option></arg>
  <arg><option>--json</option></arg>
  <arg>
    <group choice="req">
      <arg choice="plain"><option>--prebuilt-only</option></arg>
      <arg choice="plain"><option>-b</option></arg>
    </group>
  </arg>

  <arg>
    <group choice="req">
      <arg choice="plain"><option>--attr</option></arg>
      <arg choice="plain"><option>-A</option></arg>
    </group>
    <replaceable>attribute-path</replaceable>
  </arg>

  <sbr/>

  <arg choice="plain" rep="repeat"><replaceable>names</replaceable></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>The query operation displays information about either the store
paths that are installed in the current generation of the active
profile (<option>--installed</option>), or the derivations that are
available for installation in the active Nix expression
(<option>--available</option>).  It only prints information about
derivations whose symbolic name matches one of
<replaceable>names</replaceable>.</para>

<para>The derivations are sorted by their <literal>name</literal>
attributes.</para>

</refsection>


<refsection><title>Source selection</title>

<para>The following flags specify the set of things on which the query
operates.</para>

<variablelist>

  <varlistentry><term><option>--installed</option></term>

    <listitem><para>The query operates on the store paths that are
    installed in the current generation of the active profile.  This
    is the default.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--available</option></term>
    <term><option>-a</option></term>

    <listitem><para>The query operates on the derivations that are
    available in the active Nix expression.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Queries</title>

<para>The following flags specify what information to display about
the selected derivations.  Multiple flags may be specified, in which
case the information is shown in the order given here.  Note that the
name of the derivation is shown unless <option>--no-name</option> is
specified.</para>

<!-- TODO: fix the terminology here; i.e., derivations, store paths,
user environment elements, etc. -->

<variablelist>

  <varlistentry><term><option>--xml</option></term>

    <listitem><para>Print the result in an XML representation suitable
    for automatic processing by other tools.  The root element is
    called <literal>items</literal>, which contains a
    <literal>item</literal> element for each available or installed
    derivation.  The fields discussed below are all stored in
    attributes of the <literal>item</literal>
    elements.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--json</option></term>

    <listitem><para>Print the result in a JSON representation suitable
    for automatic processing by other tools.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--prebuilt-only</option> / <option>-b</option></term>

    <listitem><para>Show only derivations for which a substitute is
    registered, i.e., there is a pre-built binary available that can
    be downloaded in lieu of building the derivation.  Thus, this
    shows all packages that probably can be installed
    quickly.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--status</option></term>
    <term><option>-s</option></term>

    <listitem><para>Print the <emphasis>status</emphasis> of the
    derivation.  The status consists of three characters.  The first
    is <literal>I</literal> or <literal>-</literal>, indicating
    whether the derivation is currently installed in the current
    generation of the active profile.  This is by definition the case
    for <option>--installed</option>, but not for
    <option>--available</option>.  The second is <literal>P</literal>
    or <literal>-</literal>, indicating whether the derivation is
    present on the system.  This indicates whether installation of an
    available derivation will require the derivation to be built.  The
    third is <literal>S</literal> or <literal>-</literal>, indicating
    whether a substitute is available for the
    derivation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--attr-path</option></term>
    <term><option>-P</option></term>

    <listitem><para>Print the <emphasis>attribute path</emphasis> of
    the derivation, which can be used to unambiguously select it using
    the <link linkend="opt-attr"><option>--attr</option> option</link>
    available in commands that install derivations like
    <literal>nix-env --install</literal>. This option only works
    together with <option>--available</option></para></listitem>

  </varlistentry>

  <varlistentry><term><option>--no-name</option></term>

    <listitem><para>Suppress printing of the <literal>name</literal>
    attribute of each derivation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--compare-versions</option> /
  <option>-c</option></term>

    <listitem><para>Compare installed versions to available versions,
    or vice versa (if <option>--available</option> is given).  This is
    useful for quickly seeing whether upgrades for installed
    packages are available in a Nix expression.  A column is added
    with the following meaning:

    <variablelist>

      <varlistentry><term><literal>&lt;</literal> <replaceable>version</replaceable></term>

        <listitem><para>A newer version of the package is available
        or installed.</para></listitem>

      </varlistentry>

      <varlistentry><term><literal>=</literal> <replaceable>version</replaceable></term>

        <listitem><para>At most the same version of the package is
        available or installed.</para></listitem>

      </varlistentry>

      <varlistentry><term><literal>&gt;</literal> <replaceable>version</replaceable></term>

        <listitem><para>Only older versions of the package are
        available or installed.</para></listitem>

      </varlistentry>

      <varlistentry><term><literal>- ?</literal></term>

        <listitem><para>No version of the package is available or
        installed.</para></listitem>

      </varlistentry>

    </variablelist>

    </para></listitem>

  </varlistentry>

  <varlistentry><term><option>--system</option></term>

    <listitem><para>Print the <literal>system</literal> attribute of
    the derivation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--drv-path</option></term>

    <listitem><para>Print the path of the store
    derivation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--out-path</option></term>

    <listitem><para>Print the output path of the
    derivation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--description</option></term>

    <listitem><para>Print a short (one-line) description of the
    derivation, if available.  The description is taken from the
    <literal>meta.description</literal> attribute of the
    derivation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--meta</option></term>

    <listitem><para>Print all of the meta-attributes of the
    derivation.  This option is only available with
    <option>--xml</option> or <option>--json</option>.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>To show installed packages:

<screen>
$ nix-env -q
bison-1.875c
docbook-xml-4.2
firefox-1.0.4
MPlayer-1.0pre7
ORBit2-2.8.3
<replaceable>&#x2026;</replaceable>
</screen>

</para>

<para>To show available packages:

<screen>
$ nix-env -qa
firefox-1.0.7
GConf-2.4.0.1
MPlayer-1.0pre7
ORBit2-2.8.3
<replaceable>&#x2026;</replaceable>
</screen>

</para>

<para>To show the status of available packages:

<screen>
$ nix-env -qas
-P- firefox-1.0.7   <lineannotation>(not installed but present)</lineannotation>
--S GConf-2.4.0.1   <lineannotation>(not present, but there is a substitute for fast installation)</lineannotation>
--S MPlayer-1.0pre3 <lineannotation>(i.e., this is not the installed MPlayer, even though the version is the same!)</lineannotation>
IP- ORBit2-2.8.3    <lineannotation>(installed and by definition present)</lineannotation>
<replaceable>&#x2026;</replaceable>
</screen>

</para>

<para>To show available packages in the Nix expression <filename>foo.nix</filename>:

<screen>
$ nix-env -f ./foo.nix -qa
foo-1.2.3
</screen>

</para>

<para>To compare installed versions to what&#x2019;s available:

<screen>
$ nix-env -qc
<replaceable>...</replaceable>
acrobat-reader-7.0 - ?      <lineannotation>(package is not available at all)</lineannotation>
autoconf-2.59      = 2.59   <lineannotation>(same version)</lineannotation>
firefox-1.0.4      &lt; 1.0.7  <lineannotation>(a more recent version is available)</lineannotation>
<replaceable>...</replaceable>
</screen>

</para>

<para>To show all packages with &#x201C;<literal>zip</literal>&#x201D; in the name:

<screen>
$ nix-env -qa '.*zip.*'
bzip2-1.0.6
gzip-1.6
zip-3.0
<replaceable>&#x2026;</replaceable>
</screen>

</para>

<para>To show all packages with &#x201C;<literal>firefox</literal>&#x201D; or
&#x201C;<literal>chromium</literal>&#x201D; in the name:

<screen>
$ nix-env -qa '.*(firefox|chromium).*'
chromium-37.0.2062.94
chromium-beta-38.0.2125.24
firefox-32.0.3
firefox-with-plugins-13.0.1
<replaceable>&#x2026;</replaceable>
</screen>

</para>

<para>To show all packages in the latest revision of the Nixpkgs
repository:

<screen>
$ nix-env -f https://github.com/NixOS/nixpkgs/archive/master.tar.gz -qa
</screen>

</para>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--switch-profile</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <group choice="req">
    <arg choice="plain"><option>--switch-profile</option></arg>
    <arg choice="plain"><option>-S</option></arg>
  </group>
  <arg choice="req"><replaceable>path</replaceable></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>This operation makes <replaceable>path</replaceable> the current
profile for the user.  That is, the symlink
<filename>~/.nix-profile</filename> is made to point to
<replaceable>path</replaceable>.</para>

</refsection>

<refsection><title>Examples</title>

<screen>
$ nix-env -S ~/my-profile</screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--list-generations</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <arg choice="plain"><option>--list-generations</option></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>This operation print a list of all the currently existing
generations for the active profile.  These may be switched to using
the <option>--switch-generation</option> operation.  It also prints
the creation date of the generation, and indicates the current
generation.</para>

</refsection>


<refsection><title>Examples</title>

<screen>
$ nix-env --list-generations
  95   2004-02-06 11:48:24
  96   2004-02-06 11:49:01
  97   2004-02-06 16:22:45
  98   2004-02-06 16:24:33   (current)</screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--delete-generations</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <arg choice="plain"><option>--delete-generations</option></arg>
  <arg choice="plain" rep="repeat"><replaceable>generations</replaceable></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>This operation deletes the specified generations of the current
profile.  The generations can be a list of generation numbers, the
special value <literal>old</literal> to delete all non-current
generations,  a value such as <literal>30d</literal> to delete all
generations older than the specified number of days (except for the
generation that was active at that point in time), or a value such as
<literal>+5</literal> to keep the last <literal>5</literal> generations
ignoring any newer than current, e.g., if <literal>30</literal> is the current
generation <literal>+5</literal> will delete generation <literal>25</literal>
and all older generations.
Periodically deleting old generations is important to make garbage collection
effective.</para>

</refsection>

<refsection><title>Examples</title>

<screen>
$ nix-env --delete-generations 3 4 8

$ nix-env --delete-generations +5

$ nix-env --delete-generations 30d

$ nix-env -p other_profile --delete-generations old</screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--switch-generation</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <group choice="req">
    <arg choice="plain"><option>--switch-generation</option></arg>
    <arg choice="plain"><option>-G</option></arg>
  </group>
  <arg choice="req"><replaceable>generation</replaceable></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>This operation makes generation number
<replaceable>generation</replaceable> the current generation of the
active profile.  That is, if the
<filename><replaceable>profile</replaceable></filename> is the path to
the active profile, then the symlink
<filename><replaceable>profile</replaceable></filename> is made to
point to
<filename><replaceable>profile</replaceable>-<replaceable>generation</replaceable>-link</filename>,
which is in turn a symlink to the actual user environment in the Nix
store.</para>

<para>Switching will fail if the specified generation does not exist.</para>

</refsection>


<refsection><title>Examples</title>

<screen>
$ nix-env -G 42
switching from generation 50 to 42</screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--rollback</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-env</command>
  <arg choice="plain"><option>--rollback</option></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>This operation switches to the &#x201C;previous&#x201D; generation of the
active profile, that is, the highest numbered generation lower than
the current generation, if it exists.  It is just a convenience
wrapper around <option>--list-generations</option> and
<option>--switch-generation</option>.</para>

</refsection>


<refsection><title>Examples</title>

<screen>
$ nix-env --rollback
switching from generation 92 to 91

$ nix-env --rollback
error: no generation older than the current (91) exists</screen>

</refsection>

</refsection>


<refsection condition="manpage"><title>Environment variables</title>

<variablelist>

  <varlistentry><term><envar>NIX_PROFILE</envar></term>

    <listitem><para>Location of the Nix profile.  Defaults to the
    target of the symlink <filename>~/.nix-profile</filename>, if it
    exists, or <filename>/nix/var/nix/profiles/default</filename>
    otherwise.</para></listitem>

  </varlistentry>

  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>IN_NIX_SHELL</envar></term>

  <listitem><para>Indicator that tells if the current environment was set up by
  <command>nix-shell</command>.  Since Nix 2.0 the values are
  <literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>

  <listitem>

    <para>A colon-separated list of directories used to look up Nix
    expressions enclosed in angle brackets (i.e.,
    <literal>&lt;<replaceable>path</replaceable>&gt;</literal>).  For
    instance, the value

    <screen>
/home/eelco/Dev:/etc/nixos</screen>

    will cause Nix to look for paths relative to
    <filename>/home/eelco/Dev</filename> and
    <filename>/etc/nixos</filename>, in this order.  It is also
    possible to match paths against a prefix.  For example, the value

    <screen>
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>

    will cause Nix to search for
    <literal>&lt;nixpkgs/<replaceable>path</replaceable>&gt;</literal> in
    <filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
    and
    <filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>

    <para>If a path in the Nix search path starts with
    <literal>http://</literal> or <literal>https://</literal>, it is
    interpreted as the URL of a tarball that will be downloaded and
    unpacked to a temporary location. The tarball must consist of a
    single top-level directory. For example, setting
    <envar>NIX_PATH</envar> to

    <screen>
nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-15.09.tar.gz</screen>

    tells Nix to download the latest revision in the Nixpkgs/NixOS
    15.09 channel.</para>

    <para>A following shorthand can be used to refer to the official channels:

    <screen>nixpkgs=channel:nixos-15.09</screen>
    </para>

    <para>The search path can be extended using the <option linkend="opt-I">-I</option> option, which takes precedence over
    <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>

  <listitem>

  <para>Normally, the Nix store directory (typically
  <filename>/nix/store</filename>) is not allowed to contain any
  symlink components.  This is to prevent &#x201C;impure&#x201D; builds.  Builders
  sometimes &#x201C;canonicalise&#x201D; paths by resolving all symlink components.
  Thus, builds on different machines (with
  <filename>/nix/store</filename> resolving to different locations)
  could yield different results.  This is generally not a problem,
  except when builds are deployed to machines where
  <filename>/nix/store</filename> resolves differently.  If you are
  sure that you&#x2019;re not going to do that, you can set
  <envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>

  <para>Note that if you&#x2019;re symlinking the Nix store so that you can
  put it on another file system than the root file system, on Linux
  you&#x2019;re better off using <literal>bind</literal> mount points, e.g.,

  <screen>
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix</screen>

  Consult the <citerefentry><refentrytitle>mount</refentrytitle>
  <manvolnum>8</manvolnum></citerefentry> manual page for details.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STORE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix store (default
  <filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_DATA_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix static data
  directory (default
  <filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_LOG_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix log directory
  (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STATE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix state directory
  (default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_CONF_DIR</envar></term>

  <listitem><para>Overrides the location of the system Nix configuration
  directory (default
  <filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_USER_CONF_FILES</envar></term>

  <listitem><para>Overrides the location of the user Nix configuration files
  to load from (defaults to the XDG spec locations). The variable is treated
  as a list separated by the <literal>:</literal> token.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>TMPDIR</envar></term>

  <listitem><para>Use the specified directory to store temporary
  files.  In particular, this includes temporary build directories;
  these can take up substantial amounts of disk space.  The default is
  <filename>/tmp</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>

  <listitem><para>This variable should be set to
  <literal>daemon</literal> if you want to use the Nix daemon to
  execute Nix operations. This is necessary in <link linkend="ssec-multi-user">multi-user Nix installations</link>.
  If the Nix daemon's Unix socket is at some non-standard path,
  this variable should be set to <literal>unix://path/to/socket</literal>.
  Otherwise, it should be left unset.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_SHOW_STATS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print some
  evaluation statistics, such as the number of values
  allocated.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_COUNT_CALLS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print how
  often functions were called during Nix expression evaluation.  This
  is useful for profiling your Nix expressions.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>

  <listitem><para>If Nix has been configured to use the Boehm garbage
  collector, this variable sets the initial size of the heap in bytes.
  It defaults to 384 MiB.  Setting it to a low value reduces memory
  consumption, but will increase runtime due to the overhead of
  garbage collection.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-build">

<refmeta>
  <refentrytitle>nix-build</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-build</refname>
  <refpurpose>build a Nix expression</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-build</command>
    <arg xmlns="http://docbook.org/ns/docbook"><option>--help</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--version</option></arg><arg xmlns="http://docbook.org/ns/docbook" rep="repeat">
  <group choice="req">
    <arg choice="plain"><option>--verbose</option></arg>
    <arg choice="plain"><option>-v</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <arg choice="plain"><option>--quiet</option></arg>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--log-format</option>
  <replaceable>format</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--no-build-output</option></arg>
    <arg choice="plain"><option>-Q</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="req">
    <arg choice="plain"><option>--max-jobs</option></arg>
    <arg choice="plain"><option>-j</option></arg>
  </group>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--cores</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--max-silent-time</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--timeout</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--keep-going</option></arg>
    <arg choice="plain"><option>-k</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--keep-failed</option></arg>
    <arg choice="plain"><option>-K</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook"><option>--fallback</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--readonly-mode</option></arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>-I</option>
  <replaceable>path</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--option</option>
  <replaceable>name</replaceable>
  <replaceable>value</replaceable>
</arg><sbr xmlns="http://docbook.org/ns/docbook"/>
    <arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg>
      <group choice="req">
        <arg choice="plain"><option>--attr</option></arg>
        <arg choice="plain"><option>-A</option></arg>
      </group>
      <replaceable>attrPath</replaceable>
    </arg>
    <arg><option>--no-out-link</option></arg>
    <arg><option>--dry-run</option></arg>
    <arg>
      <group choice="req">
        <arg choice="plain"><option>--out-link</option></arg>
        <arg choice="plain"><option>-o</option></arg>
      </group>
      <replaceable>outlink</replaceable>
    </arg>
    <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>The <command>nix-build</command> command builds the derivations
described by the Nix expressions in <replaceable>paths</replaceable>.
If the build succeeds, it places a symlink to the result in the
current directory.  The symlink is called <filename>result</filename>.
If there are multiple Nix expressions, or the Nix expressions evaluate
to multiple derivations, multiple sequentially numbered symlinks are
created (<filename>result</filename>, <filename>result-2</filename>,
and so on).</para>

<para>If no <replaceable>paths</replaceable> are specified, then
<command>nix-build</command> will use <filename>default.nix</filename>
in the current directory, if it exists.</para>

<para>If an element of <replaceable>paths</replaceable> starts with
<literal>http://</literal> or <literal>https://</literal>, it is
interpreted as the URL of a tarball that will be downloaded and
unpacked to a temporary location. The tarball must include a single
top-level directory containing at least a file named
<filename>default.nix</filename>.</para>

<para><command>nix-build</command> is essentially a wrapper around
<link linkend="sec-nix-instantiate"><command>nix-instantiate</command></link>
(to translate a high-level Nix expression to a low-level store
derivation) and <link linkend="rsec-nix-store-realise"><command>nix-store
--realise</command></link> (to build the store derivation).</para>

<warning><para>The result of the build is automatically registered as
a root of the Nix garbage collector.  This root disappears
automatically when the <filename>result</filename> symlink is deleted
or renamed.  So don&#x2019;t rename the symlink.</para></warning>

</refsection>


<refsection><title>Options</title>

<para>All options not listed here are passed to <command>nix-store
--realise</command>, except for <option>--arg</option> and
<option>--attr</option> / <option>-A</option> which are passed to
<command>nix-instantiate</command>.  <phrase condition="manual">See
also <xref linkend="sec-common-options"/>.</phrase></para>

<variablelist>

  <varlistentry><term><option>--no-out-link</option></term>

    <listitem><para>Do not create a symlink to the output path.  Note
    that as a result the output does not become a root of the garbage
    collector, and so might be deleted by <command>nix-store
    --gc</command>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--dry-run</option></term>
   <listitem><para>Show what store paths would be built or downloaded.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="opt-out-link"><term><option>--out-link</option> /
  <option>-o</option> <replaceable>outlink</replaceable></term>

    <listitem><para>Change the name of the symlink to the output path
    created from <filename>result</filename> to
    <replaceable>outlink</replaceable>.</para></listitem>

  </varlistentry>

</variablelist>

<para>The following common options are supported:</para>

<variablelist condition="manpage">
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--help</option></term>

  <listitem><para>Prints out a summary of the command syntax and
  exits.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--version</option></term>

  <listitem><para>Prints out the Nix version number on standard output
  and exits.</para></listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--verbose</option> / <option>-v</option></term>

  <listitem>

  <para>Increases the level of verbosity of diagnostic messages
  printed on standard error.  For each Nix operation, the information
  printed on standard output is well-defined; any diagnostic
  information is printed on standard error, never on standard
  output.</para>

  <para>This option may be specified repeatedly.  Currently, the
  following verbosity levels exist:</para>

  <variablelist>

    <varlistentry><term>0</term>
    <listitem><para>&#x201C;Errors only&#x201D;: only print messages
    explaining why the Nix invocation failed.</para></listitem>
    </varlistentry>

    <varlistentry><term>1</term>
    <listitem><para>&#x201C;Informational&#x201D;: print
    <emphasis>useful</emphasis> messages about what Nix is doing.
    This is the default.</para></listitem>
    </varlistentry>

    <varlistentry><term>2</term>
    <listitem><para>&#x201C;Talkative&#x201D;: print more informational
    messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>3</term>
    <listitem><para>&#x201C;Chatty&#x201D;: print even more
    informational messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>4</term>
    <listitem><para>&#x201C;Debug&#x201D;: print debug
    information.</para></listitem>
    </varlistentry>

    <varlistentry><term>5</term>
    <listitem><para>&#x201C;Vomit&#x201D;: print vast amounts of debug
    information.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--quiet</option></term>

  <listitem>

  <para>Decreases the level of verbosity of diagnostic messages
  printed on standard error.  This is the inverse option to
  <option>-v</option> / <option>--verbose</option>.
  </para>

  <para>This option may be specified repeatedly.  See the previous
  verbosity levels list.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-log-format"><term><option>--log-format</option> <replaceable>format</replaceable></term>

  <listitem>

  <para>This option can be used to change the output of the log format, with
  <replaceable>format</replaceable> being one of:</para>

  <variablelist>

    <varlistentry><term>raw</term>
    <listitem><para>This is the raw format, as outputted by nix-build.</para></listitem>
    </varlistentry>

    <varlistentry><term>internal-json</term>
    <listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar</term>
    <listitem><para>Only display a progress bar during the builds.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar-with-logs</term>
    <listitem><para>Display the raw logs, with the progress bar at the bottom.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-output</option> / <option>-Q</option></term>

  <listitem><para>By default, output written by builders to standard
  output and standard error is echoed to the Nix command's standard
  error.  This option suppresses this behaviour.  Note that the
  builder's standard output and error are always written to a log file
  in
  <filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-jobs"><term><option>--max-jobs</option> / <option>-j</option>
<replaceable>number</replaceable></term>

  <listitem>

  <para>Sets the maximum number of build jobs that Nix will
  perform in parallel to the specified number.  Specify
  <literal>auto</literal> to use the number of CPUs in the system.
  The default is specified by the <link linkend="conf-max-jobs"><literal>max-jobs</literal></link>
  configuration setting, which itself defaults to
  <literal>1</literal>.  A higher value is useful on SMP systems or to
  exploit I/O latency.</para>

  <para> Setting it to <literal>0</literal> disallows building on the local
  machine, which is useful when you want builds to happen only on remote
  builders.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-cores"><term><option>--cores</option></term>

  <listitem><para>Sets the value of the <envar>NIX_BUILD_CORES</envar>
  environment variable in the invocation of builders.  Builders can
  use this variable at their discretion to control the maximum amount
  of parallelism.  For instance, in Nixpkgs, if the derivation
  attribute <varname>enableParallelBuilding</varname> is set to
  <literal>true</literal>, the builder passes the
  <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
  It defaults to the value of the <link linkend="conf-cores"><literal>cores</literal></link>
  configuration setting, if set, or <literal>1</literal> otherwise.
  The value <literal>0</literal> means that the builder should use all
  available CPU cores in the system.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can go without producing any data on standard output or standard
  error.  The default is specified by the <link linkend="conf-max-silent-time"><literal>max-silent-time</literal></link>
  configuration setting.  <literal>0</literal> means no
  time-out.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-timeout"><term><option>--timeout</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can run.  The default is specified by the <link linkend="conf-timeout"><literal>timeout</literal></link>
  configuration setting.  <literal>0</literal> means no
  timeout.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-going</option> / <option>-k</option></term>

  <listitem><para>Keep going in case of failed builds, to the
  greatest extent possible.  That is, if building an input of some
  derivation fails, Nix will still build the other inputs, but not the
  derivation itself.  Without this option, Nix stops if any build
  fails (except for builds of substitutes), possibly killing builds in
  progress (in case of parallel or distributed builds).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-failed</option> / <option>-K</option></term>

  <listitem><para>Specifies that in case of a build failure, the
  temporary directory (usually in <filename>/tmp</filename>) in which
  the build takes place should not be deleted.  The path of the build
  directory is printed as an informational message.
    </para>
  </listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--fallback</option></term>

  <listitem>

  <para>Whenever Nix attempts to build a derivation for which
  substitutes are known for each output path, but realising the output
  paths through the substitutes fails, fall back on building the
  derivation.</para>

  <para>The most common scenario in which this is useful is when we
  have registered substitutes in order to perform binary distribution
  from, say, a network repository.  If the repository is down, the
  realisation of the derivation will fail.  When this option is
  specified, Nix will build the derivation instead.  Thus,
  installation from binaries falls back on installation from source.
  This option is not the default since it is generally not desirable
  for a transient failure in obtaining the substitutes to lead to a
  full build from source (with the related consumption of
  resources).</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-hook</option></term>

  <listitem>

  <para>Disables the build hook mechanism.  This allows to ignore remote
  builders if they are setup on the machine.</para>

  <para>It's useful in cases where the bandwidth between the client and the
  remote builder is too low.  In that case it can take more time to upload the
  sources to the remote builder and fetch back the result than to do the
  computation locally.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--readonly-mode</option></term>

  <listitem><para>When this option is used, no attempt is made to open
  the Nix database.  Most Nix operations do need database access, so
  those operations will fail.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is accepted by
  <command>nix-env</command>, <command>nix-instantiate</command>,
  <command>nix-shell</command> and <command>nix-build</command>.
  When evaluating Nix expressions, the expression evaluator will
  automatically try to call functions that
  it encounters.  It can automatically call functions for which every
  argument has a <link linkend="ss-functions">default value</link>
  (e.g., <literal>{ <replaceable>argName</replaceable> ?
  <replaceable>defaultValue</replaceable> }:
  <replaceable>...</replaceable></literal>).  With
  <option>--arg</option>, you can also call functions that have
  arguments without a default value (or override a default value).
  That is, if the evaluator encounters a function with an argument
  named <replaceable>name</replaceable>, it will call it with value
  <replaceable>value</replaceable>.</para>

  <para>For instance, the top-level <literal>default.nix</literal> in
  Nixpkgs is actually a function:

<programlisting>
{ # The system (e.g., `i686-linux') for which to build the packages.
  system ? builtins.currentSystem
  <replaceable>...</replaceable>
}: <replaceable>...</replaceable></programlisting>

  So if you call this Nix expression (e.g., when you do
  <literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
  the function will be called automatically using the value <link linkend="builtin-currentSystem"><literal>builtins.currentSystem</literal></link>
  for the <literal>system</literal> argument.  You can override this
  using <option>--arg</option>, e.g., <literal>nix-env -i
  <replaceable>pkgname</replaceable> --arg system
  \"i686-freebsd\"</literal>.  (Note that since the argument is a Nix
  string literal, you have to escape the quotes.)</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is like <option>--arg</option>, only the
  value is not a Nix expression but a string.  So instead of
  <literal>--arg system \"i686-linux\"</literal> (the outer quotes are
  to keep the shell happy) you can say <literal>--argstr system
  i686-linux</literal>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
<replaceable>attrPath</replaceable></term>

  <listitem><para>Select an attribute from the top-level Nix
  expression being evaluated.  (<command>nix-env</command>,
  <command>nix-instantiate</command>, <command>nix-build</command> and
  <command>nix-shell</command> only.)  The <emphasis>attribute
  path</emphasis> <replaceable>attrPath</replaceable> is a sequence of
  attribute names separated by dots.  For instance, given a top-level
  Nix expression <replaceable>e</replaceable>, the attribute path
  <literal>xorg.xorgserver</literal> would cause the expression
  <literal><replaceable>e</replaceable>.xorg.xorgserver</literal> to
  be used.  See <link linkend="refsec-nix-env-install-examples"><command>nix-env
  --install</command></link> for some concrete examples.</para>

  <para>In addition to attribute names, you can also specify array
  indices.  For instance, the attribute path
  <literal>foo.3.bar</literal> selects the <literal>bar</literal>
  attribute of the fourth element of the array in the
  <literal>foo</literal> attribute of the top-level
  expression.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--expr</option> / <option>-E</option></term>

  <listitem><para>Interpret the command line arguments as a list of
  Nix expressions to be parsed and evaluated, rather than as a list
  of file names of Nix expressions.
  (<command>nix-instantiate</command>, <command>nix-build</command>
  and <command>nix-shell</command> only.)</para>

  <para>For <command>nix-shell</command>, this option is commonly used
  to give you a shell in which you can build the packages returned
  by the expression. If you want to get a shell which contain the
  <emphasis>built</emphasis> packages ready for use, give your
  expression to the <command>nix-shell -p</command> convenience flag
  instead.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-I"><term><option>-I</option> <replaceable>path</replaceable></term>

  <listitem><para>Add a path to the Nix expression search path.  This
  option may be given multiple times.  See the <envar linkend="env-NIX_PATH">NIX_PATH</envar> environment variable for
  information on the semantics of the Nix search path.  Paths added
  through <option>-I</option> take precedence over
  <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>Set the Nix configuration option
  <replaceable>name</replaceable> to <replaceable>value</replaceable>.
  This overrides settings in the Nix configuration file (see
  <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--repair</option></term>

  <listitem><para>Fix corrupted or missing store paths by
  redownloading or rebuilding them.  Note that this is slow because it
  requires computing a cryptographic hash of the contents of every
  path in the closure of the build.  Also note the warning under
  <command>nix-store --repair-path</command>.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


<refsection><title>Examples</title>

<screen>
$ nix-build '&lt;nixpkgs&gt;' -A firefox
store derivation is /nix/store/qybprl8sz2lc...-firefox-1.5.0.7.drv
/nix/store/d18hyl92g30l...-firefox-1.5.0.7

$ ls -l result
lrwxrwxrwx  <replaceable>...</replaceable>  result -&gt; /nix/store/d18hyl92g30l...-firefox-1.5.0.7

$ ls ./result/bin/
firefox  firefox-config</screen>

<para>If a derivation has multiple outputs,
<command>nix-build</command> will build the default (first) output.
You can also build all outputs:
<screen>
$ nix-build '&lt;nixpkgs&gt;' -A openssl.all
</screen>
This will create a symlink for each output named
<filename>result-<replaceable>outputname</replaceable></filename>.
The suffix is omitted if the output name is <literal>out</literal>.
So if <literal>openssl</literal> has outputs <literal>out</literal>,
<literal>bin</literal> and <literal>man</literal>,
<command>nix-build</command> will create symlinks
<literal>result</literal>, <literal>result-bin</literal> and
<literal>result-man</literal>.  It&#x2019;s also possible to build a specific
output:
<screen>
$ nix-build '&lt;nixpkgs&gt;' -A openssl.man
</screen>
This will create a symlink <literal>result-man</literal>.</para>

<para>Build a Nix expression given on the command line:

<screen>
$ nix-build -E 'with import &lt;nixpkgs&gt; { }; runCommand "foo" { } "echo bar &gt; $out"'
$ cat ./result
bar
</screen>

</para>

<para>Build the GNU Hello package from the latest revision of the
master branch of Nixpkgs:

<screen>
$ nix-build https://github.com/NixOS/nixpkgs/archive/master.tar.gz -A hello
</screen>

</para>

</refsection>


<refsection condition="manpage"><title>Environment variables</title>

<variablelist>
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>IN_NIX_SHELL</envar></term>

  <listitem><para>Indicator that tells if the current environment was set up by
  <command>nix-shell</command>.  Since Nix 2.0 the values are
  <literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>

  <listitem>

    <para>A colon-separated list of directories used to look up Nix
    expressions enclosed in angle brackets (i.e.,
    <literal>&lt;<replaceable>path</replaceable>&gt;</literal>).  For
    instance, the value

    <screen>
/home/eelco/Dev:/etc/nixos</screen>

    will cause Nix to look for paths relative to
    <filename>/home/eelco/Dev</filename> and
    <filename>/etc/nixos</filename>, in this order.  It is also
    possible to match paths against a prefix.  For example, the value

    <screen>
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>

    will cause Nix to search for
    <literal>&lt;nixpkgs/<replaceable>path</replaceable>&gt;</literal> in
    <filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
    and
    <filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>

    <para>If a path in the Nix search path starts with
    <literal>http://</literal> or <literal>https://</literal>, it is
    interpreted as the URL of a tarball that will be downloaded and
    unpacked to a temporary location. The tarball must consist of a
    single top-level directory. For example, setting
    <envar>NIX_PATH</envar> to

    <screen>
nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-15.09.tar.gz</screen>

    tells Nix to download the latest revision in the Nixpkgs/NixOS
    15.09 channel.</para>

    <para>A following shorthand can be used to refer to the official channels:

    <screen>nixpkgs=channel:nixos-15.09</screen>
    </para>

    <para>The search path can be extended using the <option linkend="opt-I">-I</option> option, which takes precedence over
    <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>

  <listitem>

  <para>Normally, the Nix store directory (typically
  <filename>/nix/store</filename>) is not allowed to contain any
  symlink components.  This is to prevent &#x201C;impure&#x201D; builds.  Builders
  sometimes &#x201C;canonicalise&#x201D; paths by resolving all symlink components.
  Thus, builds on different machines (with
  <filename>/nix/store</filename> resolving to different locations)
  could yield different results.  This is generally not a problem,
  except when builds are deployed to machines where
  <filename>/nix/store</filename> resolves differently.  If you are
  sure that you&#x2019;re not going to do that, you can set
  <envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>

  <para>Note that if you&#x2019;re symlinking the Nix store so that you can
  put it on another file system than the root file system, on Linux
  you&#x2019;re better off using <literal>bind</literal> mount points, e.g.,

  <screen>
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix</screen>

  Consult the <citerefentry><refentrytitle>mount</refentrytitle>
  <manvolnum>8</manvolnum></citerefentry> manual page for details.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STORE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix store (default
  <filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_DATA_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix static data
  directory (default
  <filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_LOG_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix log directory
  (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STATE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix state directory
  (default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_CONF_DIR</envar></term>

  <listitem><para>Overrides the location of the system Nix configuration
  directory (default
  <filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_USER_CONF_FILES</envar></term>

  <listitem><para>Overrides the location of the user Nix configuration files
  to load from (defaults to the XDG spec locations). The variable is treated
  as a list separated by the <literal>:</literal> token.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>TMPDIR</envar></term>

  <listitem><para>Use the specified directory to store temporary
  files.  In particular, this includes temporary build directories;
  these can take up substantial amounts of disk space.  The default is
  <filename>/tmp</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>

  <listitem><para>This variable should be set to
  <literal>daemon</literal> if you want to use the Nix daemon to
  execute Nix operations. This is necessary in <link linkend="ssec-multi-user">multi-user Nix installations</link>.
  If the Nix daemon's Unix socket is at some non-standard path,
  this variable should be set to <literal>unix://path/to/socket</literal>.
  Otherwise, it should be left unset.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_SHOW_STATS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print some
  evaluation statistics, such as the number of values
  allocated.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_COUNT_CALLS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print how
  often functions were called during Nix expression evaluation.  This
  is useful for profiling your Nix expressions.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>

  <listitem><para>If Nix has been configured to use the Boehm garbage
  collector, this variable sets the initial size of the heap in bytes.
  It defaults to 384 MiB.  Setting it to a low value reduces memory
  consumption, but will increase runtime due to the overhead of
  garbage collection.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-shell">

<refmeta>
  <refentrytitle>nix-shell</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-shell</refname>
  <refpurpose>start an interactive shell based on a Nix expression</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-shell</command>
    <arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg>
      <group choice="req">
        <arg choice="plain"><option>--attr</option></arg>
        <arg choice="plain"><option>-A</option></arg>
      </group>
      <replaceable>attrPath</replaceable>
    </arg>
    <arg><option>--command</option> <replaceable>cmd</replaceable></arg>
    <arg><option>--run</option> <replaceable>cmd</replaceable></arg>
    <arg><option>--exclude</option> <replaceable>regexp</replaceable></arg>
    <arg><option>--pure</option></arg>
    <arg><option>--keep</option> <replaceable>name</replaceable></arg>
    <group choice="req">
      <arg choice="plain">
        <group choice="req">
          <arg choice="plain"><option>--packages</option></arg>
          <arg choice="plain"><option>-p</option></arg>
        </group>
        <arg choice="plain" rep="repeat">
          <group choice="req">
            <arg choice="plain"><replaceable>packages</replaceable></arg>
            <arg choice="plain"><replaceable>expressions</replaceable></arg>
          </group>
        </arg>
      </arg>
      <arg><replaceable>path</replaceable></arg>
    </group>
  </cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>The command <command>nix-shell</command> will build the
dependencies of the specified derivation, but not the derivation
itself.  It will then start an interactive shell in which all
environment variables defined by the derivation
<replaceable>path</replaceable> have been set to their corresponding
values, and the script <literal>$stdenv/setup</literal> has been
sourced.  This is useful for reproducing the environment of a
derivation for development.</para>

<para>If <replaceable>path</replaceable> is not given,
<command>nix-shell</command> defaults to
<filename>shell.nix</filename> if it exists, and
<filename>default.nix</filename> otherwise.</para>

<para>If <replaceable>path</replaceable> starts with
<literal>http://</literal> or <literal>https://</literal>, it is
interpreted as the URL of a tarball that will be downloaded and
unpacked to a temporary location. The tarball must include a single
top-level directory containing at least a file named
<filename>default.nix</filename>.</para>

<para>If the derivation defines the variable
<varname>shellHook</varname>, it will be evaluated after
<literal>$stdenv/setup</literal> has been sourced.  Since this hook is
not executed by regular Nix builds, it allows you to perform
initialisation specific to <command>nix-shell</command>.  For example,
the derivation attribute

<programlisting>
shellHook =
  ''
    echo "Hello shell"
  '';
</programlisting>

will cause <command>nix-shell</command> to print <literal>Hello shell</literal>.</para>

</refsection>


<refsection><title>Options</title>

<para>All options not listed here are passed to <command>nix-store
--realise</command>, except for <option>--arg</option> and
<option>--attr</option> / <option>-A</option> which are passed to
<command>nix-instantiate</command>.  <phrase condition="manual">See
also <xref linkend="sec-common-options"/>.</phrase></para>

<variablelist>

  <varlistentry><term><option>--command</option> <replaceable>cmd</replaceable></term>

    <listitem><para>In the environment of the derivation, run the
    shell command <replaceable>cmd</replaceable>. This command is
    executed in an interactive shell. (Use <option>--run</option> to
    use a non-interactive shell instead.) However, a call to
    <literal>exit</literal> is implicitly added to the command, so the
    shell will exit after running the command. To prevent this, add
    <literal>return</literal> at the end; e.g. <literal>--command
    "echo Hello; return"</literal> will print <literal>Hello</literal>
    and then drop you into the interactive shell. This can be useful
    for doing any additional initialisation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--run</option> <replaceable>cmd</replaceable></term>

    <listitem><para>Like <option>--command</option>, but executes the
    command in a non-interactive shell. This means (among other
    things) that if you hit Ctrl-C while the command is running, the
    shell exits.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--exclude</option> <replaceable>regexp</replaceable></term>

    <listitem><para>Do not build any dependencies whose store path
    matches the regular expression <replaceable>regexp</replaceable>.
    This option may be specified multiple times.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--pure</option></term>

    <listitem><para>If this flag is specified, the environment is
    almost entirely cleared before the interactive shell is started,
    so you get an environment that more closely corresponds to the
    &#x201C;real&#x201D; Nix build.  A few variables, in particular
    <envar>HOME</envar>, <envar>USER</envar> and
    <envar>DISPLAY</envar>, are retained.  Note that
    <filename>~/.bashrc</filename> and (depending on your Bash
    installation) <filename>/etc/bashrc</filename> are still sourced,
    so any variables set there will affect the interactive
    shell.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--packages</option> / <option>-p</option> <replaceable>packages</replaceable>&#x2026;</term>

    <listitem><para>Set up an environment in which the specified
    packages are present.  The command line arguments are interpreted
    as attribute names inside the Nix Packages collection.  Thus,
    <literal>nix-shell -p libjpeg openjdk</literal> will start a shell
    in which the packages denoted by the attribute names
    <varname>libjpeg</varname> and <varname>openjdk</varname> are
    present.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>-i</option> <replaceable>interpreter</replaceable></term>

    <listitem><para>The chained script interpreter to be invoked by
    <command>nix-shell</command>. Only applicable in
    <literal>#!</literal>-scripts (described <link linkend="ssec-nix-shell-shebang">below</link>).</para>

    </listitem></varlistentry>

  <varlistentry><term><option>--keep</option> <replaceable>name</replaceable></term>

    <listitem><para>When a <option>--pure</option> shell is started,
    keep the listed environment variables.</para></listitem>

  </varlistentry>

</variablelist>

<para>The following common options are supported:</para>

<variablelist condition="manpage">
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--help</option></term>

  <listitem><para>Prints out a summary of the command syntax and
  exits.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--version</option></term>

  <listitem><para>Prints out the Nix version number on standard output
  and exits.</para></listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--verbose</option> / <option>-v</option></term>

  <listitem>

  <para>Increases the level of verbosity of diagnostic messages
  printed on standard error.  For each Nix operation, the information
  printed on standard output is well-defined; any diagnostic
  information is printed on standard error, never on standard
  output.</para>

  <para>This option may be specified repeatedly.  Currently, the
  following verbosity levels exist:</para>

  <variablelist>

    <varlistentry><term>0</term>
    <listitem><para>&#x201C;Errors only&#x201D;: only print messages
    explaining why the Nix invocation failed.</para></listitem>
    </varlistentry>

    <varlistentry><term>1</term>
    <listitem><para>&#x201C;Informational&#x201D;: print
    <emphasis>useful</emphasis> messages about what Nix is doing.
    This is the default.</para></listitem>
    </varlistentry>

    <varlistentry><term>2</term>
    <listitem><para>&#x201C;Talkative&#x201D;: print more informational
    messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>3</term>
    <listitem><para>&#x201C;Chatty&#x201D;: print even more
    informational messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>4</term>
    <listitem><para>&#x201C;Debug&#x201D;: print debug
    information.</para></listitem>
    </varlistentry>

    <varlistentry><term>5</term>
    <listitem><para>&#x201C;Vomit&#x201D;: print vast amounts of debug
    information.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--quiet</option></term>

  <listitem>

  <para>Decreases the level of verbosity of diagnostic messages
  printed on standard error.  This is the inverse option to
  <option>-v</option> / <option>--verbose</option>.
  </para>

  <para>This option may be specified repeatedly.  See the previous
  verbosity levels list.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-log-format"><term><option>--log-format</option> <replaceable>format</replaceable></term>

  <listitem>

  <para>This option can be used to change the output of the log format, with
  <replaceable>format</replaceable> being one of:</para>

  <variablelist>

    <varlistentry><term>raw</term>
    <listitem><para>This is the raw format, as outputted by nix-build.</para></listitem>
    </varlistentry>

    <varlistentry><term>internal-json</term>
    <listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar</term>
    <listitem><para>Only display a progress bar during the builds.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar-with-logs</term>
    <listitem><para>Display the raw logs, with the progress bar at the bottom.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-output</option> / <option>-Q</option></term>

  <listitem><para>By default, output written by builders to standard
  output and standard error is echoed to the Nix command's standard
  error.  This option suppresses this behaviour.  Note that the
  builder's standard output and error are always written to a log file
  in
  <filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-jobs"><term><option>--max-jobs</option> / <option>-j</option>
<replaceable>number</replaceable></term>

  <listitem>

  <para>Sets the maximum number of build jobs that Nix will
  perform in parallel to the specified number.  Specify
  <literal>auto</literal> to use the number of CPUs in the system.
  The default is specified by the <link linkend="conf-max-jobs"><literal>max-jobs</literal></link>
  configuration setting, which itself defaults to
  <literal>1</literal>.  A higher value is useful on SMP systems or to
  exploit I/O latency.</para>

  <para> Setting it to <literal>0</literal> disallows building on the local
  machine, which is useful when you want builds to happen only on remote
  builders.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-cores"><term><option>--cores</option></term>

  <listitem><para>Sets the value of the <envar>NIX_BUILD_CORES</envar>
  environment variable in the invocation of builders.  Builders can
  use this variable at their discretion to control the maximum amount
  of parallelism.  For instance, in Nixpkgs, if the derivation
  attribute <varname>enableParallelBuilding</varname> is set to
  <literal>true</literal>, the builder passes the
  <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
  It defaults to the value of the <link linkend="conf-cores"><literal>cores</literal></link>
  configuration setting, if set, or <literal>1</literal> otherwise.
  The value <literal>0</literal> means that the builder should use all
  available CPU cores in the system.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can go without producing any data on standard output or standard
  error.  The default is specified by the <link linkend="conf-max-silent-time"><literal>max-silent-time</literal></link>
  configuration setting.  <literal>0</literal> means no
  time-out.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-timeout"><term><option>--timeout</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can run.  The default is specified by the <link linkend="conf-timeout"><literal>timeout</literal></link>
  configuration setting.  <literal>0</literal> means no
  timeout.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-going</option> / <option>-k</option></term>

  <listitem><para>Keep going in case of failed builds, to the
  greatest extent possible.  That is, if building an input of some
  derivation fails, Nix will still build the other inputs, but not the
  derivation itself.  Without this option, Nix stops if any build
  fails (except for builds of substitutes), possibly killing builds in
  progress (in case of parallel or distributed builds).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-failed</option> / <option>-K</option></term>

  <listitem><para>Specifies that in case of a build failure, the
  temporary directory (usually in <filename>/tmp</filename>) in which
  the build takes place should not be deleted.  The path of the build
  directory is printed as an informational message.
    </para>
  </listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--fallback</option></term>

  <listitem>

  <para>Whenever Nix attempts to build a derivation for which
  substitutes are known for each output path, but realising the output
  paths through the substitutes fails, fall back on building the
  derivation.</para>

  <para>The most common scenario in which this is useful is when we
  have registered substitutes in order to perform binary distribution
  from, say, a network repository.  If the repository is down, the
  realisation of the derivation will fail.  When this option is
  specified, Nix will build the derivation instead.  Thus,
  installation from binaries falls back on installation from source.
  This option is not the default since it is generally not desirable
  for a transient failure in obtaining the substitutes to lead to a
  full build from source (with the related consumption of
  resources).</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-hook</option></term>

  <listitem>

  <para>Disables the build hook mechanism.  This allows to ignore remote
  builders if they are setup on the machine.</para>

  <para>It's useful in cases where the bandwidth between the client and the
  remote builder is too low.  In that case it can take more time to upload the
  sources to the remote builder and fetch back the result than to do the
  computation locally.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--readonly-mode</option></term>

  <listitem><para>When this option is used, no attempt is made to open
  the Nix database.  Most Nix operations do need database access, so
  those operations will fail.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is accepted by
  <command>nix-env</command>, <command>nix-instantiate</command>,
  <command>nix-shell</command> and <command>nix-build</command>.
  When evaluating Nix expressions, the expression evaluator will
  automatically try to call functions that
  it encounters.  It can automatically call functions for which every
  argument has a <link linkend="ss-functions">default value</link>
  (e.g., <literal>{ <replaceable>argName</replaceable> ?
  <replaceable>defaultValue</replaceable> }:
  <replaceable>...</replaceable></literal>).  With
  <option>--arg</option>, you can also call functions that have
  arguments without a default value (or override a default value).
  That is, if the evaluator encounters a function with an argument
  named <replaceable>name</replaceable>, it will call it with value
  <replaceable>value</replaceable>.</para>

  <para>For instance, the top-level <literal>default.nix</literal> in
  Nixpkgs is actually a function:

<programlisting>
{ # The system (e.g., `i686-linux') for which to build the packages.
  system ? builtins.currentSystem
  <replaceable>...</replaceable>
}: <replaceable>...</replaceable></programlisting>

  So if you call this Nix expression (e.g., when you do
  <literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
  the function will be called automatically using the value <link linkend="builtin-currentSystem"><literal>builtins.currentSystem</literal></link>
  for the <literal>system</literal> argument.  You can override this
  using <option>--arg</option>, e.g., <literal>nix-env -i
  <replaceable>pkgname</replaceable> --arg system
  \"i686-freebsd\"</literal>.  (Note that since the argument is a Nix
  string literal, you have to escape the quotes.)</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is like <option>--arg</option>, only the
  value is not a Nix expression but a string.  So instead of
  <literal>--arg system \"i686-linux\"</literal> (the outer quotes are
  to keep the shell happy) you can say <literal>--argstr system
  i686-linux</literal>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
<replaceable>attrPath</replaceable></term>

  <listitem><para>Select an attribute from the top-level Nix
  expression being evaluated.  (<command>nix-env</command>,
  <command>nix-instantiate</command>, <command>nix-build</command> and
  <command>nix-shell</command> only.)  The <emphasis>attribute
  path</emphasis> <replaceable>attrPath</replaceable> is a sequence of
  attribute names separated by dots.  For instance, given a top-level
  Nix expression <replaceable>e</replaceable>, the attribute path
  <literal>xorg.xorgserver</literal> would cause the expression
  <literal><replaceable>e</replaceable>.xorg.xorgserver</literal> to
  be used.  See <link linkend="refsec-nix-env-install-examples"><command>nix-env
  --install</command></link> for some concrete examples.</para>

  <para>In addition to attribute names, you can also specify array
  indices.  For instance, the attribute path
  <literal>foo.3.bar</literal> selects the <literal>bar</literal>
  attribute of the fourth element of the array in the
  <literal>foo</literal> attribute of the top-level
  expression.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--expr</option> / <option>-E</option></term>

  <listitem><para>Interpret the command line arguments as a list of
  Nix expressions to be parsed and evaluated, rather than as a list
  of file names of Nix expressions.
  (<command>nix-instantiate</command>, <command>nix-build</command>
  and <command>nix-shell</command> only.)</para>

  <para>For <command>nix-shell</command>, this option is commonly used
  to give you a shell in which you can build the packages returned
  by the expression. If you want to get a shell which contain the
  <emphasis>built</emphasis> packages ready for use, give your
  expression to the <command>nix-shell -p</command> convenience flag
  instead.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-I"><term><option>-I</option> <replaceable>path</replaceable></term>

  <listitem><para>Add a path to the Nix expression search path.  This
  option may be given multiple times.  See the <envar linkend="env-NIX_PATH">NIX_PATH</envar> environment variable for
  information on the semantics of the Nix search path.  Paths added
  through <option>-I</option> take precedence over
  <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>Set the Nix configuration option
  <replaceable>name</replaceable> to <replaceable>value</replaceable>.
  This overrides settings in the Nix configuration file (see
  <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--repair</option></term>

  <listitem><para>Fix corrupted or missing store paths by
  redownloading or rebuilding them.  Note that this is slow because it
  requires computing a cryptographic hash of the contents of every
  path in the closure of the build.  Also note the warning under
  <command>nix-store --repair-path</command>.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


<refsection><title>Environment variables</title>

<variablelist>

  <varlistentry><term><envar>NIX_BUILD_SHELL</envar></term>

    <listitem><para>Shell used to start the interactive environment.
    Defaults to the <command>bash</command> found in <envar>PATH</envar>.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>To build the dependencies of the package Pan, and start an
interactive shell in which to build it:

<screen>
$ nix-shell '&lt;nixpkgs&gt;' -A pan
[nix-shell]$ unpackPhase
[nix-shell]$ cd pan-*
[nix-shell]$ configurePhase
[nix-shell]$ buildPhase
[nix-shell]$ ./pan/gui/pan
</screen>

To clear the environment first, and do some additional automatic
initialisation of the interactive shell:

<screen>
$ nix-shell '&lt;nixpkgs&gt;' -A pan --pure \
    --command 'export NIX_DEBUG=1; export NIX_CORES=8; return'
</screen>

Nix expressions can also be given on the command line using the
<command>-E</command> and <command>-p</command> flags.
For instance, the following starts a shell containing the packages
<literal>sqlite</literal> and <literal>libX11</literal>:

<screen>
$ nix-shell -E 'with import &lt;nixpkgs&gt; { }; runCommand "dummy" { buildInputs = [ sqlite xorg.libX11 ]; } ""'
</screen>

A shorter way to do the same is:

<screen>
$ nix-shell -p sqlite xorg.libX11
[nix-shell]$ echo $NIX_LDFLAGS
&#x2026; -L/nix/store/j1zg5v&#x2026;-sqlite-3.8.0.2/lib -L/nix/store/0gmcz9&#x2026;-libX11-1.6.1/lib &#x2026;
</screen>

Note that <command>-p</command> accepts multiple full nix expressions that
are valid in the <literal>buildInputs = [ ... ]</literal> shown above,
not only package names. So the following is also legal:

<screen>
$ nix-shell -p sqlite 'git.override { withManual = false; }'
</screen>

The <command>-p</command> flag looks up Nixpkgs in the Nix search
path. You can override it by passing <option>-I</option> or setting
<envar>NIX_PATH</envar>. For example, the following gives you a shell
containing the Pan package from a specific revision of Nixpkgs:

<screen>
$ nix-shell -p pan -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/8a3eea054838b55aca962c3fbde9c83c102b8bf2.tar.gz

[nix-shell:~]$ pan --version
Pan 0.139
</screen>

</para>

</refsection>


<refsection xml:id="ssec-nix-shell-shebang"><title>Use as a <literal>#!</literal>-interpreter</title>

<para>You can use <command>nix-shell</command> as a script interpreter
to allow scripts written in arbitrary languages to obtain their own
dependencies via Nix. This is done by starting the script with the
following lines:

<programlisting>
#! /usr/bin/env nix-shell
#! nix-shell -i <replaceable>real-interpreter</replaceable> -p <replaceable>packages</replaceable>
</programlisting>

where <replaceable>real-interpreter</replaceable> is the &#x201C;real&#x201D; script
interpreter that will be invoked by <command>nix-shell</command> after
it has obtained the dependencies and initialised the environment, and
<replaceable>packages</replaceable> are the attribute names of the
dependencies in Nixpkgs.</para>

<para>The lines starting with <literal>#! nix-shell</literal> specify
<command>nix-shell</command> options (see above). Note that you cannot
write <literal>#! /usr/bin/env nix-shell -i ...</literal> because
many operating systems only allow one argument in
<literal>#!</literal> lines.</para>

<para>For example, here is a Python script that depends on Python and
the <literal>prettytable</literal> package:

<programlisting>
#! /usr/bin/env nix-shell
#! nix-shell -i python -p python pythonPackages.prettytable

import prettytable

# Print a simple table.
t = prettytable.PrettyTable(["N", "N^2"])
for n in range(1, 10): t.add_row([n, n * n])
print t
</programlisting>

</para>

<para>Similarly, the following is a Perl script that specifies that it
requires Perl and the <literal>HTML::TokeParser::Simple</literal> and
<literal>LWP</literal> packages:

<programlisting>
#! /usr/bin/env nix-shell
#! nix-shell -i perl -p perl perlPackages.HTMLTokeParserSimple perlPackages.LWP

use HTML::TokeParser::Simple;

# Fetch nixos.org and print all hrefs.
my $p = HTML::TokeParser::Simple-&gt;new(url =&gt; 'http://nixos.org/');

while (my $token = $p-&gt;get_tag("a")) {
    my $href = $token-&gt;get_attr("href");
    print "$href\n" if $href;
}
</programlisting>

</para>

<para>Sometimes you need to pass a simple Nix expression to customize
a package like Terraform:

<programlisting><![CDATA[
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p "terraform.withPlugins (plugins: [ plugins.openstack ])"

terraform apply
]]></programlisting>

<note><para>You must use double quotes (<literal>"</literal>) when
passing a simple Nix expression in a nix-shell shebang.</para></note>
</para>

<para>Finally, using the merging of multiple nix-shell shebangs the
following Haskell script uses a specific branch of Nixpkgs/NixOS (the
18.03 stable branch):

<programlisting><![CDATA[
#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages (ps: [ps.HTTP ps.tagsoup])"
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-18.03.tar.gz

import Network.HTTP
import Text.HTML.TagSoup

-- Fetch nixos.org and print all hrefs.
main = do
  resp <- Network.HTTP.simpleHTTP (getRequest "http://nixos.org/")
  body <- getResponseBody resp
  let tags = filter (isTagOpenName "a") $ parseTags body
  let tags' = map (fromAttrib "href") tags
  mapM_ putStrLn $ filter (/= "") tags'
]]></programlisting>

If you want to be even more precise, you can specify a specific
revision of Nixpkgs:

<programlisting>
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/0672315759b3e15e2121365f067c1c8c56bb4722.tar.gz
</programlisting>

</para>

<para>The examples above all used <option>-p</option> to get
dependencies from Nixpkgs. You can also use a Nix expression to build
your own dependencies. For example, the Python example could have been
written as:

<programlisting>
#! /usr/bin/env nix-shell
#! nix-shell deps.nix -i python
</programlisting>

where the file <filename>deps.nix</filename> in the same directory
as the <literal>#!</literal>-script contains:

<programlisting>
with import &lt;nixpkgs&gt; {};

runCommand "dummy" { buildInputs = [ python pythonPackages.prettytable ]; } ""
</programlisting>

</para>

</refsection>


<refsection condition="manpage"><title>Environment variables</title>

<variablelist>
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>IN_NIX_SHELL</envar></term>

  <listitem><para>Indicator that tells if the current environment was set up by
  <command>nix-shell</command>.  Since Nix 2.0 the values are
  <literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>

  <listitem>

    <para>A colon-separated list of directories used to look up Nix
    expressions enclosed in angle brackets (i.e.,
    <literal>&lt;<replaceable>path</replaceable>&gt;</literal>).  For
    instance, the value

    <screen>
/home/eelco/Dev:/etc/nixos</screen>

    will cause Nix to look for paths relative to
    <filename>/home/eelco/Dev</filename> and
    <filename>/etc/nixos</filename>, in this order.  It is also
    possible to match paths against a prefix.  For example, the value

    <screen>
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>

    will cause Nix to search for
    <literal>&lt;nixpkgs/<replaceable>path</replaceable>&gt;</literal> in
    <filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
    and
    <filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>

    <para>If a path in the Nix search path starts with
    <literal>http://</literal> or <literal>https://</literal>, it is
    interpreted as the URL of a tarball that will be downloaded and
    unpacked to a temporary location. The tarball must consist of a
    single top-level directory. For example, setting
    <envar>NIX_PATH</envar> to

    <screen>
nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-15.09.tar.gz</screen>

    tells Nix to download the latest revision in the Nixpkgs/NixOS
    15.09 channel.</para>

    <para>A following shorthand can be used to refer to the official channels:

    <screen>nixpkgs=channel:nixos-15.09</screen>
    </para>

    <para>The search path can be extended using the <option linkend="opt-I">-I</option> option, which takes precedence over
    <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>

  <listitem>

  <para>Normally, the Nix store directory (typically
  <filename>/nix/store</filename>) is not allowed to contain any
  symlink components.  This is to prevent &#x201C;impure&#x201D; builds.  Builders
  sometimes &#x201C;canonicalise&#x201D; paths by resolving all symlink components.
  Thus, builds on different machines (with
  <filename>/nix/store</filename> resolving to different locations)
  could yield different results.  This is generally not a problem,
  except when builds are deployed to machines where
  <filename>/nix/store</filename> resolves differently.  If you are
  sure that you&#x2019;re not going to do that, you can set
  <envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>

  <para>Note that if you&#x2019;re symlinking the Nix store so that you can
  put it on another file system than the root file system, on Linux
  you&#x2019;re better off using <literal>bind</literal> mount points, e.g.,

  <screen>
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix</screen>

  Consult the <citerefentry><refentrytitle>mount</refentrytitle>
  <manvolnum>8</manvolnum></citerefentry> manual page for details.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STORE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix store (default
  <filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_DATA_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix static data
  directory (default
  <filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_LOG_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix log directory
  (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STATE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix state directory
  (default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_CONF_DIR</envar></term>

  <listitem><para>Overrides the location of the system Nix configuration
  directory (default
  <filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_USER_CONF_FILES</envar></term>

  <listitem><para>Overrides the location of the user Nix configuration files
  to load from (defaults to the XDG spec locations). The variable is treated
  as a list separated by the <literal>:</literal> token.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>TMPDIR</envar></term>

  <listitem><para>Use the specified directory to store temporary
  files.  In particular, this includes temporary build directories;
  these can take up substantial amounts of disk space.  The default is
  <filename>/tmp</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>

  <listitem><para>This variable should be set to
  <literal>daemon</literal> if you want to use the Nix daemon to
  execute Nix operations. This is necessary in <link linkend="ssec-multi-user">multi-user Nix installations</link>.
  If the Nix daemon's Unix socket is at some non-standard path,
  this variable should be set to <literal>unix://path/to/socket</literal>.
  Otherwise, it should be left unset.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_SHOW_STATS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print some
  evaluation statistics, such as the number of values
  allocated.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_COUNT_CALLS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print how
  often functions were called during Nix expression evaluation.  This
  is useful for profiling your Nix expressions.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>

  <listitem><para>If Nix has been configured to use the Boehm garbage
  collector, this variable sets the initial size of the heap in bytes.
  It defaults to 384 MiB.  Setting it to a low value reduces memory
  consumption, but will increase runtime due to the overhead of
  garbage collection.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-store">

<refmeta>
  <refentrytitle>nix-store</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-store</refname>
  <refpurpose>manipulate or query the Nix store</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg xmlns="http://docbook.org/ns/docbook"><option>--help</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--version</option></arg><arg xmlns="http://docbook.org/ns/docbook" rep="repeat">
  <group choice="req">
    <arg choice="plain"><option>--verbose</option></arg>
    <arg choice="plain"><option>-v</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <arg choice="plain"><option>--quiet</option></arg>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--log-format</option>
  <replaceable>format</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--no-build-output</option></arg>
    <arg choice="plain"><option>-Q</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="req">
    <arg choice="plain"><option>--max-jobs</option></arg>
    <arg choice="plain"><option>-j</option></arg>
  </group>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--cores</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--max-silent-time</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--timeout</option>
  <replaceable>number</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--keep-going</option></arg>
    <arg choice="plain"><option>-k</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <group choice="plain">
    <arg choice="plain"><option>--keep-failed</option></arg>
    <arg choice="plain"><option>-K</option></arg>
  </group>
</arg><arg xmlns="http://docbook.org/ns/docbook"><option>--fallback</option></arg><arg xmlns="http://docbook.org/ns/docbook"><option>--readonly-mode</option></arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>-I</option>
  <replaceable>path</replaceable>
</arg><arg xmlns="http://docbook.org/ns/docbook">
  <option>--option</option>
  <replaceable>name</replaceable>
  <replaceable>value</replaceable>
</arg><sbr xmlns="http://docbook.org/ns/docbook"/>
    <arg><option>--add-root</option> <replaceable>path</replaceable></arg>
    <arg><option>--indirect</option></arg>
    <arg choice="plain"><replaceable>operation</replaceable></arg>
    <arg rep="repeat"><replaceable>options</replaceable></arg>
    <arg rep="repeat"><replaceable>arguments</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para>The command <command>nix-store</command> performs primitive
operations on the Nix store.  You generally do not need to run this
command manually.</para>

<para><command>nix-store</command> takes exactly one
<emphasis>operation</emphasis> flag which indicates the subcommand to
be performed.  These are documented below.</para>

</refsection>



<!--######################################################################-->

<refsection><title>Common options</title>

<para>This section lists the options that are common to all
operations.  These options are allowed for every subcommand, though
they may not always have an effect.  <phrase condition="manual">See
also <xref linkend="sec-common-options"/> for a list of common
options.</phrase></para>

<variablelist>

  <varlistentry xml:id="opt-add-root"><term><option>--add-root</option> <replaceable>path</replaceable></term>

    <listitem><para>Causes the result of a realisation
    (<option>--realise</option> and <option>--force-realise</option>)
    to be registered as a root of the garbage collector<phrase condition="manual"> (see <xref linkend="ssec-gc-roots"/>)</phrase>.  The root is stored in
    <replaceable>path</replaceable>, which must be inside a directory
    that is scanned for roots by the garbage collector (i.e.,
    typically in a subdirectory of
    <filename>/nix/var/nix/gcroots/</filename>)
    <emphasis>unless</emphasis> the <option>--indirect</option> flag
    is used.</para>

    <para>If there are multiple results, then multiple symlinks will
    be created by sequentially numbering symlinks beyond the first one
    (e.g., <filename>foo</filename>, <filename>foo-2</filename>,
    <filename>foo-3</filename>, and so on).</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--indirect</option></term>

    <listitem>

    <para>In conjunction with <option>--add-root</option>, this option
    allows roots to be stored <emphasis>outside</emphasis> of the GC
    roots directory.  This is useful for commands such as
    <command>nix-build</command> that place a symlink to the build
    result in the current directory; such a build result should not be
    garbage-collected unless the symlink is removed.</para>

    <para>The <option>--indirect</option> flag causes a uniquely named
    symlink to <replaceable>path</replaceable> to be stored in
    <filename>/nix/var/nix/gcroots/auto/</filename>.  For instance,

    <screen>
$ nix-store --add-root /home/eelco/bla/result --indirect -r <replaceable>...</replaceable>

$ ls -l /nix/var/nix/gcroots/auto
lrwxrwxrwx    1 ... 2005-03-13 21:10 dn54lcypm8f8... -&gt; /home/eelco/bla/result

$ ls -l /home/eelco/bla/result
lrwxrwxrwx    1 ... 2005-03-13 21:10 /home/eelco/bla/result -&gt; /nix/store/1r11343n6qd4...-f-spot-0.0.10</screen>

    Thus, when <filename>/home/eelco/bla/result</filename> is removed,
    the GC root in the <filename>auto</filename> directory becomes a
    dangling symlink and will be ignored by the collector.</para>

    <warning><para>Note that it is not possible to move or rename
    indirect GC roots, since the symlink in the
    <filename>auto</filename> directory will still point to the old
    location.</para></warning>

    </listitem>

  </varlistentry>

</variablelist>

<variablelist condition="manpage">
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--help</option></term>

  <listitem><para>Prints out a summary of the command syntax and
  exits.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--version</option></term>

  <listitem><para>Prints out the Nix version number on standard output
  and exits.</para></listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--verbose</option> / <option>-v</option></term>

  <listitem>

  <para>Increases the level of verbosity of diagnostic messages
  printed on standard error.  For each Nix operation, the information
  printed on standard output is well-defined; any diagnostic
  information is printed on standard error, never on standard
  output.</para>

  <para>This option may be specified repeatedly.  Currently, the
  following verbosity levels exist:</para>

  <variablelist>

    <varlistentry><term>0</term>
    <listitem><para>&#x201C;Errors only&#x201D;: only print messages
    explaining why the Nix invocation failed.</para></listitem>
    </varlistentry>

    <varlistentry><term>1</term>
    <listitem><para>&#x201C;Informational&#x201D;: print
    <emphasis>useful</emphasis> messages about what Nix is doing.
    This is the default.</para></listitem>
    </varlistentry>

    <varlistentry><term>2</term>
    <listitem><para>&#x201C;Talkative&#x201D;: print more informational
    messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>3</term>
    <listitem><para>&#x201C;Chatty&#x201D;: print even more
    informational messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>4</term>
    <listitem><para>&#x201C;Debug&#x201D;: print debug
    information.</para></listitem>
    </varlistentry>

    <varlistentry><term>5</term>
    <listitem><para>&#x201C;Vomit&#x201D;: print vast amounts of debug
    information.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--quiet</option></term>

  <listitem>

  <para>Decreases the level of verbosity of diagnostic messages
  printed on standard error.  This is the inverse option to
  <option>-v</option> / <option>--verbose</option>.
  </para>

  <para>This option may be specified repeatedly.  See the previous
  verbosity levels list.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-log-format"><term><option>--log-format</option> <replaceable>format</replaceable></term>

  <listitem>

  <para>This option can be used to change the output of the log format, with
  <replaceable>format</replaceable> being one of:</para>

  <variablelist>

    <varlistentry><term>raw</term>
    <listitem><para>This is the raw format, as outputted by nix-build.</para></listitem>
    </varlistentry>

    <varlistentry><term>internal-json</term>
    <listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar</term>
    <listitem><para>Only display a progress bar during the builds.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar-with-logs</term>
    <listitem><para>Display the raw logs, with the progress bar at the bottom.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-output</option> / <option>-Q</option></term>

  <listitem><para>By default, output written by builders to standard
  output and standard error is echoed to the Nix command's standard
  error.  This option suppresses this behaviour.  Note that the
  builder's standard output and error are always written to a log file
  in
  <filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-jobs"><term><option>--max-jobs</option> / <option>-j</option>
<replaceable>number</replaceable></term>

  <listitem>

  <para>Sets the maximum number of build jobs that Nix will
  perform in parallel to the specified number.  Specify
  <literal>auto</literal> to use the number of CPUs in the system.
  The default is specified by the <link linkend="conf-max-jobs"><literal>max-jobs</literal></link>
  configuration setting, which itself defaults to
  <literal>1</literal>.  A higher value is useful on SMP systems or to
  exploit I/O latency.</para>

  <para> Setting it to <literal>0</literal> disallows building on the local
  machine, which is useful when you want builds to happen only on remote
  builders.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-cores"><term><option>--cores</option></term>

  <listitem><para>Sets the value of the <envar>NIX_BUILD_CORES</envar>
  environment variable in the invocation of builders.  Builders can
  use this variable at their discretion to control the maximum amount
  of parallelism.  For instance, in Nixpkgs, if the derivation
  attribute <varname>enableParallelBuilding</varname> is set to
  <literal>true</literal>, the builder passes the
  <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
  It defaults to the value of the <link linkend="conf-cores"><literal>cores</literal></link>
  configuration setting, if set, or <literal>1</literal> otherwise.
  The value <literal>0</literal> means that the builder should use all
  available CPU cores in the system.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can go without producing any data on standard output or standard
  error.  The default is specified by the <link linkend="conf-max-silent-time"><literal>max-silent-time</literal></link>
  configuration setting.  <literal>0</literal> means no
  time-out.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-timeout"><term><option>--timeout</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can run.  The default is specified by the <link linkend="conf-timeout"><literal>timeout</literal></link>
  configuration setting.  <literal>0</literal> means no
  timeout.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-going</option> / <option>-k</option></term>

  <listitem><para>Keep going in case of failed builds, to the
  greatest extent possible.  That is, if building an input of some
  derivation fails, Nix will still build the other inputs, but not the
  derivation itself.  Without this option, Nix stops if any build
  fails (except for builds of substitutes), possibly killing builds in
  progress (in case of parallel or distributed builds).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-failed</option> / <option>-K</option></term>

  <listitem><para>Specifies that in case of a build failure, the
  temporary directory (usually in <filename>/tmp</filename>) in which
  the build takes place should not be deleted.  The path of the build
  directory is printed as an informational message.
    </para>
  </listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--fallback</option></term>

  <listitem>

  <para>Whenever Nix attempts to build a derivation for which
  substitutes are known for each output path, but realising the output
  paths through the substitutes fails, fall back on building the
  derivation.</para>

  <para>The most common scenario in which this is useful is when we
  have registered substitutes in order to perform binary distribution
  from, say, a network repository.  If the repository is down, the
  realisation of the derivation will fail.  When this option is
  specified, Nix will build the derivation instead.  Thus,
  installation from binaries falls back on installation from source.
  This option is not the default since it is generally not desirable
  for a transient failure in obtaining the substitutes to lead to a
  full build from source (with the related consumption of
  resources).</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-hook</option></term>

  <listitem>

  <para>Disables the build hook mechanism.  This allows to ignore remote
  builders if they are setup on the machine.</para>

  <para>It's useful in cases where the bandwidth between the client and the
  remote builder is too low.  In that case it can take more time to upload the
  sources to the remote builder and fetch back the result than to do the
  computation locally.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--readonly-mode</option></term>

  <listitem><para>When this option is used, no attempt is made to open
  the Nix database.  Most Nix operations do need database access, so
  those operations will fail.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is accepted by
  <command>nix-env</command>, <command>nix-instantiate</command>,
  <command>nix-shell</command> and <command>nix-build</command>.
  When evaluating Nix expressions, the expression evaluator will
  automatically try to call functions that
  it encounters.  It can automatically call functions for which every
  argument has a <link linkend="ss-functions">default value</link>
  (e.g., <literal>{ <replaceable>argName</replaceable> ?
  <replaceable>defaultValue</replaceable> }:
  <replaceable>...</replaceable></literal>).  With
  <option>--arg</option>, you can also call functions that have
  arguments without a default value (or override a default value).
  That is, if the evaluator encounters a function with an argument
  named <replaceable>name</replaceable>, it will call it with value
  <replaceable>value</replaceable>.</para>

  <para>For instance, the top-level <literal>default.nix</literal> in
  Nixpkgs is actually a function:

<programlisting>
{ # The system (e.g., `i686-linux') for which to build the packages.
  system ? builtins.currentSystem
  <replaceable>...</replaceable>
}: <replaceable>...</replaceable></programlisting>

  So if you call this Nix expression (e.g., when you do
  <literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
  the function will be called automatically using the value <link linkend="builtin-currentSystem"><literal>builtins.currentSystem</literal></link>
  for the <literal>system</literal> argument.  You can override this
  using <option>--arg</option>, e.g., <literal>nix-env -i
  <replaceable>pkgname</replaceable> --arg system
  \"i686-freebsd\"</literal>.  (Note that since the argument is a Nix
  string literal, you have to escape the quotes.)</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is like <option>--arg</option>, only the
  value is not a Nix expression but a string.  So instead of
  <literal>--arg system \"i686-linux\"</literal> (the outer quotes are
  to keep the shell happy) you can say <literal>--argstr system
  i686-linux</literal>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
<replaceable>attrPath</replaceable></term>

  <listitem><para>Select an attribute from the top-level Nix
  expression being evaluated.  (<command>nix-env</command>,
  <command>nix-instantiate</command>, <command>nix-build</command> and
  <command>nix-shell</command> only.)  The <emphasis>attribute
  path</emphasis> <replaceable>attrPath</replaceable> is a sequence of
  attribute names separated by dots.  For instance, given a top-level
  Nix expression <replaceable>e</replaceable>, the attribute path
  <literal>xorg.xorgserver</literal> would cause the expression
  <literal><replaceable>e</replaceable>.xorg.xorgserver</literal> to
  be used.  See <link linkend="refsec-nix-env-install-examples"><command>nix-env
  --install</command></link> for some concrete examples.</para>

  <para>In addition to attribute names, you can also specify array
  indices.  For instance, the attribute path
  <literal>foo.3.bar</literal> selects the <literal>bar</literal>
  attribute of the fourth element of the array in the
  <literal>foo</literal> attribute of the top-level
  expression.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--expr</option> / <option>-E</option></term>

  <listitem><para>Interpret the command line arguments as a list of
  Nix expressions to be parsed and evaluated, rather than as a list
  of file names of Nix expressions.
  (<command>nix-instantiate</command>, <command>nix-build</command>
  and <command>nix-shell</command> only.)</para>

  <para>For <command>nix-shell</command>, this option is commonly used
  to give you a shell in which you can build the packages returned
  by the expression. If you want to get a shell which contain the
  <emphasis>built</emphasis> packages ready for use, give your
  expression to the <command>nix-shell -p</command> convenience flag
  instead.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-I"><term><option>-I</option> <replaceable>path</replaceable></term>

  <listitem><para>Add a path to the Nix expression search path.  This
  option may be given multiple times.  See the <envar linkend="env-NIX_PATH">NIX_PATH</envar> environment variable for
  information on the semantics of the Nix search path.  Paths added
  through <option>-I</option> take precedence over
  <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>Set the Nix configuration option
  <replaceable>name</replaceable> to <replaceable>value</replaceable>.
  This overrides settings in the Nix configuration file (see
  <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--repair</option></term>

  <listitem><para>Fix corrupted or missing store paths by
  redownloading or rebuilding them.  Note that this is slow because it
  requires computing a cryptographic hash of the contents of every
  path in the closure of the build.  Also note the warning under
  <command>nix-store --repair-path</command>.</para></listitem>

</varlistentry>
</variablelist>

</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-store-realise"><title>Operation <option>--realise</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <group choice="req">
    <arg choice="plain"><option>--realise</option></arg>
    <arg choice="plain"><option>-r</option></arg>
  </group>
  <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
  <arg><option>--dry-run</option></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>The operation <option>--realise</option> essentially &#x201C;builds&#x201D;
the specified store paths.  Realisation is a somewhat overloaded term:

<itemizedlist>

  <listitem><para>If the store path is a
  <emphasis>derivation</emphasis>, realisation ensures that the output
  paths of the derivation are <link linkend="gloss-validity">valid</link> (i.e., the output path and its
  closure exist in the file system).  This can be done in several
  ways.  First, it is possible that the outputs are already valid, in
  which case we are done immediately.  Otherwise, there may be <link linkend="gloss-substitute">substitutes</link> that produce the
  outputs (e.g., by downloading them).  Finally, the outputs can be
  produced by performing the build action described by the
  derivation.</para></listitem>

  <listitem><para>If the store path is not a derivation, realisation
  ensures that the specified path is valid (i.e., it and its closure
  exist in the file system).  If the path is already valid, we are
  done immediately.  Otherwise, the path and any missing paths in its
  closure may be produced through substitutes.  If there are no
  (successful) subsitutes, realisation fails.</para></listitem>

</itemizedlist>

</para>

<para>The output path of each derivation is printed on standard
output.  (For non-derivations argument, the argument itself is
printed.)</para>

<para>The following flags are available:</para>

<variablelist>

  <varlistentry><term><option>--dry-run</option></term>

    <listitem><para>Print on standard error a description of what
    packages would be built or downloaded, without actually performing
    the operation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--ignore-unknown</option></term>

    <listitem><para>If a non-derivation path does not have a
    substitute, then silently ignore it.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--check</option></term>

    <listitem><para>This option allows you to check whether a
    derivation is deterministic. It rebuilds the specified derivation
    and checks whether the result is bitwise-identical with the
    existing outputs, printing an error if that&#x2019;s not the case. The
    outputs of the specified derivation must already exist. When used
    with <option>-K</option>, if an output path is not identical to
    the corresponding output from the previous build, the new output
    path is left in
    <filename>/nix/store/<replaceable>name</replaceable>.check.</filename></para>

    <para>See also the <option>build-repeat</option> configuration
    option, which repeats a derivation a number of times and prevents
    its outputs from being registered as &#x201C;valid&#x201D; in the Nix store
    unless they are identical.</para></listitem>

  </varlistentry>

</variablelist>

<para>Special exit codes:</para>

<variablelist>

  <varlistentry><term><literal>100</literal></term>
    <listitem><para>Generic build failure, the builder process
    returned with a non-zero exit code.</para></listitem>
  </varlistentry>

  <varlistentry><term><literal>101</literal></term>
    <listitem><para>Build timeout, the build was aborted because it
    did not complete within the specified <link linkend="conf-timeout"><literal>timeout</literal></link>.
    </para></listitem>
  </varlistentry>

  <varlistentry><term><literal>102</literal></term>
    <listitem><para>Hash mismatch, the build output was rejected
    because it does not match the specified <link linkend="fixed-output-drvs"><varname>outputHash</varname></link>.
    </para></listitem>
  </varlistentry>

  <varlistentry><term><literal>104</literal></term>
    <listitem><para>Not deterministic, the build succeeded in check
    mode but the resulting output is not binary reproducable.</para>
    </listitem>
  </varlistentry>

</variablelist>

<para>With the <option>--keep-going</option> flag it's possible for
multiple failures to occur, in this case the 1xx status codes are or combined
using binary or. <screen>
1100100
   ^^^^
   |||`- timeout
   ||`-- output hash mismatch
   |`--- build failure
   `---- not deterministic
</screen></para>

</refsection>


<refsection><title>Examples</title>

<para>This operation is typically used to build store derivations
produced by <link linkend="sec-nix-instantiate"><command>nix-instantiate</command></link>:

<screen>
$ nix-store -r $(nix-instantiate ./test.nix)
/nix/store/31axcgrlbfsxzmfff1gyj1bf62hvkby2-aterm-2.3.1</screen>

This is essentially what <link linkend="sec-nix-build"><command>nix-build</command></link> does.</para>

<para>To test whether a previously-built derivation is deterministic:

<screen>
$ nix-build '&lt;nixpkgs&gt;' -A hello --check -K
</screen>

</para>

</refsection>


</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-store-serve"><title>Operation <option>--serve</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <arg choice="plain"><option>--serve</option></arg>
  <arg><option>--write</option></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>The operation <option>--serve</option> provides access to
the Nix store over stdin and stdout, and is intended to be used
as a means of providing Nix store access to a restricted ssh user.
</para>

<para>The following flags are available:</para>

<variablelist>

  <varlistentry><term><option>--write</option></term>

    <listitem><para>Allow the connected client to request the realization
    of derivations. In effect, this can be used to make the host act
    as a remote builder.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>To turn a host into a build server, the
<filename>authorized_keys</filename> file can be used to provide build
access to a given SSH public key:

<screen>
$ cat &lt;&lt;EOF &gt;&gt;/root/.ssh/authorized_keys
command="nice -n20 nix-store --serve --write" ssh-rsa AAAAB3NzaC1yc2EAAAA...
EOF
</screen>

</para>

</refsection>


</refsection>



<!--######################################################################-->

<refsection xml:id="rsec-nix-store-gc"><title>Operation <option>--gc</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <arg choice="plain"><option>--gc</option></arg>
  <group>
    <arg choice="plain"><option>--print-roots</option></arg>
    <arg choice="plain"><option>--print-live</option></arg>
    <arg choice="plain"><option>--print-dead</option></arg>
  </group>
  <arg><option>--max-freed</option> <replaceable>bytes</replaceable></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>Without additional flags, the operation <option>--gc</option>
performs a garbage collection on the Nix store.  That is, all paths in
the Nix store not reachable via file system references from a set of
&#x201C;roots&#x201D;, are deleted.</para>

<para>The following suboperations may be specified:</para>

<variablelist>

  <varlistentry><term><option>--print-roots</option></term>

    <listitem><para>This operation prints on standard output the set
    of roots used by the garbage collector.  What constitutes a root
    is described in <xref linkend="ssec-gc-roots"/>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--print-live</option></term>

    <listitem><para>This operation prints on standard output the set
    of &#x201C;live&#x201D; store paths, which are all the store paths reachable
    from the roots.  Live paths should never be deleted, since that
    would break consistency &#x2014; it would become possible that
    applications are installed that reference things that are no
    longer present in the store.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--print-dead</option></term>

    <listitem><para>This operation prints out on standard output the
    set of &#x201C;dead&#x201D; store paths, which is just the opposite of the set
    of live paths: any path in the store that is not live (with
    respect to the roots) is dead.</para></listitem>

  </varlistentry>

</variablelist>

<para>By default, all unreachable paths are deleted.  The following
options control what gets deleted and in what order:

<variablelist>

  <varlistentry><term><option>--max-freed</option> <replaceable>bytes</replaceable></term>

    <listitem><para>Keep deleting paths until at least
    <replaceable>bytes</replaceable> bytes have been deleted, then
    stop.  The argument <replaceable>bytes</replaceable> can be
    followed by the multiplicative suffix <literal>K</literal>,
    <literal>M</literal>, <literal>G</literal> or
    <literal>T</literal>, denoting KiB, MiB, GiB or TiB
    units.</para></listitem>

  </varlistentry>

</variablelist>

</para>

<para>The behaviour of the collector is also influenced by the <link linkend="conf-keep-outputs"><literal>keep-outputs</literal></link>
and <link linkend="conf-keep-derivations"><literal>keep-derivations</literal></link>
variables in the Nix configuration file.</para>

<para>By default, the collector prints the total number of freed bytes
when it finishes (or when it is interrupted). With
<option>--print-dead</option>, it prints the number of bytes that would
be freed.</para>

</refsection>


<refsection><title>Examples</title>

<para>To delete all unreachable paths, just do:

<screen>
$ nix-store --gc
deleting `/nix/store/kq82idx6g0nyzsp2s14gfsc38npai7lf-cairo-1.0.4.tar.gz.drv'
<replaceable>...</replaceable>
8825586 bytes freed (8.42 MiB)</screen>

</para>

<para>To delete at least 100 MiBs of unreachable paths:

<screen>
$ nix-store --gc --max-freed $((100 * 1024 * 1024))</screen>

</para>

</refsection>


</refsection>



<!--######################################################################-->

<refsection><title>Operation <option>--delete</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <arg choice="plain"><option>--delete</option></arg>
  <arg><option>--ignore-liveness</option></arg>
  <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>The operation <option>--delete</option> deletes the store paths
<replaceable>paths</replaceable> from the Nix store, but only if it is
safe to do so; that is, when the path is not reachable from a root of
the garbage collector.  This means that you can only delete paths that
would also be deleted by <literal>nix-store --gc</literal>.  Thus,
<literal>--delete</literal> is a more targeted version of
<literal>--gc</literal>.</para>

<para>With the option <option>--ignore-liveness</option>, reachability
from the roots is ignored.  However, the path still won&#x2019;t be deleted
if there are other paths in the store that refer to it (i.e., depend
on it).</para>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store --delete /nix/store/zq0h41l75vlb4z45kzgjjmsjxvcv1qk7-mesa-6.4
0 bytes freed (0.00 MiB)
error: cannot delete path `/nix/store/zq0h41l75vlb4z45kzgjjmsjxvcv1qk7-mesa-6.4' since it is still alive</screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection xml:id="refsec-nix-store-query"><title>Operation <option>--query</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <group choice="req">
    <arg choice="plain"><option>--query</option></arg>
    <arg choice="plain"><option>-q</option></arg>
  </group>
  <group choice="req">
    <arg choice="plain"><option>--outputs</option></arg>
    <arg choice="plain"><option>--requisites</option></arg>
    <arg choice="plain"><option>-R</option></arg>
    <arg choice="plain"><option>--references</option></arg>
    <arg choice="plain"><option>--referrers</option></arg>
    <arg choice="plain"><option>--referrers-closure</option></arg>
    <arg choice="plain"><option>--deriver</option></arg>
    <arg choice="plain"><option>-d</option></arg>
    <arg choice="plain"><option>--graph</option></arg>
    <arg choice="plain"><option>--tree</option></arg>
    <arg choice="plain"><option>--binding</option> <replaceable>name</replaceable></arg>
    <arg choice="plain"><option>-b</option> <replaceable>name</replaceable></arg>
    <arg choice="plain"><option>--hash</option></arg>
    <arg choice="plain"><option>--size</option></arg>
    <arg choice="plain"><option>--roots</option></arg>
  </group>
  <arg><option>--use-output</option></arg>
  <arg><option>-u</option></arg>
  <arg><option>--force-realise</option></arg>
  <arg><option>-f</option></arg>
  <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
</cmdsynopsis>

</refsection>


<refsection><title>Description</title>

<para>The operation <option>--query</option> displays various bits of
information about the store paths .  The queries are described below.  At
most one query can be specified.  The default query is
<option>--outputs</option>.</para>

<para>The paths <replaceable>paths</replaceable> may also be symlinks
from outside of the Nix store, to the Nix store.  In that case, the
query is applied to the target of the symlink.</para>


</refsection>


<refsection><title>Common query options</title>

<variablelist>

  <varlistentry><term><option>--use-output</option></term>
    <term><option>-u</option></term>

    <listitem><para>For each argument to the query that is a store
    derivation, apply the query to the output path of the derivation
    instead.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--force-realise</option></term>
    <term><option>-f</option></term>

    <listitem><para>Realise each argument to the query first (see
    <link linkend="rsec-nix-store-realise"><command>nix-store
    --realise</command></link>).</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection xml:id="nixref-queries"><title>Queries</title>

<variablelist>

  <varlistentry><term><option>--outputs</option></term>

    <listitem><para>Prints out the <link linkend="gloss-output-path">output paths</link> of the store
    derivations <replaceable>paths</replaceable>.  These are the paths
    that will be produced when the derivation is
    built.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--requisites</option></term>
    <term><option>-R</option></term>

    <listitem><para>Prints out the <link linkend="gloss-closure">closure</link> of the store path
    <replaceable>paths</replaceable>.</para>

    <para>This query has one option:</para>

    <variablelist>

      <varlistentry><term><option>--include-outputs</option></term>

        <listitem><para>Also include the output path of store
        derivations, and their closures.</para></listitem>

      </varlistentry>

    </variablelist>

    <para>This query can be used to implement various kinds of
    deployment.  A <emphasis>source deployment</emphasis> is obtained
    by distributing the closure of a store derivation.  A
    <emphasis>binary deployment</emphasis> is obtained by distributing
    the closure of an output path.  A <emphasis>cache
    deployment</emphasis> (combined source/binary deployment,
    including binaries of build-time-only dependencies) is obtained by
    distributing the closure of a store derivation and specifying the
    option <option>--include-outputs</option>.</para>

    </listitem>

  </varlistentry>

  <varlistentry><term><option>--references</option></term>

    <listitem><para>Prints the set of <link linkend="gloss-reference">references</link> of the store paths
    <replaceable>paths</replaceable>, that is, their immediate
    dependencies.  (For <emphasis>all</emphasis> dependencies, use
    <option>--requisites</option>.)</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--referrers</option></term>

    <listitem><para>Prints the set of <emphasis>referrers</emphasis> of
    the store paths <replaceable>paths</replaceable>, that is, the
    store paths currently existing in the Nix store that refer to one
    of <replaceable>paths</replaceable>.  Note that contrary to the
    references, the set of referrers is not constant; it can change as
    store paths are added or removed.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--referrers-closure</option></term>

    <listitem><para>Prints the closure of the set of store paths
    <replaceable>paths</replaceable> under the referrers relation; that
    is, all store paths that directly or indirectly refer to one of
    <replaceable>paths</replaceable>.  These are all the path currently
    in the Nix store that are dependent on
    <replaceable>paths</replaceable>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--deriver</option></term>
    <term><option>-d</option></term>

    <listitem><para>Prints the <link linkend="gloss-deriver">deriver</link> of the store paths
    <replaceable>paths</replaceable>.  If the path has no deriver
    (e.g., if it is a source file), or if the deriver is not known
    (e.g., in the case of a binary-only deployment), the string
    <literal>unknown-deriver</literal> is printed.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--graph</option></term>

    <listitem><para>Prints the references graph of the store paths
    <replaceable>paths</replaceable> in the format of the
    <command>dot</command> tool of AT&amp;T's <link xlink:href="http://www.graphviz.org/">Graphviz package</link>.
    This can be used to visualise dependency graphs.  To obtain a
    build-time dependency graph, apply this to a store derivation.  To
    obtain a runtime dependency graph, apply it to an output
    path.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--tree</option></term>

    <listitem><para>Prints the references graph of the store paths
    <replaceable>paths</replaceable> as a nested ASCII tree.
    References are ordered by descending closure size; this tends to
    flatten the tree, making it more readable.  The query only
    recurses into a store path when it is first encountered; this
    prevents a blowup of the tree representation of the
    graph.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--graphml</option></term>

    <listitem><para>Prints the references graph of the store paths
    <replaceable>paths</replaceable> in the <link xlink:href="http://graphml.graphdrawing.org/">GraphML</link> file format.
    This can be used to visualise dependency graphs. To obtain a
    build-time dependency graph, apply this to a store derivation. To
    obtain a runtime dependency graph, apply it to an output
    path.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--binding</option> <replaceable>name</replaceable></term>
    <term><option>-b</option> <replaceable>name</replaceable></term>

    <listitem><para>Prints the value of the attribute
    <replaceable>name</replaceable> (i.e., environment variable) of
    the store derivations <replaceable>paths</replaceable>.  It is an
    error for a derivation to not have the specified
    attribute.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--hash</option></term>

    <listitem><para>Prints the SHA-256 hash of the contents of the
    store paths <replaceable>paths</replaceable> (that is, the hash of
    the output of <command>nix-store --dump</command> on the given
    paths).  Since the hash is stored in the Nix database, this is a
    fast operation.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--size</option></term>

    <listitem><para>Prints the size in bytes of the contents of the
    store paths <replaceable>paths</replaceable> &#x2014; to be precise, the
    size of the output of <command>nix-store --dump</command> on the
    given paths.  Note that the actual disk space required by the
    store paths may be higher, especially on filesystems with large
    cluster sizes.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--roots</option></term>

    <listitem><para>Prints the garbage collector roots that point,
    directly or indirectly, at the store paths
    <replaceable>paths</replaceable>.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>Print the closure (runtime dependencies) of the
<command>svn</command> program in the current user environment:

<screen>
$ nix-store -qR $(which svn)
/nix/store/5mbglq5ldqld8sj57273aljwkfvj22mc-subversion-1.1.4
/nix/store/9lz9yc6zgmc0vlqmn2ipcpkjlmbi51vv-glibc-2.3.4
<replaceable>...</replaceable></screen>

</para>

<para>Print the build-time dependencies of <command>svn</command>:

<screen>
$ nix-store -qR $(nix-store -qd $(which svn))
/nix/store/02iizgn86m42q905rddvg4ja975bk2i4-grep-2.5.1.tar.bz2.drv
/nix/store/07a2bzxmzwz5hp58nf03pahrv2ygwgs3-gcc-wrapper.sh
/nix/store/0ma7c9wsbaxahwwl04gbw3fcd806ski4-glibc-2.3.4.drv
<replaceable>... lots of other paths ...</replaceable></screen>

The difference with the previous example is that we ask the closure of
the derivation (<option>-qd</option>), not the closure of the output
path that contains <command>svn</command>.</para>

<para>Show the build-time dependencies as a tree:

<screen>
$ nix-store -q --tree $(nix-store -qd $(which svn))
/nix/store/7i5082kfb6yjbqdbiwdhhza0am2xvh6c-subversion-1.1.4.drv
+---/nix/store/d8afh10z72n8l1cr5w42366abiblgn54-builder.sh
+---/nix/store/fmzxmpjx2lh849ph0l36snfj9zdibw67-bash-3.0.drv
|   +---/nix/store/570hmhmx3v57605cqg9yfvvyh0nnb8k8-bash
|   +---/nix/store/p3srsbd8dx44v2pg6nbnszab5mcwx03v-builder.sh
<replaceable>...</replaceable></screen>

</para>

<para>Show all paths that depend on the same OpenSSL library as
<command>svn</command>:

<screen>
$ nix-store -q --referrers $(nix-store -q --binding openssl $(nix-store -qd $(which svn)))
/nix/store/23ny9l9wixx21632y2wi4p585qhva1q8-sylpheed-1.0.0
/nix/store/5mbglq5ldqld8sj57273aljwkfvj22mc-subversion-1.1.4
/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3
/nix/store/l51240xqsgg8a7yrbqdx1rfzyv6l26fx-lynx-2.8.5</screen>

</para>

<para>Show all paths that directly or indirectly depend on the Glibc
(C library) used by <command>svn</command>:

<screen>
$ nix-store -q --referrers-closure $(ldd $(which svn) | grep /libc.so | awk '{print $3}')
/nix/store/034a6h4vpz9kds5r6kzb9lhh81mscw43-libgnomeprintui-2.8.2
/nix/store/15l3yi0d45prm7a82pcrknxdh6nzmxza-gawk-3.1.4
<replaceable>...</replaceable></screen>

Note that <command>ldd</command> is a command that prints out the
dynamic libraries used by an ELF executable.</para>

<para>Make a picture of the runtime dependency graph of the current
user environment:

<screen>
$ nix-store -q --graph ~/.nix-profile | dot -Tps &gt; graph.ps
$ gv graph.ps</screen>

</para>

<para>Show every garbage collector root that points to a store path
that depends on <command>svn</command>:

<screen>
$ nix-store -q --roots $(which svn)
/nix/var/nix/profiles/default-81-link
/nix/var/nix/profiles/default-82-link
/nix/var/nix/profiles/per-user/eelco/profile-97-link
</screen>

</para>

</refsection>


</refsection>



<!--######################################################################-->

<!--
<refsection xml:id="rsec-nix-store-reg-val"><title>Operation <option>-XXX-register-validity</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <arg choice='plain'><option>-XXX-register-validity</option></arg>
</cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>TODO</para>

</refsection>

</refsection>
-->



<!--######################################################################-->

<refsection><title>Operation <option>--add</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <arg choice="plain"><option>--add</option></arg>
  <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>The operation <option>--add</option> adds the specified paths to
the Nix store.  It prints the resulting paths in the Nix store on
standard output.</para>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store --add ./foo.c
/nix/store/m7lrha58ph6rcnv109yzx1nk1cj7k7zf-foo.c</screen>

</refsection>

</refsection>

<!--######################################################################-->

<refsection><title>Operation <option>--add-fixed</option></title>

<refsection><title>Synopsis</title>

<cmdsynopsis>
  <command>nix-store</command>
  <arg><option>--recursive</option></arg>
  <arg choice="plain"><option>--add-fixed</option></arg>
  <arg choice="plain"><replaceable>algorithm</replaceable></arg>
  <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
</cmdsynopsis>

</refsection>

<refsection><title>Description</title>

<para>The operation <option>--add-fixed</option> adds the specified paths to
the Nix store.  Unlike <option>--add</option> paths are registered using the
specified hashing algorithm, resulting in the same output path as a fixed-output
derivation.  This can be used for sources that are not available from a public
url or broke since the download expression was written.
</para>

<para>This operation has the following options:

<variablelist>

  <varlistentry><term><option>--recursive</option></term>

    <listitem><para>
      Use recursive instead of flat hashing mode, used when adding directories
      to the store.
    </para></listitem>

  </varlistentry>

</variablelist>

</para>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store --add-fixed sha256 ./hello-2.10.tar.gz
/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz</screen>

</refsection>

</refsection>



<!--######################################################################-->

<refsection xml:id="refsec-nix-store-verify"><title>Operation <option>--verify</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--verify</option></arg>
    <arg><option>--check-contents</option></arg>
    <arg><option>--repair</option></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--verify</option> verifies the internal
consistency of the Nix database, and the consistency between the Nix
database and the Nix store.  Any inconsistencies encountered are
automatically repaired.  Inconsistencies are generally the result of
the Nix store or database being modified by non-Nix tools, or of bugs
in Nix itself.</para>

<para>This operation has the following options:

<variablelist>

  <varlistentry><term><option>--check-contents</option></term>

    <listitem><para>Checks that the contents of every valid store path
    has not been altered by computing a SHA-256 hash of the contents
    and comparing it with the hash stored in the Nix database at build
    time.  Paths that have been modified are printed out.  For large
    stores, <option>--check-contents</option> is obviously quite
    slow.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--repair</option></term>

    <listitem><para>If any valid path is missing from the store, or
    (if <option>--check-contents</option> is given) the contents of a
    valid path has been modified, then try to repair the path by
    redownloading it.  See <command>nix-store --repair-path</command>
    for details.</para></listitem>

  </varlistentry>

</variablelist>

</para>

</refsection>


</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--verify-path</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--verify-path</option></arg>
    <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--verify-path</option> compares the
contents of the given store paths to their cryptographic hashes stored
in Nix&#x2019;s database.  For every changed path, it prints a warning
message.  The exit status is 0 if no path has changed, and 1
otherwise.</para>

</refsection>

<refsection><title>Example</title>

<para>To verify the integrity of the <command>svn</command> command and all its dependencies:

<screen>
$ nix-store --verify-path $(nix-store -qR $(which svn))
</screen>

</para>

</refsection>

</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--repair-path</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--repair-path</option></arg>
    <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--repair-path</option> attempts to
&#x201C;repair&#x201D; the specified paths by redownloading them using the available
substituters.  If no substitutes are available, then repair is not
possible.</para>

<warning><para>During repair, there is a very small time window during
which the old path (if it exists) is moved out of the way and replaced
with the new path.  If repair is interrupted in between, then the
system may be left in a broken state (e.g., if the path contains a
critical system component like the GNU C Library).</para></warning>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store --verify-path /nix/store/dj7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13
path `/nix/store/dj7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13' was modified!
  expected hash `2db57715ae90b7e31ff1f2ecb8c12ec1cc43da920efcbe3b22763f36a1861588',
  got `481c5aa5483ebc97c20457bb8bca24deea56550d3985cda0027f67fe54b808e4'

$ nix-store --repair-path /nix/store/dj7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13
fetching path `/nix/store/d7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13'...
&#x2026;
</screen>

</refsection>

</refsection>


<!--######################################################################-->

<refsection xml:id="refsec-nix-store-dump"><title>Operation <option>--dump</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--dump</option></arg>
    <arg choice="plain"><replaceable>path</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--dump</option> produces a NAR (Nix
ARchive) file containing the contents of the file system tree rooted
at <replaceable>path</replaceable>.  The archive is written to
standard output.</para>

<para>A NAR archive is like a TAR or Zip archive, but it contains only
the information that Nix considers important.  For instance,
timestamps are elided because all files in the Nix store have their
timestamp set to 0 anyway.  Likewise, all permissions are left out
except for the execute bit, because all files in the Nix store have
444 or 555 permission.</para>

<para>Also, a NAR archive is <emphasis>canonical</emphasis>, meaning
that &#x201C;equal&#x201D; paths always produce the same NAR archive.  For instance,
directory entries are always sorted so that the actual on-disk order
doesn&#x2019;t influence the result.  This means that the cryptographic hash
of a NAR dump of a path is usable as a fingerprint of the contents of
the path.  Indeed, the hashes of store paths stored in Nix&#x2019;s database
(see <link linkend="refsec-nix-store-query"><literal>nix-store -q
--hash</literal></link>) are SHA-256 hashes of the NAR dump of each
store path.</para>

<para>NAR archives support filenames of unlimited length and 64-bit
file sizes.  They can contain regular files, directories, and symbolic
links, but not other types of files (such as device nodes).</para>

<para>A Nix archive can be unpacked using <literal>nix-store
--restore</literal>.</para>

</refsection>


</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--restore</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--restore</option></arg>
    <arg choice="plain"><replaceable>path</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--restore</option> unpacks a NAR archive
to <replaceable>path</replaceable>, which must not already exist.  The
archive is read from standard input.</para>

</refsection>


</refsection>


<!--######################################################################-->

<refsection xml:id="refsec-nix-store-export"><title>Operation <option>--export</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--export</option></arg>
    <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--export</option> writes a serialisation
of the specified store paths to standard output in a format that can
be imported into another Nix store with <command linkend="refsec-nix-store-import">nix-store --import</command>.  This
is like <command linkend="refsec-nix-store-dump">nix-store
--dump</command>, except that the NAR archive produced by that command
doesn&#x2019;t contain the necessary meta-information to allow it to be
imported into another Nix store (namely, the set of references of the
path).</para>

<para>This command does not produce a <emphasis>closure</emphasis> of
the specified paths, so if a store path references other store paths
that are missing in the target Nix store, the import will fail.  To
copy a whole closure, do something like:

<screen>
$ nix-store --export $(nix-store -qR <replaceable>paths</replaceable>) &gt; out</screen>

To import the whole closure again, run:

<screen>
$ nix-store --import &lt; out</screen>

</para>

</refsection>


</refsection>


<!--######################################################################-->

<refsection xml:id="refsec-nix-store-import"><title>Operation <option>--import</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--import</option></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--import</option> reads a serialisation of
a set of store paths produced by <command linkend="refsec-nix-store-export">nix-store --export</command> from
standard input and adds those store paths to the Nix store.  Paths
that already exist in the Nix store are ignored.  If a path refers to
another path that doesn&#x2019;t exist in the Nix store, the import
fails.</para>

</refsection>


</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--optimise</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--optimise</option></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--optimise</option> reduces Nix store disk
space usage by finding identical files in the store and hard-linking
them to each other.  It typically reduces the size of the store by
something like 25-35%.  Only regular files and symlinks are
hard-linked in this manner.  Files are considered identical when they
have the same NAR archive serialisation: that is, regular files must
have the same contents and permission (executable or non-executable),
and symlinks must have the same contents.</para>

<para>After completion, or when the command is interrupted, a report
on the achieved savings is printed on standard error.</para>

<para>Use <option>-vv</option> or <option>-vvv</option> to get some
progress indication.</para>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store --optimise
hashing files in `/nix/store/qhqx7l2f1kmwihc9bnxs7rc159hsxnf3-gcc-4.1.1'
<replaceable>...</replaceable>
541838819 bytes (516.74 MiB) freed by hard-linking 54143 files;
there are 114486 files with equal contents out of 215894 files in total
</screen>

</refsection>


</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--read-log</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <group choice="req">
      <arg choice="plain"><option>--read-log</option></arg>
      <arg choice="plain"><option>-l</option></arg>
    </group>
    <arg choice="plain" rep="repeat"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--read-log</option> prints the build log
of the specified store paths on standard output.  The build log is
whatever the builder of a derivation wrote to standard output and
standard error.  If a store path is not a derivation, the deriver of
the store path is used.</para>

<para>Build logs are kept in
<filename>/nix/var/log/nix/drvs</filename>.  However, there is no
guarantee that a build log is available for any particular store path.
For instance, if the path was downloaded as a pre-built binary through
a substitute, then the log is unavailable.</para>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store -l $(which ktorrent)
building /nix/store/dhc73pvzpnzxhdgpimsd9sw39di66ph1-ktorrent-2.2.1
unpacking sources
unpacking source archive /nix/store/p8n1jpqs27mgkjw07pb5269717nzf5f8-ktorrent-2.2.1.tar.gz
ktorrent-2.2.1/
ktorrent-2.2.1/NEWS
<replaceable>...</replaceable>
</screen>

</refsection>


</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--dump-db</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--dump-db</option></arg>
    <arg rep="repeat"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--dump-db</option> writes a dump of the
Nix database to standard output.  It can be loaded into an empty Nix
store using <option>--load-db</option>.  This is useful for making
backups and when migrating to different database schemas.</para>

<para>By default, <option>--dump-db</option> will dump the entire Nix
database.  When one or more store paths is passed, only the subset of
the Nix database for those store paths is dumped.  As with
<option>--export</option>, the user is responsible for passing all the
store paths for a closure.  See <option>--export</option> for an
example.</para>

</refsection>

</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--load-db</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--load-db</option></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--load-db</option> reads a dump of the Nix
database created by <option>--dump-db</option> from standard input and
loads it into the Nix database.</para>

</refsection>

</refsection>


<!--######################################################################-->

<refsection><title>Operation <option>--print-env</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain"><option>--print-env</option></arg>
    <arg choice="plain"><replaceable>drvpath</replaceable></arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>The operation <option>--print-env</option> prints out the
environment of a derivation in a format that can be evaluated by a
shell.  The command line arguments of the builder are placed in the
variable <envar>_args</envar>.</para>

</refsection>

<refsection><title>Example</title>

<screen>
$ nix-store --print-env $(nix-instantiate '&lt;nixpkgs&gt;' -A firefox)
<replaceable>&#x2026;</replaceable>
export src; src='/nix/store/plpj7qrwcz94z2psh6fchsi7s8yihc7k-firefox-12.0.source.tar.bz2'
export stdenv; stdenv='/nix/store/7c8asx3yfrg5dg1gzhzyq2236zfgibnn-stdenv'
export system; system='x86_64-linux'
export _args; _args='-e /nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25c-default-builder.sh'
</screen>

</refsection>

</refsection>


<!--######################################################################-->

<refsection xml:id="rsec-nix-store-generate-binary-cache-key"><title>Operation <option>--generate-binary-cache-key</option></title>

<refsection>
  <title>Synopsis</title>
  <cmdsynopsis>
    <command>nix-store</command>
    <arg choice="plain">
      <option>--generate-binary-cache-key</option>
      <option>key-name</option>
      <option>secret-key-file</option>
      <option>public-key-file</option>
    </arg>
  </cmdsynopsis>
</refsection>

<refsection><title>Description</title>

<para>This command generates an <link xlink:href="http://ed25519.cr.yp.to/">Ed25519 key pair</link> that can
be used to create a signed binary cache. It takes three mandatory
parameters:

<orderedlist>

  <listitem><para>A key name, such as
  <literal>cache.example.org-1</literal>, that is used to look up keys
  on the client when it verifies signatures. It can be anything, but
  it&#x2019;s suggested to use the host name of your cache
  (e.g. <literal>cache.example.org</literal>) with a suffix denoting
  the number of the key (to be incremented every time you need to
  revoke a key).</para></listitem>

  <listitem><para>The file name where the secret key is to be
  stored.</para></listitem>

  <listitem><para>The file name where the public key is to be
  stored.</para></listitem>

</orderedlist>

</para>

</refsection>

</refsection>


<!--######################################################################-->

<refsection condition="manpage"><title>Environment variables</title>

<variablelist>
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>IN_NIX_SHELL</envar></term>

  <listitem><para>Indicator that tells if the current environment was set up by
  <command>nix-shell</command>.  Since Nix 2.0 the values are
  <literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>

  <listitem>

    <para>A colon-separated list of directories used to look up Nix
    expressions enclosed in angle brackets (i.e.,
    <literal>&lt;<replaceable>path</replaceable>&gt;</literal>).  For
    instance, the value

    <screen>
/home/eelco/Dev:/etc/nixos</screen>

    will cause Nix to look for paths relative to
    <filename>/home/eelco/Dev</filename> and
    <filename>/etc/nixos</filename>, in this order.  It is also
    possible to match paths against a prefix.  For example, the value

    <screen>
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>

    will cause Nix to search for
    <literal>&lt;nixpkgs/<replaceable>path</replaceable>&gt;</literal> in
    <filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
    and
    <filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>

    <para>If a path in the Nix search path starts with
    <literal>http://</literal> or <literal>https://</literal>, it is
    interpreted as the URL of a tarball that will be downloaded and
    unpacked to a temporary location. The tarball must consist of a
    single top-level directory. For example, setting
    <envar>NIX_PATH</envar> to

    <screen>
nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-15.09.tar.gz</screen>

    tells Nix to download the latest revision in the Nixpkgs/NixOS
    15.09 channel.</para>

    <para>A following shorthand can be used to refer to the official channels:

    <screen>nixpkgs=channel:nixos-15.09</screen>
    </para>

    <para>The search path can be extended using the <option linkend="opt-I">-I</option> option, which takes precedence over
    <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>

  <listitem>

  <para>Normally, the Nix store directory (typically
  <filename>/nix/store</filename>) is not allowed to contain any
  symlink components.  This is to prevent &#x201C;impure&#x201D; builds.  Builders
  sometimes &#x201C;canonicalise&#x201D; paths by resolving all symlink components.
  Thus, builds on different machines (with
  <filename>/nix/store</filename> resolving to different locations)
  could yield different results.  This is generally not a problem,
  except when builds are deployed to machines where
  <filename>/nix/store</filename> resolves differently.  If you are
  sure that you&#x2019;re not going to do that, you can set
  <envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>

  <para>Note that if you&#x2019;re symlinking the Nix store so that you can
  put it on another file system than the root file system, on Linux
  you&#x2019;re better off using <literal>bind</literal> mount points, e.g.,

  <screen>
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix</screen>

  Consult the <citerefentry><refentrytitle>mount</refentrytitle>
  <manvolnum>8</manvolnum></citerefentry> manual page for details.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STORE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix store (default
  <filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_DATA_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix static data
  directory (default
  <filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_LOG_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix log directory
  (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STATE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix state directory
  (default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_CONF_DIR</envar></term>

  <listitem><para>Overrides the location of the system Nix configuration
  directory (default
  <filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_USER_CONF_FILES</envar></term>

  <listitem><para>Overrides the location of the user Nix configuration files
  to load from (defaults to the XDG spec locations). The variable is treated
  as a list separated by the <literal>:</literal> token.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>TMPDIR</envar></term>

  <listitem><para>Use the specified directory to store temporary
  files.  In particular, this includes temporary build directories;
  these can take up substantial amounts of disk space.  The default is
  <filename>/tmp</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>

  <listitem><para>This variable should be set to
  <literal>daemon</literal> if you want to use the Nix daemon to
  execute Nix operations. This is necessary in <link linkend="ssec-multi-user">multi-user Nix installations</link>.
  If the Nix daemon's Unix socket is at some non-standard path,
  this variable should be set to <literal>unix://path/to/socket</literal>.
  Otherwise, it should be left unset.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_SHOW_STATS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print some
  evaluation statistics, such as the number of values
  allocated.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_COUNT_CALLS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print how
  often functions were called during Nix expression evaluation.  This
  is useful for profiling your Nix expressions.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>

  <listitem><para>If Nix has been configured to use the Boehm garbage
  collector, this variable sets the initial size of the heap in bytes.
  It defaults to 384 MiB.  Setting it to a low value reduces memory
  consumption, but will increase runtime due to the overhead of
  garbage collection.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


</refentry>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-utilities">

<title>Utilities</title>

<para>This section lists utilities that you can use when you
work with Nix.</para>

<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-channel">

<refmeta>
  <refentrytitle>nix-channel</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-channel</refname>
  <refpurpose>manage Nix channels</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-channel</command>
    <group choice="req">
      <arg choice="plain"><option>--add</option> <replaceable>url</replaceable> <arg choice="opt"><replaceable>name</replaceable></arg></arg>
      <arg choice="plain"><option>--remove</option> <replaceable>name</replaceable></arg>
      <arg choice="plain"><option>--list</option></arg>
      <arg choice="plain"><option>--update</option> <arg rep="repeat"><replaceable>names</replaceable></arg></arg>
      <arg choice="plain"><option>--rollback</option> <arg choice="opt"><replaceable>generation</replaceable></arg></arg>
    </group>
  </cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>A Nix channel is a mechanism that allows you to automatically
stay up-to-date with a set of pre-built Nix expressions.  A Nix
channel is just a URL that points to a place containing a set of Nix
expressions.  <phrase condition="manual">See also <xref linkend="sec-channels"/>.</phrase></para>
      
<para>To see the list of official NixOS channels, visit <link xlink:href="https://nixos.org/channels"/>.</para>

<para>This command has the following operations:

<variablelist>

  <varlistentry><term><option>--add</option> <replaceable>url</replaceable> [<replaceable>name</replaceable>]</term>

    <listitem><para>Adds a channel named
    <replaceable>name</replaceable> with URL
    <replaceable>url</replaceable> to the list of subscribed channels.
    If <replaceable>name</replaceable> is omitted, it defaults to the
    last component of <replaceable>url</replaceable>, with the
    suffixes <literal>-stable</literal> or
    <literal>-unstable</literal> removed.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--remove</option> <replaceable>name</replaceable></term>

    <listitem><para>Removes the channel named
    <replaceable>name</replaceable> from the list of subscribed
    channels.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--list</option></term>

    <listitem><para>Prints the names and URLs of all subscribed
    channels on standard output.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--update</option> [<replaceable>names</replaceable>&#x2026;]</term>

    <listitem><para>Downloads the Nix expressions of all subscribed
    channels (or only those included in
    <replaceable>names</replaceable> if specified) and makes them the
    default for <command>nix-env</command> operations (by symlinking
    them from the directory
    <filename>~/.nix-defexpr</filename>).</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--rollback</option> [<replaceable>generation</replaceable>]</term>

    <listitem><para>Reverts the previous call to <command>nix-channel
    --update</command>. Optionally, you can specify a specific channel
    generation number to restore.</para></listitem>

  </varlistentry>

</variablelist>

</para>

<para>Note that <option>--add</option> does not automatically perform
an update.</para>

<para>The list of subscribed channels is stored in
<filename>~/.nix-channels</filename>.</para>

</refsection>

<refsection><title>Examples</title>

<para>To subscribe to the Nixpkgs channel and install the GNU Hello package:</para>

<screen>
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
$ nix-env -iA nixpkgs.hello</screen>

<para>You can revert channel updates using <option>--rollback</option>:</para>

<screen>
$ nix-instantiate --eval -E '(import &lt;nixpkgs&gt; {}).lib.version'
"14.04.527.0e935f1"

$ nix-channel --rollback
switching from generation 483 to 482

$ nix-instantiate --eval -E '(import &lt;nixpkgs&gt; {}).lib.version'
"14.04.526.dbadfad"
</screen>

</refsection>

<refsection><title>Files</title>

<variablelist>

  <varlistentry><term><filename>/nix/var/nix/profiles/per-user/<replaceable>username</replaceable>/channels</filename></term>

    <listitem><para><command>nix-channel</command> uses a
    <command>nix-env</command> profile to keep track of previous
    versions of the subscribed channels. Every time you run
    <command>nix-channel --update</command>, a new channel generation
    (that is, a symlink to the channel Nix expressions in the Nix store)
    is created. This enables <command>nix-channel --rollback</command>
    to revert to previous versions.</para></listitem>

  </varlistentry>

  <varlistentry><term><filename>~/.nix-defexpr/channels</filename></term>

    <listitem><para>This is a symlink to
    <filename>/nix/var/nix/profiles/per-user/<replaceable>username</replaceable>/channels</filename>. It
    ensures that <command>nix-env</command> can find your channels. In
    a multi-user installation, you may also have
    <filename>~/.nix-defexpr/channels_root</filename>, which links to
    the channels of the root user.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>

<refsection><title>Channel format</title>

<para>A channel URL should point to a directory containing the
following files:</para>

<variablelist>

  <varlistentry><term><filename>nixexprs.tar.xz</filename></term>

    <listitem><para>A tarball containing Nix expressions and files
    referenced by them (such as build scripts and patches). At the
    top level, the tarball should contain a single directory. That
    directory must contain a file <filename>default.nix</filename>
    that serves as the channel&#x2019;s &#x201C;entry point&#x201D;.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>

</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-collect-garbage">
  
<refmeta>
  <refentrytitle>nix-collect-garbage</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-collect-garbage</refname>
  <refpurpose>delete unreachable store paths</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-collect-garbage</command>
    <arg><option>--delete-old</option></arg>
    <arg><option>-d</option></arg>
    <arg><option>--delete-older-than</option> <replaceable>period</replaceable></arg>
    <arg><option>--max-freed</option> <replaceable>bytes</replaceable></arg>
    <arg><option>--dry-run</option></arg>
  </cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>The command <command>nix-collect-garbage</command> is mostly an
alias of <link linkend="rsec-nix-store-gc"><command>nix-store
--gc</command></link>, that is, it deletes all unreachable paths in
the Nix store to clean up your system.  However, it provides two
additional options: <option>-d</option> (<option>--delete-old</option>),
which deletes all old generations of all profiles in
<filename>/nix/var/nix/profiles</filename> by invoking
<literal>nix-env --delete-generations old</literal> on all profiles
(of course, this makes rollbacks to previous configurations
impossible); and
<option>--delete-older-than</option> <replaceable>period</replaceable>,
where period is a value such as <literal>30d</literal>, which deletes
all generations older than the specified number of days in all profiles
in <filename>/nix/var/nix/profiles</filename> (except for the generations
that were active at that point in time).
</para>

</refsection>

<refsection><title>Example</title>

<para>To delete from the Nix store everything that is not used by the
current generations of each profile, do

<screen>
$ nix-collect-garbage -d</screen>

</para>

</refsection>

</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-nix-copy-closure">

<refmeta>
  <refentrytitle>nix-copy-closure</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-copy-closure</refname>
  <refpurpose>copy a closure to or from a remote machine via SSH</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-copy-closure</command>
    <group>
      <arg choice="plain"><option>--to</option></arg>
      <arg choice="plain"><option>--from</option></arg>
    </group>
    <arg><option>--gzip</option></arg>
    <!--
    <arg><option>- -show-progress</option></arg>
    -->
    <arg><option>--include-outputs</option></arg>
    <group>
      <arg choice="plain"><option>--use-substitutes</option></arg>
      <arg choice="plain"><option>-s</option></arg>
    </group>
    <arg><option>-v</option></arg>
    <arg choice="plain">
      <replaceable>user@</replaceable><replaceable>machine</replaceable>
    </arg>
    <arg choice="plain"><replaceable>paths</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para><command>nix-copy-closure</command> gives you an easy and
efficient way to exchange software between machines.  Given one or
more Nix store <replaceable>paths</replaceable> on the local
machine, <command>nix-copy-closure</command> computes the closure of
those paths (i.e. all their dependencies in the Nix store), and copies
all paths in the closure to the remote machine via the
<command>ssh</command> (Secure Shell) command.  With the
<option>--from</option>, the direction is reversed:
the closure of <replaceable>paths</replaceable> on a remote machine is
copied to the Nix store on the local machine.</para>

<para>This command is efficient because it only sends the store paths
that are missing on the target machine.</para>

<para>Since <command>nix-copy-closure</command> calls
<command>ssh</command>, you may be asked to type in the appropriate
password or passphrase.  In fact, you may be asked
<emphasis>twice</emphasis> because <command>nix-copy-closure</command>
currently connects twice to the remote machine, first to get the set
of paths missing on the target machine, and second to send the dump of
those paths.  If this bothers you, use
<command>ssh-agent</command>.</para>


<refsection><title>Options</title>

<variablelist>

  <varlistentry><term><option>--to</option></term>

    <listitem><para>Copy the closure of
    <replaceable>paths</replaceable> from the local Nix store to the
    Nix store on <replaceable>machine</replaceable>.  This is the
    default.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--from</option></term>

    <listitem><para>Copy the closure of
    <replaceable>paths</replaceable> from the Nix store on
    <replaceable>machine</replaceable> to the local Nix
    store.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--gzip</option></term>

    <listitem><para>Enable compression of the SSH
    connection.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--include-outputs</option></term>

    <listitem><para>Also copy the outputs of store derivations
    included in the closure.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--use-substitutes</option> / <option>-s</option></term>

    <listitem><para>Attempt to download missing paths on the target
    machine using Nix&#x2019;s substitute mechanism.  Any paths that cannot
    be substituted on the target are still copied normally from the
    source.  This is useful, for instance, if the connection between
    the source and target machine is slow, but the connection between
    the target machine and <literal>nixos.org</literal> (the default
    binary cache server) is fast.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>-v</option></term>

    <listitem><para>Show verbose output.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Environment variables</title>

<variablelist>

  <varlistentry><term><envar>NIX_SSHOPTS</envar></term>

    <listitem><para>Additional options to be passed to
    <command>ssh</command> on the command line.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>Copy Firefox with all its dependencies to a remote machine:

<screen>
$ nix-copy-closure --to alice@itchy.labs $(type -tP firefox)</screen>

</para>

<para>Copy Subversion from a remote machine and then install it into a
user environment:

<screen>
$ nix-copy-closure --from alice@itchy.labs \
    /nix/store/0dj0503hjxy5mbwlafv1rsbdiyx1gkdy-subversion-1.4.4
$ nix-env -i /nix/store/0dj0503hjxy5mbwlafv1rsbdiyx1gkdy-subversion-1.4.4
</screen>

</para>

</refsection>


</refsection>

</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-daemon">

<refmeta>
  <refentrytitle>nix-daemon</refentrytitle>
  <manvolnum>8</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-daemon</refname>
  <refpurpose>Nix multi-user support daemon</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-daemon</command>
  </cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para>The Nix daemon is necessary in multi-user Nix installations.  It
performs build actions and other operations on the Nix store on behalf
of unprivileged users.</para>


</refsection>

</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-hash">
  
<refmeta>
  <refentrytitle>nix-hash</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-hash</refname>
  <refpurpose>compute the cryptographic hash of a path</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-hash</command>
    <arg><option>--flat</option></arg>
    <arg><option>--base32</option></arg>
    <arg><option>--truncate</option></arg>
    <arg><option>--type</option> <replaceable>hashAlgo</replaceable></arg>
    <arg choice="plain" rep="repeat"><replaceable>path</replaceable></arg>
  </cmdsynopsis>
  <cmdsynopsis>
    <command>nix-hash</command>
    <arg choice="plain"><option>--to-base16</option></arg>
    <arg choice="plain" rep="repeat"><replaceable>hash</replaceable></arg>
  </cmdsynopsis>
  <cmdsynopsis>
    <command>nix-hash</command>
    <arg choice="plain"><option>--to-base32</option></arg>
    <arg choice="plain" rep="repeat"><replaceable>hash</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para>The command <command>nix-hash</command> computes the
cryptographic hash of the contents of each
<replaceable>path</replaceable> and prints it on standard output.  By
default, it computes an MD5 hash, but other hash algorithms are
available as well.  The hash is printed in hexadecimal.  To generate
the same hash as <command>nix-prefetch-url</command> you have to
specify multiple arguments, see below for an example.</para>

<para>The hash is computed over a <emphasis>serialisation</emphasis>
of each path: a dump of the file system tree rooted at the path.  This
allows directories and symlinks to be hashed as well as regular files.
The dump is in the <emphasis>NAR format</emphasis> produced by <link linkend="refsec-nix-store-dump"><command>nix-store</command>
<option>--dump</option></link>.  Thus, <literal>nix-hash
<replaceable>path</replaceable></literal> yields the same
cryptographic hash as <literal>nix-store --dump
<replaceable>path</replaceable> | md5sum</literal>.</para>

</refsection>


<refsection><title>Options</title>

<variablelist>
  
  <varlistentry><term><option>--flat</option></term>

    <listitem><para>Print the cryptographic hash of the contents of
    each regular file <replaceable>path</replaceable>.  That is, do
    not compute the hash over the dump of
    <replaceable>path</replaceable>.  The result is identical to that
    produced by the GNU commands <command>md5sum</command> and
    <command>sha1sum</command>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--base32</option></term>

    <listitem><para>Print the hash in a base-32 representation rather
    than hexadecimal.  This base-32 representation is more compact and
    can be used in Nix expressions (such as in calls to
    <function>fetchurl</function>).</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--truncate</option></term>

    <listitem><para>Truncate hashes longer than 160 bits (such as
    SHA-256) to 160 bits.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--type</option> <replaceable>hashAlgo</replaceable></term>

    <listitem><para>Use the specified cryptographic hash algorithm,
    which can be one of <literal>md5</literal>,
    <literal>sha1</literal>, and
    <literal>sha256</literal>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--to-base16</option></term>

    <listitem><para>Don&#x2019;t hash anything, but convert the base-32 hash
    representation <replaceable>hash</replaceable> to
    hexadecimal.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--to-base32</option></term>

    <listitem><para>Don&#x2019;t hash anything, but convert the hexadecimal
    hash representation <replaceable>hash</replaceable> to
    base-32.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>Computing the same hash as <command>nix-prefetch-url</command>:
<screen>
$ nix-prefetch-url file://&lt;(echo test)
1lkgqb6fclns49861dwk9rzb6xnfkxbpws74mxnx01z9qyv1pjpj
$ nix-hash --type sha256 --flat --base32 &lt;(echo test)
1lkgqb6fclns49861dwk9rzb6xnfkxbpws74mxnx01z9qyv1pjpj
</screen>
</para>

<para>Computing hashes:

<screen>
$ mkdir test
$ echo "hello" &gt; test/world

$ nix-hash test/ <lineannotation>(MD5 hash; default)</lineannotation>
8179d3caeff1869b5ba1744e5a245c04

$ nix-store --dump test/ | md5sum <lineannotation>(for comparison)</lineannotation>
8179d3caeff1869b5ba1744e5a245c04  -

$ nix-hash --type sha1 test/
e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6

$ nix-hash --type sha1 --base32 test/
nvd61k9nalji1zl9rrdfmsmvyyjqpzg4

$ nix-hash --type sha256 --flat test/
error: reading file `test/': Is a directory

$ nix-hash --type sha256 --flat test/world
5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03</screen>

</para>

<para>Converting between hexadecimal and base-32:

<screen>
$ nix-hash --type sha1 --to-base32 e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6
nvd61k9nalji1zl9rrdfmsmvyyjqpzg4

$ nix-hash --type sha1 --to-base16 nvd61k9nalji1zl9rrdfmsmvyyjqpzg4
e4fd8ba5f7bbeaea5ace89fe10255536cd60dab6</screen>

</para>

</refsection>


</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-instantiate">

<refmeta>
  <refentrytitle>nix-instantiate</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-instantiate</refname>
  <refpurpose>instantiate store derivations from Nix expressions</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-instantiate</command>
    <group>
      <arg choice="plain"><option>--parse</option></arg>
      <arg choice="plain">
        <option>--eval</option>
        <arg><option>--strict</option></arg>
        <arg><option>--json</option></arg>
        <arg><option>--xml</option></arg>
      </arg>
    </group>
    <arg><option>--read-write-mode</option></arg>
    <arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
    <arg>
      <group choice="req">
        <arg choice="plain"><option>--attr</option></arg>
        <arg choice="plain"><option>-A</option></arg>
      </group>
      <replaceable>attrPath</replaceable>
    </arg>
    <arg><option>--add-root</option> <replaceable>path</replaceable></arg>
    <arg><option>--indirect</option></arg>
    <group>
      <arg choice="plain"><option>--expr</option></arg>
      <arg choice="plain"><option>-E</option></arg>
    </group>
    <arg choice="plain" rep="repeat"><replaceable>files</replaceable></arg>
  </cmdsynopsis>
  <cmdsynopsis>
    <command>nix-instantiate</command>
    <arg choice="plain"><option>--find-file</option></arg>
    <arg choice="plain" rep="repeat"><replaceable>files</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>


<refsection><title>Description</title>

<para>The command <command>nix-instantiate</command> generates <link linkend="gloss-derivation">store derivations</link> from (high-level)
Nix expressions.  It evaluates the Nix expressions in each of
<replaceable>files</replaceable> (which defaults to
<replaceable>./default.nix</replaceable>).  Each top-level expression
should evaluate to a derivation, a list of derivations, or a set of
derivations.  The paths of the resulting store derivations are printed
on standard output.</para>

<para>If <replaceable>files</replaceable> is the character
<literal>-</literal>, then a Nix expression will be read from standard
input.</para>

<para condition="manual">See also <xref linkend="sec-common-options"/> for a list of common options.</para>

</refsection>


<refsection><title>Options</title>

<variablelist>

  <varlistentry>
    <term><option>--add-root</option> <replaceable>path</replaceable></term>
    <term><option>--indirect</option></term>

    <listitem><para>See the <link linkend="opt-add-root">corresponding
    options</link> in <command>nix-store</command>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--parse</option></term>

    <listitem><para>Just parse the input files, and print their
    abstract syntax trees on standard output in ATerm
    format.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--eval</option></term>

    <listitem><para>Just parse and evaluate the input files, and print
    the resulting values on standard output.  No instantiation of
    store derivations takes place.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--find-file</option></term>

    <listitem><para>Look up the given files in Nix&#x2019;s search path (as
    specified by the <envar linkend="env-NIX_PATH">NIX_PATH</envar>
    environment variable).  If found, print the corresponding absolute
    paths on standard output.  For instance, if
    <envar>NIX_PATH</envar> is
    <literal>nixpkgs=/home/alice/nixpkgs</literal>, then
    <literal>nix-instantiate --find-file nixpkgs/default.nix</literal>
    will print
    <literal>/home/alice/nixpkgs/default.nix</literal>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--strict</option></term>

    <listitem><para>When used with <option>--eval</option>,
    recursively evaluate list elements and attributes.  Normally, such
    sub-expressions are left unevaluated (since the Nix expression
    language is lazy).</para>

    <warning><para>This option can cause non-termination, because lazy
    data structures can be infinitely large.</para></warning>

    </listitem>

  </varlistentry>

  <varlistentry><term><option>--json</option></term>

    <listitem><para>When used with <option>--eval</option>, print the resulting
    value as an JSON representation of the abstract syntax tree rather
    than as an ATerm.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--xml</option></term>

    <listitem><para>When used with <option>--eval</option>, print the resulting
    value as an XML representation of the abstract syntax tree rather than as
    an ATerm. The schema is the same as that used by the <link linkend="builtin-toXML"><function>toXML</function> built-in</link>.
    </para></listitem>

  </varlistentry>

  <varlistentry><term><option>--read-write-mode</option></term>

    <listitem><para>When used with <option>--eval</option>, perform
    evaluation in read/write mode so nix language features that
    require it will still work (at the cost of needing to do
    instantiation of every evaluated derivation). If this option is
    not enabled, there may be uninstantiated store paths in the final
    output.</para>

    </listitem>

  </varlistentry>

</variablelist>

<variablelist condition="manpage">
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--help</option></term>

  <listitem><para>Prints out a summary of the command syntax and
  exits.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--version</option></term>

  <listitem><para>Prints out the Nix version number on standard output
  and exits.</para></listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--verbose</option> / <option>-v</option></term>

  <listitem>

  <para>Increases the level of verbosity of diagnostic messages
  printed on standard error.  For each Nix operation, the information
  printed on standard output is well-defined; any diagnostic
  information is printed on standard error, never on standard
  output.</para>

  <para>This option may be specified repeatedly.  Currently, the
  following verbosity levels exist:</para>

  <variablelist>

    <varlistentry><term>0</term>
    <listitem><para>&#x201C;Errors only&#x201D;: only print messages
    explaining why the Nix invocation failed.</para></listitem>
    </varlistentry>

    <varlistentry><term>1</term>
    <listitem><para>&#x201C;Informational&#x201D;: print
    <emphasis>useful</emphasis> messages about what Nix is doing.
    This is the default.</para></listitem>
    </varlistentry>

    <varlistentry><term>2</term>
    <listitem><para>&#x201C;Talkative&#x201D;: print more informational
    messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>3</term>
    <listitem><para>&#x201C;Chatty&#x201D;: print even more
    informational messages.</para></listitem>
    </varlistentry>

    <varlistentry><term>4</term>
    <listitem><para>&#x201C;Debug&#x201D;: print debug
    information.</para></listitem>
    </varlistentry>

    <varlistentry><term>5</term>
    <listitem><para>&#x201C;Vomit&#x201D;: print vast amounts of debug
    information.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--quiet</option></term>

  <listitem>

  <para>Decreases the level of verbosity of diagnostic messages
  printed on standard error.  This is the inverse option to
  <option>-v</option> / <option>--verbose</option>.
  </para>

  <para>This option may be specified repeatedly.  See the previous
  verbosity levels list.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-log-format"><term><option>--log-format</option> <replaceable>format</replaceable></term>

  <listitem>

  <para>This option can be used to change the output of the log format, with
  <replaceable>format</replaceable> being one of:</para>

  <variablelist>

    <varlistentry><term>raw</term>
    <listitem><para>This is the raw format, as outputted by nix-build.</para></listitem>
    </varlistentry>

    <varlistentry><term>internal-json</term>
    <listitem><para>Outputs the logs in a structured manner. NOTE: the json schema is not guarantees to be stable between releases.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar</term>
    <listitem><para>Only display a progress bar during the builds.</para></listitem>
    </varlistentry>

    <varlistentry><term>bar-with-logs</term>
    <listitem><para>Display the raw logs, with the progress bar at the bottom.</para></listitem>
    </varlistentry>

  </variablelist>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-output</option> / <option>-Q</option></term>

  <listitem><para>By default, output written by builders to standard
  output and standard error is echoed to the Nix command's standard
  error.  This option suppresses this behaviour.  Note that the
  builder's standard output and error are always written to a log file
  in
  <filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-jobs"><term><option>--max-jobs</option> / <option>-j</option>
<replaceable>number</replaceable></term>

  <listitem>

  <para>Sets the maximum number of build jobs that Nix will
  perform in parallel to the specified number.  Specify
  <literal>auto</literal> to use the number of CPUs in the system.
  The default is specified by the <link linkend="conf-max-jobs"><literal>max-jobs</literal></link>
  configuration setting, which itself defaults to
  <literal>1</literal>.  A higher value is useful on SMP systems or to
  exploit I/O latency.</para>

  <para> Setting it to <literal>0</literal> disallows building on the local
  machine, which is useful when you want builds to happen only on remote
  builders.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-cores"><term><option>--cores</option></term>

  <listitem><para>Sets the value of the <envar>NIX_BUILD_CORES</envar>
  environment variable in the invocation of builders.  Builders can
  use this variable at their discretion to control the maximum amount
  of parallelism.  For instance, in Nixpkgs, if the derivation
  attribute <varname>enableParallelBuilding</varname> is set to
  <literal>true</literal>, the builder passes the
  <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
  It defaults to the value of the <link linkend="conf-cores"><literal>cores</literal></link>
  configuration setting, if set, or <literal>1</literal> otherwise.
  The value <literal>0</literal> means that the builder should use all
  available CPU cores in the system.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can go without producing any data on standard output or standard
  error.  The default is specified by the <link linkend="conf-max-silent-time"><literal>max-silent-time</literal></link>
  configuration setting.  <literal>0</literal> means no
  time-out.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-timeout"><term><option>--timeout</option></term>

  <listitem><para>Sets the maximum number of seconds that a builder
  can run.  The default is specified by the <link linkend="conf-timeout"><literal>timeout</literal></link>
  configuration setting.  <literal>0</literal> means no
  timeout.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-going</option> / <option>-k</option></term>

  <listitem><para>Keep going in case of failed builds, to the
  greatest extent possible.  That is, if building an input of some
  derivation fails, Nix will still build the other inputs, but not the
  derivation itself.  Without this option, Nix stops if any build
  fails (except for builds of substitutes), possibly killing builds in
  progress (in case of parallel or distributed builds).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--keep-failed</option> / <option>-K</option></term>

  <listitem><para>Specifies that in case of a build failure, the
  temporary directory (usually in <filename>/tmp</filename>) in which
  the build takes place should not be deleted.  The path of the build
  directory is printed as an informational message.
    </para>
  </listitem>
</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--fallback</option></term>

  <listitem>

  <para>Whenever Nix attempts to build a derivation for which
  substitutes are known for each output path, but realising the output
  paths through the substitutes fails, fall back on building the
  derivation.</para>

  <para>The most common scenario in which this is useful is when we
  have registered substitutes in order to perform binary distribution
  from, say, a network repository.  If the repository is down, the
  realisation of the derivation will fail.  When this option is
  specified, Nix will build the derivation instead.  Thus,
  installation from binaries falls back on installation from source.
  This option is not the default since it is generally not desirable
  for a transient failure in obtaining the substitutes to lead to a
  full build from source (with the related consumption of
  resources).</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--no-build-hook</option></term>

  <listitem>

  <para>Disables the build hook mechanism.  This allows to ignore remote
  builders if they are setup on the machine.</para>

  <para>It's useful in cases where the bandwidth between the client and the
  remote builder is too low.  In that case it can take more time to upload the
  sources to the remote builder and fetch back the result than to do the
  computation locally.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--readonly-mode</option></term>

  <listitem><para>When this option is used, no attempt is made to open
  the Nix database.  Most Nix operations do need database access, so
  those operations will fail.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is accepted by
  <command>nix-env</command>, <command>nix-instantiate</command>,
  <command>nix-shell</command> and <command>nix-build</command>.
  When evaluating Nix expressions, the expression evaluator will
  automatically try to call functions that
  it encounters.  It can automatically call functions for which every
  argument has a <link linkend="ss-functions">default value</link>
  (e.g., <literal>{ <replaceable>argName</replaceable> ?
  <replaceable>defaultValue</replaceable> }:
  <replaceable>...</replaceable></literal>).  With
  <option>--arg</option>, you can also call functions that have
  arguments without a default value (or override a default value).
  That is, if the evaluator encounters a function with an argument
  named <replaceable>name</replaceable>, it will call it with value
  <replaceable>value</replaceable>.</para>

  <para>For instance, the top-level <literal>default.nix</literal> in
  Nixpkgs is actually a function:

<programlisting>
{ # The system (e.g., `i686-linux') for which to build the packages.
  system ? builtins.currentSystem
  <replaceable>...</replaceable>
}: <replaceable>...</replaceable></programlisting>

  So if you call this Nix expression (e.g., when you do
  <literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
  the function will be called automatically using the value <link linkend="builtin-currentSystem"><literal>builtins.currentSystem</literal></link>
  for the <literal>system</literal> argument.  You can override this
  using <option>--arg</option>, e.g., <literal>nix-env -i
  <replaceable>pkgname</replaceable> --arg system
  \"i686-freebsd\"</literal>.  (Note that since the argument is a Nix
  string literal, you have to escape the quotes.)</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>This option is like <option>--arg</option>, only the
  value is not a Nix expression but a string.  So instead of
  <literal>--arg system \"i686-linux\"</literal> (the outer quotes are
  to keep the shell happy) you can say <literal>--argstr system
  i686-linux</literal>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
<replaceable>attrPath</replaceable></term>

  <listitem><para>Select an attribute from the top-level Nix
  expression being evaluated.  (<command>nix-env</command>,
  <command>nix-instantiate</command>, <command>nix-build</command> and
  <command>nix-shell</command> only.)  The <emphasis>attribute
  path</emphasis> <replaceable>attrPath</replaceable> is a sequence of
  attribute names separated by dots.  For instance, given a top-level
  Nix expression <replaceable>e</replaceable>, the attribute path
  <literal>xorg.xorgserver</literal> would cause the expression
  <literal><replaceable>e</replaceable>.xorg.xorgserver</literal> to
  be used.  See <link linkend="refsec-nix-env-install-examples"><command>nix-env
  --install</command></link> for some concrete examples.</para>

  <para>In addition to attribute names, you can also specify array
  indices.  For instance, the attribute path
  <literal>foo.3.bar</literal> selects the <literal>bar</literal>
  attribute of the fourth element of the array in the
  <literal>foo</literal> attribute of the top-level
  expression.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--expr</option> / <option>-E</option></term>

  <listitem><para>Interpret the command line arguments as a list of
  Nix expressions to be parsed and evaluated, rather than as a list
  of file names of Nix expressions.
  (<command>nix-instantiate</command>, <command>nix-build</command>
  and <command>nix-shell</command> only.)</para>

  <para>For <command>nix-shell</command>, this option is commonly used
  to give you a shell in which you can build the packages returned
  by the expression. If you want to get a shell which contain the
  <emphasis>built</emphasis> packages ready for use, give your
  expression to the <command>nix-shell -p</command> convenience flag
  instead.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="opt-I"><term><option>-I</option> <replaceable>path</replaceable></term>

  <listitem><para>Add a path to the Nix expression search path.  This
  option may be given multiple times.  See the <envar linkend="env-NIX_PATH">NIX_PATH</envar> environment variable for
  information on the semantics of the Nix search path.  Paths added
  through <option>-I</option> take precedence over
  <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>

  <listitem><para>Set the Nix configuration option
  <replaceable>name</replaceable> to <replaceable>value</replaceable>.
  This overrides settings in the Nix configuration file (see
  <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><option>--repair</option></term>

  <listitem><para>Fix corrupted or missing store paths by
  redownloading or rebuilding them.  Note that this is slow because it
  requires computing a cryptographic hash of the contents of every
  path in the closure of the build.  Also note the warning under
  <command>nix-store --repair-path</command>.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


<refsection><title>Examples</title>

<para>Instantiating store derivations from a Nix expression, and
building them using <command>nix-store</command>:

<screen>
$ nix-instantiate test.nix <lineannotation>(instantiate)</lineannotation>
/nix/store/cigxbmvy6dzix98dxxh9b6shg7ar5bvs-perl-BerkeleyDB-0.26.drv

$ nix-store -r $(nix-instantiate test.nix) <lineannotation>(build)</lineannotation>
<replaceable>...</replaceable>
/nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26 <lineannotation>(output path)</lineannotation>

$ ls -l /nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26
dr-xr-xr-x    2 eelco    users        4096 1970-01-01 01:00 lib
...</screen>

</para>

<para>You can also give a Nix expression on the command line:

<screen>
$ nix-instantiate -E 'with import &lt;nixpkgs&gt; { }; hello'
/nix/store/j8s4zyv75a724q38cb0r87rlczaiag4y-hello-2.8.drv
</screen>

This is equivalent to:

<screen>
$ nix-instantiate '&lt;nixpkgs&gt;' -A hello
</screen>

</para>

<para>Parsing and evaluating Nix expressions:

<screen>
$ nix-instantiate --parse -E '1 + 2'
1 + 2

$ nix-instantiate --eval -E '1 + 2'
3

$ nix-instantiate --eval --xml -E '1 + 2'
<![CDATA[<?xml version='1.0' encoding='utf-8'?>
<expr>
  <int value="3" />
</expr>]]></screen>

</para>

<para>The difference between non-strict and strict evaluation:

<screen>
$ nix-instantiate --eval --xml -E 'rec { x = "foo"; y = x; }'
<replaceable>...</replaceable><![CDATA[
  <attr name="x">
    <string value="foo" />
  </attr>
  <attr name="y">
    <unevaluated />
  </attr>]]>
<replaceable>...</replaceable></screen>

Note that <varname>y</varname> is left unevaluated (the XML
representation doesn&#x2019;t attempt to show non-normal forms).

<screen>
$ nix-instantiate --eval --xml --strict -E 'rec { x = "foo"; y = x; }'
<replaceable>...</replaceable><![CDATA[
  <attr name="x">
    <string value="foo" />
  </attr>
  <attr name="y">
    <string value="foo" />
  </attr>]]>
<replaceable>...</replaceable></screen>

</para>

</refsection>


<refsection condition="manpage"><title>Environment variables</title>

<variablelist>
  <varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>IN_NIX_SHELL</envar></term>

  <listitem><para>Indicator that tells if the current environment was set up by
  <command>nix-shell</command>.  Since Nix 2.0 the values are
  <literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>

  <listitem>

    <para>A colon-separated list of directories used to look up Nix
    expressions enclosed in angle brackets (i.e.,
    <literal>&lt;<replaceable>path</replaceable>&gt;</literal>).  For
    instance, the value

    <screen>
/home/eelco/Dev:/etc/nixos</screen>

    will cause Nix to look for paths relative to
    <filename>/home/eelco/Dev</filename> and
    <filename>/etc/nixos</filename>, in this order.  It is also
    possible to match paths against a prefix.  For example, the value

    <screen>
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>

    will cause Nix to search for
    <literal>&lt;nixpkgs/<replaceable>path</replaceable>&gt;</literal> in
    <filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
    and
    <filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>

    <para>If a path in the Nix search path starts with
    <literal>http://</literal> or <literal>https://</literal>, it is
    interpreted as the URL of a tarball that will be downloaded and
    unpacked to a temporary location. The tarball must consist of a
    single top-level directory. For example, setting
    <envar>NIX_PATH</envar> to

    <screen>
nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-15.09.tar.gz</screen>

    tells Nix to download the latest revision in the Nixpkgs/NixOS
    15.09 channel.</para>

    <para>A following shorthand can be used to refer to the official channels:

    <screen>nixpkgs=channel:nixos-15.09</screen>
    </para>

    <para>The search path can be extended using the <option linkend="opt-I">-I</option> option, which takes precedence over
    <envar>NIX_PATH</envar>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>

  <listitem>

  <para>Normally, the Nix store directory (typically
  <filename>/nix/store</filename>) is not allowed to contain any
  symlink components.  This is to prevent &#x201C;impure&#x201D; builds.  Builders
  sometimes &#x201C;canonicalise&#x201D; paths by resolving all symlink components.
  Thus, builds on different machines (with
  <filename>/nix/store</filename> resolving to different locations)
  could yield different results.  This is generally not a problem,
  except when builds are deployed to machines where
  <filename>/nix/store</filename> resolves differently.  If you are
  sure that you&#x2019;re not going to do that, you can set
  <envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>

  <para>Note that if you&#x2019;re symlinking the Nix store so that you can
  put it on another file system than the root file system, on Linux
  you&#x2019;re better off using <literal>bind</literal> mount points, e.g.,

  <screen>
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix</screen>

  Consult the <citerefentry><refentrytitle>mount</refentrytitle>
  <manvolnum>8</manvolnum></citerefentry> manual page for details.</para>

  </listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STORE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix store (default
  <filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_DATA_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix static data
  directory (default
  <filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_LOG_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix log directory
  (default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_STATE_DIR</envar></term>

  <listitem><para>Overrides the location of the Nix state directory
  (default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_CONF_DIR</envar></term>

  <listitem><para>Overrides the location of the system Nix configuration
  directory (default
  <filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_USER_CONF_FILES</envar></term>

  <listitem><para>Overrides the location of the user Nix configuration files
  to load from (defaults to the XDG spec locations). The variable is treated
  as a list separated by the <literal>:</literal> token.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>TMPDIR</envar></term>

  <listitem><para>Use the specified directory to store temporary
  files.  In particular, this includes temporary build directories;
  these can take up substantial amounts of disk space.  The default is
  <filename>/tmp</filename>.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook" xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>

  <listitem><para>This variable should be set to
  <literal>daemon</literal> if you want to use the Nix daemon to
  execute Nix operations. This is necessary in <link linkend="ssec-multi-user">multi-user Nix installations</link>.
  If the Nix daemon's Unix socket is at some non-standard path,
  this variable should be set to <literal>unix://path/to/socket</literal>.
  Otherwise, it should be left unset.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_SHOW_STATS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print some
  evaluation statistics, such as the number of values
  allocated.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>NIX_COUNT_CALLS</envar></term>

  <listitem><para>If set to <literal>1</literal>, Nix will print how
  often functions were called during Nix expression evaluation.  This
  is useful for profiling your Nix expressions.</para></listitem>

</varlistentry><varlistentry xmlns="http://docbook.org/ns/docbook"><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>

  <listitem><para>If Nix has been configured to use the Boehm garbage
  collector, this variable sets the initial size of the heap in bytes.
  It defaults to 384 MiB.  Setting it to a low value reduces memory
  consumption, but will increase runtime due to the overhead of
  garbage collection.</para></listitem>

</varlistentry>
</variablelist>

</refsection>


</refentry>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-nix-prefetch-url">

<refmeta>
  <refentrytitle>nix-prefetch-url</refentrytitle>
  <manvolnum>1</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix-prefetch-url</refname>
  <refpurpose>copy a file from a URL into the store and print its hash</refpurpose>
</refnamediv>

<refsynopsisdiv>
  <cmdsynopsis>
    <command>nix-prefetch-url</command>
    <arg><option>--version</option></arg>
    <arg><option>--type</option> <replaceable>hashAlgo</replaceable></arg>
    <arg><option>--print-path</option></arg>
    <arg><option>--unpack</option></arg>
    <arg><option>--name</option> <replaceable>name</replaceable></arg>
    <arg choice="plain"><replaceable>url</replaceable></arg>
    <arg><replaceable>hash</replaceable></arg>
  </cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>The command <command>nix-prefetch-url</command> downloads the
file referenced by the URL <replaceable>url</replaceable>, prints its
cryptographic hash, and copies it into the Nix store.  The file name
in the store is
<filename><replaceable>hash</replaceable>-<replaceable>baseName</replaceable></filename>,
where <replaceable>baseName</replaceable> is everything following the
final slash in <replaceable>url</replaceable>.</para>

<para>This command is just a convenience for Nix expression writers.
Often a Nix expression fetches some source distribution from the
network using the <literal>fetchurl</literal> expression contained in
Nixpkgs.  However, <literal>fetchurl</literal> requires a
cryptographic hash.  If you don't know the hash, you would have to
download the file first, and then <literal>fetchurl</literal> would
download it again when you build your Nix expression.  Since
<literal>fetchurl</literal> uses the same name for the downloaded file
as <command>nix-prefetch-url</command>, the redundant download can be
avoided.</para>

<para>If <replaceable>hash</replaceable> is specified, then a download
is not performed if the Nix store already contains a file with the
same hash and base name.  Otherwise, the file is downloaded, and an
error is signaled if the actual hash of the file does not match the
specified hash.</para>

<para>This command prints the hash on standard output.  Additionally,
if the option <option>--print-path</option> is used, the path of the
downloaded file in the Nix store is also printed.</para>

</refsection>


<refsection><title>Options</title>

<variablelist>

  <varlistentry><term><option>--type</option> <replaceable>hashAlgo</replaceable></term>

    <listitem><para>Use the specified cryptographic hash algorithm,
    which can be one of <literal>md5</literal>,
    <literal>sha1</literal>, and
    <literal>sha256</literal>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--print-path</option></term>

    <listitem><para>Print the store path of the downloaded file on
    standard output.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--unpack</option></term>

    <listitem><para>Unpack the archive (which must be a tarball or zip
    file) and add the result to the Nix store. The resulting hash can
    be used with functions such as Nixpkgs&#x2019;s
    <varname>fetchzip</varname> or
    <varname>fetchFromGitHub</varname>.</para></listitem>

  </varlistentry>

  <varlistentry><term><option>--name</option> <replaceable>name</replaceable></term>

    <listitem><para>Override the name of the file in the Nix store. By
    default, this is
    <literal><replaceable>hash</replaceable>-<replaceable>basename</replaceable></literal>,
    where <replaceable>basename</replaceable> is the last component of
    <replaceable>url</replaceable>. Overriding the name is necessary
    when <replaceable>basename</replaceable> contains characters that
    are not allowed in Nix store paths.</para></listitem>

  </varlistentry>

</variablelist>

</refsection>


<refsection><title>Examples</title>

<screen>
$ nix-prefetch-url ftp://ftp.gnu.org/pub/gnu/hello/hello-2.10.tar.gz
0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i

$ nix-prefetch-url --print-path mirror://gnu/hello/hello-2.10.tar.gz
0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz

$ nix-prefetch-url --unpack --print-path https://github.com/NixOS/patchelf/archive/0.8.tar.gz
079agjlv0hrv7fxnx9ngipx14gyncbkllxrp9cccnh3a50fxcmy7
/nix/store/19zrmhm3m40xxaw81c8cqm6aljgrnwj2-0.8.tar.gz
</screen>

</refsection>


</refentry>

</chapter>
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-files">

<title>Files</title>

<para>This section lists configuration files that you can use when you
work with Nix.</para>

<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="sec-conf-file" version="5">

<refmeta>
  <refentrytitle>nix.conf</refentrytitle>
  <manvolnum>5</manvolnum>
  <refmiscinfo class="source">Nix</refmiscinfo>
  <refmiscinfo class="version">3.0</refmiscinfo>
</refmeta>

<refnamediv>
  <refname>nix.conf</refname>
  <refpurpose>Nix configuration file</refpurpose>
</refnamediv>

<refsection><title>Description</title>

<para>By default Nix reads settings from the following places:</para>

<para>The system-wide configuration file
<filename><replaceable>sysconfdir</replaceable>/nix/nix.conf</filename>
(i.e. <filename>/etc/nix/nix.conf</filename> on most systems), or
<filename>$NIX_CONF_DIR/nix.conf</filename> if
<envar>NIX_CONF_DIR</envar> is set. Values loaded in this file are not forwarded to the Nix daemon. The
client assumes that the daemon has already loaded them.
</para>

<para>User-specific configuration files:</para>

<para>
  If <envar>NIX_USER_CONF_FILES</envar> is set, then each path separated by
  <literal>:</literal> will be loaded in reverse order.
</para>

<para>
  Otherwise it will look for <filename>nix/nix.conf</filename> files in
  <envar>XDG_CONFIG_DIRS</envar> and <envar>XDG_CONFIG_HOME</envar>.

  The default location is <filename>$HOME/.config/nix.conf</filename> if
  those environment variables are unset.
</para>

<para>The configuration files consist of
<literal><replaceable>name</replaceable> =
<replaceable>value</replaceable></literal> pairs, one per line. Other
files can be included with a line like <literal>include
<replaceable>path</replaceable></literal>, where
<replaceable>path</replaceable> is interpreted relative to the current
conf file and a missing file is an error unless
<literal>!include</literal> is used instead.
Comments start with a <literal>#</literal> character.  Here is an
example configuration file:</para>

<programlisting>
keep-outputs = true       # Nice for developers
keep-derivations = true   # Idem
</programlisting>

<para>You can override settings on the command line using the
<option>--option</option> flag, e.g. <literal>--option keep-outputs
false</literal>.</para>

<para>The following settings are currently available:

<variablelist>


  <varlistentry xml:id="conf-allowed-uris"><term><literal>allowed-uris</literal></term>

    <listitem>

      <para>A list of URI prefixes to which access is allowed in
      restricted evaluation mode. For example, when set to
      <literal>https://github.com/NixOS</literal>, builtin functions
      such as <function>fetchGit</function> are allowed to access
      <literal>https://github.com/NixOS/patchelf.git</literal>.</para>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="conf-allow-import-from-derivation"><term><literal>allow-import-from-derivation</literal></term>

    <listitem><para>By default, Nix allows you to <function>import</function> from a derivation,
    allowing building at evaluation time. With this option set to false, Nix will throw an error
    when evaluating an expression that uses this feature, allowing users to ensure their evaluation
    will not require any builds to take place.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-allow-new-privileges"><term><literal>allow-new-privileges</literal></term>

    <listitem><para>(Linux-specific.) By default, builders on Linux
    cannot acquire new privileges by calling setuid/setgid programs or
    programs that have file capabilities. For example, programs such
    as <command>sudo</command> or <command>ping</command> will
    fail. (Note that in sandbox builds, no such programs are available
    unless you bind-mount them into the sandbox via the
    <option>sandbox-paths</option> option.) You can allow the
    use of such programs by enabling this option. This is impure and
    usually undesirable, but may be useful in certain scenarios
    (e.g. to spin up containers or set up userspace network interfaces
    in tests).</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-allowed-users"><term><literal>allowed-users</literal></term>

    <listitem>

      <para>A list of names of users (separated by whitespace) that
      are allowed to connect to the Nix daemon. As with the
      <option>trusted-users</option> option, you can specify groups by
      prefixing them with <literal>@</literal>. Also, you can allow
      all users by specifying <literal>*</literal>. The default is
      <literal>*</literal>.</para>

      <para>Note that trusted users are always allowed to connect.</para>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="conf-auto-optimise-store"><term><literal>auto-optimise-store</literal></term>

    <listitem><para>If set to <literal>true</literal>, Nix
    automatically detects files in the store that have identical
    contents, and replaces them with hard links to a single copy.
    This saves disk space.  If set to <literal>false</literal> (the
    default), you can still run <command>nix-store
    --optimise</command> to get rid of duplicate
    files.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-builders">
    <term><literal>builders</literal></term>
    <listitem>
      <para>A list of machines on which to perform builds. <phrase condition="manual">See <xref linkend="chap-distributed-builds"/> for details.</phrase></para>
    </listitem>
  </varlistentry>


  <varlistentry xml:id="conf-builders-use-substitutes"><term><literal>builders-use-substitutes</literal></term>

    <listitem><para>If set to <literal>true</literal>, Nix will instruct
    remote build machines to use their own binary substitutes if available. In
    practical terms, this means that remote hosts will fetch as many build
    dependencies as possible from their own substitutes (e.g, from
    <literal>cache.nixos.org</literal>), instead of waiting for this host to
    upload them all. This can drastically reduce build times if the network
    connection between this computer and the remote build host is slow. Defaults
    to <literal>false</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-build-users-group"><term><literal>build-users-group</literal></term>

    <listitem><para>This options specifies the Unix group containing
    the Nix build user accounts.  In multi-user Nix installations,
    builds should not be performed by the Nix account since that would
    allow users to arbitrarily modify the Nix store and database by
    supplying specially crafted builders; and they cannot be performed
    by the calling user since that would allow him/her to influence
    the build result.</para>

    <para>Therefore, if this option is non-empty and specifies a valid
    group, builds will be performed under the user accounts that are a
    member of the group specified here (as listed in
    <filename>/etc/group</filename>).  Those user accounts should not
    be used for any other purpose!</para>

    <para>Nix will never run two builds under the same user account at
    the same time.  This is to prevent an obvious security hole: a
    malicious user writing a Nix expression that modifies the build
    result of a legitimate Nix expression being built by another user.
    Therefore it is good to have as many Nix build user accounts as
    you can spare.  (Remember: uids are cheap.)</para>

    <para>The build users should have permission to create files in
    the Nix store, but not delete them.  Therefore,
    <filename>/nix/store</filename> should be owned by the Nix
    account, its group should be the group specified here, and its
    mode should be <literal>1775</literal>.</para>

    <para>If the build users group is empty, builds will be performed
    under the uid of the Nix process (that is, the uid of the caller
    if <envar>NIX_REMOTE</envar> is empty, the uid under which the Nix
    daemon runs if <envar>NIX_REMOTE</envar> is
    <literal>daemon</literal>).  Obviously, this should not be used in
    multi-user settings with untrusted users.</para>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="conf-compress-build-log"><term><literal>compress-build-log</literal></term>

    <listitem><para>If set to <literal>true</literal> (the default),
    build logs written to <filename>/nix/var/log/nix/drvs</filename>
    will be compressed on the fly using bzip2.  Otherwise, they will
    not be compressed.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-connect-timeout"><term><literal>connect-timeout</literal></term>

    <listitem>

      <para>The timeout (in seconds) for establishing connections in
      the binary cache substituter.  It corresponds to
      <command>curl</command>&#x2019;s <option>--connect-timeout</option>
      option.</para>

    </listitem>

  </varlistentry>


  <varlistentry xml:id="conf-cores"><term><literal>cores</literal></term>

    <listitem><para>Sets the value of the
    <envar>NIX_BUILD_CORES</envar> environment variable in the
    invocation of builders.  Builders can use this variable at their
    discretion to control the maximum amount of parallelism.  For
    instance, in Nixpkgs, if the derivation attribute
    <varname>enableParallelBuilding</varname> is set to
    <literal>true</literal>, the builder passes the
    <option>-j<replaceable>N</replaceable></option> flag to GNU Make.
    It can be overridden using the <option linkend="opt-cores">--cores</option> command line switch and
    defaults to <literal>1</literal>.  The value <literal>0</literal>
    means that the builder should use all available CPU cores in the
    system.</para>

    <para>See also <xref linkend="chap-tuning-cores-and-jobs"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-diff-hook"><term><literal>diff-hook</literal></term>
  <listitem>
    <para>
      Absolute path to an executable capable of diffing build results.
      The hook executes if <xref linkend="conf-run-diff-hook"/> is
      true, and the output of a build is known to not be the same.
      This program is not executed to determine if two results are the
      same.
    </para>

    <para>
      The diff hook is executed by the same user and group who ran the
      build. However, the diff hook does not have write access to the
      store path just built.
    </para>

    <para>The diff hook program receives three parameters:</para>

    <orderedlist>
      <listitem>
        <para>
          A path to the previous build's results
        </para>
      </listitem>

      <listitem>
        <para>
          A path to the current build's results
        </para>
      </listitem>

      <listitem>
        <para>
          The path to the build's derivation
        </para>
      </listitem>

      <listitem>
        <para>
          The path to the build's scratch directory. This directory
          will exist only if the build was run with
          <option>--keep-failed</option>.
        </para>
      </listitem>
    </orderedlist>

    <para>
      The stderr and stdout output from the diff hook will not be
      displayed to the user. Instead, it will print to the nix-daemon's
      log.
    </para>

    <para>When using the Nix daemon, <literal>diff-hook</literal> must
    be set in the <filename>nix.conf</filename> configuration file, and
    cannot be passed at the command line.
    </para>
  </listitem>
  </varlistentry>

  <varlistentry xml:id="conf-enforce-determinism">
    <term><literal>enforce-determinism</literal></term>

    <listitem><para>See <xref linkend="conf-repeat"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-extra-sandbox-paths">
    <term><literal>extra-sandbox-paths</literal></term>

    <listitem><para>A list of additional paths appended to
    <option>sandbox-paths</option>. Useful if you want to extend
    its default value.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-extra-platforms"><term><literal>extra-platforms</literal></term>

    <listitem><para>Platforms other than the native one which
    this machine is capable of building for. This can be useful for
    supporting additional architectures on compatible machines:
    i686-linux can be built on x86_64-linux machines (and the default
    for this setting reflects this); armv7 is backwards-compatible with
    armv6 and armv5tel; some aarch64 machines can also natively run
    32-bit ARM code; and qemu-user may be used to support non-native
    platforms (though this may be slow and buggy). Most values for this
    are not enabled by default because build systems will often
    misdetect the target platform and generate incompatible code, so you
    may wish to cross-check the results of using this option against
    proper natively-built versions of your
    derivations.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-extra-substituters"><term><literal>extra-substituters</literal></term>

    <listitem><para>Additional binary caches appended to those
    specified in <option>substituters</option>.  When used by
    unprivileged users, untrusted substituters (i.e. those not listed
    in <option>trusted-substituters</option>) are silently
    ignored.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-fallback"><term><literal>fallback</literal></term>

    <listitem><para>If set to <literal>true</literal>, Nix will fall
    back to building from source if a binary substitute fails.  This
    is equivalent to the <option>--fallback</option> flag.  The
    default is <literal>false</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-fsync-metadata"><term><literal>fsync-metadata</literal></term>

    <listitem><para>If set to <literal>true</literal>, changes to the
    Nix store metadata (in <filename>/nix/var/nix/db</filename>) are
    synchronously flushed to disk.  This improves robustness in case
    of system crashes, but reduces performance.  The default is
    <literal>true</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-hashed-mirrors"><term><literal>hashed-mirrors</literal></term>

    <listitem><para>A list of web servers used by
    <function>builtins.fetchurl</function> to obtain files by hash.
    Given a hash type <replaceable>ht</replaceable> and a base-16 hash
    <replaceable>h</replaceable>, Nix will try to download the file
    from
    <literal>hashed-mirror/<replaceable>ht</replaceable>/<replaceable>h</replaceable></literal>.
    This allows files to be downloaded even if they have disappeared
    from their original URI. For example, given the hashed mirror
    <literal>http://tarballs.example.com/</literal>, when building the
    derivation

<programlisting>
builtins.fetchurl {
  url = "https://example.org/foo-1.2.3.tar.xz";
  sha256 = "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae";
}
</programlisting>

    Nix will attempt to download this file from
    <literal>http://tarballs.example.com/sha256/2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae</literal>
    first. If it is not available there, if will try the original URI.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-http-connections"><term><literal>http-connections</literal></term>

    <listitem><para>The maximum number of parallel TCP connections
    used to fetch files from binary caches and by other downloads. It
    defaults to 25. 0 means no limit.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-keep-build-log"><term><literal>keep-build-log</literal></term>

    <listitem><para>If set to <literal>true</literal> (the default),
    Nix will write the build log of a derivation (i.e. the standard
    output and error of its builder) to the directory
    <filename>/nix/var/log/nix/drvs</filename>.  The build log can be
    retrieved using the command <command>nix-store -l
    <replaceable>path</replaceable></command>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-keep-derivations"><term><literal>keep-derivations</literal></term>

    <listitem><para>If <literal>true</literal> (default), the garbage
    collector will keep the derivations from which non-garbage store
    paths were built.  If <literal>false</literal>, they will be
    deleted unless explicitly registered as a root (or reachable from
    other roots).</para>

    <para>Keeping derivation around is useful for querying and
    traceability (e.g., it allows you to ask with what dependencies or
    options a store path was built), so by default this option is on.
    Turn it off to save a bit of disk space (or a lot if
    <literal>keep-outputs</literal> is also turned on).</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-keep-env-derivations"><term><literal>keep-env-derivations</literal></term>

    <listitem><para>If <literal>false</literal> (default), derivations
    are not stored in Nix user environments.  That is, the derivations of
    any build-time-only dependencies may be garbage-collected.</para>

    <para>If <literal>true</literal>, when you add a Nix derivation to
    a user environment, the path of the derivation is stored in the
    user environment.  Thus, the derivation will not be
    garbage-collected until the user environment generation is deleted
    (<command>nix-env --delete-generations</command>).  To prevent
    build-time-only dependencies from being collected, you should also
    turn on <literal>keep-outputs</literal>.</para>

    <para>The difference between this option and
    <literal>keep-derivations</literal> is that this one is
    &#x201C;sticky&#x201D;: it applies to any user environment created while this
    option was enabled, while <literal>keep-derivations</literal>
    only applies at the moment the garbage collector is
    run.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-keep-outputs"><term><literal>keep-outputs</literal></term>

    <listitem><para>If <literal>true</literal>, the garbage collector
    will keep the outputs of non-garbage derivations.  If
    <literal>false</literal> (default), outputs will be deleted unless
    they are GC roots themselves (or reachable from other roots).</para>

    <para>In general, outputs must be registered as roots separately.
    However, even if the output of a derivation is registered as a
    root, the collector will still delete store paths that are used
    only at build time (e.g., the C compiler, or source tarballs
    downloaded from the network).  To prevent it from doing so, set
    this option to <literal>true</literal>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-max-build-log-size"><term><literal>max-build-log-size</literal></term>

    <listitem>

      <para>This option defines the maximum number of bytes that a
      builder can write to its stdout/stderr.  If the builder exceeds
      this limit, it&#x2019;s killed.  A value of <literal>0</literal> (the
      default) means that there is no limit.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-max-free"><term><literal>max-free</literal></term>

    <listitem><para>When a garbage collection is triggered by the
    <literal>min-free</literal> option, it stops as soon as
    <literal>max-free</literal> bytes are available. The default is
    infinity (i.e. delete all garbage).</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-max-jobs"><term><literal>max-jobs</literal></term>

    <listitem><para>This option defines the maximum number of jobs
    that Nix will try to build in parallel.  The default is
    <literal>1</literal>. The special value <literal>auto</literal>
    causes Nix to use the number of CPUs in your system.  <literal>0</literal>
    is useful when using remote builders to prevent any local builds (except for
    <literal>preferLocalBuild</literal> derivation attribute which executes locally
    regardless).  It can be
    overridden using the <option linkend="opt-max-jobs">--max-jobs</option> (<option>-j</option>)
    command line switch.</para>

    <para>See also <xref linkend="chap-tuning-cores-and-jobs"/>.</para>
    </listitem>
  </varlistentry>

  <varlistentry xml:id="conf-max-silent-time"><term><literal>max-silent-time</literal></term>

    <listitem>

      <para>This option defines the maximum number of seconds that a
      builder can go without producing any data on standard output or
      standard error.  This is useful (for instance in an automated
      build system) to catch builds that are stuck in an infinite
      loop, or to catch remote builds that are hanging due to network
      problems.  It can be overridden using the <option linkend="opt-max-silent-time">--max-silent-time</option> command
      line switch.</para>

      <para>The value <literal>0</literal> means that there is no
      timeout.  This is also the default.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-min-free"><term><literal>min-free</literal></term>

    <listitem>
      <para>When free disk space in <filename>/nix/store</filename>
      drops below <literal>min-free</literal> during a build, Nix
      performs a garbage-collection until <literal>max-free</literal>
      bytes are available or there is no more garbage.  A value of
      <literal>0</literal> (the default) disables this feature.</para>
    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-narinfo-cache-negative-ttl"><term><literal>narinfo-cache-negative-ttl</literal></term>

    <listitem>

      <para>The TTL in seconds for negative lookups. If a store path is
      queried from a substituter but was not found, there will be a
      negative lookup cached in the local disk cache database for the
      specified duration.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-narinfo-cache-positive-ttl"><term><literal>narinfo-cache-positive-ttl</literal></term>

    <listitem>

      <para>The TTL in seconds for positive lookups. If a store path is
      queried from a substituter, the result of the query will be cached
      in the local disk cache database including some of the NAR
      metadata. The default TTL is a month, setting a shorter TTL for
      positive lookups can be useful for binary caches that have
      frequent garbage collection, in which case having a more frequent
      cache invalidation would prevent trying to pull the path again and
      failing with a hash mismatch if the build isn't reproducible.
      </para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-netrc-file"><term><literal>netrc-file</literal></term>

    <listitem><para>If set to an absolute path to a <filename>netrc</filename>
    file, Nix will use the HTTP authentication credentials in this file when
    trying to download from a remote host through HTTP or HTTPS. Defaults to
    <filename>$NIX_CONF_DIR/netrc</filename>.</para>

    <para>The <filename>netrc</filename> file consists of a list of
    accounts in the following format:

<screen>
machine <replaceable>my-machine</replaceable>
login <replaceable>my-username</replaceable>
password <replaceable>my-password</replaceable>
</screen>

    For the exact syntax, see <link xlink:href="https://ec.haxx.se/usingcurl-netrc.html">the
    <literal>curl</literal> documentation.</link></para>

    <note><para>This must be an absolute path, and <literal>~</literal>
    is not resolved. For example, <filename>~/.netrc</filename> won't
    resolve to your home directory's <filename>.netrc</filename>.</para></note>
    </listitem>

  </varlistentry>


  <varlistentry xml:id="conf-plugin-files">
    <term><literal>plugin-files</literal></term>
    <listitem>
      <para>
        A list of plugin files to be loaded by Nix. Each of these
        files will be dlopened by Nix, allowing them to affect
        execution through static initialization. In particular, these
        plugins may construct static instances of RegisterPrimOp to
        add new primops or constants to the expression language,
        RegisterStoreImplementation to add new store implementations,
        RegisterCommand to add new subcommands to the
        <literal>nix</literal> command, and RegisterSetting to add new
        nix config settings. See the constructors for those types for
        more details.
      </para>
      <para>
        Since these files are loaded into the same address space as
        Nix itself, they must be DSOs compatible with the instance of
        Nix running at the time (i.e. compiled against the same
        headers, not linked to any incompatible libraries). They
        should not be linked to any Nix libs directly, as those will
        be available already at load time.
      </para>
      <para>
        If an entry in the list is a directory, all files in the
        directory are loaded as plugins (non-recursively).
      </para>
    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-pre-build-hook"><term><literal>pre-build-hook</literal></term>

    <listitem>


      <para>If set, the path to a program that can set extra
      derivation-specific settings for this system. This is used for settings
      that can't be captured by the derivation model itself and are too variable
      between different versions of the same system to be hard-coded into nix.
      </para>

      <para>The hook is passed the derivation path and, if sandboxes are enabled,
      the sandbox directory. It can then modify the sandbox and send a series of
      commands to modify various settings to stdout. The currently recognized
      commands are:</para>

      <variablelist>
        <varlistentry xml:id="extra-sandbox-paths">
          <term><literal>extra-sandbox-paths</literal></term>

          <listitem>

            <para>Pass a list of files and directories to be included in the
            sandbox for this build. One entry per line, terminated by an empty
            line. Entries have the same format as
            <literal>sandbox-paths</literal>.</para>

          </listitem>

        </varlistentry>
      </variablelist>
    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-post-build-hook">
    <term><literal>post-build-hook</literal></term>
    <listitem>
      <para>Optional. The path to a program to execute after each build.</para>

      <para>This option is only settable in the global
      <filename>nix.conf</filename>, or on the command line by trusted
      users.</para>

      <para>When using the nix-daemon, the daemon executes the hook as
      <literal>root</literal>. If the nix-daemon is not involved, the
      hook runs as the user executing the nix-build.</para>

      <itemizedlist>
        <listitem><para>The hook executes after an evaluation-time build.</para></listitem>
        <listitem><para>The hook does not execute on substituted paths.</para></listitem>
        <listitem><para>The hook's output always goes to the user's terminal.</para></listitem>
        <listitem><para>If the hook fails, the build succeeds but no further builds execute.</para></listitem>
        <listitem><para>The hook executes synchronously, and blocks other builds from progressing while it runs.</para></listitem>
      </itemizedlist>

      <para>The program executes with no arguments. The program's environment
      contains the following environment variables:</para>

      <variablelist>
        <varlistentry>
          <term><envar>DRV_PATH</envar></term>
          <listitem>
            <para>The derivation for the built paths.</para>
            <para>Example:
            <literal>/nix/store/5nihn1a7pa8b25l9zafqaqibznlvvp3f-bash-4.4-p23.drv</literal>
            </para>
          </listitem>
        </varlistentry>

        <varlistentry>
          <term><envar>OUT_PATHS</envar></term>
          <listitem>
            <para>Output paths of the built derivation, separated by a space character.</para>
            <para>Example:
            <literal>/nix/store/zf5lbh336mnzf1nlswdn11g4n2m8zh3g-bash-4.4-p23-dev
            /nix/store/rjxwxwv1fpn9wa2x5ssk5phzwlcv4mna-bash-4.4-p23-doc
            /nix/store/6bqvbzjkcp9695dq0dpl5y43nvy37pq1-bash-4.4-p23-info
            /nix/store/r7fng3kk3vlpdlh2idnrbn37vh4imlj2-bash-4.4-p23-man
            /nix/store/xfghy8ixrhz3kyy6p724iv3cxji088dx-bash-4.4-p23</literal>.
            </para>
          </listitem>
        </varlistentry>
      </variablelist>

      <para>See <xref linkend="chap-post-build-hook"/> for an example
      implementation.</para>

    </listitem>
  </varlistentry>

  <varlistentry xml:id="conf-repeat"><term><literal>repeat</literal></term>

    <listitem><para>How many times to repeat builds to check whether
    they are deterministic. The default value is 0. If the value is
    non-zero, every build is repeated the specified number of
    times. If the contents of any of the runs differs from the
    previous ones and <xref linkend="conf-enforce-determinism"/> is
    true, the build is rejected and the resulting store paths are not
    registered as &#x201C;valid&#x201D; in Nix&#x2019;s database.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-require-sigs"><term><literal>require-sigs</literal></term>

    <listitem><para>If set to <literal>true</literal> (the default),
    any non-content-addressed path added or copied to the Nix store
    (e.g. when substituting from a binary cache) must have a valid
    signature, that is, be signed using one of the keys listed in
    <option>trusted-public-keys</option> or
    <option>secret-key-files</option>. Set to <literal>false</literal>
    to disable signature checking.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-restrict-eval"><term><literal>restrict-eval</literal></term>

    <listitem>

      <para>If set to <literal>true</literal>, the Nix evaluator will
      not allow access to any files outside of the Nix search path (as
      set via the <envar>NIX_PATH</envar> environment variable or the
      <option>-I</option> option), or to URIs outside of
      <option>allowed-uri</option>. The default is
      <literal>false</literal>.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-run-diff-hook"><term><literal>run-diff-hook</literal></term>
  <listitem>
    <para>
      If true, enable the execution of <xref linkend="conf-diff-hook"/>.
    </para>

    <para>
      When using the Nix daemon, <literal>run-diff-hook</literal> must
      be set in the <filename>nix.conf</filename> configuration file,
      and cannot be passed at the command line.
    </para>
  </listitem>
  </varlistentry>

  <varlistentry xml:id="conf-sandbox"><term><literal>sandbox</literal></term>

    <listitem><para>If set to <literal>true</literal>, builds will be
    performed in a <emphasis>sandboxed environment</emphasis>, i.e.,
    they&#x2019;re isolated from the normal file system hierarchy and will
    only see their dependencies in the Nix store, the temporary build
    directory, private versions of <filename>/proc</filename>,
    <filename>/dev</filename>, <filename>/dev/shm</filename> and
    <filename>/dev/pts</filename> (on Linux), and the paths configured with the
    <link linkend="conf-sandbox-paths"><literal>sandbox-paths</literal>
    option</link>. This is useful to prevent undeclared dependencies
    on files in directories such as <filename>/usr/bin</filename>. In
    addition, on Linux, builds run in private PID, mount, network, IPC
    and UTS namespaces to isolate them from other processes in the
    system (except that fixed-output derivations do not run in private
    network namespace to ensure they can access the network).</para>

    <para>Currently, sandboxing only work on Linux and macOS. The use
    of a sandbox requires that Nix is run as root (so you should use
    the <link linkend="conf-build-users-group">&#x201C;build users&#x201D;
    feature</link> to perform the actual builds under different users
    than root).</para>

    <para>If this option is set to <literal>relaxed</literal>, then
    fixed-output derivations and derivations that have the
    <varname>__noChroot</varname> attribute set to
    <literal>true</literal> do not run in sandboxes.</para>

    <para>The default is <literal>true</literal> on Linux and
    <literal>false</literal> on all other platforms.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-sandbox-dev-shm-size"><term><literal>sandbox-dev-shm-size</literal></term>

    <listitem><para>This option determines the maximum size of the
    <literal>tmpfs</literal> filesystem mounted on
    <filename>/dev/shm</filename> in Linux sandboxes. For the format,
    see the description of the <option>size</option> option of
    <literal>tmpfs</literal> in
    <citerefentry><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>. The
    default is <literal>50%</literal>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-sandbox-paths">
    <term><literal>sandbox-paths</literal></term>

    <listitem><para>A list of paths bind-mounted into Nix sandbox
    environments. You can use the syntax
    <literal><replaceable>target</replaceable>=<replaceable>source</replaceable></literal>
    to mount a path in a different location in the sandbox; for
    instance, <literal>/bin=/nix-bin</literal> will mount the path
    <literal>/nix-bin</literal> as <literal>/bin</literal> inside the
    sandbox. If <replaceable>source</replaceable> is followed by
    <literal>?</literal>, then it is not an error if
    <replaceable>source</replaceable> does not exist; for example,
    <literal>/dev/nvidiactl?</literal> specifies that
    <filename>/dev/nvidiactl</filename> will only be mounted in the
    sandbox if it exists in the host filesystem.</para>

    <para>Depending on how Nix was built, the default value for this option
    may be empty or provide <filename>/bin/sh</filename> as a
    bind-mount of <command>bash</command>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-secret-key-files"><term><literal>secret-key-files</literal></term>

    <listitem><para>A whitespace-separated list of files containing
    secret (private) keys. These are used to sign locally-built
    paths. They can be generated using <command>nix-store
    --generate-binary-cache-key</command>. The corresponding public
    key can be distributed to other users, who can add it to
    <option>trusted-public-keys</option> in their
    <filename>nix.conf</filename>.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-show-trace"><term><literal>show-trace</literal></term>

    <listitem><para>Causes Nix to print out a stack trace in case of Nix
    expression evaluation errors.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-substitute"><term><literal>substitute</literal></term>

    <listitem><para>If set to <literal>true</literal> (default), Nix
    will use binary substitutes if available.  This option can be
    disabled to force building from source.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-stalled-download-timeout"><term><literal>stalled-download-timeout</literal></term>
    <listitem>
      <para>The timeout (in seconds) for receiving data from servers
      during download. Nix cancels idle downloads after this timeout's
      duration.</para>
    </listitem>
  </varlistentry>

  <varlistentry xml:id="conf-substituters"><term><literal>substituters</literal></term>

    <listitem><para>A list of URLs of substituters, separated by
    whitespace.  The default is
    <literal>https://cache.nixos.org</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-system"><term><literal>system</literal></term>

    <listitem><para>This option specifies the canonical Nix system
    name of the current installation, such as
    <literal>i686-linux</literal> or
    <literal>x86_64-darwin</literal>.  Nix can only build derivations
    whose <literal>system</literal> attribute equals the value
    specified here.  In general, it never makes sense to modify this
    value from its default, since you can use it to &#x2018;lie&#x2019; about the
    platform you are building on (e.g., perform a Mac OS build on a
    Linux machine; the result would obviously be wrong).  It only
    makes sense if the Nix binaries can run on multiple platforms,
    e.g., &#x2018;universal binaries&#x2019; that run on <literal>x86_64-linux</literal> and
    <literal>i686-linux</literal>.</para>

    <para>It defaults to the canonical Nix system name detected by
    <filename>configure</filename> at build time.</para></listitem>

  </varlistentry>


  <varlistentry xml:id="conf-system-features"><term><literal>system-features</literal></term>

    <listitem><para>A set of system &#x201C;features&#x201D; supported by this
    machine, e.g. <literal>kvm</literal>. Derivations can express a
    dependency on such features through the derivation attribute
    <varname>requiredSystemFeatures</varname>. For example, the
    attribute

<programlisting>
requiredSystemFeatures = [ "kvm" ];
</programlisting>

    ensures that the derivation can only be built on a machine with
    the <literal>kvm</literal> feature.</para>

    <para>This setting by default includes <literal>kvm</literal> if
    <filename>/dev/kvm</filename> is accessible, and the
    pseudo-features <literal>nixos-test</literal>,
    <literal>benchmark</literal> and <literal>big-parallel</literal>
    that are used in Nixpkgs to route builds to specific
    machines.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-tarball-ttl"><term><literal>tarball-ttl</literal></term>

    <listitem>
      <para>Default: <literal>3600</literal> seconds.</para>

      <para>The number of seconds a downloaded tarball is considered
      fresh. If the cached tarball is stale, Nix will check whether
      it is still up to date using the ETag header. Nix will download
      a new version if the ETag header is unsupported, or the
      cached ETag doesn't match.
      </para>

      <para>Setting the TTL to <literal>0</literal> forces Nix to always
      check if the tarball is up to date.</para>

      <para>Nix caches tarballs in
      <filename>$XDG_CACHE_HOME/nix/tarballs</filename>.</para>

      <para>Files fetched via <envar>NIX_PATH</envar>,
      <function>fetchGit</function>, <function>fetchMercurial</function>,
      <function>fetchTarball</function>, and <function>fetchurl</function>
      respect this TTL.
      </para>
    </listitem>
  </varlistentry>

  <varlistentry xml:id="conf-timeout"><term><literal>timeout</literal></term>

    <listitem>

      <para>This option defines the maximum number of seconds that a
      builder can run.  This is useful (for instance in an automated
      build system) to catch builds that are stuck in an infinite loop
      but keep writing to their standard output or standard error.  It
      can be overridden using the <option linkend="opt-timeout">--timeout</option> command line
      switch.</para>

      <para>The value <literal>0</literal> means that there is no
      timeout.  This is also the default.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-trace-function-calls"><term><literal>trace-function-calls</literal></term>

    <listitem>

      <para>Default: <literal>false</literal>.</para>

      <para>If set to <literal>true</literal>, the Nix evaluator will
      trace every function call. Nix will print a log message at the
      "vomit" level for every function entrance and function exit.</para>

      <informalexample><screen>
function-trace entered undefined position at 1565795816999559622
function-trace exited undefined position at 1565795816999581277
function-trace entered /nix/store/.../example.nix:226:41 at 1565795253249935150
function-trace exited /nix/store/.../example.nix:226:41 at 1565795253249941684
</screen></informalexample>

      <para>The <literal>undefined position</literal> means the function
      call is a builtin.</para>

      <para>Use the <literal>contrib/stack-collapse.py</literal> script
      distributed with the Nix source code to convert the trace logs
      in to a format suitable for <command>flamegraph.pl</command>.</para>

    </listitem>

  </varlistentry>

  <varlistentry xml:id="conf-trusted-public-keys"><term><literal>trusted-public-keys</literal></term>

    <listitem><para>A whitespace-separated list of public keys. When
    paths are copied from another Nix store (such as a binary cache),
    they must be signed with one of these keys. For example:
    <literal>cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
    hydra.nixos.org-1:CNHJZBh9K4tP3EKF6FkkgeVYsS3ohTl+oS0Qa8bezVs=</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-trusted-substituters"><term><literal>trusted-substituters</literal></term>

    <listitem><para>A list of URLs of substituters, separated by
    whitespace.  These are not used by default, but can be enabled by
    users of the Nix daemon by specifying <literal>--option
    substituters <replaceable>urls</replaceable></literal> on the
    command line.  Unprivileged users are only allowed to pass a
    subset of the URLs listed in <literal>substituters</literal> and
    <literal>trusted-substituters</literal>.</para></listitem>

  </varlistentry>

  <varlistentry xml:id="conf-trusted-users"><term><literal>trusted-users</literal></term>

    <listitem>

      <para>A list of names of users (separated by whitespace) that
      have additional rights when connecting to the Nix daemon, such
      as the ability to specify additional binary caches, or to import
      unsigned NARs. You can also specify groups by prefixing them
      with <literal>@</literal>; for instance,
      <literal>@wheel</literal> means all users in the
      <literal>wheel</literal> group. The default is
      <literal>root</literal>.</para>

      <warning><para>Adding a user to <option>trusted-users</option>
      is essentially equivalent to giving that user root access to the
      system. For example, the user can set
      <option>sandbox-paths</option> and thereby obtain read access to
      directories that are otherwise inacessible to
      them.</para></warning>

    </listitem>

  </varlistentry>

</variablelist>
</para>

<refsection>
  <title>Deprecated Settings</title>

<para>

<variablelist>

  <varlistentry xml:id="conf-binary-caches">
    <term><literal>binary-caches</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>binary-caches</literal> is now an alias to
    <xref linkend="conf-substituters"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-binary-cache-public-keys">
    <term><literal>binary-cache-public-keys</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>binary-cache-public-keys</literal> is now an alias to
    <xref linkend="conf-trusted-public-keys"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-compress-log">
    <term><literal>build-compress-log</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-compress-log</literal> is now an alias to
    <xref linkend="conf-compress-build-log"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-cores">
    <term><literal>build-cores</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-cores</literal> is now an alias to
    <xref linkend="conf-cores"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-extra-chroot-dirs">
    <term><literal>build-extra-chroot-dirs</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-extra-chroot-dirs</literal> is now an alias to
    <xref linkend="conf-extra-sandbox-paths"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-extra-sandbox-paths">
    <term><literal>build-extra-sandbox-paths</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-extra-sandbox-paths</literal> is now an alias to
    <xref linkend="conf-extra-sandbox-paths"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-fallback">
    <term><literal>build-fallback</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-fallback</literal> is now an alias to
    <xref linkend="conf-fallback"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-max-jobs">
    <term><literal>build-max-jobs</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-max-jobs</literal> is now an alias to
    <xref linkend="conf-max-jobs"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-max-log-size">
    <term><literal>build-max-log-size</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-max-log-size</literal> is now an alias to
    <xref linkend="conf-max-build-log-size"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-max-silent-time">
    <term><literal>build-max-silent-time</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-max-silent-time</literal> is now an alias to
    <xref linkend="conf-max-silent-time"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-repeat">
    <term><literal>build-repeat</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-repeat</literal> is now an alias to
    <xref linkend="conf-repeat"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-timeout">
    <term><literal>build-timeout</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-timeout</literal> is now an alias to
    <xref linkend="conf-timeout"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-use-chroot">
    <term><literal>build-use-chroot</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-use-chroot</literal> is now an alias to
    <xref linkend="conf-sandbox"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-use-sandbox">
    <term><literal>build-use-sandbox</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-use-sandbox</literal> is now an alias to
    <xref linkend="conf-sandbox"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-build-use-substitutes">
    <term><literal>build-use-substitutes</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>build-use-substitutes</literal> is now an alias to
    <xref linkend="conf-substitute"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-gc-keep-derivations">
    <term><literal>gc-keep-derivations</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>gc-keep-derivations</literal> is now an alias to
    <xref linkend="conf-keep-derivations"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-gc-keep-outputs">
    <term><literal>gc-keep-outputs</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>gc-keep-outputs</literal> is now an alias to
    <xref linkend="conf-keep-outputs"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-env-keep-derivations">
    <term><literal>env-keep-derivations</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>env-keep-derivations</literal> is now an alias to
    <xref linkend="conf-keep-env-derivations"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-extra-binary-caches">
    <term><literal>extra-binary-caches</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>extra-binary-caches</literal> is now an alias to
    <xref linkend="conf-extra-substituters"/>.</para></listitem>
  </varlistentry>

  <varlistentry xml:id="conf-trusted-binary-caches">
    <term><literal>trusted-binary-caches</literal></term>

    <listitem><para><emphasis>Deprecated:</emphasis>
    <literal>trusted-binary-caches</literal> is now an alias to
    <xref linkend="conf-trusted-substituters"/>.</para></listitem>
  </varlistentry>
</variablelist>
</para>
</refsection>

</refsection>

</refentry>

</chapter>

</part>
  <appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="part-glossary" xml:base="glossary/glossary.xml">

<title>Glossary</title>


<glosslist>


<glossentry xml:id="gloss-derivation"><glossterm>derivation</glossterm>

  <glossdef><para>A description of a build action.  The result of a
  derivation is a store object.  Derivations are typically specified
  in Nix expressions using the <link linkend="ssec-derivation"><function>derivation</function>
  primitive</link>.  These are translated into low-level
  <emphasis>store derivations</emphasis> (implicitly by
  <command>nix-env</command> and <command>nix-build</command>, or
  explicitly by <command>nix-instantiate</command>).</para></glossdef>

</glossentry>


<glossentry><glossterm>store</glossterm>

  <glossdef><para>The location in the file system where store objects
  live.  Typically <filename>/nix/store</filename>.</para></glossdef>

</glossentry>


<glossentry><glossterm>store path</glossterm>

  <glossdef><para>The location in the file system of a store object,
  i.e., an immediate child of the Nix store
  directory.</para></glossdef>

</glossentry>


<glossentry><glossterm>store object</glossterm>

  <glossdef><para>A file that is an immediate child of the Nix store
  directory.  These can be regular files, but also entire directory
  trees.  Store objects can be sources (objects copied from outside of
  the store), derivation outputs (objects produced by running a build
  action), or derivations (files describing a build
  action).</para></glossdef>

</glossentry>


<glossentry xml:id="gloss-substitute"><glossterm>substitute</glossterm>

  <glossdef><para>A substitute is a command invocation stored in the
  Nix database that describes how to build a store object, bypassing
  the normal build mechanism (i.e., derivations).  Typically, the
  substitute builds the store object by downloading a pre-built
  version of the store object from some server.</para></glossdef>

</glossentry>


<glossentry><glossterm>purity</glossterm>

  <glossdef><para>The assumption that equal Nix derivations when run
  always produce the same output.  This cannot be guaranteed in
  general (e.g., a builder can rely on external inputs such as the
  network or the system time) but the Nix model assumes
  it.</para></glossdef>

</glossentry>


<glossentry><glossterm>Nix expression</glossterm>

  <glossdef><para>A high-level description of software packages and
  compositions thereof.  Deploying software using Nix entails writing
  Nix expressions for your packages.  Nix expressions are translated
  to derivations that are stored in the Nix store.  These derivations
  can then be built.</para></glossdef>

</glossentry>


<glossentry xml:id="gloss-reference"><glossterm>reference</glossterm>

  <glossdef>
    <para>A store path <varname>P</varname> is said to have a
    reference to a store path <varname>Q</varname> if the store object
    at <varname>P</varname> contains the path <varname>Q</varname>
    somewhere. The <emphasis>references</emphasis> of a store path are
    the set of store paths to which it has a reference.
    </para>
    <para>A derivation can reference other derivations and sources
    (but not output paths), whereas an output path only references other
    output paths.
    </para>
  </glossdef>

</glossentry>

<glossentry xml:id="gloss-reachable"><glossterm>reachable</glossterm>

  <glossdef><para>A store path <varname>Q</varname> is reachable from
  another store path <varname>P</varname> if <varname>Q</varname> is in the
  <link linkend="gloss-closure">closure</link> of the
  <link linkend="gloss-reference">references</link> relation.
  </para></glossdef>
</glossentry>

<glossentry xml:id="gloss-closure"><glossterm>closure</glossterm>

  <glossdef><para>The closure of a store path is the set of store
  paths that are directly or indirectly &#x201C;reachable&#x201D; from that store
  path; that is, it&#x2019;s the closure of the path under the <link linkend="gloss-reference">references</link> relation. For a package, the
  closure of its derivation is equivalent to the build-time
  dependencies, while the closure of its output path is equivalent to its
  runtime dependencies. For correct deployment it is necessary to deploy whole
  closures, since otherwise at runtime files could be missing. The command
  <command>nix-store -qR</command> prints out closures of store paths.
  </para>
  <para>As an example, if the store object at path <varname>P</varname> contains
  a reference to path <varname>Q</varname>, then <varname>Q</varname> is
  in the closure of <varname>P</varname>. Further, if <varname>Q</varname>
  references <varname>R</varname> then <varname>R</varname> is also in
  the closure of <varname>P</varname>.
  </para></glossdef>

</glossentry>


<glossentry xml:id="gloss-output-path"><glossterm>output path</glossterm>

  <glossdef><para>A store path produced by a derivation.</para></glossdef>

</glossentry>


<glossentry xml:id="gloss-deriver"><glossterm>deriver</glossterm>

  <glossdef><para>The deriver of an <link linkend="gloss-output-path">output path</link> is the store
  derivation that built it.</para></glossdef>

</glossentry>


<glossentry xml:id="gloss-validity"><glossterm>validity</glossterm>

  <glossdef><para>A store path is considered
  <emphasis>valid</emphasis> if it exists in the file system, is
  listed in the Nix database as being valid, and if all paths in its
  closure are also valid.</para></glossdef>

</glossentry>


<glossentry xml:id="gloss-user-env"><glossterm>user environment</glossterm>

  <glossdef><para>An automatically generated store object that
  consists of a set of symlinks to &#x201C;active&#x201D; applications, i.e., other
  store paths.  These are generated automatically by <link linkend="sec-nix-env"><command>nix-env</command></link>.  See <xref linkend="sec-profiles"/>.</para>

  </glossdef>

</glossentry>


<glossentry xml:id="gloss-profile"><glossterm>profile</glossterm>

  <glossdef><para>A symlink to the current <link linkend="gloss-user-env">user environment</link> of a user, e.g.,
  <filename>/nix/var/nix/profiles/default</filename>.</para></glossdef>

</glossentry>


<glossentry xml:id="gloss-nar"><glossterm>NAR</glossterm>

  <glossdef><para>A <emphasis>N</emphasis>ix
  <emphasis>AR</emphasis>chive.  This is a serialisation of a path in
  the Nix store.  It can contain regular files, directories and
  symbolic links.  NARs are generated and unpacked using
  <command>nix-store --dump</command> and <command>nix-store
  --restore</command>.</para></glossdef>

</glossentry>



</glosslist>


</appendix>
  <appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="chap-hacking">

<title>Hacking</title>

<para>This section provides some notes on how to hack on Nix. To get
the latest version of Nix from GitHub:
<screen>
$ git clone https://github.com/NixOS/nix.git
$ cd nix
</screen>
</para>

<para>To build Nix for the current operating system/architecture use

<screen>
$ nix-build
</screen>

or if you have a flakes-enabled nix:

<screen>
$ nix build
</screen>

This will build <literal>defaultPackage</literal> attribute defined in the <literal>flake.nix</literal> file.

To build for other platforms add one of the following suffixes to it: aarch64-linux,
i686-linux, x86_64-darwin, x86_64-linux.

i.e.

<screen>
nix-build -A defaultPackage.x86_64-linux
</screen>

</para>

<para>To build all dependencies and start a shell in which all
environment variables are set up so that those dependencies can be
found:
<screen>
$ nix-shell
</screen>
To build Nix itself in this shell:
<screen>
[nix-shell]$ ./bootstrap.sh
[nix-shell]$ ./configure $configureFlags
[nix-shell]$ make -j $NIX_BUILD_CORES
</screen>
To install it in <literal>$(pwd)/inst</literal> and test it:
<screen>
[nix-shell]$ make install
[nix-shell]$ make installcheck
[nix-shell]$ ./inst/bin/nix --version
nix (Nix) 2.4
</screen>

If you have a flakes-enabled nix you can replace:

<screen>
$ nix-shell
</screen>

by:

<screen>
$ nix develop
</screen>

</para>

</appendix>
  <appendix xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="sec-relnotes" xml:base="release-notes/release-notes.xml">

<title>Nix Release Notes</title>

<!--
<partintro>
<para>This section lists the release notes for each stable version of Nix.</para>
</partintro>
-->

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-2.3">

<title>Release 2.3 (2019-09-04)</title>

<para>This is primarily a bug fix release. However, it makes some
incompatible changes:</para>

<itemizedlist>

  <listitem>
    <para>Nix now uses BSD file locks instead of POSIX file
    locks. Because of this, you should not use Nix 2.3 and previous
    releases at the same time on a Nix store.</para>
  </listitem>

</itemizedlist>

<para>It also has the following changes:</para>

<itemizedlist>

  <listitem>
    <para><function>builtins.fetchGit</function>'s <varname>ref</varname>
    argument now allows specifying an absolute remote ref.
    Nix will automatically prefix <varname>ref</varname> with
    <literal>refs/heads</literal> only if <varname>ref</varname> doesn't
    already begin with <literal>refs/</literal>.
    </para>
  </listitem>

  <listitem>
    <para>The installer now enables sandboxing by default on Linux when the
    system has the necessary kernel support.
    </para>
  </listitem>

  <listitem>
    <para>The <literal>max-jobs</literal> setting now defaults to 1.</para>
  </listitem>

  <listitem>
    <para>New builtin functions:
    <literal>builtins.isPath</literal>,
    <literal>builtins.hashFile</literal>.
    </para>
  </listitem>

  <listitem>
    <para>The <command>nix</command> command has a new
    <option>--print-build-logs</option> (<option>-L</option>) flag to
    print build log output to stderr, rather than showing the last log
    line in the progress bar. To distinguish between concurrent
    builds, log lines are prefixed by the name of the package.
    </para>
  </listitem>

  <listitem>
    <para>Builds are now executed in a pseudo-terminal, and the
    <envar>TERM</envar> environment variable is set to
    <literal>xterm-256color</literal>. This allows many programs
    (e.g. <command>gcc</command>, <command>clang</command>,
    <command>cmake</command>) to print colorized log output.</para>
  </listitem>

  <listitem>
    <para>Add <option>--no-net</option> convenience flag. This flag
    disables substituters; sets the <literal>tarball-ttl</literal>
    setting to infinity (ensuring that any previously downloaded files
    are considered current); and disables retrying downloads and sets
    the connection timeout to the minimum. This flag is enabled
    automatically if there are no configured non-loopback network
    interfaces.</para>
  </listitem>

  <listitem>
    <para>Add a <literal>post-build-hook</literal> setting to run a
    program after a build has succeeded.</para>
  </listitem>

  <listitem>
    <para>Add a <literal>trace-function-calls</literal> setting to log
    the duration of Nix function calls to stderr.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-2.2">

<title>Release 2.2 (2019-01-11)</title>

<para>This is primarily a bug fix release. It also has the following
changes:</para>

<itemizedlist>

  <listitem>
    <para>In derivations that use structured attributes (i.e. that
    specify set the <varname>__structuredAttrs</varname> attribute to
    <literal>true</literal> to cause all attributes to be passed to
    the builder in JSON format), you can now specify closure checks
    per output, e.g.:

<programlisting>
outputChecks."out" = {
  # The closure of 'out' must not be larger than 256 MiB.
  maxClosureSize = 256 * 1024 * 1024;

  # It must not refer to C compiler or to the 'dev' output.
  disallowedRequisites = [ stdenv.cc "dev" ];
};

outputChecks."dev" = {
  # The 'dev' output must not be larger than 128 KiB.
  maxSize = 128 * 1024;
};
</programlisting>

    </para>
  </listitem>


  <listitem>
    <para>The derivation attribute
    <varname>requiredSystemFeatures</varname> is now enforced for
    local builds, and not just to route builds to remote builders.
    The supported features of a machine can be specified through the
    configuration setting <varname>system-features</varname>.</para>

    <para>By default, <varname>system-features</varname> includes
    <literal>kvm</literal> if <filename>/dev/kvm</filename>
    exists. For compatibility, it also includes the pseudo-features
    <literal>nixos-test</literal>, <literal>benchmark</literal> and
    <literal>big-parallel</literal> which are used by Nixpkgs to route
    builds to particular Hydra build machines.</para>

  </listitem>

  <listitem>
    <para>Sandbox builds are now enabled by default on Linux.</para>
  </listitem>

  <listitem>
    <para>The new command <command>nix doctor</command> shows
    potential issues with your Nix installation.</para>
  </listitem>

  <listitem>
    <para>The <literal>fetchGit</literal> builtin function now uses a
    caching scheme that puts different remote repositories in distinct
    local repositories, rather than a single shared repository. This
    may require more disk space but is faster.</para>
  </listitem>

  <listitem>
    <para>The <literal>dirOf</literal> builtin function now works on
    relative paths.</para>
  </listitem>

  <listitem>
    <para>Nix now supports <link xlink:href="https://www.w3.org/TR/SRI/">SRI hashes</link>,
    allowing the hash algorithm and hash to be specified in a single
    string. For example, you can write:

<programlisting>
import &lt;nix/fetchurl.nix&gt; {
  url = https://nixos.org/releases/nix/nix-2.1.3/nix-2.1.3.tar.xz;
  hash = "sha256-XSLa0FjVyADWWhFfkZ2iKTjFDda6mMXjoYMXLRSYQKQ=";
};
</programlisting>

    instead of

<programlisting>
import &lt;nix/fetchurl.nix&gt; {
  url = https://nixos.org/releases/nix/nix-2.1.3/nix-2.1.3.tar.xz;
  sha256 = "5d22dad058d5c800d65a115f919da22938c50dd6ba98c5e3a183172d149840a4";
};
</programlisting>

    </para>

    <para>In fixed-output derivations, the
    <varname>outputHashAlgo</varname> attribute is no longer mandatory
    if <varname>outputHash</varname> specifies the hash.</para>

    <para><command>nix hash-file</command> and <command>nix
    hash-path</command> now print hashes in SRI format by
    default. They also use SHA-256 by default instead of SHA-512
    because that's what we use most of the time in Nixpkgs.</para>
  </listitem>

  <listitem>
    <para>Integers are now 64 bits on all platforms.</para>
  </listitem>

  <listitem>
    <para>The evaluator now prints profiling statistics (enabled via
    the <envar>NIX_SHOW_STATS</envar> and
    <envar>NIX_COUNT_CALLS</envar> environment variables) in JSON
    format.</para>
  </listitem>

  <listitem>
    <para>The option <option>--xml</option> in <command>nix-store
    --query</command> has been removed. Instead, there now is an
    option <option>--graphml</option> to output the dependency graph
    in GraphML format.</para>
  </listitem>

  <listitem>
    <para>All <filename>nix-*</filename> commands are now symlinks to
    <filename>nix</filename>. This saves a bit of disk space.</para>
  </listitem>

  <listitem>
    <para><command>nix repl</command> now uses
    <literal>libeditline</literal> or
    <literal>libreadline</literal>.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-2.1">

<title>Release 2.1 (2018-09-02)</title>

<para>This is primarily a bug fix release. It also reduces memory
consumption in certain situations. In addition, it has the following
new features:</para>

<itemizedlist>

  <listitem>
    <para>The Nix installer will no longer default to the Multi-User
    installation for macOS. You can still <link linkend="sect-multi-user-installation">instruct the installer to
    run in multi-user mode</link>.
    </para>
  </listitem>

  <listitem>
    <para>The Nix installer now supports performing a Multi-User
    installation for Linux computers which are running systemd. You
    can <link linkend="sect-multi-user-installation">select a Multi-User installation</link> by passing the
    <option>--daemon</option> flag to the installer: <command>sh &lt;(curl
    https://nixos.org/nix/install) --daemon</command>.
    </para>

    <para>The multi-user installer cannot handle systems with SELinux.
    If your system has SELinux enabled, you can <link linkend="sect-single-user-installation">force the installer to run
    in single-user mode</link>.</para>
  </listitem>

  <listitem>
    <para>New builtin functions:
    <literal>builtins.bitAnd</literal>,
    <literal>builtins.bitOr</literal>,
    <literal>builtins.bitXor</literal>,
    <literal>builtins.fromTOML</literal>,
    <literal>builtins.concatMap</literal>,
    <literal>builtins.mapAttrs</literal>.
    </para>
  </listitem>

  <listitem>
    <para>The S3 binary cache store now supports uploading NARs larger
    than 5 GiB.</para>
  </listitem>

  <listitem>
    <para>The S3 binary cache store now supports uploading to
    S3-compatible services with the <literal>endpoint</literal>
    option.</para>
  </listitem>

  <listitem>
    <para>The flag <option>--fallback</option> is no longer required
    to recover from disappeared NARs in binary caches.</para>
  </listitem>

  <listitem>
    <para><command>nix-daemon</command> now respects
    <option>--store</option>.</para>
  </listitem>

  <listitem>
    <para><command>nix run</command> now respects
    <varname>nix-support/propagated-user-env-packages</varname>.</para>
  </listitem>

</itemizedlist>

<para>This release has contributions from

Adrien Devresse,
Aleksandr Pashkov,
Alexandre Esteves,
Amine Chikhaoui,
Andrew Dunham,
Asad Saeeduddin,
aszlig,
Ben Challenor,
Ben Gamari,
Benjamin Hipple,
Bogdan Seniuc,
Corey O'Connor,
Daiderd Jordan,
Daniel Peebles,
Daniel Poelzleithner,
Danylo Hlynskyi,
Dmitry Kalinkin,
Domen Ko&#x17E;ar,
Doug Beardsley,
Eelco Dolstra,
Erik Arvstedt,
F&#xE9;lix Baylac-Jacqu&#xE9;,
Gleb Peregud,
Graham Christensen,
Guillaume Maudoux,
Ivan Kozik,
John Arnold,
Justin Humm,
Linus Heckemann,
Lorenzo Manacorda,
Matthew Justin Bauer,
Matthew O'Gorman,
Maximilian Bosch,
Michael Bishop,
Michael Fiano,
Michael Mercier,
Michael Raskin,
Michael Weiss,
Nicolas Dudebout,
Peter Simons,
Ryan Trinkle,
Samuel Dionne-Riel,
Sean Seefried,
Shea Levy,
Symphorien Gibol,
Tim Engler,
Tim Sears,
Tuomas Tynkkynen,
volth,
Will Dietz,
Yorick van Pelt and
zimbatm.
</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-2.0">

<title>Release 2.0 (2018-02-22)</title>

<para>The following incompatible changes have been made:</para>

<itemizedlist>

  <listitem>
    <para>The manifest-based substituter mechanism
    (<command>download-using-manifests</command>) has been <link xlink:href="https://github.com/NixOS/nix/commit/867967265b80946dfe1db72d40324b4f9af988ed">removed</link>. It
    has been superseded by the binary cache substituter mechanism
    since several years. As a result, the following programs have been
    removed:

    <itemizedlist>
      <listitem><para><command>nix-pull</command></para></listitem>
      <listitem><para><command>nix-generate-patches</command></para></listitem>
      <listitem><para><command>bsdiff</command></para></listitem>
      <listitem><para><command>bspatch</command></para></listitem>
    </itemizedlist>
    </para>
  </listitem>

  <listitem>
    <para>The &#x201C;copy from other stores&#x201D; substituter mechanism
    (<command>copy-from-other-stores</command> and the
    <envar>NIX_OTHER_STORES</envar> environment variable) has been
    removed. It was primarily used by the NixOS installer to copy
    available paths from the installation medium. The replacement is
    to use a chroot store as a substituter
    (e.g. <literal>--substituters /mnt</literal>), or to build into a
    chroot store (e.g. <literal>--store /mnt --substituters /</literal>).</para>
  </listitem>

  <listitem>
    <para>The command <command>nix-push</command> has been removed as
    part of the effort to eliminate Nix's dependency on Perl. You can
    use <command>nix copy</command> instead, e.g. <literal>nix copy
    --to file:///tmp/my-binary-cache <replaceable>paths&#x2026;</replaceable></literal></para>
  </listitem>

  <listitem>
    <para>The &#x201C;nested&#x201D; log output feature (<option>--log-type
    pretty</option>) has been removed. As a result,
    <command>nix-log2xml</command> was also removed.</para>
  </listitem>

  <listitem>
    <para>OpenSSL-based signing has been <link xlink:href="https://github.com/NixOS/nix/commit/f435f8247553656774dd1b2c88e9de5d59cab203">removed</link>. This
    feature was never well-supported. A better alternative is provided
    by the <option>secret-key-files</option> and
    <option>trusted-public-keys</option> options.</para>
  </listitem>

  <listitem>
    <para>Failed build caching has been <link xlink:href="https://github.com/NixOS/nix/commit/8cffec84859cec8b610a2a22ab0c4d462a9351ff">removed</link>. This
    feature was introduced to support the Hydra continuous build
    system, but Hydra no longer uses it.</para>
  </listitem>

  <listitem>
    <para><filename>nix-mode.el</filename> has been removed from
    Nix. It is now <link xlink:href="https://github.com/NixOS/nix-mode">a separate
    repository</link> and can be installed through the MELPA package
    repository.</para>
  </listitem>

</itemizedlist>

<para>This release has the following new features:</para>

<itemizedlist>

  <listitem>
    <para>It introduces a new command named <command>nix</command>,
    which is intended to eventually replace all
    <command>nix-*</command> commands with a more consistent and
    better designed user interface. It currently provides replacements
    for some (but not all) of the functionality provided by
    <command>nix-store</command>, <command>nix-build</command>,
    <command>nix-shell -p</command>, <command>nix-env -qa</command>,
    <command>nix-instantiate --eval</command>,
    <command>nix-push</command> and
    <command>nix-copy-closure</command>. It has the following major
    features:</para>

    <itemizedlist>

      <listitem>
        <para>Unlike the legacy commands, it has a consistent way to
        refer to packages and package-like arguments (like store
        paths). For example, the following commands all copy the GNU
        Hello package to a remote machine:

        <screen>nix copy --to ssh://machine nixpkgs.hello</screen>
        <screen>nix copy --to ssh://machine /nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10</screen>
        <screen>nix copy --to ssh://machine '(with import &lt;nixpkgs&gt; {}; hello)'</screen>

        By contrast, <command>nix-copy-closure</command> only accepted
        store paths as arguments.</para>
      </listitem>

      <listitem>
        <para>It is self-documenting: <option>--help</option> shows
        all available command-line arguments. If
        <option>--help</option> is given after a subcommand, it shows
        examples for that subcommand. <command>nix
        --help-config</command> shows all configuration
        options.</para>
      </listitem>

      <listitem>
        <para>It is much less verbose. By default, it displays a
        single-line progress indicator that shows how many packages
        are left to be built or downloaded, and (if there are running
        builds) the most recent line of builder output. If a build
        fails, it shows the last few lines of builder output. The full
        build log can be retrieved using <command>nix
        log</command>.</para>
      </listitem>

      <listitem>
        <para>It <link xlink:href="https://github.com/NixOS/nix/commit/b8283773bd64d7da6859ed520ee19867742a03ba">provides</link>
        all <filename>nix.conf</filename> configuration options as
        command line flags. For example, instead of <literal>--option
        http-connections 100</literal> you can write
        <literal>--http-connections 100</literal>. Boolean options can
        be written as
        <literal>--<replaceable>foo</replaceable></literal> or
        <literal>--no-<replaceable>foo</replaceable></literal>
        (e.g. <option>--no-auto-optimise-store</option>).</para>
      </listitem>

      <listitem>
        <para>Many subcommands have a <option>--json</option> flag to
        write results to stdout in JSON format.</para>
      </listitem>

    </itemizedlist>

    <warning><para>Please note that the <command>nix</command> command
    is a work in progress and the interface is subject to
    change.</para></warning>

    <para>It provides the following high-level (&#x201C;porcelain&#x201D;)
    subcommands:</para>

    <itemizedlist>

      <listitem>
        <para><command>nix build</command> is a replacement for
        <command>nix-build</command>.</para>
      </listitem>

      <listitem>
        <para><command>nix run</command> executes a command in an
        environment in which the specified packages are available. It
        is (roughly) a replacement for <command>nix-shell
        -p</command>. Unlike that command, it does not execute the
        command in a shell, and has a flag (<command>-c</command>)
        that specifies the unquoted command line to be
        executed.</para>

        <para>It is particularly useful in conjunction with chroot
        stores, allowing Linux users who do not have permission to
        install Nix in <command>/nix/store</command> to still use
        binary substitutes that assume
        <command>/nix/store</command>. For example,

        <screen>nix run --store ~/my-nix nixpkgs.hello -c hello --greeting 'Hi everybody!'</screen>

        downloads (or if not substitutes are available, builds) the
        GNU Hello package into
        <filename>~/my-nix/nix/store</filename>, then runs
        <command>hello</command> in a mount namespace where
        <filename>~/my-nix/nix/store</filename> is mounted onto
        <command>/nix/store</command>.</para>
      </listitem>

      <listitem>
        <para><command>nix search</command> replaces <command>nix-env
        -qa</command>. It searches the available packages for
        occurrences of a search string in the attribute name, package
        name or description. Unlike <command>nix-env -qa</command>, it
        has a cache to speed up subsequent searches.</para>
      </listitem>

      <listitem>
        <para><command>nix copy</command> copies paths between
        arbitrary Nix stores, generalising
        <command>nix-copy-closure</command> and
        <command>nix-push</command>.</para>
      </listitem>

      <listitem>
        <para><command>nix repl</command> replaces the external
        program <command>nix-repl</command>. It provides an
        interactive environment for evaluating and building Nix
        expressions. Note that it uses <literal>linenoise-ng</literal>
        instead of GNU Readline.</para>
      </listitem>

      <listitem>
        <para><command>nix upgrade-nix</command> upgrades Nix to the
        latest stable version. This requires that Nix is installed in
        a profile. (Thus it won&#x2019;t work on NixOS, or if it&#x2019;s installed
        outside of the Nix store.)</para>
      </listitem>

      <listitem>
        <para><command>nix verify</command> checks whether store paths
        are unmodified and/or &#x201C;trusted&#x201D; (see below). It replaces
        <command>nix-store --verify</command> and <command>nix-store
        --verify-path</command>.</para>
      </listitem>

      <listitem>
        <para><command>nix log</command> shows the build log of a
        package or path. If the build log is not available locally, it
        will try to obtain it from the configured substituters (such
        as <uri>cache.nixos.org</uri>, which now provides build
        logs).</para>
      </listitem>

      <listitem>
        <para><command>nix edit</command> opens the source code of a
        package in your editor.</para>
      </listitem>

      <listitem>
        <para><command>nix eval</command> replaces
        <command>nix-instantiate --eval</command>.</para>
      </listitem>

      <listitem>
        <para><command xlink:href="https://github.com/NixOS/nix/commit/d41c5eb13f4f3a37d80dbc6d3888644170c3b44a">nix
        why-depends</command> shows why one store path has another in
        its closure. This is primarily useful to finding the causes of
        closure bloat. For example,

        <screen>nix why-depends nixpkgs.vlc nixpkgs.libdrm.dev</screen>

        shows a chain of files and fragments of file contents that
        cause the VLC package to have the &#x201C;dev&#x201D; output of
        <literal>libdrm</literal> in its closure &#x2014; an undesirable
        situation.</para>
      </listitem>

      <listitem>
        <para><command>nix path-info</command> shows information about
        store paths, replacing <command>nix-store -q</command>. A
        useful feature is the option <option>--closure-size</option>
        (<option>-S</option>). For example, the following command show
        the closure sizes of every path in the current NixOS system
        closure, sorted by size:

        <screen>nix path-info -rS /run/current-system | sort -nk2</screen>

        </para>
      </listitem>

      <listitem>
        <para><command>nix optimise-store</command> replaces
        <command>nix-store --optimise</command>. The main difference
        is that it has a progress indicator.</para>
      </listitem>

    </itemizedlist>

    <para>A number of low-level (&#x201C;plumbing&#x201D;) commands are also
    available:</para>

    <itemizedlist>

      <listitem>
        <para><command>nix ls-store</command> and <command>nix
        ls-nar</command> list the contents of a store path or NAR
        file. The former is primarily useful in conjunction with
        remote stores, e.g.

        <screen>nix ls-store --store https://cache.nixos.org/ -lR /nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10</screen>

        lists the contents of path in a binary cache.</para>
      </listitem>

      <listitem>
        <para><command>nix cat-store</command> and <command>nix
        cat-nar</command> allow extracting a file from a store path or
        NAR file.</para>
      </listitem>

      <listitem>
        <para><command>nix dump-path</command> writes the contents of
        a store path to stdout in NAR format. This replaces
        <command>nix-store --dump</command>.</para>
      </listitem>

      <listitem>
        <para><command xlink:href="https://github.com/NixOS/nix/commit/e8d6ee7c1b90a2fe6d824f1a875acc56799ae6e2">nix
        show-derivation</command> displays a store derivation in JSON
        format. This is an alternative to
        <command>pp-aterm</command>.</para>
      </listitem>

      <listitem>
        <para><command xlink:href="https://github.com/NixOS/nix/commit/970366266b8df712f5f9cedb45af183ef5a8357f">nix
        add-to-store</command> replaces <command>nix-store
        --add</command>.</para>
      </listitem>

      <listitem>
        <para><command>nix sign-paths</command> signs store
        paths.</para>
      </listitem>

      <listitem>
        <para><command>nix copy-sigs</command> copies signatures from
        one store to another.</para>
      </listitem>

      <listitem>
        <para><command>nix show-config</command> shows all
        configuration options and their current values.</para>
      </listitem>

    </itemizedlist>

  </listitem>

  <listitem>
    <para>The store abstraction that Nix has had for a long time to
    support store access via the Nix daemon has been extended
    significantly. In particular, substituters (which used to be
    external programs such as
    <command>download-from-binary-cache</command>) are now subclasses
    of the abstract <classname>Store</classname> class. This allows
    many Nix commands to operate on such store types. For example,
    <command>nix path-info</command> shows information about paths in
    your local Nix store, while <command>nix path-info --store
    https://cache.nixos.org/</command> shows information about paths
    in the specified binary cache. Similarly,
    <command>nix-copy-closure</command>, <command>nix-push</command>
    and substitution are all instances of the general notion of
    copying paths between different kinds of Nix stores.</para>

    <para>Stores are specified using an URI-like syntax,
    e.g. <uri>https://cache.nixos.org/</uri> or
    <uri>ssh://machine</uri>. The following store types are supported:

    <itemizedlist>

      <listitem>

        <para><classname>LocalStore</classname> (stori URI
        <literal>local</literal> or an absolute path) and the misnamed
        <classname>RemoteStore</classname> (<literal>daemon</literal>)
        provide access to a local Nix store, the latter via the Nix
        daemon. You can use <literal>auto</literal> or the empty
        string to auto-select a local or daemon store depending on
        whether you have write permission to the Nix store. It is no
        longer necessary to set the <envar>NIX_REMOTE</envar>
        environment variable to use the Nix daemon.</para>

        <para>As noted above, <classname>LocalStore</classname> now
        supports chroot builds, allowing the &#x201C;physical&#x201D; location of
        the Nix store
        (e.g. <filename>/home/alice/nix/store</filename>) to differ
        from its &#x201C;logical&#x201D; location (typically
        <filename>/nix/store</filename>). This allows non-root users
        to use Nix while still getting the benefits from prebuilt
        binaries from <uri>cache.nixos.org</uri>.</para>

      </listitem>

      <listitem>

        <para><classname>BinaryCacheStore</classname> is the abstract
        superclass of all binary cache stores. It supports writing
        build logs and NAR content listings in JSON format.</para>

      </listitem>

      <listitem>

        <para><classname>HttpBinaryCacheStore</classname>
        (<literal>http://</literal>, <literal>https://</literal>)
        supports binary caches via HTTP or HTTPS. If the server
        supports <literal>PUT</literal> requests, it supports
        uploading store paths via commands such as <command>nix
        copy</command>.</para>

      </listitem>

      <listitem>

        <para><classname>LocalBinaryCacheStore</classname>
        (<literal>file://</literal>) supports binary caches in the
        local filesystem.</para>

      </listitem>

      <listitem>

        <para><classname>S3BinaryCacheStore</classname>
        (<literal>s3://</literal>) supports binary caches stored in
        Amazon S3, if enabled at compile time.</para>

      </listitem>

      <listitem>

        <para><classname>LegacySSHStore</classname> (<literal>ssh://</literal>)
        is used to implement remote builds and
        <command>nix-copy-closure</command>.</para>

      </listitem>

      <listitem>

        <para><classname>SSHStore</classname>
        (<literal>ssh-ng://</literal>) supports arbitrary Nix
        operations on a remote machine via the same protocol used by
        <command>nix-daemon</command>.</para>

      </listitem>

    </itemizedlist>

    </para>

  </listitem>

  <listitem>

    <para>Security has been improved in various ways:

    <itemizedlist>

      <listitem>
        <para>Nix now stores signatures for local store
        paths. When paths are copied between stores (e.g., copied from
        a binary cache to a local store), signatures are
        propagated.</para>

        <para>Locally-built paths are signed automatically using the
        secret keys specified by the <option>secret-key-files</option>
        store option. Secret/public key pairs can be generated using
        <command>nix-store
        --generate-binary-cache-key</command>.</para>

        <para>In addition, locally-built store paths are marked as
        &#x201C;ultimately trusted&#x201D;, but this bit is not propagated when
        paths are copied between stores.</para>
      </listitem>

      <listitem>
        <para>Content-addressable store paths no longer require
        signatures &#x2014; they can be imported into a store by unprivileged
        users even if they lack signatures.</para>
      </listitem>

      <listitem>
        <para>The command <command>nix verify</command> checks whether
        the specified paths are trusted, i.e., have a certain number
        of trusted signatures, are ultimately trusted, or are
        content-addressed.</para>
      </listitem>

      <listitem>
        <para>Substitutions from binary caches <link xlink:href="https://github.com/NixOS/nix/commit/ecbc3fedd3d5bdc5a0e1a0a51b29062f2874ac8b">now</link>
        require signatures by default. This was already the case on
        NixOS.</para>
      </listitem>

      <listitem>
        <para>In Linux sandbox builds, we <link xlink:href="https://github.com/NixOS/nix/commit/eba840c8a13b465ace90172ff76a0db2899ab11b">now</link>
        use <filename>/build</filename> instead of
        <filename>/tmp</filename> as the temporary build
        directory. This fixes potential security problems when a build
        accidentally stores its <envar>TMPDIR</envar> in some
        security-sensitive place, such as an RPATH.</para>
      </listitem>

    </itemizedlist>

    </para>

  </listitem>

  <listitem>
    <para><emphasis>Pure evaluation mode</emphasis>. With the
    <literal>--pure-eval</literal> flag, Nix enables a variant of the existing
    restricted evaluation mode that forbids access to anything that could cause
    different evaluations of the same command line arguments to produce a
    different result. This includes builtin functions such as
    <function>builtins.getEnv</function>, but more importantly,
    <emphasis>all</emphasis> filesystem or network access unless a content hash
    or commit hash is specified. For example, calls to
    <function>builtins.fetchGit</function> are only allowed if a
    <varname>rev</varname> attribute is specified.</para>

    <para>The goal of this feature is to enable true reproducibility
    and traceability of builds (including NixOS system configurations)
    at the evaluation level. For example, in the future,
    <command>nixos-rebuild</command> might build configurations from a
    Nix expression in a Git repository in pure mode. That expression
    might fetch other repositories such as Nixpkgs via
    <function>builtins.fetchGit</function>. The commit hash of the
    top-level repository then uniquely identifies a running system,
    and, in conjunction with that repository, allows it to be
    reproduced or modified.</para>

  </listitem>

  <listitem>
    <para>There are several new features to support binary
    reproducibility (i.e. to help ensure that multiple builds of the
    same derivation produce exactly the same output). When
    <option>enforce-determinism</option> is set to
    <literal>false</literal>, it&#x2019;s <link xlink:href="https://github.com/NixOS/nix/commit/8bdf83f936adae6f2c907a6d2541e80d4120f051">no
    longer</link> a fatal error if build rounds produce different
    output. Also, a hook named <option>diff-hook</option> is <link xlink:href="https://github.com/NixOS/nix/commit/9a313469a4bdea2d1e8df24d16289dc2a172a169">provided</link>
    to allow you to run tools such as <command>diffoscope</command>
    when build rounds produce different output.</para>
  </listitem>

  <listitem>
    <para>Configuring remote builds is a lot easier now. Provided you
    are not using the Nix daemon, you can now just specify a remote
    build machine on the command line, e.g. <literal>--option builders
    'ssh://my-mac x86_64-darwin'</literal>. The environment variable
    <envar>NIX_BUILD_HOOK</envar> has been removed and is no longer
    needed. The environment variable <envar>NIX_REMOTE_SYSTEMS</envar>
    is still supported for compatibility, but it is also possible to
    specify builders in <command>nix.conf</command> by setting the
    option <literal>builders =
    @<replaceable>path</replaceable></literal>.</para>
  </listitem>

  <listitem>
    <para>If a fixed-output derivation produces a result with an
    incorrect hash, the output path is moved to the location
    corresponding to the actual hash and registered as valid. Thus, a
    subsequent build of the fixed-output derivation with the correct
    hash is unnecessary.</para>
  </listitem>

  <listitem>
    <para><command>nix-shell</command> <link xlink:href="https://github.com/NixOS/nix/commit/ea59f39326c8e9dc42dfed4bcbf597fbce58797c">now</link>
    sets the <varname>IN_NIX_SHELL</varname> environment variable
    during evaluation and in the shell itself. This can be used to
    perform different actions depending on whether you&#x2019;re in a Nix
    shell or in a regular build. Nixpkgs provides
    <varname>lib.inNixShell</varname> to check this variable during
    evaluation.</para>
  </listitem>

  <listitem>
    <para><envar>NIX_PATH</envar> is now lazy, so URIs in the path are
    only downloaded if they are needed for evaluation.</para>
  </listitem>

  <listitem>
    <para>You can now use
    <uri>channel:<replaceable>channel-name</replaceable></uri> as a
    short-hand for
    <uri>https://nixos.org/channels/<replaceable>channel-name</replaceable>/nixexprs.tar.xz</uri>. For
    example, <literal>nix-build channel:nixos-15.09 -A hello</literal>
    will build the GNU Hello package from the
    <literal>nixos-15.09</literal> channel. In the future, this may
    use Git to fetch updates more efficiently.</para>
  </listitem>

  <listitem>
    <para>When <option>--no-build-output</option> is given, the last
    10 lines of the build log will be shown if a build
    fails.</para>
  </listitem>

  <listitem>
    <para>Networking has been improved:

    <itemizedlist>

      <listitem>
        <para>HTTP/2 is now supported. This makes binary cache lookups
        <link xlink:href="https://github.com/NixOS/nix/commit/90ad02bf626b885a5dd8967894e2eafc953bdf92">much
        more efficient</link>.</para>
      </listitem>

      <listitem>
        <para>We now retry downloads on many HTTP errors, making
        binary caches substituters more resilient to temporary
        failures.</para>
      </listitem>

      <listitem>
        <para>HTTP credentials can now be configured via the standard
        <filename>netrc</filename> mechanism.</para>
      </listitem>

      <listitem>
        <para>If S3 support is enabled at compile time,
        <uri>s3://</uri> URIs are <link xlink:href="https://github.com/NixOS/nix/commit/9ff9c3f2f80ba4108e9c945bbfda2c64735f987b">supported</link>
        in all places where Nix allows URIs.</para>
      </listitem>

      <listitem>
        <para>Brotli compression is now supported. In particular,
        <uri>cache.nixos.org</uri> build logs are now compressed using
        Brotli.</para>
      </listitem>

    </itemizedlist>

    </para>

  </listitem>

  <listitem>
    <para><command>nix-env</command> <link xlink:href="https://github.com/NixOS/nix/commit/b0cb11722626e906a73f10dd9a0c9eea29faf43a">now</link>
    ignores packages with bad derivation names (in particular those
    starting with a digit or containing a dot).</para>
  </listitem>

  <listitem>
    <para>Many configuration options have been renamed, either because
    they were unnecessarily verbose
    (e.g. <option>build-use-sandbox</option> is now just
    <option>sandbox</option>) or to reflect generalised behaviour
    (e.g. <option>binary-caches</option> is now
    <option>substituters</option> because it allows arbitrary store
    URIs). The old names are still supported for compatibility.</para>
  </listitem>

  <listitem>
    <para>The <option>max-jobs</option> option can <link xlink:href="https://github.com/NixOS/nix/commit/7251d048fa812d2551b7003bc9f13a8f5d4c95a5">now</link>
    be set to <literal>auto</literal> to use the number of CPUs in the
    system.</para>
  </listitem>

  <listitem>
    <para>Hashes can <link xlink:href="https://github.com/NixOS/nix/commit/c0015e87af70f539f24d2aa2bc224a9d8b84276b">now</link>
    be specified in base-64 format, in addition to base-16 and the
    non-standard base-32.</para>
  </listitem>

  <listitem>
    <para><command>nix-shell</command> now uses
    <varname>bashInteractive</varname> from Nixpkgs, rather than the
    <command>bash</command> command that happens to be in the caller&#x2019;s
    <envar>PATH</envar>. This is especially important on macOS where
    the <command>bash</command> provided by the system is seriously
    outdated and cannot execute <literal>stdenv</literal>&#x2019;s setup
    script.</para>
  </listitem>

  <listitem>
    <para>Nix can now automatically trigger a garbage collection if
    free disk space drops below a certain level during a build. This
    is configured using the <option>min-free</option> and
    <option>max-free</option> options.</para>
  </listitem>

  <listitem>
    <para><command>nix-store -q --roots</command> and
    <command>nix-store --gc --print-roots</command> now show temporary
    and in-memory roots.</para>
  </listitem>

  <listitem>
    <para>
      Nix can now be extended with plugins. See the documentation of
      the <option>plugin-files</option> option for more details.
    </para>
  </listitem>

</itemizedlist>

<para>The Nix language has the following new features:

<itemizedlist>

  <listitem>
    <para>It supports floating point numbers. They are based on the
    C++ <literal>float</literal> type and are supported by the
    existing numerical operators. Export and import to and from JSON
    and XML works, too.</para>
  </listitem>

  <listitem>
    <para>Derivation attributes can now reference the outputs of the
    derivation using the <function>placeholder</function> builtin
    function. For example, the attribute

<programlisting>
configureFlags = "--prefix=${placeholder "out"} --includedir=${placeholder "dev"}";
</programlisting>

    will cause the <envar>configureFlags</envar> environment variable
    to contain the actual store paths corresponding to the
    <literal>out</literal> and <literal>dev</literal> outputs.</para>
  </listitem>

</itemizedlist>

</para>

<para>The following builtin functions are new or extended:

<itemizedlist>

  <listitem>
    <para><function xlink:href="https://github.com/NixOS/nix/commit/38539b943a060d9cdfc24d6e5d997c0885b8aa2f">builtins.fetchGit</function>
    allows Git repositories to be fetched at evaluation time. Thus it
    differs from the <function>fetchgit</function> function in
    Nixpkgs, which fetches at build time and cannot be used to fetch
    Nix expressions during evaluation. A typical use case is to import
    external NixOS modules from your configuration, e.g.

    <programlisting>imports = [ (builtins.fetchGit https://github.com/edolstra/dwarffs + "/module.nix") ];</programlisting>

    </para>
  </listitem>

  <listitem>
    <para>Similarly, <function>builtins.fetchMercurial</function>
    allows you to fetch Mercurial repositories.</para>
  </listitem>

  <listitem>
    <para><function>builtins.path</function> generalises
    <function>builtins.filterSource</function> and path literals
    (e.g. <literal>./foo</literal>). It allows specifying a store path
    name that differs from the source path name
    (e.g. <literal>builtins.path { path = ./foo; name = "bar";
    }</literal>) and also supports filtering out unwanted
    files.</para>
  </listitem>

  <listitem>
    <para><function>builtins.fetchurl</function> and
    <function>builtins.fetchTarball</function> now support
    <varname>sha256</varname> and <varname>name</varname>
    attributes.</para>
  </listitem>

  <listitem>
    <para><function xlink:href="https://github.com/NixOS/nix/commit/b8867a0239b1930a16f9ef3f7f3e864b01416dff">builtins.split</function>
    splits a string using a POSIX extended regular expression as the
    separator.</para>
  </listitem>

  <listitem>
    <para><function xlink:href="https://github.com/NixOS/nix/commit/26d92017d3b36cff940dcb7d1611c42232edb81a">builtins.partition</function>
    partitions the elements of a list into two lists, depending on a
    Boolean predicate.</para>
  </listitem>

  <listitem>
    <para><literal>&lt;nix/fetchurl.nix&gt;</literal> now uses the
    content-addressable tarball cache at
    <uri>http://tarballs.nixos.org/</uri>, just like
    <function>fetchurl</function> in
    Nixpkgs. (f2682e6e18a76ecbfb8a12c17e3a0ca15c084197)</para>
  </listitem>

  <listitem>
    <para>In restricted and pure evaluation mode, builtin functions
    that download from the network (such as
    <function>fetchGit</function>) are permitted to fetch underneath a
    list of URI prefixes specified in the option
    <option>allowed-uris</option>.</para>
  </listitem>

</itemizedlist>

</para>

<para>The Nix build environment has the following changes:

<itemizedlist>

  <listitem>
    <para>Values such as Booleans, integers, (nested) lists and
    attribute sets can <link xlink:href="https://github.com/NixOS/nix/commit/6de33a9c675b187437a2e1abbcb290981a89ecb1">now</link>
    be passed to builders in a non-lossy way. If the special attribute
    <varname>__structuredAttrs</varname> is set to
    <literal>true</literal>, the other derivation attributes are
    serialised in JSON format and made available to the builder via
    the file <envar>.attrs.json</envar> in the builder&#x2019;s temporary
    directory. This obviates the need for
    <varname>passAsFile</varname> since JSON files have no size
    restrictions, unlike process environments.</para>

    <para><link xlink:href="https://github.com/NixOS/nix/commit/2d5b1b24bf70a498e4c0b378704cfdb6471cc699">As
    a convenience to Bash builders</link>, Nix writes a script named
    <envar>.attrs.sh</envar> to the builder&#x2019;s directory that
    initialises shell variables corresponding to all attributes that
    are representable in Bash. This includes non-nested (associative)
    arrays. For example, the attribute <literal>hardening.format =
    true</literal> ends up as the Bash associative array element
    <literal>${hardening[format]}</literal>.</para>
  </listitem>

  <listitem>
    <para>Builders can <link xlink:href="https://github.com/NixOS/nix/commit/88e6bb76de5564b3217be9688677d1c89101b2a3">now</link>
    communicate what build phase they are in by writing messages to
    the file descriptor specified in <envar>NIX_LOG_FD</envar>. The
    current phase is shown by the <command>nix</command> progress
    indicator.
    </para>
  </listitem>

  <listitem>
    <para>In Linux sandbox builds, we <link xlink:href="https://github.com/NixOS/nix/commit/a2d92bb20e82a0957067ede60e91fab256948b41">now</link>
    provide a default <filename>/bin/sh</filename> (namely
    <filename>ash</filename> from BusyBox).</para>
  </listitem>

  <listitem>
    <para>In structured attribute mode,
    <varname>exportReferencesGraph</varname> <link xlink:href="https://github.com/NixOS/nix/commit/c2b0d8749f7e77afc1c4b3e8dd36b7ee9720af4a">exports</link>
    extended information about closures in JSON format. In particular,
    it includes the sizes and hashes of paths. This is primarily
    useful for NixOS image builders.</para>
  </listitem>

  <listitem>
    <para>Builds are <link xlink:href="https://github.com/NixOS/nix/commit/21948deed99a3295e4d5666e027a6ca42dc00b40">now</link>
    killed as soon as Nix receives EOF on the builder&#x2019;s stdout or
    stderr. This fixes a bug that allowed builds to hang Nix
    indefinitely, regardless of
    timeouts.</para>
  </listitem>

  <listitem>
    <para>The <option>sandbox-paths</option> configuration
    option can now specify optional paths by appending a
    <literal>?</literal>, e.g. <literal>/dev/nvidiactl?</literal> will
    bind-mount <varname>/dev/nvidiactl</varname> only if it
    exists.</para>
  </listitem>

  <listitem>
    <para>On Linux, builds are now executed in a user
    namespace with UID 1000 and GID 100.</para>
  </listitem>

</itemizedlist>

</para>

<para>A number of significant internal changes were made:

<itemizedlist>

  <listitem>
    <para>Nix no longer depends on Perl and all Perl components have
    been rewritten in C++ or removed. The Perl bindings that used to
    be part of Nix have been moved to a separate package,
    <literal>nix-perl</literal>.</para>
  </listitem>

  <listitem>
    <para>All <classname>Store</classname> classes are now
    thread-safe. <classname>RemoteStore</classname> supports multiple
    concurrent connections to the daemon. This is primarily useful in
    multi-threaded programs such as
    <command>hydra-queue-runner</command>.</para>
  </listitem>

</itemizedlist>

</para>

<para>This release has contributions from

Adrien Devresse,
Alexander Ried,
Alex Cruice,
Alexey Shmalko,
AmineChikhaoui,
Andy Wingo,
Aneesh Agrawal,
Anthony Cowley,
Armijn Hemel,
aszlig,
Ben Gamari,
Benjamin Hipple,
Benjamin Staffin,
Benno F&#xFC;nfst&#xFC;ck,
Bj&#xF8;rn Forsman,
Brian McKenna,
Charles Strahan,
Chase Adams,
Chris Martin,
Christian Theune,
Chris Warburton,
Daiderd Jordan,
Dan Connolly,
Daniel Peebles,
Dan Peebles,
davidak,
David McFarland,
Dmitry Kalinkin,
Domen Ko&#x17E;ar,
Eelco Dolstra,
Emery Hemingway,
Eric Litak,
Eric Wolf,
Fabian Schmitthenner,
Frederik Rietdijk,
Gabriel Gonzalez,
Giorgio Gallo,
Graham Christensen,
Guillaume Maudoux,
Harmen,
Iavael,
James Broadhead,
James Earl Douglas,
Janus Troelsen,
Jeremy Shaw,
Joachim Schiele,
Joe Hermaszewski,
Joel Moberg,
Johannes 'fish' Ziemke,
J&#xF6;rg Thalheim,
Jude Taylor,
kballou,
Keshav Kini,
Kjetil Orbekk,
Langston Barrett,
Linus Heckemann,
Ludovic Court&#xE8;s,
Manav Rathi,
Marc Scholten,
Markus Hauck,
Matt Audesse,
Matthew Bauer,
Matthias Beyer,
Matthieu Coudron,
N1X,
Nathan Zadoks,
Neil Mayhew,
Nicolas B. Pierron,
Niklas Hamb&#xFC;chen,
Nikolay Amiantov,
Ole J&#xF8;rgen Br&#xF8;nner,
Orivej Desh,
Peter Simons,
Peter Stuart,
Pyry Jahkola,
regnat,
Renzo Carbonara,
Rhys,
Robert Vollmert,
Scott Olson,
Scott R. Parish,
Sergei Trofimovich,
Shea Levy,
Sheena Artrip,
Spencer Baugh,
Stefan Junker,
Susan Potter,
Thomas Tuegel,
Timothy Allen,
Tristan Hume,
Tuomas Tynkkynen,
tv,
Tyson Whitehead,
Vladim&#xED;r &#x10C;un&#xE1;t,
Will Dietz,
wmertens,
Wout Mertens,
zimbatm and
Zoran Plesiv&#x10D;ak.
</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.11.10">

<title>Release 1.11.10 (2017-06-12)</title>

<para>This release fixes a security bug in Nix&#x2019;s &#x201C;build user&#x201D; build
isolation mechanism. Previously, Nix builders had the ability to
create setuid binaries owned by a <literal>nixbld</literal>
user. Such a binary could then be used by an attacker to assume a
<literal>nixbld</literal> identity and interfere with subsequent
builds running under the same UID.</para>

<para>To prevent this issue, Nix now disallows builders to create
setuid and setgid binaries. On Linux, this is done using a seccomp BPF
filter. Note that this imposes a small performance penalty (e.g. 1%
when building GNU Hello). Using seccomp, we now also prevent the
creation of extended attributes and POSIX ACLs since these cannot be
represented in the NAR format and (in the case of POSIX ACLs) allow
bypassing regular Nix store permissions. On macOS, the restriction is
implemented using the existing sandbox mechanism, which now uses a
minimal &#x201C;allow all except the creation of setuid/setgid binaries&#x201D;
profile when regular sandboxing is disabled. On other platforms, the
&#x201C;build user&#x201D; mechanism is now disabled.</para>

<para>Thanks go to Linus Heckemann for discovering and reporting this
bug.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.11">

<title>Release 1.11 (2016-01-19)</title>

<para>This is primarily a bug fix release. It also has a number of new
features:</para>

<itemizedlist>

  <listitem>
    <para><command>nix-prefetch-url</command> can now download URLs
    specified in a Nix expression. For example,

<screen>
$ nix-prefetch-url -A hello.src
</screen>

    will prefetch the file specified by the
    <function>fetchurl</function> call in the attribute
    <literal>hello.src</literal> from the Nix expression in the
    current directory, and print the cryptographic hash of the
    resulting file on stdout. This differs from <literal>nix-build -A
    hello.src</literal> in that it doesn't verify the hash, and is
    thus useful when you&#x2019;re updating a Nix expression.</para>

    <para>You can also prefetch the result of functions that unpack a
    tarball, such as <function>fetchFromGitHub</function>. For example:

<screen>
$ nix-prefetch-url --unpack https://github.com/NixOS/patchelf/archive/0.8.tar.gz
</screen>

    or from a Nix expression:

<screen>
$ nix-prefetch-url -A nix-repl.src
</screen>

    </para>

  </listitem>

  <listitem>
    <para>The builtin function
    <function>&lt;nix/fetchurl.nix&gt;</function> now supports
    downloading and unpacking NARs. This removes the need to have
    multiple downloads in the Nixpkgs stdenv bootstrap process (like a
    separate busybox binary for Linux, or curl/mkdir/sh/bzip2 for
    Darwin). Now all those files can be combined into a single NAR,
    optionally compressed using <command>xz</command>.</para>
  </listitem>

  <listitem>
    <para>Nix now supports SHA-512 hashes for verifying fixed-output
    derivations, and in <function>builtins.hashString</function>.</para>
  </listitem>

  <listitem>
    <para>
      The new flag <option>--option build-repeat
      <replaceable>N</replaceable></option> will cause every build to
      be executed <replaceable>N</replaceable>+1 times. If the build
      output differs between any round, the build is rejected, and the
      output paths are not registered as valid. This is primarily
      useful to verify build determinism. (We already had a
      <option>--check</option> option to repeat a previously succeeded
      build. However, with <option>--check</option>, non-deterministic
      builds are registered in the DB. Preventing that is useful for
      Hydra to ensure that non-deterministic builds don't end up
      getting published to the binary cache.)
    </para>
  </listitem>

  <listitem>
    <para>
      The options <option>--check</option> and <option>--option
      build-repeat <replaceable>N</replaceable></option>, if they
      detect a difference between two runs of the same derivation and
      <option>-K</option> is given, will make the output of the other
      run available under
      <filename><replaceable>store-path</replaceable>-check</filename>. This
      makes it easier to investigate the non-determinism using tools
      like <command>diffoscope</command>, e.g.,

<screen>
$ nix-build pkgs/stdenv/linux -A stage1.pkgs.zlib --check -K
error: derivation &#x2018;/nix/store/l54i8wlw2265&#x2026;-zlib-1.2.8.drv&#x2019; may not
be deterministic: output &#x2018;/nix/store/11a27shh6n2i&#x2026;-zlib-1.2.8&#x2019;
differs from &#x2018;/nix/store/11a27shh6n2i&#x2026;-zlib-1.2.8-check&#x2019;

$ diffoscope /nix/store/11a27shh6n2i&#x2026;-zlib-1.2.8 /nix/store/11a27shh6n2i&#x2026;-zlib-1.2.8-check
&#x2026;
&#x251C;&#x2500;&#x2500; lib/libz.a
&#x2502;   &#x251C;&#x2500;&#x2500; metadata
&#x2502;   &#x2502; @@ -1,15 +1,15 @@
&#x2502;   &#x2502; -rw-r--r-- 30001/30000   3096 Jan 12 15:20 2016 adler32.o
&#x2026;
&#x2502;   &#x2502; +rw-r--r-- 30001/30000   3096 Jan 12 15:28 2016 adler32.o
&#x2026;
</screen>

    </para></listitem>

  <listitem>
    <para>Improved FreeBSD support.</para>
  </listitem>

  <listitem>
    <para><command>nix-env -qa --xml --meta</command> now prints
    license information.</para>
  </listitem>

  <listitem>
    <para>The maximum number of parallel TCP connections that the
    binary cache substituter will use has been decreased from 150 to
    25. This should prevent upsetting some broken NAT routers, and
    also improves performance.</para>
  </listitem>

  <listitem>
    <para>All "chroot"-containing strings got renamed to "sandbox".
      In particular, some Nix options got renamed, but the old names
      are still accepted as lower-priority aliases.
    </para>
  </listitem>

</itemizedlist>

<para>This release has contributions from Anders Claesson, Anthony
Cowley, Bj&#xF8;rn Forsman, Brian McKenna, Danny Wilson, davidak, Eelco Dolstra,
Fabian Schmitthenner, FrankHB, Ilya Novoselov, janus, Jim Garrison, John
Ericson, Jude Taylor, Ludovic Court&#xE8;s, Manuel Jacob, Mathnerd314,
Pascal Wittmann, Peter Simons, Philip Potter, Preston Bennes, Rommel
M. Martinez, Sander van der Burg, Shea Levy, Tim Cuthbertson, Tuomas
Tynkkynen, Utku Demir and Vladim&#xED;r &#x10C;un&#xE1;t.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.10">

<title>Release 1.10 (2015-09-03)</title>

<para>This is primarily a bug fix release. It also has a number of new
features:</para>

<itemizedlist>

  <listitem>
    <para>A number of builtin functions have been added to reduce
    Nixpkgs/NixOS evaluation time and memory consumption:
    <function>all</function>,
    <function>any</function>,
    <function>concatStringsSep</function>,
    <function>foldl&#x2019;</function>,
    <function>genList</function>,
    <function>replaceStrings</function>,
    <function>sort</function>.
    </para>
  </listitem>

  <listitem>
    <para>The garbage collector is more robust when the disk is full.</para>
  </listitem>

  <listitem>
    <para>Nix supports a new API for building derivations that doesn&#x2019;t
    require a <literal>.drv</literal> file to be present on disk; it
    only requires an in-memory representation of the derivation. This
    is used by the Hydra continuous build system to make remote builds
    more efficient.</para>
  </listitem>

  <listitem>
    <para>The function <literal>&lt;nix/fetchurl.nix&gt;</literal> now
    uses a <emphasis>builtin</emphasis> builder (i.e. it doesn&#x2019;t
    require starting an external process; the download is performed by
    Nix itself). This ensures that derivation paths don&#x2019;t change when
    Nix is upgraded, and obviates the need for ugly hacks to support
    chroot execution.</para>
  </listitem>

  <listitem>
    <para><option>--version -v</option> now prints some configuration
    information, in particular what compile-time optional features are
    enabled, and the paths of various directories.</para>
  </listitem>

  <listitem>
    <para>Build users have their supplementary groups set correctly.</para>
  </listitem>

</itemizedlist>

<para>This release has contributions from Eelco Dolstra, Guillaume
Maudoux, Iwan Aucamp, Jaka Hudoklin, Kirill Elagin, Ludovic Court&#xE8;s,
Manolis Ragkousis, Nicolas B. Pierron and Shea Levy.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.9">

<title>Release 1.9 (2015-06-12)</title>

<para>In addition to the usual bug fixes, this release has the
following new features:</para>

<itemizedlist>

  <listitem>
    <para>Signed binary cache support. You can enable signature
    checking by adding the following to <filename>nix.conf</filename>:

<programlisting>
signed-binary-caches = *
binary-cache-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
</programlisting>

    This will prevent Nix from downloading any binary from the cache
    that is not signed by one of the keys listed in
    <option>binary-cache-public-keys</option>.</para>

    <para>Signature checking is only supported if you built Nix with
    the <literal>libsodium</literal> package.</para>

    <para>Note that while Nix has had experimental support for signed
    binary caches since version 1.7, this release changes the
    signature format in a backwards-incompatible way.</para>

  </listitem>

  <listitem>

    <para>Automatic downloading of Nix expression tarballs. In various
    places, you can now specify the URL of a tarball containing Nix
    expressions (such as Nixpkgs), which will be downloaded and
    unpacked automatically. For example:</para>

    <itemizedlist>

      <listitem><para>In <command>nix-env</command>:

<screen>
$ nix-env -f https://github.com/NixOS/nixpkgs-channels/archive/nixos-14.12.tar.gz -iA firefox
</screen>

      This installs Firefox from the latest tested and built revision
      of the NixOS 14.12 channel.</para></listitem>

      <listitem><para>In <command>nix-build</command> and
      <command>nix-shell</command>:

<screen>
$ nix-build https://github.com/NixOS/nixpkgs/archive/master.tar.gz -A hello
</screen>

      This builds GNU Hello from the latest revision of the Nixpkgs
      master branch.</para></listitem>

      <listitem><para>In the Nix search path (as specified via
      <envar>NIX_PATH</envar> or <option>-I</option>). For example, to
      start a shell containing the Pan package from a specific version
      of Nixpkgs:

<screen>
$ nix-shell -p pan -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/8a3eea054838b55aca962c3fbde9c83c102b8bf2.tar.gz
</screen>

      </para></listitem>

      <listitem><para>In <command>nixos-rebuild</command> (on NixOS):

<screen>
$ nixos-rebuild test -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz
</screen>

      </para></listitem>

      <listitem><para>In Nix expressions, via the new builtin function <function>fetchTarball</function>:

<programlisting>
with import (fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-14.12.tar.gz) {}; &#x2026;
</programlisting>

      (This is not allowed in restricted mode.)</para></listitem>

    </itemizedlist>

  </listitem>

  <listitem>

    <para><command>nix-shell</command> improvements:</para>

    <itemizedlist>

      <listitem><para><command>nix-shell</command> now has a flag
      <option>--run</option> to execute a command in the
      <command>nix-shell</command> environment,
      e.g. <literal>nix-shell --run make</literal>. This is like
      the existing <option>--command</option> flag, except that it
      uses a non-interactive shell (ensuring that hitting Ctrl-C won&#x2019;t
      drop you into the child shell).</para></listitem>

      <listitem><para><command>nix-shell</command> can now be used as
      a <literal>#!</literal>-interpreter. This allows you to write
      scripts that dynamically fetch their own dependencies. For
      example, here is a Haskell script that, when invoked, first
      downloads GHC and the Haskell packages on which it depends:

<programlisting>
#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p haskellPackages.ghc haskellPackages.HTTP

import Network.HTTP

main = do
  resp &lt;- Network.HTTP.simpleHTTP (getRequest "http://nixos.org/")
  body &lt;- getResponseBody resp
  print (take 100 body)
</programlisting>

      Of course, the dependencies are cached in the Nix store, so the
      second invocation of this script will be much
      faster.</para></listitem>

    </itemizedlist>

  </listitem>

  <listitem>

    <para>Chroot improvements:</para>

    <itemizedlist>

      <listitem><para>Chroot builds are now supported on Mac OS X
      (using its sandbox mechanism).</para></listitem>

      <listitem><para>If chroots are enabled, they are now used for
      all derivations, including fixed-output derivations (such as
      <function>fetchurl</function>). The latter do have network
      access, but can no longer access the host filesystem. If you
      need the old behaviour, you can set the option
      <option>build-use-chroot</option> to
      <literal>relaxed</literal>.</para></listitem>

      <listitem><para>On Linux, if chroots are enabled, builds are
      performed in a private PID namespace once again. (This
      functionality was lost in Nix 1.8.)</para></listitem>

      <listitem><para>Store paths listed in
      <option>build-chroot-dirs</option> are now automatically
      expanded to their closure. For instance, if you want
      <filename>/nix/store/&#x2026;-bash/bin/sh</filename> mounted in your
      chroot as <filename>/bin/sh</filename>, you only need to say
      <literal>build-chroot-dirs =
      /bin/sh=/nix/store/&#x2026;-bash/bin/sh</literal>; it is no longer
      necessary to specify the dependencies of Bash.</para></listitem>

    </itemizedlist>

  </listitem>

  <listitem><para>The new derivation attribute
  <varname>passAsFile</varname> allows you to specify that the
  contents of derivation attributes should be passed via files rather
  than environment variables. This is useful if you need to pass very
  long strings that exceed the size limit of the environment. The
  Nixpkgs function <function>writeTextFile</function> uses
  this.</para></listitem>

  <listitem><para>You can now use <literal>~</literal> in Nix file
  names to refer to your home directory, e.g. <literal>import
  ~/.nixpkgs/config.nix</literal>.</para></listitem>

  <listitem><para>Nix has a new option <option>restrict-eval</option>
  that allows limiting what paths the Nix evaluator has access to. By
  passing <literal>--option restrict-eval true</literal> to Nix, the
  evaluator will throw an exception if an attempt is made to access
  any file outside of the Nix search path. This is primarily intended
  for Hydra to ensure that a Hydra jobset only refers to its declared
  inputs (and is therefore reproducible).</para></listitem>

  <listitem><para><command>nix-env</command> now only creates a new
  &#x201C;generation&#x201D; symlink in <filename>/nix/var/nix/profiles</filename>
  if something actually changed.</para></listitem>

  <listitem><para>The environment variable <envar>NIX_PAGER</envar>
  can now be set to override <envar>PAGER</envar>. You can set it to
  <literal>cat</literal> to disable paging for Nix commands
  only.</para></listitem>

  <listitem><para>Failing <literal>&lt;...&gt;</literal>
  lookups now show position information.</para></listitem>

  <listitem><para>Improved Boehm GC use: we disabled scanning for
  interior pointers, which should reduce the &#x201C;<literal>Repeated
  allocation of very large block</literal>&#x201D; warnings and associated
  retention of memory.</para></listitem>

</itemizedlist>

<para>This release has contributions from aszlig, Benjamin Staffin,
Charles Strahan, Christian Theune, Daniel Hahler, Danylo Hlynskyi
Daniel Peebles, Dan Peebles, Domen Ko&#x17E;ar, Eelco Dolstra, Harald van
Dijk, Hoang Xuan Phu, Jaka Hudoklin, Jeff Ramnani, j-keck, Linquize,
Luca Bruno, Michael Merickel, Oliver Dunkl, Rob Vermaas, Rok Garbas,
Shea Levy, Tobias Geerinckx-Rice and William A. Kennington III.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.8">

<title>Release 1.8 (2014-12-14)</title>

<itemizedlist>

  <listitem><para>Breaking change: to address a race condition, the
  remote build hook mechanism now uses <command>nix-store
  --serve</command> on the remote machine. This requires build slaves
  to be updated to Nix 1.8.</para></listitem>

  <listitem><para>Nix now uses HTTPS instead of HTTP to access the
  default binary cache,
  <literal>cache.nixos.org</literal>.</para></listitem>

  <listitem><para><command>nix-env</command> selectors are now regular
  expressions. For instance, you can do

<screen>
$ nix-env -qa '.*zip.*'
</screen>

  to query all packages with a name containing
  <literal>zip</literal>.</para></listitem>

  <listitem><para><command>nix-store --read-log</command> can now
  fetch remote build logs. If a build log is not available locally,
  then &#x2018;nix-store -l&#x2019; will now try to download it from the servers
  listed in the &#x2018;log-servers&#x2019; option in nix.conf. For instance, if you
  have the configuration option

<programlisting>
log-servers = http://hydra.nixos.org/log
</programlisting>

then it will try to get logs from
<literal>http://hydra.nixos.org/log/<replaceable>base name of the
store path</replaceable></literal>. This allows you to do things like:

<screen>
$ nix-store -l $(which xterm)
</screen>

  and get a log even if <command>xterm</command> wasn't built
  locally.</para></listitem>

  <listitem><para>New builtin functions:
  <function>attrValues</function>, <function>deepSeq</function>,
  <function>fromJSON</function>, <function>readDir</function>,
  <function>seq</function>.</para></listitem>

  <listitem><para><command>nix-instantiate --eval</command> now has a
  <option>--json</option> flag to print the resulting value in JSON
  format.</para></listitem>

  <listitem><para><command>nix-copy-closure</command> now uses
  <command>nix-store --serve</command> on the remote side to send or
  receive closures. This fixes a race condition between
  <command>nix-copy-closure</command> and the garbage
  collector.</para></listitem>

  <listitem><para>Derivations can specify the new special attribute
  <varname>allowedRequisites</varname>, which has a similar meaning to
  <varname>allowedReferences</varname>. But instead of only enforcing
  to explicitly specify the immediate references, it requires the
  derivation to specify all the dependencies recursively (hence the
  name, requisites) that are used by the resulting
  output.</para></listitem>

  <listitem><para>On Mac OS X, Nix now handles case collisions when
  importing closures from case-sensitive file systems. This is mostly
  useful for running NixOps on Mac OS X.</para></listitem>

  <listitem><para>The Nix daemon has new configuration options
  <option>allowed-users</option> (specifying the users and groups that
  are allowed to connect to the daemon) and
  <option>trusted-users</option> (specifying the users and groups that
  can perform privileged operations like specifying untrusted binary
  caches).</para></listitem>

  <listitem><para>The configuration option
  <option>build-cores</option> now defaults to the number of available
  CPU cores.</para></listitem>

  <listitem><para>Build users are now used by default when Nix is
  invoked as root. This prevents builds from accidentally running as
  root.</para></listitem>

  <listitem><para>Nix now includes systemd units and Upstart
  jobs.</para></listitem>

  <listitem><para>Speed improvements to <command>nix-store
  --optimise</command>.</para></listitem>

  <listitem><para>Language change: the <literal>==</literal> operator
  now ignores string contexts (the &#x201C;dependencies&#x201D; of a
  string).</para></listitem>

  <listitem><para>Nix now filters out Nix-specific ANSI escape
  sequences on standard error. They are supposed to be invisible, but
  some terminals show them anyway.</para></listitem>

  <listitem><para>Various commands now automatically pipe their output
  into the pager as specified by the <envar>PAGER</envar> environment
  variable.</para></listitem>

  <listitem><para>Several improvements to reduce memory consumption in
  the evaluator.</para></listitem>

</itemizedlist>

<para>This release has contributions from Adam Szkoda, Aristid
Breitkreuz, Bob van der Linden, Charles Strahan, darealshinji, Eelco
Dolstra, Gergely Risko, Joel Taylor, Ludovic Court&#xE8;s, Marko Durkovic,
Mikey Ariel, Paul Colomiets, Ricardo M.  Correia, Ricky Elrod, Robert
Helgesson, Rob Vermaas, Russell O'Connor, Shea Levy, Shell Turner,
S&#xF6;nke Hahn, Steve Purcell, Vladim&#xED;r &#x10C;un&#xE1;t and Wout Mertens.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.7">

<title>Release 1.7 (2014-04-11)</title>

<para>In addition to the usual bug fixes, this release has the
following new features:</para>

<itemizedlist>

  <listitem>
    <para>Antiquotation is now allowed inside of quoted attribute
    names (e.g. <literal>set."${foo}"</literal>). In the case where
    the attribute name is just a single antiquotation, the quotes can
    be dropped (e.g. the above example can be written
    <literal>set.${foo}</literal>). If an attribute name inside of a
    set declaration evaluates to <literal>null</literal> (e.g.
    <literal>{ ${null} = false; }</literal>), then that attribute is
    not added to the set.</para>
  </listitem>

  <listitem>
    <para>Experimental support for cryptographically signed binary
    caches.  See <link xlink:href="https://github.com/NixOS/nix/commit/0fdf4da0e979f992db75cc17376e455ddc5a96d8">the
    commit for details</link>.</para>
  </listitem>

  <listitem>
    <para>An experimental new substituter,
    <command>download-via-ssh</command>, that fetches binaries from
    remote machines via SSH.  Specifying the flags <literal>--option
    use-ssh-substituter true --option ssh-substituter-hosts
    <replaceable>user@hostname</replaceable></literal> will cause Nix
    to download binaries from the specified machine, if it has
    them.</para>
  </listitem>

  <listitem>
    <para><command>nix-store -r</command> and
    <command>nix-build</command> have a new flag,
    <option>--check</option>, that builds a previously built
    derivation again, and prints an error message if the output is not
    exactly the same. This helps to verify whether a derivation is
    truly deterministic.  For example:

<screen>
$ nix-build '&lt;nixpkgs&gt;' -A patchelf
<replaceable>&#x2026;</replaceable>
$ nix-build '&lt;nixpkgs&gt;' -A patchelf --check
<replaceable>&#x2026;</replaceable>
error: derivation `/nix/store/1ipvxs&#x2026;-patchelf-0.6' may not be deterministic:
  hash mismatch in output `/nix/store/4pc1dm&#x2026;-patchelf-0.6.drv'
</screen>

    </para>

  </listitem>

  <listitem>
    <para>The <command>nix-instantiate</command> flags
    <option>--eval-only</option> and <option>--parse-only</option>
    have been renamed to <option>--eval</option> and
    <option>--parse</option>, respectively.</para>
  </listitem>

  <listitem>
    <para><command>nix-instantiate</command>,
    <command>nix-build</command> and <command>nix-shell</command> now
    have a flag <option>--expr</option> (or <option>-E</option>) that
    allows you to specify the expression to be evaluated as a command
    line argument.  For instance, <literal>nix-instantiate --eval -E
    '1 + 2'</literal> will print <literal>3</literal>.</para>
  </listitem>

  <listitem>
    <para><command>nix-shell</command> improvements:</para>

    <itemizedlist>

      <listitem>
        <para>It has a new flag, <option>--packages</option> (or
        <option>-p</option>), that sets up a build environment
        containing the specified packages from Nixpkgs. For example,
        the command

<screen>
$ nix-shell -p sqlite xorg.libX11 hello
</screen>

        will start a shell in which the given packages are
        present.</para>
      </listitem>

      <listitem>
        <para>It now uses <filename>shell.nix</filename> as the
        default expression, falling back to
        <filename>default.nix</filename> if the former doesn&#x2019;t
        exist.  This makes it convenient to have a
        <filename>shell.nix</filename> in your project to set up a
        nice development environment.</para>
      </listitem>

      <listitem>
        <para>It evaluates the derivation attribute
        <varname>shellHook</varname>, if set. Since
        <literal>stdenv</literal> does not normally execute this hook,
        it allows you to do <command>nix-shell</command>-specific
        setup.</para>
      </listitem>

      <listitem>
        <para>It preserves the user&#x2019;s timezone setting.</para>
      </listitem>

    </itemizedlist>

  </listitem>

  <listitem>
    <para>In chroots, Nix now sets up a <filename>/dev</filename>
    containing only a minimal set of devices (such as
    <filename>/dev/null</filename>). Note that it only does this if
    you <emphasis>don&#x2019;t</emphasis> have <filename>/dev</filename>
    listed in your <option>build-chroot-dirs</option> setting;
    otherwise, it will bind-mount the <literal>/dev</literal> from
    outside the chroot.</para>

    <para>Similarly, if you don&#x2019;t have <filename>/dev/pts</filename> listed
    in <option>build-chroot-dirs</option>, Nix will mount a private
    <literal>devpts</literal> filesystem on the chroot&#x2019;s
    <filename>/dev/pts</filename>.</para>

  </listitem>

  <listitem>
    <para>New built-in function: <function>builtins.toJSON</function>,
    which returns a JSON representation of a value.</para>
  </listitem>

  <listitem>
    <para><command>nix-env -q</command> has a new flag
    <option>--json</option> to print a JSON representation of the
    installed or available packages.</para>
  </listitem>

  <listitem>
    <para><command>nix-env</command> now supports meta attributes with
    more complex values, such as attribute sets.</para>
  </listitem>

  <listitem>
    <para>The <option>-A</option> flag now allows attribute names with
    dots in them, e.g.

<screen>
$ nix-instantiate --eval '&lt;nixos&gt;' -A 'config.systemd.units."nscd.service".text'
</screen>

    </para>
  </listitem>

  <listitem>
    <para>The <option>--max-freed</option> option to
    <command>nix-store --gc</command> now accepts a unit
    specifier. For example, <literal>nix-store --gc --max-freed
    1G</literal> will free up to 1 gigabyte of disk space.</para>
  </listitem>

  <listitem>
    <para><command>nix-collect-garbage</command> has a new flag
    <option>--delete-older-than</option>
    <replaceable>N</replaceable><literal>d</literal>, which deletes
    all user environment generations older than
    <replaceable>N</replaceable> days.  Likewise, <command>nix-env
    --delete-generations</command> accepts a
    <replaceable>N</replaceable><literal>d</literal> age limit.</para>
  </listitem>

  <listitem>
    <para>Nix now heuristically detects whether a build failure was
    due to a disk-full condition. In that case, the build is not
    flagged as &#x201C;permanently failed&#x201D;. This is mostly useful for Hydra,
    which needs to distinguish between permanent and transient build
    failures.</para>
  </listitem>

  <listitem>
    <para>There is a new symbol <literal>__curPos</literal> that
    expands to an attribute set containing its file name and line and
    column numbers, e.g. <literal>{ file = "foo.nix"; line = 10;
    column = 5; }</literal>.  There also is a new builtin function,
    <varname>unsafeGetAttrPos</varname>, that returns the position of
    an attribute.  This is used by Nixpkgs to provide location
    information in error messages, e.g.

<screen>
$ nix-build '&lt;nixpkgs&gt;' -A libreoffice --argstr system x86_64-darwin
error: the package &#x2018;libreoffice-4.0.5.2&#x2019; in &#x2018;.../applications/office/libreoffice/default.nix:263&#x2019;
  is not supported on &#x2018;x86_64-darwin&#x2019;
</screen>

    </para>
  </listitem>

  <listitem>
    <para>The garbage collector is now more concurrent with other Nix
    processes because it releases certain locks earlier.</para>
  </listitem>

  <listitem>
    <para>The binary tarball installer has been improved.  You can now
    install Nix by running:

<screen>
$ bash &lt;(curl https://nixos.org/nix/install)
</screen>

    </para>
  </listitem>

  <listitem>
    <para>More evaluation errors include position information. For
    instance, selecting a missing attribute will print something like

<screen>
error: attribute `nixUnstabl' missing, at /etc/nixos/configurations/misc/eelco/mandark.nix:216:15
</screen>

    </para>
  </listitem>

  <listitem>
    <para>The command <command>nix-setuid-helper</command> is
    gone.</para>
  </listitem>

  <listitem>
    <para>Nix no longer uses Automake, but instead has a
    non-recursive, GNU Make-based build system.</para>
  </listitem>

  <listitem>
    <para>All installed libraries now have the prefix
    <literal>libnix</literal>.  In particular, this gets rid of
    <literal>libutil</literal>, which could clash with libraries with
    the same name from other packages.</para>
  </listitem>

  <listitem>
    <para>Nix now requires a compiler that supports C++11.</para>
  </listitem>

</itemizedlist>

<para>This release has contributions from Danny Wilson, Domen Ko&#x17E;ar,
Eelco Dolstra, Ian-Woo Kim, Ludovic Court&#xE8;s, Maxim Ivanov, Petr
Rockai, Ricardo M. Correia and Shea Levy.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.6.1">

<title>Release 1.6.1 (2013-10-28)</title>

<para>This is primarily a bug fix release.  Changes of interest
are:</para>

<itemizedlist>

  <listitem>
    <para>Nix 1.6 accidentally changed the semantics of antiquoted
    paths in strings, such as <literal>"${/foo}/bar"</literal>.  This
    release reverts to the Nix 1.5.3 behaviour.</para>
  </listitem>

  <listitem>
    <para>Previously, Nix optimised expressions such as
    <literal>"${<replaceable>expr</replaceable>}"</literal> to
    <replaceable>expr</replaceable>.  Thus it neither checked whether
    <replaceable>expr</replaceable> could be coerced to a string, nor
    applied such coercions.  This meant that
    <literal>"${123}"</literal> evaluatued to <literal>123</literal>,
    and <literal>"${./foo}"</literal> evaluated to
    <literal>./foo</literal> (even though
    <literal>"${./foo} "</literal> evaluates to
    <literal>"/nix/store/<replaceable>hash</replaceable>-foo "</literal>).
    Nix now checks the type of antiquoted expressions and
    applies coercions.</para>
  </listitem>

  <listitem>
    <para>Nix now shows the exact position of undefined variables.  In
    particular, undefined variable errors in a <literal>with</literal>
    previously didn't show <emphasis>any</emphasis> position
    information, so this makes it a lot easier to fix such
    errors.</para>
  </listitem>

  <listitem>
    <para>Undefined variables are now treated consistently.
    Previously, the <function>tryEval</function> function would catch
    undefined variables inside a <literal>with</literal> but not
    outside.  Now <function>tryEval</function> never catches undefined
    variables.</para>
  </listitem>

  <listitem>
    <para>Bash completion in <command>nix-shell</command> now works
    correctly.</para>
  </listitem>

  <listitem>
    <para>Stack traces are less verbose: they no longer show calls to
    builtin functions and only show a single line for each derivation
    on the call stack.</para>
  </listitem>

  <listitem>
    <para>New built-in function: <function>builtins.typeOf</function>,
    which returns the type of its argument as a string.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.6.0">

<title>Release 1.6 (2013-09-10)</title>

<para>In addition to the usual bug fixes, this release has several new
features:</para>

<itemizedlist>

  <listitem>
    <para>The command <command>nix-build --run-env</command> has been
    renamed to <command>nix-shell</command>.</para>
  </listitem>

  <listitem>
    <para><command>nix-shell</command> now sources
    <filename>$stdenv/setup</filename> <emphasis>inside</emphasis> the
    interactive shell, rather than in a parent shell.  This ensures
    that shell functions defined by <literal>stdenv</literal> can be
    used in the interactive shell.</para>
  </listitem>

  <listitem>
    <para><command>nix-shell</command> has a new flag
    <option>--pure</option> to clear the environment, so you get an
    environment that more closely corresponds to the &#x201C;real&#x201D; Nix build.
    </para>
  </listitem>

  <listitem>
    <para><command>nix-shell</command> now sets the shell prompt
    (<envar>PS1</envar>) to ensure that Nix shells are distinguishable
    from your regular shells.</para>
  </listitem>

  <listitem>
    <para><command>nix-env</command> no longer requires a
    <literal>*</literal> argument to match all packages, so
    <literal>nix-env -qa</literal> is equivalent to <literal>nix-env
    -qa '*'</literal>.</para>
  </listitem>

  <listitem>
    <para><command>nix-env -i</command> has a new flag
    <option>--remove-all</option> (<option>-r</option>) to remove all
    previous packages from the profile.  This makes it easier to do
    declarative package management similar to NixOS&#x2019;s
    <option>environment.systemPackages</option>.  For instance, if you
    have a specification <filename>my-packages.nix</filename> like this:

<programlisting>
with import &lt;nixpkgs&gt; {};
[ thunderbird
  geeqie
  ...
]
</programlisting>

    then after any change to this file, you can run:

<screen>
$ nix-env -f my-packages.nix -ir
</screen>

    to update your profile to match the specification.</para>
  </listitem>

  <listitem>
    <para>The &#x2018;<literal>with</literal>&#x2019; language construct is now more
    lazy.  It only evaluates its argument if a variable might actually
    refer to an attribute in the argument.  For instance, this now
    works:

<programlisting>
let
  pkgs = with pkgs; { foo = "old"; bar = foo; } // overrides;
  overrides = { foo = "new"; };
in pkgs.bar
</programlisting>

    This evaluates to <literal>"new"</literal>, while previously it
    gave an &#x201C;infinite recursion&#x201D; error.</para>
  </listitem>

  <listitem>
    <para>Nix now has proper integer arithmetic operators. For
    instance, you can write <literal>x + y</literal> instead of
    <literal>builtins.add x y</literal>, or <literal>x &lt;
    y</literal> instead of <literal>builtins.lessThan x y</literal>.
    The comparison operators also work on strings.</para>
  </listitem>

  <listitem>
    <para>On 64-bit systems, Nix integers are now 64 bits rather than
    32 bits.</para>
  </listitem>

  <listitem>
    <para>When using the Nix daemon, the <command>nix-daemon</command>
    worker process now runs on the same CPU as the client, on systems
    that support setting CPU affinity.  This gives a significant speedup
    on some systems.</para>
  </listitem>

  <listitem>
    <para>If a stack overflow occurs in the Nix evaluator, you now get
    a proper error message (rather than &#x201C;Segmentation fault&#x201D;) on some
    systems.</para>
  </listitem>

  <listitem>
    <para>In addition to directories, you can now bind-mount regular
    files in chroots through the (now misnamed) option
    <option>build-chroot-dirs</option>.</para>
  </listitem>

</itemizedlist>

<para>This release has contributions from Domen Ko&#x17E;ar, Eelco Dolstra,
Florian Friesdorf, Gergely Risko, Ivan Kozik, Ludovic Court&#xE8;s and Shea
Levy.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.5.2">

<title>Release 1.5.2 (2013-05-13)</title>

<para>This is primarily a bug fix release.  It has contributions from
Eelco Dolstra, Llu&#xED;s Batlle i Rossell and Shea Levy.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.5">

<title>Release 1.5 (2013-02-27)</title>

<para>This is a brown paper bag release to fix a regression introduced
by the hard link security fix in 1.4.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.4">

<title>Release 1.4 (2013-02-26)</title>

<para>This release fixes a security bug in multi-user operation.  It
was possible for derivations to cause the mode of files outside of the
Nix store to be changed to 444 (read-only but world-readable) by
creating hard links to those files (<link xlink:href="https://github.com/NixOS/nix/commit/5526a282b5b44e9296e61e07d7d2626a79141ac4">details</link>).</para>

<para>There are also the following improvements:</para>

<itemizedlist>

  <listitem><para>New built-in function:
  <function>builtins.hashString</function>.</para></listitem>

  <listitem><para>Build logs are now stored in
  <filename>/nix/var/log/nix/drvs/<replaceable>XX</replaceable>/</filename>,
  where <replaceable>XX</replaceable> is the first two characters of
  the derivation.  This is useful on machines that keep a lot of build
  logs (such as Hydra servers).</para></listitem>

  <listitem><para>The function <function>corepkgs/fetchurl</function>
  can now make the downloaded file executable.  This will allow
  getting rid of all bootstrap binaries in the Nixpkgs source
  tree.</para></listitem>

  <listitem><para>Language change: The expression <literal>"${./path}
  ..."</literal> now evaluates to a string instead of a
  path.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.3">

<title>Release 1.3 (2013-01-04)</title>

<para>This is primarily a bug fix release.  When this version is first
run on Linux, it removes any immutable bits from the Nix store and
increases the schema version of the Nix store.  (The previous release
removed support for setting the immutable bit; this release clears any
remaining immutable bits to make certain operations more
efficient.)</para>

<para>This release has contributions from Eelco Dolstra and Stuart
Pernsteiner.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.2">

<title>Release 1.2 (2012-12-06)</title>

<para>This release has the following improvements and changes:</para>

<itemizedlist>

  <listitem>
    <para>Nix has a new binary substituter mechanism: the
    <emphasis>binary cache</emphasis>.  A binary cache contains
    pre-built binaries of Nix packages.  Whenever Nix wants to build a
    missing Nix store path, it will check a set of binary caches to
    see if any of them has a pre-built binary of that path.  The
    configuration setting <option>binary-caches</option> contains a
    list of URLs of binary caches.  For instance, doing
<screen>
$ nix-env -i thunderbird --option binary-caches http://cache.nixos.org
</screen>
    will install Thunderbird and its dependencies, using the available
    pre-built binaries in <uri>http://cache.nixos.org</uri>.
    The main advantage over the old &#x201C;manifest&#x201D;-based method of getting
    pre-built binaries is that you don&#x2019;t have to worry about your
    manifest being in sync with the Nix expressions you&#x2019;re installing
    from; i.e., you don&#x2019;t need to run <command>nix-pull</command> to
    update your manifest.  It&#x2019;s also more scalable because you don&#x2019;t
    need to redownload a giant manifest file every time.
    </para>

    <para>A Nix channel can provide a binary cache URL that will be
    used automatically if you subscribe to that channel.  If you use
    the Nixpkgs or NixOS channels
    (<uri>http://nixos.org/channels</uri>) you automatically get the
    cache <uri>http://cache.nixos.org</uri>.</para>

    <para>Binary caches are created using <command>nix-push</command>.
    For details on the operation and format of binary caches, see the
    <command>nix-push</command> manpage.  More details are provided in
    <link xlink:href="https://nixos.org/nix-dev/2012-September/009826.html">this
    nix-dev posting</link>.</para>
  </listitem>

  <listitem>
    <para>Multiple output support should now be usable.  A derivation
    can declare that it wants to produce multiple store paths by
    saying something like
<programlisting>
outputs = [ "lib" "headers" "doc" ];
</programlisting>
    This will cause Nix to pass the intended store path of each output
    to the builder through the environment variables
    <literal>lib</literal>, <literal>headers</literal> and
    <literal>doc</literal>.  Other packages can refer to a specific
    output by referring to
    <literal><replaceable>pkg</replaceable>.<replaceable>output</replaceable></literal>,
    e.g.
<programlisting>
buildInputs = [ pkg.lib pkg.headers ];
</programlisting>
    If you install a package with multiple outputs using
    <command>nix-env</command>, each output path will be symlinked
    into the user environment.</para>
  </listitem>

  <listitem>
    <para>Dashes are now valid as part of identifiers and attribute
    names.</para>
  </listitem>

  <listitem>
    <para>The new operation <command>nix-store --repair-path</command>
    allows corrupted or missing store paths to be repaired by
    redownloading them.  <command>nix-store --verify --check-contents
    --repair</command> will scan and repair all paths in the Nix
    store.  Similarly, <command>nix-env</command>,
    <command>nix-build</command>, <command>nix-instantiate</command>
    and <command>nix-store --realise</command> have a
    <option>--repair</option> flag to detect and fix bad paths by
    rebuilding or redownloading them.</para>
  </listitem>

  <listitem>
    <para>Nix no longer sets the immutable bit on files in the Nix
    store.  Instead, the recommended way to guard the Nix store
    against accidental modification on Linux is to make it a read-only
    bind mount, like this:

<screen>
$ mount --bind /nix/store /nix/store
$ mount -o remount,ro,bind /nix/store
</screen>

    Nix will automatically make <filename>/nix/store</filename>
    writable as needed (using a private mount namespace) to allow
    modifications.</para>
  </listitem>

  <listitem>
    <para>Store optimisation (replacing identical files in the store
    with hard links) can now be done automatically every time a path
    is added to the store.  This is enabled by setting the
    configuration option <literal>auto-optimise-store</literal> to
    <literal>true</literal> (disabled by default).</para>
  </listitem>

  <listitem>
    <para>Nix now supports <command>xz</command> compression for NARs
    in addition to <command>bzip2</command>.  It compresses about 30%
    better on typical archives and decompresses about twice as
    fast.</para>
  </listitem>

  <listitem>
    <para>Basic Nix expression evaluation profiling: setting the
    environment variable <envar>NIX_COUNT_CALLS</envar> to
    <literal>1</literal> will cause Nix to print how many times each
    primop or function was executed.</para>
  </listitem>

  <listitem>
    <para>New primops: <varname>concatLists</varname>,
    <varname>elem</varname>, <varname>elemAt</varname> and
    <varname>filter</varname>.</para>
  </listitem>

  <listitem>
    <para>The command <command>nix-copy-closure</command> has a new
    flag <option>--use-substitutes</option> (<option>-s</option>) to
    download missing paths on the target machine using the substitute
    mechanism.</para>
  </listitem>

  <listitem>
    <para>The command <command>nix-worker</command> has been renamed
    to <command>nix-daemon</command>.  Support for running the Nix
    worker in &#x201C;slave&#x201D; mode has been removed.</para>
  </listitem>

  <listitem>
    <para>The <option>--help</option> flag of every Nix command now
    invokes <command>man</command>.</para>
  </listitem>

  <listitem>
    <para>Chroot builds are now supported on systemd machines.</para>
  </listitem>

</itemizedlist>

<para>This release has contributions from Eelco Dolstra, Florian
Friesdorf, Mats Erik Andersson and Shea Levy.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.1">

<title>Release 1.1 (2012-07-18)</title>

<para>This release has the following improvements:</para>

<itemizedlist>

  <listitem>
    <para>On Linux, when doing a chroot build, Nix now uses various
    namespace features provided by the Linux kernel to improve
    build isolation.  Namely:
    <itemizedlist>
      <listitem><para>The private network namespace ensures that
      builders cannot talk to the outside world (or vice versa): each
      build only sees a private loopback interface.  This also means
      that two concurrent builds can listen on the same port (e.g. as
      part of a test) without conflicting with each
      other.</para></listitem>
      <listitem><para>The PID namespace causes each build to start as
      PID 1.  Processes outside of the chroot are not visible to those
      on the inside.  On the other hand, processes inside the chroot
      <emphasis>are</emphasis> visible from the outside (though with
      different PIDs).</para></listitem>
      <listitem><para>The IPC namespace prevents the builder from
      communicating with outside processes using SysV IPC mechanisms
      (shared memory, message queues, semaphores).  It also ensures
      that all IPC objects are destroyed when the builder
      exits.</para></listitem>
      <listitem><para>The UTS namespace ensures that builders see a
      hostname of <literal>localhost</literal> rather than the actual
      hostname.</para></listitem>
      <listitem><para>The private mount namespace was already used by
      Nix to ensure that the bind-mounts used to set up the chroot are
      cleaned up automatically.</para></listitem>
    </itemizedlist>
    </para>
  </listitem>

  <listitem>
    <para>Build logs are now compressed using
    <command>bzip2</command>.  The command <command>nix-store
    -l</command> decompresses them on the fly.  This can be disabled
    by setting the option <literal>build-compress-log</literal> to
    <literal>false</literal>.</para>
  </listitem>

  <listitem>
    <para>The creation of build logs in
    <filename>/nix/var/log/nix/drvs</filename> can be disabled by
    setting the new option <literal>build-keep-log</literal> to
    <literal>false</literal>.  This is useful, for instance, for Hydra
    build machines.</para>
  </listitem>

  <listitem>
    <para>Nix now reserves some space in
    <filename>/nix/var/nix/db/reserved</filename> to ensure that the
    garbage collector can run successfully if the disk is full.  This
    is necessary because SQLite transactions fail if the disk is
    full.</para>
  </listitem>

  <listitem>
    <para>Added a basic <function>fetchurl</function> function.  This
    is not intended to replace the <function>fetchurl</function> in
    Nixpkgs, but is useful for bootstrapping; e.g., it will allow us
    to get rid of the bootstrap binaries in the Nixpkgs source tree
    and download them instead.  You can use it by doing
    <literal>import &lt;nix/fetchurl.nix&gt; { url =
    <replaceable>url</replaceable>; sha256 =
    "<replaceable>hash</replaceable>"; }</literal>. (Shea Levy)</para>
  </listitem>

  <listitem>
    <para>Improved RPM spec file. (Michel Alexandre Salim)</para>
  </listitem>

  <listitem>
    <para>Support for on-demand socket-based activation in the Nix
    daemon with <command>systemd</command>.</para>
  </listitem>

  <listitem>
    <para>Added a manpage for
    <citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
  </listitem>

  <listitem>
    <para>When using the Nix daemon, the <option>-s</option> flag in
    <command>nix-env -qa</command> is now much faster.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-1.0">

<title>Release 1.0 (2012-05-11)</title>

<para>There have been numerous improvements and bug fixes since the
previous release.  Here are the most significant:</para>

<itemizedlist>

  <listitem>
    <para>Nix can now optionally use the Boehm garbage collector.
    This significantly reduces the Nix evaluator&#x2019;s memory footprint,
    especially when evaluating large NixOS system configurations.  It
    can be enabled using the <option>--enable-gc</option> configure
    option.</para>
  </listitem>

  <listitem>
    <para>Nix now uses SQLite for its database.  This is faster and
    more flexible than the old <emphasis>ad hoc</emphasis> format.
    SQLite is also used to cache the manifests in
    <filename>/nix/var/nix/manifests</filename>, resulting in a
    significant speedup.</para>
  </listitem>

  <listitem>
    <para>Nix now has an search path for expressions.  The search path
    is set using the environment variable <envar>NIX_PATH</envar> and
    the <option>-I</option> command line option.  In Nix expressions,
    paths between angle brackets are used to specify files that must
    be looked up in the search path.  For instance, the expression
    <literal>&lt;nixpkgs/default.nix&gt;</literal> looks for a file
    <filename>nixpkgs/default.nix</filename> relative to every element
    in the search path.</para>
  </listitem>

  <listitem>
    <para>The new command <command>nix-build --run-env</command>
    builds all dependencies of a derivation, then starts a shell in an
    environment containing all variables from the derivation.  This is
    useful for reproducing the environment of a derivation for
    development.</para>
  </listitem>

  <listitem>
    <para>The new command <command>nix-store --verify-path</command>
    verifies that the contents of a store path have not
    changed.</para>
  </listitem>

  <listitem>
    <para>The new command <command>nix-store --print-env</command>
    prints out the environment of a derivation in a format that can be
    evaluated by a shell.</para>
  </listitem>

  <listitem>
    <para>Attribute names can now be arbitrary strings.  For instance,
    you can write <literal>{ "foo-1.2" = &#x2026;; "bla bla" = &#x2026;; }."bla
    bla"</literal>.</para>
  </listitem>

  <listitem>
    <para>Attribute selection can now provide a default value using
    the <literal>or</literal> operator.  For instance, the expression
    <literal>x.y.z or e</literal> evaluates to the attribute
    <literal>x.y.z</literal> if it exists, and <literal>e</literal>
    otherwise.</para>
  </listitem>

  <listitem>
    <para>The right-hand side of the <literal>?</literal> operator can
    now be an attribute path, e.g., <literal>attrs ?
    a.b.c</literal>.</para>
  </listitem>

  <listitem>
    <para>On Linux, Nix will now make files in the Nix store immutable
    on filesystems that support it.  This prevents accidental
    modification of files in the store by the root user.</para>
  </listitem>

  <listitem>
    <para>Nix has preliminary support for derivations with multiple
    outputs.  This is useful because it allows parts of a package to
    be deployed and garbage-collected separately.  For instance,
    development parts of a package such as header files or static
    libraries would typically not be part of the closure of an
    application, resulting in reduced disk usage and installation
    time.</para>
  </listitem>

  <listitem>
    <para>The Nix store garbage collector is faster and holds the
    global lock for a shorter amount of time.</para>
  </listitem>

  <listitem>
    <para>The option <option>--timeout</option> (corresponding to the
    configuration setting <literal>build-timeout</literal>) allows you
    to set an absolute timeout on builds &#x2014; if a build runs for more than
    the given number of seconds, it is terminated.  This is useful for
    recovering automatically from builds that are stuck in an infinite
    loop but keep producing output, and for which
    <literal>--max-silent-time</literal> is ineffective.</para>
  </listitem>

  <listitem>
    <para>Nix development has moved to GitHub (<link xlink:href="https://github.com/NixOS/nix"/>).</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-0.16">

<title>Release 0.16 (2010-08-17)</title>

<para>This release has the following improvements:</para>

<itemizedlist>

  <listitem>
    <para>The Nix expression evaluator is now much faster in most
    cases: typically, <link xlink:href="http://www.mail-archive.com/nix-dev@cs.uu.nl/msg04113.html">3
    to 8 times compared to the old implementation</link>.  It also
    uses less memory.  It no longer depends on the ATerm
    library.</para>
  </listitem>

  <listitem>
    <para>
      Support for configurable parallelism inside builders.  Build
      scripts have always had the ability to perform multiple build
      actions in parallel (for instance, by running <command>make -j
      2</command>), but this was not desirable because the number of
      actions to be performed in parallel was not configurable.  Nix
      now has an option <option>--cores
      <replaceable>N</replaceable></option> as well as a configuration
      setting <varname>build-cores =
      <replaceable>N</replaceable></varname> that causes the
      environment variable <envar>NIX_BUILD_CORES</envar> to be set to
      <replaceable>N</replaceable> when the builder is invoked.  The
      builder can use this at its discretion to perform a parallel
      build, e.g., by calling <command>make -j
      <replaceable>N</replaceable></command>.  In Nixpkgs, this can be
      enabled on a per-package basis by setting the derivation
      attribute <varname>enableParallelBuilding</varname> to
      <literal>true</literal>.
    </para>
  </listitem>

  <listitem>
    <para><command>nix-store -q</command> now supports XML output
    through the <option>--xml</option> flag.</para>
  </listitem>

  <listitem>
    <para>Several bug fixes.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-0.15">

<title>Release 0.15 (2010-03-17)</title>

<para>This is a bug-fix release.  Among other things, it fixes
building on Mac OS X (Snow Leopard), and improves the contents of
<filename>/etc/passwd</filename> and <filename>/etc/group</filename>
in <literal>chroot</literal> builds.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-0.14">

<title>Release 0.14 (2010-02-04)</title>

<para>This release has the following improvements:</para>

<itemizedlist>

  <listitem>
    <para>The garbage collector now starts deleting garbage much
    faster than before.  It no longer determines liveness of all paths
    in the store, but does so on demand.</para>
  </listitem>

  <listitem>
    <para>Added a new operation, <command>nix-store --query
    --roots</command>, that shows the garbage collector roots that
    directly or indirectly point to the given store paths.</para>
  </listitem>

  <listitem>
    <para>Removed support for converting Berkeley DB-based Nix
    databases to the new schema.</para>
  </listitem>

  <listitem>
    <para>Removed the <option>--use-atime</option> and
    <option>--max-atime</option> garbage collector options.  They were
    not very useful in practice.</para>
  </listitem>

  <listitem>
    <para>On Windows, Nix now requires Cygwin 1.7.x.</para>
  </listitem>

  <listitem>
    <para>A few bug fixes.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-0.13">

<title>Release 0.13 (2009-11-05)</title>

<para>This is primarily a bug fix release.  It has some new
features:</para>

<itemizedlist>

  <listitem>
    <para>Syntactic sugar for writing nested attribute sets.  Instead of

<programlisting>
{
  foo = {
    bar = 123;
    xyzzy = true;
  };
  a = { b = { c = "d"; }; };
}
</programlisting>

    you can write

<programlisting>
{
  foo.bar = 123;
  foo.xyzzy = true;
  a.b.c = "d";
}
</programlisting>

    This is useful, for instance, in NixOS configuration files.</para>

  </listitem>

  <listitem>
    <para>Support for Nix channels generated by Hydra, the Nix-based
    continuous build system.  (Hydra generates NAR archives on the
    fly, so the size and hash of these archives isn&#x2019;t known in
    advance.)</para>
  </listitem>

  <listitem>
    <para>Support <literal>i686-linux</literal> builds directly on
    <literal>x86_64-linux</literal> Nix installations.  This is
    implemented using the <function>personality()</function> syscall,
    which causes <command>uname</command> to return
    <literal>i686</literal> in child processes.</para>
  </listitem>

  <listitem>
    <para>Various improvements to the <literal>chroot</literal>
    support.  Building in a <literal>chroot</literal> works quite well
    now.</para>
  </listitem>

  <listitem>
    <para>Nix no longer blocks if it tries to build a path and another
    process is already building the same path.  Instead it tries to
    build another buildable path first.  This improves
    parallelism.</para>
  </listitem>

  <listitem>
    <para>Support for large (&gt; 4 GiB) files in NAR archives.</para>
  </listitem>

  <listitem>
    <para>Various (performance) improvements to the remote build
    mechanism.</para>
  </listitem>

  <listitem>
    <para>New primops: <varname>builtins.addErrorContext</varname> (to
    add a string to stack traces &#x2014; useful for debugging),
    <varname>builtins.isBool</varname>,
    <varname>builtins.isString</varname>,
    <varname>builtins.isInt</varname>,
    <varname>builtins.intersectAttrs</varname>.</para>
  </listitem>

  <listitem>
    <para>OpenSolaris support (Sander van der Burg).</para>
  </listitem>

  <listitem>
    <para>Stack traces are no longer displayed unless the
    <option>--show-trace</option> option is used.</para>
  </listitem>

  <listitem>
    <para>The scoping rules for <literal>inherit
    (<replaceable>e</replaceable>) ...</literal> in recursive
    attribute sets have changed.  The expression
    <replaceable>e</replaceable> can now refer to the attributes
    defined in the containing set.</para>
  </listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-0.12">

<title>Release 0.12 (2008-11-20)</title>

<itemizedlist>

  <listitem>
    <para>Nix no longer uses Berkeley DB to store Nix store metadata.
    The principal advantages of the new storage scheme are: it works
    properly over decent implementations of NFS (allowing Nix stores
    to be shared between multiple machines); no recovery is needed
    when a Nix process crashes; no write access is needed for
    read-only operations; no more running out of Berkeley DB locks on
    certain operations.</para>

    <para>You still need to compile Nix with Berkeley DB support if
    you want Nix to automatically convert your old Nix store to the
    new schema.  If you don&#x2019;t need this, you can build Nix with the
    <filename>configure</filename> option
    <option>--disable-old-db-compat</option>.</para>

    <para>After the automatic conversion to the new schema, you can
    delete the old Berkeley DB files:

    <screen>
$ cd /nix/var/nix/db
$ rm __db* log.* derivers references referrers reserved validpaths DB_CONFIG</screen>

    The new metadata is stored in the directories
    <filename>/nix/var/nix/db/info</filename> and
    <filename>/nix/var/nix/db/referrer</filename>.  Though the
    metadata is stored in human-readable plain-text files, they are
    not intended to be human-editable, as Nix is rather strict about
    the format.</para>

    <para>The new storage schema may or may not require less disk
    space than the Berkeley DB environment, mostly depending on the
    cluster size of your file system.  With 1 KiB clusters (which
    seems to be the <literal>ext3</literal> default nowadays) it
    usually takes up much less space.</para>
  </listitem>

  <listitem><para>There is a new substituter that copies paths
  directly from other (remote) Nix stores mounted somewhere in the
  filesystem.  For instance, you can speed up an installation by
  mounting some remote Nix store that already has the packages in
  question via NFS or <literal>sshfs</literal>.  The environment
  variable <envar>NIX_OTHER_STORES</envar> specifies the locations of
  the remote Nix directories,
  e.g. <literal>/mnt/remote-fs/nix</literal>.</para></listitem>

  <listitem><para>New <command>nix-store</command> operations
  <option>--dump-db</option> and <option>--load-db</option> to dump
  and reload the Nix database.</para></listitem>

  <listitem><para>The garbage collector has a number of new options to
  allow only some of the garbage to be deleted.  The option
  <option>--max-freed <replaceable>N</replaceable></option> tells the
  collector to stop after at least <replaceable>N</replaceable> bytes
  have been deleted.  The option <option>--max-links
  <replaceable>N</replaceable></option> tells it to stop after the
  link count on <filename>/nix/store</filename> has dropped below
  <replaceable>N</replaceable>.  This is useful for very large Nix
  stores on filesystems with a 32000 subdirectories limit (like
  <literal>ext3</literal>).  The option <option>--use-atime</option>
  causes store paths to be deleted in order of ascending last access
  time.  This allows non-recently used stuff to be deleted.  The
  option <option>--max-atime <replaceable>time</replaceable></option>
  specifies an upper limit to the last accessed time of paths that may
  be deleted.  For instance,

    <screen>
    $ nix-store --gc -v --max-atime $(date +%s -d "2 months ago")</screen>

  deletes everything that hasn&#x2019;t been accessed in two months.</para></listitem>

  <listitem><para><command>nix-env</command> now uses optimistic
  profile locking when performing an operation like installing or
  upgrading, instead of setting an exclusive lock on the profile.
  This allows multiple <command>nix-env -i / -u / -e</command>
  operations on the same profile in parallel.  If a
  <command>nix-env</command> operation sees at the end that the profile
  was changed in the meantime by another process, it will just
  restart.  This is generally cheap because the build results are
  still in the Nix store.</para></listitem>

  <listitem><para>The option <option>--dry-run</option> is now
  supported by <command>nix-store -r</command> and
  <command>nix-build</command>.</para></listitem>

  <listitem><para>The information previously shown by
  <option>--dry-run</option> (i.e., which derivations will be built
  and which paths will be substituted) is now always shown by
  <command>nix-env</command>, <command>nix-store -r</command> and
  <command>nix-build</command>.  The total download size of
  substitutable paths is now also shown.  For instance, a build will
  show something like

    <screen>
the following derivations will be built:
  /nix/store/129sbxnk5n466zg6r1qmq1xjv9zymyy7-activate-configuration.sh.drv
  /nix/store/7mzy971rdm8l566ch8hgxaf89x7lr7ik-upstart-jobs.drv
  ...
the following paths will be downloaded/copied (30.02 MiB):
  /nix/store/4m8pvgy2dcjgppf5b4cj5l6wyshjhalj-samba-3.2.4
  /nix/store/7h1kwcj29ip8vk26rhmx6bfjraxp0g4l-libunwind-0.98.6
  ...</screen>

  </para></listitem>

  <listitem><para>Language features:

    <itemizedlist>

      <listitem><para>@-patterns as in Haskell.  For instance, in a
      function definition

      <programlisting>f = args @ {x, y, z}: <replaceable>...</replaceable>;</programlisting>

      <varname>args</varname> refers to the argument as a whole, which
      is further pattern-matched against the attribute set pattern
      <literal>{x, y, z}</literal>.</para></listitem>

      <listitem><para>&#x201C;<literal>...</literal>&#x201D; (ellipsis) patterns.
      An attribute set pattern can now say <literal>...</literal>  at
      the end of the attribute name list to specify that the function
      takes <emphasis>at least</emphasis> the listed attributes, while
      ignoring additional attributes.  For instance,

      <programlisting>{stdenv, fetchurl, fuse, ...}: <replaceable>...</replaceable></programlisting>

      defines a function that accepts any attribute set that includes
      at least the three listed attributes.</para></listitem>

      <listitem><para>New primops:
      <varname>builtins.parseDrvName</varname> (split a package name
      string like <literal>"nix-0.12pre12876"</literal> into its name
      and version components, e.g. <literal>"nix"</literal> and
      <literal>"0.12pre12876"</literal>),
      <varname>builtins.compareVersions</varname> (compare two version
      strings using the same algorithm that <command>nix-env</command>
      uses), <varname>builtins.length</varname> (efficiently compute
      the length of a list), <varname>builtins.mul</varname> (integer
      multiplication), <varname>builtins.div</varname> (integer
      division).
      <!-- <varname>builtins.genericClosure</varname> -->
      </para></listitem>

    </itemizedlist>

  </para></listitem>

  <listitem><para><command>nix-prefetch-url</command> now supports
  <literal>mirror://</literal> URLs, provided that the environment
  variable <envar>NIXPKGS_ALL</envar> points at a Nixpkgs
  tree.</para></listitem>

  <listitem><para>Removed the commands
  <command>nix-pack-closure</command> and
  <command>nix-unpack-closure</command>.   You can do almost the same
  thing but much more efficiently by doing <literal>nix-store --export
  $(nix-store -qR <replaceable>paths</replaceable>) &gt; closure</literal> and
  <literal>nix-store --import &lt;
  closure</literal>.</para></listitem>

  <listitem><para>Lots of bug fixes, including a big performance bug in
  the handling of <literal>with</literal>-expressions.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ssec-relnotes-0.11">

<title>Release 0.11 (2007-12-31)</title>

<para>Nix 0.11 has many improvements over the previous stable release.
The most important improvement is secure multi-user support.  It also
features many usability enhancements and language extensions, many of
them prompted by NixOS, the purely functional Linux distribution based
on Nix.  Here is an (incomplete) list:</para>


<itemizedlist>


  <listitem><para>Secure multi-user support.  A single Nix store can
  now be shared between multiple (possible untrusted) users.  This is
  an important feature for NixOS, where it allows non-root users to
  install software.  The old setuid method for sharing a store between
  multiple users has been removed.  Details for setting up a
  multi-user store can be found in the manual.</para></listitem>


  <listitem><para>The new command <command>nix-copy-closure</command>
  gives you an easy and efficient way to exchange software between
  machines.  It copies the missing parts of the closure of a set of
  store path to or from a remote machine via
  <command>ssh</command>.</para></listitem>


  <listitem><para>A new kind of string literal: strings between double
  single-quotes (<literal>''</literal>) have indentation
  &#x201C;intelligently&#x201D; removed.  This allows large strings (such as shell
  scripts or configuration file fragments in NixOS) to cleanly follow
  the indentation of the surrounding expression.  It also requires
  much less escaping, since <literal>''</literal> is less common in
  most languages than <literal>"</literal>.</para></listitem>


  <listitem><para><command>nix-env</command> <option>--set</option>
  modifies the current generation of a profile so that it contains
  exactly the specified derivation, and nothing else.  For example,
  <literal>nix-env -p /nix/var/nix/profiles/browser --set
  firefox</literal> lets the profile named
  <filename>browser</filename> contain just Firefox.</para></listitem>


  <listitem><para><command>nix-env</command> now maintains
  meta-information about installed packages in profiles.  The
  meta-information is the contents of the <varname>meta</varname>
  attribute of derivations, such as <varname>description</varname> or
  <varname>homepage</varname>.  The command <literal>nix-env -q --xml
  --meta</literal> shows all meta-information.</para></listitem>


  <listitem><para><command>nix-env</command> now uses the
  <varname>meta.priority</varname> attribute of derivations to resolve
  filename collisions between packages.  Lower priority values denote
  a higher priority.  For instance, the GCC wrapper package and the
  Binutils package in Nixpkgs both have a file
  <filename>bin/ld</filename>, so previously if you tried to install
  both you would get a collision.  Now, on the other hand, the GCC
  wrapper declares a higher priority than Binutils, so the former&#x2019;s
  <filename>bin/ld</filename> is symlinked in the user
  environment.</para></listitem>


  <listitem><para><command>nix-env -i / -u</command>: instead of
  breaking package ties by version, break them by priority and version
  number.  That is, if there are multiple packages with the same name,
  then pick the package with the highest priority, and only use the
  version if there are multiple packages with the same
  priority.</para>

  <para>This makes it possible to mark specific versions/variant in
  Nixpkgs more or less desirable than others.  A typical example would
  be a beta version of some package (e.g.,
  <literal>gcc-4.2.0rc1</literal>) which should not be installed even
  though it is the highest version, except when it is explicitly
  selected (e.g., <literal>nix-env -i
  gcc-4.2.0rc1</literal>).</para></listitem>


  <listitem><para><command>nix-env --set-flag</command> allows meta
  attributes of installed packages to be modified.  There are several
  attributes that can be usefully modified, because they affect the
  behaviour of <command>nix-env</command> or the user environment
  build script:

    <itemizedlist>

      <listitem><para><varname>meta.priority</varname> can be changed
      to resolve filename clashes (see above).</para></listitem>

      <listitem><para><varname>meta.keep</varname> can be set to
      <literal>true</literal> to prevent the package from being
      upgraded or replaced.  Useful if you want to hang on to an older
      version of a package.</para></listitem>

      <listitem><para><varname>meta.active</varname> can be set to
      <literal>false</literal> to &#x201C;disable&#x201D; the package.  That is, no
      symlinks will be generated to the files of the package, but it
      remains part of the profile (so it won&#x2019;t be garbage-collected).
      Set it back to <literal>true</literal> to re-enable the
      package.</para></listitem>

    </itemizedlist>

  </para></listitem>


  <listitem><para><command>nix-env -q</command> now has a flag
  <option>--prebuilt-only</option> (<option>-b</option>) that causes
  <command>nix-env</command> to show only those derivations whose
  output is already in the Nix store or that can be substituted (i.e.,
  downloaded from somewhere).  In other words, it shows the packages
  that can be installed &#x201C;quickly&#x201D;, i.e., don&#x2019;t need to be built from
  source.  The <option>-b</option> flag is also available in
  <command>nix-env -i</command> and <command>nix-env -u</command> to
  filter out derivations for which no pre-built binary is
  available.</para></listitem>


  <listitem><para>The new option <option>--argstr</option> (in
  <command>nix-env</command>, <command>nix-instantiate</command> and
  <command>nix-build</command>) is like <option>--arg</option>, except
  that the value is a string.  For example, <literal>--argstr system
  i686-linux</literal> is equivalent to <literal>--arg system
  \"i686-linux\"</literal> (note that <option>--argstr</option>
  prevents annoying quoting around shell arguments).</para></listitem>


  <listitem><para><command>nix-store</command> has a new operation
  <option>--read-log</option> (<option>-l</option>)
  <parameter>paths</parameter> that shows the build log of the given
  paths.</para></listitem>


  <!--
  <listitem><para>TODO: semantic cleanups of string concatenation
  etc. (mostly in r6740).</para></listitem>
  -->


  <listitem><para>Nix now uses Berkeley DB 4.5.  The database is
  upgraded automatically, but you should be careful not to use old
  versions of Nix that still use Berkeley DB 4.4.</para></listitem>


  <!-- foo
  <listitem><para>TODO: option <option>- -reregister</option> in
  <command>nix-store - -register-validity</command>.</para></listitem>
  -->


  <listitem><para>The option <option>--max-silent-time</option>
  (corresponding to the configuration setting
  <literal>build-max-silent-time</literal>) allows you to set a
  timeout on builds &#x2014; if a build produces no output on
  <literal>stdout</literal> or <literal>stderr</literal> for the given
  number of seconds, it is terminated.  This is useful for recovering
  automatically from builds that are stuck in an infinite
  loop.</para></listitem>


  <listitem><para><command>nix-channel</command>: each subscribed
  channel is its own attribute in the top-level expression generated
  for the channel.  This allows disambiguation (e.g. <literal>nix-env
  -i -A nixpkgs_unstable.firefox</literal>).</para></listitem>


  <listitem><para>The substitutes table has been removed from the
  database.  This makes operations such as <command>nix-pull</command>
  and <command>nix-channel --update</command> much, much
  faster.</para></listitem>


  <listitem><para><command>nix-pull</command> now supports
  bzip2-compressed manifests.  This speeds up
  channels.</para></listitem>


  <listitem><para><command>nix-prefetch-url</command> now has a
  limited form of caching.  This is used by
  <command>nix-channel</command> to prevent unnecessary downloads when
  the channel hasn&#x2019;t changed.</para></listitem>


  <listitem><para><command>nix-prefetch-url</command> now by default
  computes the SHA-256 hash of the file instead of the MD5 hash.  In
  calls to <function>fetchurl</function> you should pass the
  <literal>sha256</literal> attribute instead of
  <literal>md5</literal>.  You can pass either a hexadecimal or a
  base-32 encoding of the hash.</para></listitem>


  <listitem><para>Nix can now perform builds in an automatically
  generated &#x201C;chroot&#x201D;.  This prevents a builder from accessing stuff
  outside of the Nix store, and thus helps ensure purity.  This is an
  experimental feature.</para></listitem>


  <listitem><para>The new command <command>nix-store
  --optimise</command> reduces Nix store disk space usage by finding
  identical files in the store and hard-linking them to each other.
  It typically reduces the size of the store by something like
  25-35%.</para></listitem>


  <listitem><para><filename>~/.nix-defexpr</filename> can now be a
  directory, in which case the Nix expressions in that directory are
  combined into an attribute set, with the file names used as the
  names of the attributes.  The command <command>nix-env
  --import</command> (which set the
  <filename>~/.nix-defexpr</filename> symlink) is
  removed.</para></listitem>


  <listitem><para>Derivations can specify the new special attribute
  <varname>allowedReferences</varname> to enforce that the references
  in the output of a derivation are a subset of a declared set of
  paths.  For example, if <varname>allowedReferences</varname> is an
  empty list, then the output must not have any references.  This is
  used in NixOS to check that generated files such as initial ramdisks
  for booting Linux don&#x2019;t have any dependencies.</para></listitem>


  <listitem><para>The new attribute
  <varname>exportReferencesGraph</varname> allows builders access to
  the references graph of their inputs.  This is used in NixOS for
  tasks such as generating ISO-9660 images that contain a Nix store
  populated with the closure of certain paths.</para></listitem>


  <listitem><para>Fixed-output derivations (like
  <function>fetchurl</function>) can define the attribute
  <varname>impureEnvVars</varname> to allow external environment
  variables to be passed to builders.  This is used in Nixpkgs to
  support proxy configuration, among other things.</para></listitem>


  <listitem><para>Several new built-in functions:
  <function>builtins.attrNames</function>,
  <function>builtins.filterSource</function>,
  <function>builtins.isAttrs</function>,
  <function>builtins.isFunction</function>,
  <function>builtins.listToAttrs</function>,
  <function>builtins.stringLength</function>,
  <function>builtins.sub</function>,
  <function>builtins.substring</function>,
  <function>throw</function>,
  <function>builtins.trace</function>,
  <function>builtins.readFile</function>.</para></listitem>


</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.10.1">

<title>Release 0.10.1 (2006-10-11)</title>

<para>This release fixes two somewhat obscure bugs that occur when
evaluating Nix expressions that are stored inside the Nix store
(<literal>NIX-67</literal>).  These do not affect most users.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.10">

<title>Release 0.10 (2006-10-06)</title>

<note><para>This version of Nix uses Berkeley DB 4.4 instead of 4.3.
The database is upgraded automatically, but you should be careful not
to use old versions of Nix that still use Berkeley DB 4.3.  In
particular, if you use a Nix installed through Nix, you should run

<screen>
$ nix-store --clear-substitutes</screen>

first.</para></note>

<warning><para>Also, the database schema has changed slighted to fix a
performance issue (see below).  When you run any Nix 0.10 command for
the first time, the database will be upgraded automatically.  This is
irreversible.</para></warning>

<itemizedlist>


  <!-- Usability / features -->


  <listitem><para><command>nix-env</command> usability improvements:

    <itemizedlist>

      <listitem><para>An option <option>--compare-versions</option>
      (or <option>-c</option>) has been added to <command>nix-env
      --query</command> to allow you to compare installed versions of
      packages to available versions, or vice versa.  An easy way to
      see if you are up to date with what&#x2019;s in your subscribed
      channels is <literal>nix-env -qc \*</literal>.</para></listitem>

      <listitem><para><literal>nix-env --query</literal> now takes as
      arguments a list of package names about which to show
      information, just like <option>--install</option>, etc.: for
      example, <literal>nix-env -q gcc</literal>.  Note that to show
      all derivations, you need to specify
      <literal>\*</literal>.</para></listitem>

      <listitem><para><literal>nix-env -i
      <replaceable>pkgname</replaceable></literal> will now install
      the highest available version of
      <replaceable>pkgname</replaceable>, rather than installing all
      available versions (which would probably give collisions)
      (<literal>NIX-31</literal>).</para></listitem>

      <listitem><para><literal>nix-env (-i|-u) --dry-run</literal> now
      shows exactly which missing paths will be built or
      substituted.</para></listitem>

      <listitem><para><literal>nix-env -qa --description</literal>
      shows human-readable descriptions of packages, provided that
      they have a <literal>meta.description</literal> attribute (which
      most packages in Nixpkgs don&#x2019;t have yet).</para></listitem>

    </itemizedlist>

  </para></listitem>


  <listitem><para>New language features:

    <itemizedlist>

      <listitem><para>Reference scanning (which happens after each
      build) is much faster and takes a constant amount of
      memory.</para></listitem>

      <listitem><para>String interpolation.  Expressions like

<programlisting>
"--with-freetype2-library=" + freetype + "/lib"</programlisting>

      can now be written as

<programlisting>
"--with-freetype2-library=${freetype}/lib"</programlisting>

      You can write arbitrary expressions within
      <literal>${<replaceable>...</replaceable>}</literal>, not just
      identifiers.</para></listitem>

      <listitem><para>Multi-line string literals.</para></listitem>

      <listitem><para>String concatenations can now involve
      derivations, as in the example <code>"--with-freetype2-library="
      + freetype + "/lib"</code>.  This was not previously possible
      because we need to register that a derivation that uses such a
      string is dependent on <literal>freetype</literal>.  The
      evaluator now properly propagates this information.
      Consequently, the subpath operator (<literal>~</literal>) has
      been deprecated.</para></listitem>

      <listitem><para>Default values of function arguments can now
      refer to other function arguments; that is, all arguments are in
      scope in the default values
      (<literal>NIX-45</literal>).</para></listitem>

      <!--
      <listitem><para>TODO: domain checks (r5895).</para></listitem>
      -->

      <listitem><para>Lots of new built-in primitives, such as
      functions for list manipulation and integer arithmetic.  See the
      manual for a complete list.  All primops are now available in
      the set <varname>builtins</varname>, allowing one to test for
      the availability of primop in a backwards-compatible
      way.</para></listitem>

      <listitem><para>Real let-expressions: <literal>let x = ...;
      ... z = ...; in ...</literal>.</para></listitem>

    </itemizedlist>

  </para></listitem>


  <listitem><para>New commands <command>nix-pack-closure</command> and
  <command>nix-unpack-closure</command> than can be used to easily
  transfer a store path with all its dependencies to another machine.
  Very convenient whenever you have some package on your machine and
  you want to copy it somewhere else.</para></listitem>


  <listitem><para>XML support:

    <itemizedlist>

      <listitem><para><literal>nix-env -q --xml</literal> prints the
      installed or available packages in an XML representation for
      easy processing by other tools.</para></listitem>

      <listitem><para><literal>nix-instantiate --eval-only
      --xml</literal> prints an XML representation of the resulting
      term.  (The new flag <option>--strict</option> forces &#x2018;deep&#x2019;
      evaluation of the result, i.e., list elements and attributes are
      evaluated recursively.)</para></listitem>

      <listitem><para>In Nix expressions, the primop
      <function>builtins.toXML</function> converts a term to an XML
      representation.  This is primarily useful for passing structured
      information to builders.</para></listitem>

    </itemizedlist>

  </para></listitem>


  <listitem><para>You can now unambiguously specify which derivation to
  build or install in <command>nix-env</command>,
  <command>nix-instantiate</command> and <command>nix-build</command>
  using the <option>--attr</option> / <option>-A</option> flags, which
  takes an attribute name as argument.  (Unlike symbolic package names
  such as <literal>subversion-1.4.0</literal>, attribute names in an
  attribute set are unique.)  For instance, a quick way to perform a
  test build of a package in Nixpkgs is <literal>nix-build
  pkgs/top-level/all-packages.nix -A
  <replaceable>foo</replaceable></literal>.  <literal>nix-env -q
  --attr</literal> shows the attribute names corresponding to each
  derivation.</para></listitem>


  <listitem><para>If the top-level Nix expression used by
  <command>nix-env</command>, <command>nix-instantiate</command> or
  <command>nix-build</command> evaluates to a function whose arguments
  all have default values, the function will be called automatically.
  Also, the new command-line switch <option>--arg
  <replaceable>name</replaceable>
  <replaceable>value</replaceable></option> can be used to specify
  function arguments on the command line.</para></listitem>


  <listitem><para><literal>nix-install-package --url
  <replaceable>URL</replaceable></literal> allows a package to be
  installed directly from the given URL.</para></listitem>


  <listitem><para>Nix now works behind an HTTP proxy server; just set
  the standard environment variables <envar>http_proxy</envar>,
  <envar>https_proxy</envar>, <envar>ftp_proxy</envar> or
  <envar>all_proxy</envar> appropriately.  Functions such as
  <function>fetchurl</function> in Nixpkgs also respect these
  variables.</para></listitem>


  <listitem><para><literal>nix-build -o
  <replaceable>symlink</replaceable></literal> allows the symlink to
  the build result to be named something other than
  <literal>result</literal>.</para></listitem>


  <!-- Stability / performance / etc. -->


  <listitem><para>Platform support:

    <itemizedlist>

      <listitem><para>Support for 64-bit platforms, provided a <link xlink:href="http://bugzilla.sen.cwi.nl:8080/show_bug.cgi?id=606">suitably
      patched ATerm library</link> is used.  Also, files larger than 2
      GiB are now supported.</para></listitem>

      <listitem><para>Added support for Cygwin (Windows,
      <literal>i686-cygwin</literal>), Mac OS X on Intel
      (<literal>i686-darwin</literal>) and Linux on PowerPC
      (<literal>powerpc-linux</literal>).</para></listitem>

      <listitem><para>Users of SMP and multicore machines will
      appreciate that the number of builds to be performed in parallel
      can now be specified in the configuration file in the
      <literal>build-max-jobs</literal> setting.</para></listitem>

    </itemizedlist>

  </para></listitem>


  <listitem><para>Garbage collector improvements:

    <itemizedlist>

      <listitem><para>Open files (such as running programs) are now
      used as roots of the garbage collector.  This prevents programs
      that have been uninstalled from being garbage collected while
      they are still running.  The script that detects these
      additional runtime roots
      (<filename>find-runtime-roots.pl</filename>) is inherently
      system-specific, but it should work on Linux and on all
      platforms that have the <command>lsof</command>
      utility.</para></listitem>

      <listitem><para><literal>nix-store --gc</literal>
      (a.k.a. <command>nix-collect-garbage</command>) prints out the
      number of bytes freed on standard output.  <literal>nix-store
      --gc --print-dead</literal> shows how many bytes would be freed
      by an actual garbage collection.</para></listitem>

      <listitem><para><literal>nix-collect-garbage -d</literal>
      removes all old generations of <emphasis>all</emphasis> profiles
      before calling the actual garbage collector (<literal>nix-store
      --gc</literal>).  This is an easy way to get rid of all old
      packages in the Nix store.</para></listitem>

      <listitem><para><command>nix-store</command> now has an
      operation <option>--delete</option> to delete specific paths
      from the Nix store.  It won&#x2019;t delete reachable (non-garbage)
      paths unless <option>--ignore-liveness</option> is
      specified.</para></listitem>

    </itemizedlist>

  </para></listitem>


  <listitem><para>Berkeley DB 4.4&#x2019;s process registry feature is used
  to recover from crashed Nix processes.</para></listitem>

  <!--  <listitem><para>TODO: shared stores.</para></listitem> -->

  <listitem><para>A performance issue has been fixed with the
  <literal>referer</literal> table, which stores the inverse of the
  <literal>references</literal> table (i.e., it tells you what store
  paths refer to a given path).  Maintaining this table could take a
  quadratic amount of time, as well as a quadratic amount of Berkeley
  DB log file space (in particular when running the garbage collector)
  (<literal>NIX-23</literal>).</para></listitem>

  <listitem><para>Nix now catches the <literal>TERM</literal> and
  <literal>HUP</literal> signals in addition to the
  <literal>INT</literal> signal.  So you can now do a <literal>killall
  nix-store</literal> without triggering a database
  recovery.</para></listitem>

  <listitem><para><command>bsdiff</command> updated to version
  4.3.</para></listitem>

  <listitem><para>Substantial performance improvements in expression
  evaluation and <literal>nix-env -qa</literal>, all thanks to <link xlink:href="http://valgrind.org/">Valgrind</link>.  Memory use has
  been reduced by a factor 8 or so.  Big speedup by memoisation of
  path hashing.</para></listitem>

  <listitem><para>Lots of bug fixes, notably:

    <itemizedlist>

      <listitem><para>Make sure that the garbage collector can run
      successfully when the disk is full
      (<literal>NIX-18</literal>).</para></listitem>

      <listitem><para><command>nix-env</command> now locks the profile
      to prevent races between concurrent <command>nix-env</command>
      operations on the same profile
      (<literal>NIX-7</literal>).</para></listitem>

      <listitem><para>Removed misleading messages from
      <literal>nix-env -i</literal> (e.g., <literal>installing
      `foo'</literal> followed by <literal>uninstalling
      `foo'</literal>) (<literal>NIX-17</literal>).</para></listitem>

    </itemizedlist>

  </para></listitem>

  <listitem><para>Nix source distributions are a lot smaller now since
  we no longer include a full copy of the Berkeley DB source
  distribution (but only the bits we need).</para></listitem>

  <listitem><para>Header files are now installed so that external
  programs can use the Nix libraries.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.9.2">

<title>Release 0.9.2 (2005-09-21)</title>

<para>This bug fix release fixes two problems on Mac OS X:

<itemizedlist>

  <listitem><para>If Nix was linked against statically linked versions
  of the ATerm or Berkeley DB library, there would be dynamic link
  errors at runtime.</para></listitem>

  <listitem><para><command>nix-pull</command> and
  <command>nix-push</command> intermittently failed due to race
  conditions involving pipes and child processes with error messages
  such as <literal>open2: open(GLOB(0x180b2e4), &gt;&amp;=9) failed: Bad
  file descriptor at /nix/bin/nix-pull line 77</literal> (issue
  <literal>NIX-14</literal>).</para></listitem>

</itemizedlist>

</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.9.1">

<title>Release 0.9.1 (2005-09-20)</title>

<para>This bug fix release addresses a problem with the ATerm library
when the <option>--with-aterm</option> flag in
<command>configure</command> was <emphasis>not</emphasis> used.</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.9">

<title>Release 0.9 (2005-09-16)</title>

<para>NOTE: this version of Nix uses Berkeley DB 4.3 instead of 4.2.
The database is upgraded automatically, but you should be careful not
to use old versions of Nix that still use Berkeley DB 4.2.  In
particular, if you use a Nix installed through Nix, you should run

<screen>
$ nix-store --clear-substitutes</screen>

first.</para>


<itemizedlist>

  <listitem><para>Unpacking of patch sequences is much faster now
  since we no longer do redundant unpacking and repacking of
  intermediate paths.</para></listitem>

  <listitem><para>Nix now uses Berkeley DB 4.3.</para></listitem>

  <listitem><para>The <function>derivation</function> primitive is
  lazier.  Attributes of dependent derivations can mutually refer to
  each other (as long as there are no data dependencies on the
  <varname>outPath</varname> and <varname>drvPath</varname> attributes
  computed by <function>derivation</function>).</para>

  <para>For example, the expression <literal>derivation
  attrs</literal> now evaluates to (essentially)

  <programlisting>
attrs // {
  type = "derivation";
  outPath = derivation! attrs;
  drvPath = derivation! attrs;
}</programlisting>

  where <function>derivation!</function> is a primop that does the
  actual derivation instantiation (i.e., it does what
  <function>derivation</function> used to do).  The advantage is that
  it allows commands such as <command>nix-env -qa</command> and
  <command>nix-env -i</command> to be much faster since they no longer
  need to instantiate all derivations, just the
  <varname>name</varname> attribute.</para>

  <para>Also, it allows derivations to cyclically reference each
  other, for example,

  <programlisting>
webServer = derivation {
  ...
  hostName = "svn.cs.uu.nl";
  services = [svnService];
};
 
svnService = derivation {
  ...
  hostName = webServer.hostName;
};</programlisting>

  Previously, this would yield a black hole (infinite recursion).</para>

  </listitem>

  <listitem><para><command>nix-build</command> now defaults to using
  <filename>./default.nix</filename> if no Nix expression is
  specified.</para></listitem>

  <listitem><para><command>nix-instantiate</command>, when applied to
  a Nix expression that evaluates to a function, will call the
  function automatically if all its arguments have
  defaults.</para></listitem>

  <listitem><para>Nix now uses libtool to build dynamic libraries.
  This reduces the size of executables.</para></listitem>

  <listitem><para>A new list concatenation operator
  <literal>++</literal>.  For example, <literal>[1 2 3] ++ [4 5
  6]</literal> evaluates to <literal>[1 2 3 4 5
  6]</literal>.</para></listitem>

  <listitem><para>Some currently undocumented primops to support
  low-level build management using Nix (i.e., using Nix as a Make
  replacement).  See the commit messages for <literal>r3578</literal>
  and <literal>r3580</literal>.</para></listitem>

  <listitem><para>Various bug fixes and performance
  improvements.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.8.1">

<title>Release 0.8.1 (2005-04-13)</title>

<para>This is a bug fix release.</para>

<itemizedlist>

  <listitem><para>Patch downloading was broken.</para></listitem>

  <listitem><para>The garbage collector would not delete paths that
  had references from invalid (but substitutable)
  paths.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.8">

<title>Release 0.8 (2005-04-11)</title>

<para>NOTE: the hashing scheme in Nix 0.8 changed (as detailed below).
As a result, <command>nix-pull</command> manifests and channels built
for Nix 0.7 and below will not work anymore.  However, the Nix
expression language has not changed, so you can still build from
source.  Also, existing user environments continue to work.  Nix 0.8
will automatically upgrade the database schema of previous
installations when it is first run.</para>

<para>If you get the error message

<screen>
you have an old-style manifest `/nix/var/nix/manifests/[...]'; please
delete it</screen>

you should delete previously downloaded manifests:

<screen>
$ rm /nix/var/nix/manifests/*</screen>

If <command>nix-channel</command> gives the error message

<screen>
manifest `http://catamaran.labs.cs.uu.nl/dist/nix/channels/[channel]/MANIFEST'
is too old (i.e., for Nix &lt;= 0.7)</screen>

then you should unsubscribe from the offending channel
(<command>nix-channel --remove
<replaceable>URL</replaceable></command>; leave out
<literal>/MANIFEST</literal>), and subscribe to the same URL, with
<literal>channels</literal> replaced by <literal>channels-v3</literal>
(e.g., <link xlink:href="http://catamaran.labs.cs.uu.nl/dist/nix/channels-v3/nixpkgs-unstable"/>).</para>

<para>Nix 0.8 has the following improvements:

<itemizedlist>

  <listitem><para>The cryptographic hashes used in store paths are now
  160 bits long, but encoded in base-32 so that they are still only 32
  characters long (e.g.,
  <filename>/nix/store/csw87wag8bqlqk7ipllbwypb14xainap-atk-1.9.0</filename>).
  (This is actually a 160 bit truncation of a SHA-256
  hash.)</para></listitem>

  <listitem><para>Big cleanups and simplifications of the basic store
  semantics.  The notion of &#x201C;closure store expressions&#x201D; is gone (and
  so is the notion of &#x201C;successors&#x201D;); the file system references of a
  store path are now just stored in the database.</para>

  <para>For instance, given any store path, you can query its closure:

  <screen>
$ nix-store -qR $(which firefox)
... lots of paths ...</screen>

  Also, Nix now remembers for each store path the derivation that
  built it (the &#x201C;deriver&#x201D;):

  <screen>
$ nix-store -qR $(which firefox)
/nix/store/4b0jx7vq80l9aqcnkszxhymsf1ffa5jd-firefox-1.0.1.drv</screen>

  So to see the build-time dependencies, you can do

  <screen>
$ nix-store -qR $(nix-store -qd $(which firefox))</screen>

  or, in a nicer format:

  <screen>
$ nix-store -q --tree $(nix-store -qd $(which firefox))</screen>

  </para>

  <para>File system references are also stored in reverse.  For
  instance, you can query all paths that directly or indirectly use a
  certain Glibc:

  <screen>
$ nix-store -q --referrers-closure \
    /nix/store/8lz9yc6zgmc0vlqmn2ipcpkjlmbi51vv-glibc-2.3.4</screen>

  </para>

  </listitem>

  <listitem><para>The concept of fixed-output derivations has been
  formalised.  Previously, functions such as
  <function>fetchurl</function> in Nixpkgs used a hack (namely,
  explicitly specifying a store path hash) to prevent changes to, say,
  the URL of the file from propagating upwards through the dependency
  graph, causing rebuilds of everything.  This can now be done cleanly
  by specifying the <varname>outputHash</varname> and
  <varname>outputHashAlgo</varname> attributes.  Nix itself checks
  that the content of the output has the specified hash.  (This is
  important for maintaining certain invariants necessary for future
  work on secure shared stores.)</para></listitem>

  <listitem><para>One-click installation :-) It is now possible to
  install any top-level component in Nixpkgs directly, through the web
  &#x2014; see, e.g., <link xlink:href="http://catamaran.labs.cs.uu.nl/dist/nixpkgs-0.8/"/>.
  All you have to do is associate
  <filename>/nix/bin/nix-install-package</filename> with the MIME type
  <literal>application/nix-package</literal> (or the extension
  <filename>.nixpkg</filename>), and clicking on a package link will
  cause it to be installed, with all appropriate dependencies.  If you
  just want to install some specific application, this is easier than
  subscribing to a channel.</para></listitem>

  <listitem><para><command>nix-store -r
  <replaceable>PATHS</replaceable></command> now builds all the
  derivations PATHS in parallel.  Previously it did them sequentially
  (though exploiting possible parallelism between subderivations).
  This is nice for build farms.</para></listitem>

  <listitem><para><command>nix-channel</command> has new operations
  <option>--list</option> and
  <option>--remove</option>.</para></listitem>

  <listitem><para>New ways of installing components into user
  environments:

  <itemizedlist>

    <listitem><para>Copy from another user environment:

    <screen>
$ nix-env -i --from-profile .../other-profile firefox</screen>

    </para></listitem>

    <listitem><para>Install a store derivation directly (bypassing the
    Nix expression language entirely):

    <screen>
$ nix-env -i /nix/store/z58v41v21xd3...-aterm-2.3.1.drv</screen>

    (This is used to implement <command>nix-install-package</command>,
    which is therefore immune to evolution in the Nix expression
    language.)</para></listitem>

    <listitem><para>Install an already built store path directly:

    <screen>
$ nix-env -i /nix/store/hsyj5pbn0d9i...-aterm-2.3.1</screen>

    </para></listitem>

    <listitem><para>Install the result of a Nix expression specified
    as a command-line argument:

    <screen>
$ nix-env -f .../i686-linux.nix -i -E 'x: x.firefoxWrapper'</screen>

    The difference with the normal installation mode is that
    <option>-E</option> does not use the <varname>name</varname>
    attributes of derivations.  Therefore, this can be used to
    disambiguate multiple derivations with the same
    name.</para></listitem>

  </itemizedlist></para></listitem>

  <listitem><para>A hash of the contents of a store path is now stored
  in the database after a successful build.  This allows you to check
  whether store paths have been tampered with: <command>nix-store
  --verify --check-contents</command>.</para></listitem>

  <listitem>

    <para>Implemented a concurrent garbage collector.  It is now
    always safe to run the garbage collector, even if other Nix
    operations are happening simultaneously.</para>

    <para>However, there can still be GC races if you use
    <command>nix-instantiate</command> and <command>nix-store
    --realise</command> directly to build things.  To prevent races,
    use the <option>--add-root</option> flag of those commands.</para>

  </listitem>

  <listitem><para>The garbage collector now finally deletes paths in
  the right order (i.e., topologically sorted under the &#x201C;references&#x201D;
  relation), thus making it safe to interrupt the collector without
  risking a store that violates the closure
  invariant.</para></listitem>

  <listitem><para>Likewise, the substitute mechanism now downloads
  files in the right order, thus preserving the closure invariant at
  all times.</para></listitem>

  <listitem><para>The result of <command>nix-build</command> is now
  registered as a root of the garbage collector.  If the
  <filename>./result</filename> link is deleted, the GC root
  disappears automatically.</para></listitem>

  <listitem>

    <para>The behaviour of the garbage collector can be changed
    globally by setting options in
    <filename>/nix/etc/nix/nix.conf</filename>.

    <itemizedlist>

      <listitem><para><literal>gc-keep-derivations</literal> specifies
      whether deriver links should be followed when searching for live
      paths.</para></listitem>

      <listitem><para><literal>gc-keep-outputs</literal> specifies
      whether outputs of derivations should be followed when searching
      for live paths.</para></listitem>

      <listitem><para><literal>env-keep-derivations</literal>
      specifies whether user environments should store the paths of
      derivations when they are added (thus keeping the derivations
      alive).</para></listitem>

    </itemizedlist>

  </para></listitem>

  <listitem><para>New <command>nix-env</command> query flags
  <option>--drv-path</option> and
  <option>--out-path</option>.</para></listitem>

  <listitem><para><command>fetchurl</command> allows SHA-1 and SHA-256
  in addition to MD5.  Just specify the attribute
  <varname>sha1</varname> or <varname>sha256</varname> instead of
  <varname>md5</varname>.</para></listitem>

  <listitem><para>Manual updates.</para></listitem>

</itemizedlist>

</para>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.7">

<title>Release 0.7 (2005-01-12)</title>

<itemizedlist>

  <listitem><para>Binary patching.  When upgrading components using
  pre-built binaries (through nix-pull / nix-channel), Nix can
  automatically download and apply binary patches to already installed
  components instead of full downloads.  Patching is &#x201C;smart&#x201D;: if there
  is a <emphasis>sequence</emphasis> of patches to an installed
  component, Nix will use it.  Patches are currently generated
  automatically between Nixpkgs (pre-)releases.</para></listitem>

  <listitem><para>Simplifications to the substitute
  mechanism.</para></listitem>

  <listitem><para>Nix-pull now stores downloaded manifests in
  <filename>/nix/var/nix/manifests</filename>.</para></listitem>

  <listitem><para>Metadata on files in the Nix store is canonicalised
  after builds: the last-modified timestamp is set to 0 (00:00:00
  1/1/1970), the mode is set to 0444 or 0555 (readable and possibly
  executable by all; setuid/setgid bits are dropped), and the group is
  set to the default.  This ensures that the result of a build and an
  installation through a substitute is the same; and that timestamp
  dependencies are revealed.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.6">

<title>Release 0.6 (2004-11-14)</title>

<itemizedlist>

  <listitem>
    <para>Rewrite of the normalisation engine.

    <itemizedlist>

      <listitem><para>Multiple builds can now be performed in parallel
      (option <option>-j</option>).</para></listitem>

      <listitem><para>Distributed builds.  Nix can now call a shell
      script to forward builds to Nix installations on remote
      machines, which may or may not be of the same platform
      type.</para></listitem>

      <listitem><para>Option <option>--fallback</option> allows
      recovery from broken substitutes.</para></listitem>

      <listitem><para>Option <option>--keep-going</option> causes
      building of other (unaffected) derivations to continue if one
      failed.</para></listitem>

    </itemizedlist>

    </para>

  </listitem>

  <listitem><para>Improvements to the garbage collector (i.e., it
  should actually work now).</para></listitem>

  <listitem><para>Setuid Nix installations allow a Nix store to be
  shared among multiple users.</para></listitem>

  <listitem><para>Substitute registration is much faster
  now.</para></listitem>

  <listitem><para>A utility <command>nix-build</command> to build a
  Nix expression and create a symlink to the result int the current
  directory; useful for testing Nix derivations.</para></listitem>

  <listitem><para>Manual updates.</para></listitem>

  <listitem>

    <para><command>nix-env</command> changes:

    <itemizedlist>

      <listitem><para>Derivations for other platforms are filtered out
      (which can be overridden using
      <option>--system-filter</option>).</para></listitem>

      <listitem><para><option>--install</option> by default now
      uninstall previous derivations with the same
      name.</para></listitem>

      <listitem><para><option>--upgrade</option> allows upgrading to a
      specific version.</para></listitem>

      <listitem><para>New operation
      <option>--delete-generations</option> to remove profile
      generations (necessary for effective garbage
      collection).</para></listitem>

      <listitem><para>Nicer output (sorted,
      columnised).</para></listitem>

    </itemizedlist>

    </para>

  </listitem>

  <listitem><para>More sensible verbosity levels all around (builder
  output is now shown always, unless <option>-Q</option> is
  given).</para></listitem>

  <listitem>

    <para>Nix expression language changes:

    <itemizedlist>

      <listitem><para>New language construct: <literal>with
      <replaceable>E1</replaceable>;
      <replaceable>E2</replaceable></literal> brings all attributes
      defined in the attribute set <replaceable>E1</replaceable> in
      scope in <replaceable>E2</replaceable>.</para></listitem>

      <listitem><para>Added a <function>map</function>
      function.</para></listitem>

      <listitem><para>Various new operators (e.g., string
      concatenation).</para></listitem>

    </itemizedlist>

    </para>

  </listitem>

  <listitem><para>Expression evaluation is much
  faster.</para></listitem>

  <listitem><para>An Emacs mode for editing Nix expressions (with
  syntax highlighting and indentation) has been
  added.</para></listitem>

  <listitem><para>Many bug fixes.</para></listitem>

</itemizedlist>

</section>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.0" xml:id="ch-relnotes-0.5">

<title>Release 0.5 and earlier</title>

<para>Please refer to the Subversion commit log messages.</para>

</section>

</appendix>

<!--
<appendix>
    <title>Nix Release Notes</title>
    <xi:include href="release-notes/release-notes.xml"
                xpointer="xmlns(x=http://docbook.org/ns/docbook)xpointer(x:article/x:section)" />
  </appendix>
-->

</book>