-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNix-Package-Manager-Guide-Version-2.3.10.html
8583 lines (7764 loc) · 809 KB
/
Nix-Package-Manager-Guide-Version-2.3.10.html
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
<!DOCTYPE html>
<!-- saved from url=(0036)https://nixos.org/manual/nix/stable/ -->
<html lang="en" class="with-js"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NixOS - Nix 2.3.10 manual</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0">
<style class="anchorjs"></style><link rel="stylesheet" href="./Nix-Package-Manager-Guide-Version-2.3.10_files/index.css" type="text/css">
<link rel="shortcut icon" type="image/png" href="https://nixos.org/favicon.png">
<meta name="google-site-verification" content="ir-07nYvo3u3x_VmkTO1wCfYJ8uC-SrVBGR7hZgqPSE">
<script>
var html = document.documentElement;
html.className = html.className.replace("without-js", "with-js");
</script><style>@media print {#ghostery-tracker-tally {display:none !important}}</style>
<script type="text/javascript" src="./Nix-Package-Manager-Guide-Version-2.3.10_files/jquery.min.js"></script>
<link rel="canonical" url="https://nixos.org/manual/nix/stable">
</head>
<body data-nix-channels="[{"channel":"unstable","version":"2.4pre20210210_4e98f03"},{"channel":"stable","version":"2.3.10"}]">
<header>
<div>
<h1><a href="https://nixos.org/">NixOS</a></h1>
<nav style="display: none;">
<ul>
<li class=""> <a href="https://nixos.org/explore.html">Explore</a></li>
<li class=""> <a href="https://nixos.org/download.html">Download</a></li>
<li class=""> <a href="https://nixos.org/learn.html">Learn</a></li>
<li class=""> <a href="https://nixos.org/community.html">Community</a></li>
<li class=""> <a href="https://nixos.org/governance.html">Governance</a></li>
<li class=""> <a href="https://nixos.org/donate.html">Donate</a></li>
<li class=" activesearch"> <a href="https://search.nixos.org/packages">Search</a></li> </ul>
</nav>
</div>
<button class="menu-toggle">Toggle the menu</button></header>
<main>
<section class="generic-layout docbook-page"><div xmlns="http://www.w3.org/1999/xhtml" class="page-header"><h1 id="nix-package-manager-guide"><a id="idm140737349402624" shape="rect"></a>Nix Package Manager Guide<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#nix-package-manager-guide" aria-label="Anchor link for: nix package manager guide" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h1><h2 id="version-2-3-10">Version 2.3.10<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#version-2-3-10" aria-label="Anchor link for: version 2 3 10" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div><div xmlns="http://www.w3.org/1999/xhtml" class="docbook"><div class="toc"><dl class="toc"><dt><span class="part"><a href="https://nixos.org/manual/nix/stable/#chap-introduction" shape="rect">I. Introduction</a></span></dt><dd><dl><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-about-nix" shape="rect">1. About Nix</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#chap-quick-start" shape="rect">2. Quick Start</a></span></dt></dl></dd><dt><span class="part"><a href="https://nixos.org/manual/nix/stable/#chap-installation" shape="rect">II. Installation</a></span></dt><dd><dl><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-supported-platforms" shape="rect">3. Supported Platforms</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-installing-binary" shape="rect">4. Installing a Binary Distribution</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-single-user-installation" shape="rect">4.1. Single User Installation</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-multi-user-installation" shape="rect">4.2. Multi User Installation</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-macos-installation" shape="rect">4.3. macOS Installation</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-macos-installation-change-store-prefix" shape="rect">4.3.1. Change the Nix store path prefix</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-macos-installation-encrypted-volume" shape="rect">4.3.2. Use a separate encrypted volume</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-macos-installation-symlink" shape="rect">4.3.3. Symlink the Nix store to a custom location</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-macos-installation-recommended-notes" shape="rect">4.3.4. Notes on the recommended approach</a></span></dt></dl></dd><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-nix-install-pinned-version-url" shape="rect">4.4. Installing a pinned Nix version from a URL</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sect-nix-install-binary-tarball" shape="rect">4.5. Installing from a binary tarball</a></span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-installing-source" shape="rect">5. Installing Nix from Source</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-prerequisites-source" shape="rect">5.1. Prerequisites</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-obtaining-source" shape="rect">5.2. Obtaining a Source Distribution</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-building-source" shape="rect">5.3. Building Nix from Source</a></span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-nix-security" shape="rect">6. Security</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-single-user" shape="rect">6.1. Single-User Mode</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-multi-user" shape="rect">6.2. Multi-User Mode</a></span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-env-variables" shape="rect">7. Environment Variables</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-nix-ssl-cert-file" shape="rect">7.1. <code class="envar">NIX_SSL_CERT_FILE</code></a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-nix-ssl-cert-file-with-nix-daemon-and-macos" shape="rect">7.1.1. <code class="envar">NIX_SSL_CERT_FILE</code> with macOS and the Nix daemon</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-installer-proxy-settings" shape="rect">7.1.2. Proxy Environment Variables</a></span></dt></dl></dd></dl></dd></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-upgrading-nix" shape="rect">8. Upgrading Nix</a></span></dt><dt><span class="part"><a href="https://nixos.org/manual/nix/stable/#chap-package-management" shape="rect">III. Package Management</a></span></dt><dd><dl><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-basic-package-mgmt" shape="rect">9. Basic Package Management</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#sec-profiles" shape="rect">10. Profiles</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#sec-garbage-collection" shape="rect">11. Garbage Collection</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-gc-roots" shape="rect">11.1. Garbage Collector Roots</a></span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#sec-channels" shape="rect">12. Channels</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#sec-sharing-packages" shape="rect">13. Sharing Packages Between Machines</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-binary-cache-substituter" shape="rect">13.1. Serving a Nix store via HTTP</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-copy-closure" shape="rect">13.2. Copying Closures Via SSH</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-ssh-substituter" shape="rect">13.3. Serving a Nix store via SSH</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-s3-substituter" shape="rect">13.4. Serving a Nix store via AWS S3 or S3-compatible Service</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-s3-substituter-anonymous-reads" shape="rect">13.4.1. Anonymous Reads to your S3-compatible binary cache</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-s3-substituter-authenticated-reads" shape="rect">13.4.2. Authenticated Reads to your S3 binary cache</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-s3-substituter-authenticated-writes" shape="rect">13.4.3. Authenticated Writes to your S3-compatible binary cache</a></span></dt></dl></dd></dl></dd></dl></dd><dt><span class="part"><a href="https://nixos.org/manual/nix/stable/#chap-writing-nix-expressions" shape="rect">IV. Writing Nix Expressions</a></span></dt><dd><dl><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-simple-expression" shape="rect">14. A Simple Nix Expression</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-expression-syntax" shape="rect">14.1. Expression Syntax</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-build-script" shape="rect">14.2. Build Script</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-arguments" shape="rect">14.3. Arguments and Variables</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-building-simple" shape="rect">14.4. Building and Testing</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-generic-builder" shape="rect">14.5. Generic Builder Syntax</a></span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-expression-language" shape="rect">15. Nix Expression Language</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-values" shape="rect">15.1. Values</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-constructs" shape="rect">15.2. Language Constructs</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-language-operators" shape="rect">15.3. Operators</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-derivation" shape="rect">15.4. Derivations</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#sec-advanced-attributes" shape="rect">15.4.1. Advanced Attributes</a></span></dt></dl></dd><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-builtins" shape="rect">15.5. Built-in Functions</a></span></dt></dl></dd></dl></dd><dt><span class="part"><a href="https://nixos.org/manual/nix/stable/#part-advanced-topics" shape="rect">V. Advanced Topics</a></span></dt><dd><dl><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#chap-distributed-builds" shape="rect">16. Remote Builds</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#chap-tuning-cores-and-jobs" shape="rect">17. Tuning Cores and Jobs</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#chap-diff-hook" shape="rect">18. Verifying Build Reproducibility with <code class="option"></code></a><code class="option"><a class="option" href="https://nixos.org/manual/nix/stable/#conf-diff-hook" shape="rect">diff-hook</a></code></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321178144" shape="rect">18.1.
Spot-Checking Build Determinism
</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321163136" shape="rect">18.2.
Automatic and Optionally Enforced Determinism Verification
</a></span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#chap-post-build-hook" shape="rect">19. Using the <code class="literal">post-build-hook</code></a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#chap-post-build-hook-caveats" shape="rect">19.1. Implementation Caveats</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321149920" shape="rect">19.2. Prerequisites</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321147520" shape="rect">19.3. Set up a Signing Key</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321142032" shape="rect">19.4. Implementing the build hook</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321135120" shape="rect">19.5. Updating Nix Configuration</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321132096" shape="rect">19.6. Testing</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#idm140737321127168" shape="rect">19.7. Conclusion</a></span></dt></dl></dd></dl></dd><dt><span class="part"><a href="https://nixos.org/manual/nix/stable/#part-command-ref" shape="rect">VI. Command Reference</a></span></dt><dd><dl><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#sec-common-options" shape="rect">20. Common Options</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#sec-common-env" shape="rect">21. Common Environment Variables</a></span></dt><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-main-commands" shape="rect">22. Main Commands</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-env" shape="rect">nix-env</a></span><span class="refpurpose"> — manipulate or query Nix user environments</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-build" shape="rect">nix-build</a></span><span class="refpurpose"> — build a Nix expression</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-shell" shape="rect">nix-shell</a></span><span class="refpurpose"> — start an interactive shell based on a Nix expression</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-store" shape="rect">nix-store</a></span><span class="refpurpose"> — manipulate or query the Nix store</span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-utilities" shape="rect">23. Utilities</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-channel" shape="rect">nix-channel</a></span><span class="refpurpose"> — manage Nix channels</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-collect-garbage" shape="rect">nix-collect-garbage</a></span><span class="refpurpose"> — delete unreachable store paths</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-copy-closure" shape="rect">nix-copy-closure</a></span><span class="refpurpose"> — copy a closure to or from a remote machine via SSH</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-daemon" shape="rect">nix-daemon</a></span><span class="refpurpose"> — Nix multi-user support daemon</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-hash" shape="rect">nix-hash</a></span><span class="refpurpose"> — compute the cryptographic hash of a path</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-instantiate" shape="rect">nix-instantiate</a></span><span class="refpurpose"> — instantiate store derivations from Nix expressions</span></dt><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-nix-prefetch-url" shape="rect">nix-prefetch-url</a></span><span class="refpurpose"> — copy a file from a URL into the store and print its hash</span></dt></dl></dd><dt><span class="chapter"><a href="https://nixos.org/manual/nix/stable/#ch-files" shape="rect">24. Files</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="https://nixos.org/manual/nix/stable/#sec-conf-file" shape="rect">nix.conf</a></span><span class="refpurpose"> — Nix configuration file</span></dt></dl></dd></dl></dd><dt><span class="appendix"><a href="https://nixos.org/manual/nix/stable/#part-glossary" shape="rect">A. Glossary</a></span></dt><dt><span class="appendix"><a href="https://nixos.org/manual/nix/stable/#chap-hacking" shape="rect">B. Hacking</a></span></dt><dt><span class="appendix"><a href="https://nixos.org/manual/nix/stable/#sec-relnotes" shape="rect">C. Nix Release Notes</a></span></dt><dd><dl><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-2.3" shape="rect">C.1. Release 2.3 (2019-09-04)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-2.2" shape="rect">C.2. Release 2.2 (2019-01-11)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-2.1" shape="rect">C.3. Release 2.1 (2018-09-02)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-2.0" shape="rect">C.4. Release 2.0 (2018-02-22)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.11.10" shape="rect">C.5. Release 1.11.10 (2017-06-12)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.11" shape="rect">C.6. Release 1.11 (2016-01-19)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.10" shape="rect">C.7. Release 1.10 (2015-09-03)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.9" shape="rect">C.8. Release 1.9 (2015-06-12)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.8" shape="rect">C.9. Release 1.8 (2014-12-14)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.7" shape="rect">C.10. Release 1.7 (2014-04-11)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.6.1" shape="rect">C.11. Release 1.6.1 (2013-10-28)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.6.0" shape="rect">C.12. Release 1.6 (2013-09-10)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.5.2" shape="rect">C.13. Release 1.5.2 (2013-05-13)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.5" shape="rect">C.14. Release 1.5 (2013-02-27)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.4" shape="rect">C.15. Release 1.4 (2013-02-26)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.3" shape="rect">C.16. Release 1.3 (2013-01-04)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.2" shape="rect">C.17. Release 1.2 (2012-12-06)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.1" shape="rect">C.18. Release 1.1 (2012-07-18)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-1.0" shape="rect">C.19. Release 1.0 (2012-05-11)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-0.16" shape="rect">C.20. Release 0.16 (2010-08-17)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-0.15" shape="rect">C.21. Release 0.15 (2010-03-17)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-0.14" shape="rect">C.22. Release 0.14 (2010-02-04)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-0.13" shape="rect">C.23. Release 0.13 (2009-11-05)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-0.12" shape="rect">C.24. Release 0.12 (2008-11-20)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ssec-relnotes-0.11" shape="rect">C.25. Release 0.11 (2007-12-31)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.10.1" shape="rect">C.26. Release 0.10.1 (2006-10-11)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.10" shape="rect">C.27. Release 0.10 (2006-10-06)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.9.2" shape="rect">C.28. Release 0.9.2 (2005-09-21)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.9.1" shape="rect">C.29. Release 0.9.1 (2005-09-20)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.9" shape="rect">C.30. Release 0.9 (2005-09-16)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.8.1" shape="rect">C.31. Release 0.8.1 (2005-04-13)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.8" shape="rect">C.32. Release 0.8 (2005-04-11)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.7" shape="rect">C.33. Release 0.7 (2005-01-12)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.6" shape="rect">C.34. Release 0.6 (2004-11-14)</a></span></dt><dt><span class="section"><a href="https://nixos.org/manual/nix/stable/#ch-relnotes-0.5" shape="rect">C.35. Release 0.5 and earlier</a></span></dt></dl></dd></dl></div><div class="part"><div class="titlepage"><div><div><div class="page-header"><h1 id="chap-introduction" class="title">Part I. Introduction<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#chap-introduction" aria-label="Anchor link for: chap introduction" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h1></div></div></div></div><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-about-nix" class="title">Chapter 1. About Nix<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-about-nix" aria-label="Anchor link for: ch about nix" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix is a <span class="emphasis"><em>purely functional package manager</em></span>.
This means that it treats packages like values in purely functional
programming languages such as Haskell — they are built by functions
that don’t have side-effects, and they never change after they have
been built. Nix stores packages in the <span class="emphasis"><em>Nix
store</em></span>, usually the directory
<code class="filename">/nix/store</code>, where each package has its own unique
subdirectory such as
</p><pre class="programlisting" xml:space="preserve">/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-33.1/
</pre><p>
where <code class="literal">b6gvzjyb2pg0…</code> is a unique identifier for the
package that captures all its dependencies (it’s a cryptographic hash
of the package’s build dependency graph). This enables many powerful
features.</p><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322648464" class="title" style="clear: both">Multiple versions<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322648464" aria-label="Anchor link for: idm140737322648464" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>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 — it prevents the “DLL hell”. Because of the hashing
scheme, different versions of a package end up in different paths in
the Nix store, so they don’t interfere with each other.</p><p>An important consequence is that operations like upgrading or
uninstalling an application cannot break other applications, since
these operations never “destructively” update or delete files that are
used by other packages.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322645760" class="title" style="clear: both">Complete dependencies<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322645760" aria-label="Anchor link for: idm140737322645760" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix helps you make sure that package dependency specifications
are complete. In general, when you’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 <span class="emphasis"><em>your</em></span>
machine if you have the dependency installed, but not on the end
user's machine if it's not there.</p><p>Since Nix on the other hand doesn’t install packages in “global”
locations like <code class="filename">/usr/bin</code> but in package-specific
directories, the risk of incomplete dependencies is greatly reduced.
This is because tools such as compilers don’t search in per-packages
directories such as
<code class="filename">/nix/store/5lbfaxb722zp…-openssl-0.9.8d/include</code>,
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.</p><p>Once a package is built, runtime dependencies are found by
scanning binaries for the hash parts of Nix store paths (such as
<code class="literal">r8vvq9kq…</code>). This sounds risky, but it works
extremely well.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322640544" class="title" style="clear: both">Multi-user support<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322640544" aria-label="Anchor link for: idm140737322640544" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix has multi-user support. This means that non-privileged
users can securely install software. Each user can have a different
<span class="emphasis"><em>profile</em></span>, a set of packages in the Nix store that
appear in the user’s <code class="envar">PATH</code>. If a user installs a
package that another user has already installed previously, the
package won’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.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322637808" class="title" style="clear: both">Atomic upgrades and rollbacks<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322637808" aria-label="Anchor link for: idm140737322637808" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Since package management operations never overwrite packages in
the Nix store but just add new versions in different paths, they are
<span class="emphasis"><em>atomic</em></span>. 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 — which would be bad because a
program might well crash if it’s started during that period.</p><p>And since packages aren’t overwritten, the old versions are still
there after an upgrade. This means that you can <span class="emphasis"><em>roll
back</em></span> to the old version:</p><pre class="screen" xml:space="preserve">$ nix-env --upgrade <em class="replaceable"><code>some-packages</code></em>
$ nix-env --rollback
</pre></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322633712" class="title" style="clear: both">Garbage collection<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322633712" aria-label="Anchor link for: idm140737322633712" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>When you uninstall a package like this…
</p><pre class="screen" xml:space="preserve">$ nix-env --uninstall firefox
</pre><p>
the package isn’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
<span class="emphasis"><em>garbage collector</em></span>:
</p><pre class="screen" xml:space="preserve">$ nix-collect-garbage
</pre><p>
This deletes all packages that aren’t in use by any user profile or by
a currently running program.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322630576" class="title" style="clear: both">Functional package language<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322630576" aria-label="Anchor link for: idm140737322630576" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Packages are built from <span class="emphasis"><em>Nix expressions</em></span>,
which is a simple functional language. A Nix expression describes
everything that goes into a package build action (a “derivation”):
other packages, sources, the build script, environment variables for
the build script, etc. Nix tries very hard to ensure that Nix
expressions are <span class="emphasis"><em>deterministic</em></span>: building a Nix
expression twice should yield the same result.</p><p>Because it’s a functional language, it’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’t conflict with
each other in the Nix store.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322626976" class="title" style="clear: both">Transparent source/binary deployment<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322626976" aria-label="Anchor link for: idm140737322626976" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix expressions generally describe how to build a package from
source, so an installation action like
</p><pre class="screen" xml:space="preserve">$ nix-env --install firefox
</pre><p>
<span class="emphasis"><em>could</em></span> 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 <span class="emphasis"><em>source deployment
model</em></span>. 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 <span class="emphasis"><em>binary
cache</em></span>, a web server that provides pre-built binaries. For
instance, when asked to build
<code class="literal">/nix/store/b6gvzjyb2pg0…-firefox-33.1</code> from source,
Nix would first check if the file
<code class="uri">https://cache.nixos.org/b6gvzjyb2pg0….narinfo</code> exists, and
if so, fetch the pre-built binary referenced from there; otherwise, it
would fall back to building from source.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322621968" class="title" style="clear: both">Nix Packages collection<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322621968" aria-label="Anchor link for: idm140737322621968" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>We provide a large set of Nix expressions containing hundreds of
existing Unix packages, the <span class="emphasis"><em>Nix Packages
collection</em></span> (Nixpkgs).</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322620352" class="title" style="clear: both">Managing build environments<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322620352" aria-label="Anchor link for: idm140737322620352" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>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 <span class="command"><strong>nix-shell</strong></span> will build or download those
dependencies if they’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.</p><p>For example, the following command gets all dependencies of the
Pan newsreader, as described by <a class="link" href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix" target="_top" shape="rect">its
Nix expression</a>:</p><pre class="screen" xml:space="preserve">$ nix-shell '<nixpkgs>' -A pan
</pre><p>You’re then dropped into a shell where you can edit, build and test
the package:</p><pre class="screen" xml:space="preserve">[nix-shell]$ tar xf $src
[nix-shell]$ cd pan-*
[nix-shell]$ ./configure
[nix-shell]$ make
[nix-shell]$ ./pan/gui/pan
</pre></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322615008" class="title" style="clear: both">Portability<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322615008" aria-label="Anchor link for: idm140737322615008" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix runs on Linux and macOS.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322613952" class="title" style="clear: both">NixOS<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322613952" aria-label="Anchor link for: idm140737322613952" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>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
<code class="filename">/etc</code>). 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 <a class="link" href="http://nixos.org/" target="_top" shape="rect">NixOS homepage</a>.</p></div><div class="simplesect"><div class="titlepage"><div><div><h2 id="idm140737322611504" class="title" style="clear: both">License<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322611504" aria-label="Anchor link for: idm140737322611504" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix is released under the terms of the <a class="link" href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html" target="_top" shape="rect">GNU
LGPLv2.1 or (at your option) any later version</a>.</p></div></section><section class="chapter"><div class="titlepage"><div><div><h2 id="chap-quick-start" class="title">Chapter 2. Quick Start<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#chap-quick-start" aria-label="Anchor link for: chap quick start" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>This chapter is for impatient people who don't like reading
documentation. For more in-depth information you are kindly referred
to subsequent chapters.</p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p>Install single-user Nix by running the following:
</p><pre class="screen" xml:space="preserve">$ bash <(curl -L https://nixos.org/nix/install)
</pre><p>
This will install Nix in <code class="filename">/nix</code>. The install script
will create <code class="filename">/nix</code> using <span class="command"><strong>sudo</strong></span>,
so make sure you have sufficient rights. (For other installation
methods, see <a class="xref" href="https://nixos.org/manual/nix/stable/#chap-installation" title="Part II. Installation" shape="rect">Part II, “Installation”</a>.)</p></li><li class="step"><p>See what installable packages are currently available
in the channel:
</p><pre class="screen" xml:space="preserve">$ nix-env -qa
docbook-xml-4.3
docbook-xml-4.5
firefox-33.0.2
hello-2.9
libxslt-1.1.28
<em class="replaceable"><code>...</code></em></pre><p>
</p></li><li class="step"><p>Install some packages from the channel:
</p><pre class="screen" xml:space="preserve">$ nix-env -i hello</pre><p>
This should download pre-built packages; it should not build them
locally (if it does, something went wrong).</p></li><li class="step"><p>Test that they work:
</p><pre class="screen" xml:space="preserve">$ which hello
/home/eelco/.nix-profile/bin/hello
$ hello
Hello, world!
</pre><p>
</p></li><li class="step"><p>Uninstall a package:
</p><pre class="screen" xml:space="preserve">$ nix-env -e hello</pre><p>
</p></li><li class="step"><p>You can also test a package without installing it:
</p><pre class="screen" xml:space="preserve">$ nix-shell -p hello
</pre><p>
This builds or downloads GNU Hello and its dependencies, then drops
you into a Bash shell where the <span class="command"><strong>hello</strong></span> command is
present, all without affecting your normal environment:
</p><pre class="screen" xml:space="preserve">[nix-shell:~]$ hello
Hello, world!
[nix-shell:~]$ exit
$ hello
hello: command not found
</pre><p>
</p></li><li class="step"><p>To keep up-to-date with the channel, do:
</p><pre class="screen" xml:space="preserve">$ nix-channel --update nixpkgs
$ nix-env -u '*'</pre><p>
The latter command will upgrade each installed package for which there
is a “newer” version (as determined by comparing the version
numbers).</p></li><li class="step"><p>If you're unhappy with the result of a
<span class="command"><strong>nix-env</strong></span> action (e.g., an upgraded package turned
out not to work properly), you can go back:
</p><pre class="screen" xml:space="preserve">$ nix-env --rollback</pre><p>
</p></li><li class="step"><p>You should periodically run the Nix garbage collector
to get rid of unused packages, since uninstalls or upgrades don't
actually delete them:
</p><pre class="screen" xml:space="preserve">$ nix-collect-garbage -d</pre><p>
</p></li></ol></div></section></div><div class="part"><div class="titlepage"><div><div><div class="page-header"><h1 id="chap-installation" class="title">Part II. Installation<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#chap-installation" aria-label="Anchor link for: chap installation" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h1></div></div></div></div><div class="partintro"><div></div><p>This section describes how to install and configure Nix for first-time use.</p></div><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-supported-platforms" class="title">Chapter 3. Supported Platforms<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-supported-platforms" aria-label="Anchor link for: ch supported platforms" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix is currently supported on the following platforms:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Linux (i686, x86_64, aarch64).</p></li><li class="listitem"><p>macOS (x86_64).</p></li></ul></div><p>
</p></section><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-installing-binary" class="title">Chapter 4. Installing a Binary Distribution<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-installing-binary" aria-label="Anchor link for: ch installing binary" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>
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:
</p><pre class="screen" xml:space="preserve"> $ sh <(curl -L https://nixos.org/nix/install)
</pre><p>
If you're using macOS 10.15 (Catalina) or newer, consult
<a class="link" href="https://nixos.org/manual/nix/stable/#sect-macos-installation" title="4.3. macOS Installation" shape="rect">the macOS installation instructions</a>
before installing.
</p><p>
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.
</p><section class="section"><div class="titlepage"><div><div><h2 id="sect-single-user-installation" class="title" style="clear: both">4.1. Single User Installation<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-single-user-installation" aria-label="Anchor link for: sect single user installation" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>
To explicitly select a single-user installation on your system:
</p><pre class="screen" xml:space="preserve"> sh <(curl -L https://nixos.org/nix/install) --no-daemon
</pre><p>
</p><p>
This will perform a single-user installation of Nix, meaning that
<code class="filename">/nix</code> is owned by the invoking user. You should
run this under your usual user account, <span class="emphasis"><em>not</em></span> as
root. The script will invoke <span class="command"><strong>sudo</strong></span> to create
<code class="filename">/nix</code> if it doesn’t already exist. If you don’t
have <span class="command"><strong>sudo</strong></span>, you should manually create
<code class="filename">/nix</code> first as root, e.g.:
</p><pre class="screen" xml:space="preserve">$ mkdir /nix
$ chown alice /nix
</pre><p>
The install script will modify the first writable file from amongst
<code class="filename">.bash_profile</code>, <code class="filename">.bash_login</code>
and <code class="filename">.profile</code> to source
<code class="filename">~/.nix-profile/etc/profile.d/nix.sh</code>. You can set
the <code class="envar">NIX_INSTALLER_NO_MODIFY_PROFILE</code> environment
variable before executing the install script to disable this
behaviour.
</p><p>You can uninstall Nix simply by running:
</p><pre class="screen" xml:space="preserve">$ rm -rf /nix
</pre><p>
</p></section><section class="section"><div class="titlepage"><div><div><h2 id="sect-multi-user-installation" class="title" style="clear: both">4.2. Multi User Installation<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-multi-user-installation" aria-label="Anchor link for: sect multi user installation" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>
The multi-user Nix installation creates system users, and a system
service for the Nix daemon.
</p><div class="itemizedlist"><p class="title"><strong>Supported Systems</strong></p><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Linux running systemd, with SELinux disabled</p></li><li class="listitem"><p>macOS</p></li></ul></div><p>
You can instruct the installer to perform a multi-user
installation on your system:
</p><pre class="screen" xml:space="preserve">sh <(curl -L https://nixos.org/nix/install) --daemon</pre><p>
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,
<span class="emphasis"><em>not</em></span> as root. The script will invoke
<span class="command"><strong>sudo</strong></span> as needed.
</p><div class="alert alert-info"><strong>Note:</strong>
If you need Nix to use a different group ID or user ID set, you
will have to download the tarball manually and <a class="link" href="https://nixos.org/manual/nix/stable/#sect-nix-install-binary-tarball" title="4.5. Installing from a binary tarball" shape="rect">edit the install
script</a>.
</div><p>
The installer will modify <code class="filename">/etc/bashrc</code>, and
<code class="filename">/etc/zshrc</code> if they exist. The installer will
first back up these files with a
<code class="literal">.backup-before-nix</code> extension. The installer
will also create <code class="filename">/etc/profile.d/nix.sh</code>.
</p><p>You can uninstall Nix with the following commands:
</p><pre class="screen" xml:space="preserve">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
</pre><p>
There may also be references to Nix in
<code class="filename">/etc/profile</code>,
<code class="filename">/etc/bashrc</code>, and
<code class="filename">/etc/zshrc</code> which you may remove.
</p></section><section class="section"><div class="titlepage"><div><div><h2 id="sect-macos-installation" class="title" style="clear: both">4.3. macOS Installation<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-macos-installation" aria-label="Anchor link for: sect macos installation" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>
Starting with macOS 10.15 (Catalina), the root filesystem is read-only.
This means <code class="filename">/nix</code> can no longer live on your system
volume, and that you'll need a workaround to install Nix.
</p><p>
The recommended approach, which creates an unencrypted APFS volume
for your Nix store and a "synthetic" empty directory to mount it
over at <code class="filename">/nix</code>, is least likely to impair Nix
or your system.
</p><div class="alert alert-info"><strong>Note:</strong>
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.
</div><p>
If you're using a recent Mac with a
<a class="link" href="https://www.apple.com/euro/mac/shared/docs/Apple_T2_Security_Chip_Overview.pdf" target="_top" shape="rect">T2 chip</a>,
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:
</p><pre class="screen" xml:space="preserve">$ sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume</pre><p>
If you don't like the sound of this, you'll want to weigh the
other approaches and tradeoffs detailed in this section.
</p><div class="alert alert-info"><strong>Note:</strong>
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:
</div><section class="section"><div class="titlepage"><div><div><h3 id="sect-macos-installation-change-store-prefix" class="title">4.3.1. Change the Nix store path prefix<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-macos-installation-change-store-prefix" aria-label="Anchor link for: sect macos installation change store prefix" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>
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:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
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.
</p></li><li class="listitem"><p>
It's harder to build and deploy packages to Linux systems.
</p></li></ul></div><p>
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.
</p><p>
</p></section><section class="section"><div class="titlepage"><div><div><h3 id="sect-macos-installation-encrypted-volume" class="title">4.3.2. Use a separate encrypted volume<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-macos-installation-encrypted-volume" aria-label="Anchor link for: sect macos installation encrypted volume" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>
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.
</p><p>
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:
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
The additional volume won't be encrypted with your existing
FileVault key, so you'll need another mechanism to decrypt
the volume.
</p></li><li class="listitem"><p>
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.
</p><p>
On a case-by-case basis, you may be able to work around this
problem by using <span class="command"><strong>wait4path</strong></span> to block
execution until your executable is available.
</p><p>
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.
</p></li><li class="listitem"><p>
You can hard-code the password in the clear, so that your
store volume can be decrypted before Keychain is available.
</p></li></ol></div><p>
If you are comfortable navigating these tradeoffs, you can encrypt the volume with
something along the lines of:
</p><pre class="screen" xml:space="preserve">alice$ diskutil apfs enableFileVault /nix -user disk</pre></section><section class="section"><div class="titlepage"><div><div><h3 id="sect-macos-installation-symlink" class="title">4.3.3. Symlink the Nix store to a custom location<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-macos-installation-symlink" aria-label="Anchor link for: sect macos installation symlink" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>
Another simple approach is using <code class="filename">/etc/synthetic.conf</code>
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.
</p><p>
Because of these downsides, we can't recommend this approach.
</p></section><section class="section"><div class="titlepage"><div><div><h3 id="sect-macos-installation-recommended-notes" class="title">4.3.4. Notes on the recommended approach<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-macos-installation-recommended-notes" aria-label="Anchor link for: sect macos installation recommended notes" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>
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.
</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
In order to compose user-writable locations into the new
read-only system root, Apple introduced a new concept called
<code class="literal">firmlinks</code>, which it describes as a
"bi-directional wormhole" between two filesystems. You can
see the current firmlinks in <code class="filename">/usr/share/firmlinks</code>.
Unfortunately, firmlinks aren't (currently?) user-configurable.
</p><p>
For special cases like NFS mount points or package manager roots,
<a class="link" href="https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man5/synthetic.conf.5.html" target="_top" shape="rect">synthetic.conf(5)</a>
supports limited user-controlled file-creation (of symlinks,
and synthetic empty directories) at <code class="filename">/</code>.
To create a synthetic empty directory for mounting at <code class="filename">/nix</code>,
add the following line to <code class="filename">/etc/synthetic.conf</code>
(create it if necessary):
</p><pre class="screen" xml:space="preserve">nix</pre></li><li class="listitem"><p>
This configuration is applied at boot time, but you can use
<span class="command"><strong>apfs.util</strong></span> to trigger creation (not deletion)
of new entries without a reboot:
</p><pre class="screen" xml:space="preserve">alice$ /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B</pre></li><li class="listitem"><p>
Create the new APFS volume with diskutil:
</p><pre class="screen" xml:space="preserve">alice$ sudo diskutil apfs addVolume diskX APFS 'Nix Store' -mountpoint /nix</pre></li><li class="listitem"><p>
Using <span class="command"><strong>vifs</strong></span>, add the new mount to
<code class="filename">/etc/fstab</code>. If it doesn't already have
other entries, it should look something like:
</p><pre class="screen" xml:space="preserve">#
# 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
</pre><p>
The nobrowse setting will keep Spotlight from indexing this
volume, and keep it from showing up on your desktop.
</p></li></ol></div></section></section><section class="section"><div class="titlepage"><div><div><h2 id="sect-nix-install-pinned-version-url" class="title" style="clear: both">4.4. Installing a pinned Nix version from a URL<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-nix-install-pinned-version-url" aria-label="Anchor link for: sect nix install pinned version url" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>
NixOS.org hosts version-specific installation URLs for all Nix
versions since 1.11.16, at
<code class="literal">https://releases.nixos.org/nix/nix-<em class="replaceable"><code>version</code></em>/install</code>.
</p><p>
These install scripts can be used the same as the main
NixOS.org installation script:
</p><pre class="screen" xml:space="preserve"> sh <(curl -L https://nixos.org/nix/install)
</pre><p>
</p><p>
In the same directory of the install script are sha256 sums, and
gpg signature files.
</p></section><section class="section"><div class="titlepage"><div><div><h2 id="sect-nix-install-binary-tarball" class="title" style="clear: both">4.5. Installing from a binary tarball<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sect-nix-install-binary-tarball" aria-label="Anchor link for: sect nix install binary tarball" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>
You can also download a binary tarball that contains Nix and all
its dependencies. (This is what the install script at
<code class="uri">https://nixos.org/nix/install</code> does automatically.) You
should unpack it somewhere (e.g. in <code class="filename">/tmp</code>),
and then run the script named <span class="command"><strong>install</strong></span> inside
the binary tarball:
</p><pre class="screen" xml:space="preserve">alice$ cd /tmp
alice$ tar xfj nix-1.8-x86_64-darwin.tar.bz2
alice$ cd nix-1.8-x86_64-darwin
alice$ ./install
</pre><p>
</p><p>
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
<code class="filename">install-multi-user</code>.
</p></section></section><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-installing-source" class="title">Chapter 5. Installing Nix from Source<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-installing-source" aria-label="Anchor link for: ch installing source" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>If no binary package is available, you can download and compile
a source distribution.</p><section class="section"><div class="titlepage"><div><div><h2 id="sec-prerequisites-source" class="title" style="clear: both">5.1. Prerequisites<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-prerequisites-source" aria-label="Anchor link for: sec prerequisites source" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>GNU Make.</p></li><li class="listitem"><p>Bash Shell. The <code class="literal">./configure</code> script
relies on bashisms, so Bash is required.</p></li><li class="listitem"><p>A version of GCC or Clang that supports C++17.</p></li><li class="listitem"><p><span class="command"><strong>pkg-config</strong></span> to locate
dependencies. If your distribution does not provide it, you can get
it from <a class="link" href="http://www.freedesktop.org/wiki/Software/pkg-config" target="_top" shape="rect">http://www.freedesktop.org/wiki/Software/pkg-config</a>.</p></li><li class="listitem"><p>The OpenSSL library to calculate cryptographic hashes.
If your distribution does not provide it, you can get it from <a class="link" href="https://www.openssl.org/" target="_top" shape="rect">https://www.openssl.org</a>.</p></li><li class="listitem"><p>The <code class="literal">libbrotlienc</code> and
<code class="literal">libbrotlidec</code> libraries to provide implementation
of the Brotli compression algorithm. They are available for download
from the official repository <a class="link" href="https://github.com/google/brotli" target="_top" shape="rect">https://github.com/google/brotli</a>.</p></li><li class="listitem"><p>The bzip2 compressor program and the
<code class="literal">libbz2</code> library. Thus you must have bzip2
installed, including development headers and libraries. If your
distribution does not provide these, you can obtain bzip2 from <a class="link" href="https://web.archive.org/web/20180624184756/http://www.bzip.org/" target="_top" shape="rect">https://web.archive.org/web/20180624184756/http://www.bzip.org/</a>.</p></li><li class="listitem"><p><code class="literal">liblzma</code>, which is provided by
XZ Utils. If your distribution does not provide this, you can
get it from <a class="link" href="https://tukaani.org/xz/" target="_top" shape="rect">https://tukaani.org/xz/</a>.</p></li><li class="listitem"><p>cURL and its library. If your distribution does not
provide it, you can get it from <a class="link" href="https://curl.haxx.se/" target="_top" shape="rect">https://curl.haxx.se/</a>.</p></li><li class="listitem"><p>The SQLite embedded database library, version 3.6.19
or higher. If your distribution does not provide it, please install
it from <a class="link" href="http://www.sqlite.org/" target="_top" shape="rect">http://www.sqlite.org/</a>.</p></li><li class="listitem"><p>The <a class="link" href="http://www.hboehm.info/gc/" target="_top" shape="rect">Boehm
garbage collector</a> to reduce the evaluator’s memory
consumption (optional). To enable it, install
<code class="literal">pkgconfig</code> and the Boehm garbage collector, and
pass the flag <code class="option">--enable-gc</code> to
<span class="command"><strong>configure</strong></span>.</p></li><li class="listitem"><p>The <code class="literal">boost</code> library of version
1.66.0 or higher. It can be obtained from the official web site
<a class="link" href="https://www.boost.org/" target="_top" shape="rect">https://www.boost.org/</a>.</p></li><li class="listitem"><p>The <code class="literal">editline</code> library of version
1.14.0 or higher. It can be obtained from the its repository
<a class="link" href="https://github.com/troglobit/editline" target="_top" shape="rect">https://github.com/troglobit/editline</a>.</p></li><li class="listitem"><p>The <span class="command"><strong>xmllint</strong></span> and
<span class="command"><strong>xsltproc</strong></span> programs to build this manual and the
man-pages. These are part of the <code class="literal">libxml2</code> and
<code class="literal">libxslt</code> packages, respectively. You also need
the <a class="link" href="http://docbook.sourceforge.net/projects/xsl/" target="_top" shape="rect">DocBook
XSL stylesheets</a> and optionally the <a class="link" href="http://www.docbook.org/schemas/5x" target="_top" shape="rect"> DocBook 5.0 RELAX NG
schemas</a>. Note that these are only required if you modify the
manual sources or when you are building from the Git
repository.</p></li><li class="listitem"><p>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 <a class="link" href="ftp://alpha.gnu.org/pub/gnu/bison" target="_top" shape="rect">GNU FTP
server</a>. For Flex, you need version 2.5.35, which is
available on <a class="link" href="http://lex.sourceforge.net/" target="_top" shape="rect">SourceForge</a>.
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.</p></li><li class="listitem"><p>The <code class="literal">libseccomp</code> is used to provide
syscall filtering on Linux. This is an optional dependency and can
be disabled passing a <code class="option">--disable-seccomp-sandboxing</code>
option to the <span class="command"><strong>configure</strong></span> script (Not recommended
unless your system doesn't support
<code class="literal">libseccomp</code>). To get the library, visit <a class="link" href="https://github.com/seccomp/libseccomp" target="_top" shape="rect">https://github.com/seccomp/libseccomp</a>.</p></li></ul></div></section><section class="section"><div class="titlepage"><div><div><h2 id="sec-obtaining-source" class="title" style="clear: both">5.2. Obtaining a Source Distribution<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-obtaining-source" aria-label="Anchor link for: sec obtaining source" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>The source tarball of the most recent stable release can be
downloaded from the <a class="link" href="http://nixos.org/nix/download.html" target="_top" shape="rect">Nix homepage</a>.
You can also grab the <a class="link" href="http://hydra.nixos.org/job/nix/master/release/latest-finished#tabs-constituents" target="_top" shape="rect">most
recent development release</a>.</p><p>Alternatively, the most recent sources of Nix can be obtained
from its <a class="link" href="https://github.com/NixOS/nix" target="_top" shape="rect">Git
repository</a>. For example, the following command will check out
the latest revision into a directory called
<code class="filename">nix</code>:</p><pre class="screen" xml:space="preserve">$ git clone https://github.com/NixOS/nix</pre><p>Likewise, specific releases can be obtained from the <a class="link" href="https://github.com/NixOS/nix/tags" target="_top" shape="rect">tags</a> of the
repository.</p></section><section class="section"><div class="titlepage"><div><div><h2 id="sec-building-source" class="title" style="clear: both">5.3. Building Nix from Source<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-building-source" aria-label="Anchor link for: sec building source" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>After unpacking or checking out the Nix sources, issue the
following commands:
</p><pre class="screen" xml:space="preserve">$ ./configure <em class="replaceable"><code>options...</code></em>
$ make
$ make install</pre><p>
Nix requires GNU Make so you may need to invoke
<span class="command"><strong>gmake</strong></span> instead.</p><p>When building from the Git repository, these should be preceded
by the command:
</p><pre class="screen" xml:space="preserve">$ ./bootstrap.sh</pre><p>
</p><p>The installation path can be specified by passing the
<code class="option">--prefix=<em class="replaceable"><code>prefix</code></em></code> to
<span class="command"><strong>configure</strong></span>. The default installation directory is
<code class="filename">/usr/local</code>. You can change this to any location
you like. You must have write permission to the
<em class="replaceable"><code>prefix</code></em> path.</p><p>Nix keeps its <span class="emphasis"><em>store</em></span> (the place where
packages are stored) in <code class="filename">/nix/store</code> by default.
This can be changed using
<code class="option">--with-store-dir=<em class="replaceable"><code>path</code></em></code>.</p><div class="alert alert-warning"><strong>Warning:</strong> It is best <span class="emphasis"><em>not</em></span> to change the Nix
store from its default, since doing so makes it impossible to use
pre-built binaries from the standard Nixpkgs channels — that is, all
packages will need to be built from source.</div><p>Nix keeps state (such as its database and log files) in
<code class="filename">/nix/var</code> by default. This can be changed using
<code class="option">--localstatedir=<em class="replaceable"><code>path</code></em></code>.</p></section></section><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-nix-security" class="title">Chapter 6. Security<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-nix-security" aria-label="Anchor link for: ch nix security" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Nix has two basic security models. First, it can be used in
“single-user mode”, which is similar to what most other package
management tools do: there is a single user (typically <code class="systemitem">root</code>) who performs all package
management operations. All other users can then use the installed
packages, but they cannot perform package management operations
themselves.</p><p>Alternatively, you can configure Nix in “multi-user mode”. In
this model, all users can perform package management operations — for
instance, every user can install software without requiring root
privileges. Nix ensures that this is secure. For instance, it’s not
possible for one user to overwrite a package used by another user with
a Trojan horse.</p><section class="section"><div class="titlepage"><div><div><h2 id="sec-single-user" class="title" style="clear: both">6.1. Single-User Mode<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-single-user" aria-label="Anchor link for: sec single user" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>In single-user mode, all Nix operations that access the database
in <code class="filename"><em class="replaceable"><code>prefix</code></em>/var/nix/db</code>
or modify the Nix store in
<code class="filename"><em class="replaceable"><code>prefix</code></em>/store</code> must be
performed under the user ID that owns those directories. This is
typically <code class="systemitem">root</code>. (If you
install from RPM packages, that’s in fact the default ownership.)
However, on single-user machines, it is often convenient to
<span class="command"><strong>chown</strong></span> those directories to your normal user account
so that you don’t have to <span class="command"><strong>su</strong></span> to <code class="systemitem">root</code> all the time.</p></section><section class="section"><div class="titlepage"><div><div><h2 id="ssec-multi-user" class="title" style="clear: both">6.2. Multi-User Mode<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ssec-multi-user" aria-label="Anchor link for: ssec multi user" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>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.</p><p>To prevent this, the Nix store and database are owned by some
privileged user (usually <code class="literal">root</code>) and builders are
executed under special user accounts (usually named
<code class="literal">nixbld1</code>, <code class="literal">nixbld2</code>, etc.). When a
unprivileged user runs a Nix command, actions that operate on the Nix
store (such as builds) are forwarded to a <span class="emphasis"><em>Nix
daemon</em></span> running under the owner of the Nix store/database
that performs the operation.</p><div class="alert alert-info"><strong>Note:</strong> Multi-user mode has one important limitation: only
<code class="systemitem">root</code> and a set of trusted
users specified in <code class="filename">nix.conf</code> can specify arbitrary
binary caches. So while unprivileged users may install packages from
arbitrary Nix expressions, they may not get pre-built
binaries.</div><div class="simplesect"><div class="titlepage"><div><div><h3 id="idm140737322416976" class="title">Setting up the build users<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322416976" aria-label="Anchor link for: idm140737322416976" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>The <span class="emphasis"><em>build users</em></span> are the special UIDs under
which builds are performed. They should all be members of the
<span class="emphasis"><em>build users group</em></span> <code class="literal">nixbld</code>.
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:
</p><pre class="screen" xml:space="preserve">$ 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
</pre><p>
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.</p></div><div class="simplesect"><div class="titlepage"><div><div><h3 id="idm140737322413424" class="title">Running the daemon<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322413424" aria-label="Anchor link for: idm140737322413424" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>The <a class="link" href="https://nixos.org/manual/nix/stable/#sec-nix-daemon" title="nix-daemon" shape="rect">Nix daemon</a> should be
started as follows (as <code class="literal">root</code>):
</p><pre class="screen" xml:space="preserve">$ nix-daemon</pre><p>
You’ll want to put that line somewhere in your system’s boot
scripts.</p><p>To let unprivileged users use the daemon, they should set the
<a class="link" href="https://nixos.org/manual/nix/stable/#envar-remote" shape="rect"><code class="envar">NIX_REMOTE</code> environment
variable</a> to <code class="literal">daemon</code>. So you should put a
line like
</p><pre class="programlisting" xml:space="preserve">export NIX_REMOTE=daemon</pre><p>
into the users’ login scripts.</p></div><div class="simplesect"><div class="titlepage"><div><div><h3 id="idm140737322408000" class="title">Restricting access<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#idm140737322408000" aria-label="Anchor link for: idm140737322408000" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>To limit which users can perform Nix operations, you can use the
permissions on the directory
<code class="filename">/nix/var/nix/daemon-socket</code>. For instance, if you
want to restrict the use of Nix to the members of a group called
<code class="literal">nix-users</code>, do
</p><pre class="screen" xml:space="preserve">$ chgrp nix-users /nix/var/nix/daemon-socket
$ chmod ug=rwx,o= /nix/var/nix/daemon-socket
</pre><p>
This way, users who are not in the <code class="literal">nix-users</code> group
cannot connect to the Unix domain socket
<code class="filename">/nix/var/nix/daemon-socket/socket</code>, so they cannot
perform Nix operations.</p></div></section></section><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-env-variables" class="title">Chapter 7. Environment Variables<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-env-variables" aria-label="Anchor link for: ch env variables" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>To use Nix, some environment variables should be set. In
particular, <code class="envar">PATH</code> should contain the directories
<code class="filename"><em class="replaceable"><code>prefix</code></em>/bin</code> and
<code class="filename">~/.nix-profile/bin</code>. The first directory contains
the Nix tools themselves, while <code class="filename">~/.nix-profile</code> is
a symbolic link to the current <span class="emphasis"><em>user environment</em></span>
(an automatically generated package consisting of symlinks to
installed packages). The simplest way to set the required environment
variables is to include the file
<code class="filename"><em class="replaceable"><code>prefix</code></em>/etc/profile.d/nix.sh</code>
in your <code class="filename">~/.profile</code> (or similar), like this:</p><pre class="screen" xml:space="preserve">source <em class="replaceable"><code>prefix</code></em>/etc/profile.d/nix.sh</pre><section class="section"><div class="titlepage"><div><div><h2 id="sec-nix-ssl-cert-file" class="title" style="clear: both">7.1. <code class="envar">NIX_SSL_CERT_FILE</code><a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-nix-ssl-cert-file" aria-label="Anchor link for: sec nix ssl cert file" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>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
<code class="envar">NIX_SSL_CERT_FILE</code>.</p><p>If you don't specify a <code class="envar">NIX_SSL_CERT_FILE</code>
manually, Nix will install and use its own certificate
bundle.</p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p>Set the environment variable and install Nix</p><pre class="screen" xml:space="preserve">$ export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt
$ sh <(curl -L https://nixos.org/nix/install)
</pre></li><li class="step"><p>In the shell profile and rc files (for example,
<code class="filename">/etc/bashrc</code>, <code class="filename">/etc/zshrc</code>),
add the following line:</p><pre class="programlisting" xml:space="preserve">export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt
</pre></li></ol></div><div class="alert alert-info"><strong>Note:</strong> You must not add the export and then do the install, as
the Nix installer will detect the presense of Nix configuration, and
abort.</div><section class="section"><div class="titlepage"><div><div><h3 id="sec-nix-ssl-cert-file-with-nix-daemon-and-macos" class="title">7.1.1. <code class="envar">NIX_SSL_CERT_FILE</code> with macOS and the Nix daemon<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-nix-ssl-cert-file-with-nix-daemon-and-macos" aria-label="Anchor link for: sec nix ssl cert file with nix daemon and macos" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>On macOS you must specify the environment variable for the Nix
daemon service, then restart it:</p><pre class="screen" xml:space="preserve">$ sudo launchctl setenv NIX_SSL_CERT_FILE /etc/ssl/my-certificate-bundle.crt
$ sudo launchctl kickstart -k system/org.nixos.nix-daemon
</pre></section><section class="section"><div class="titlepage"><div><div><h3 id="sec-installer-proxy-settings" class="title">7.1.2. Proxy Environment Variables<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-installer-proxy-settings" aria-label="Anchor link for: sec installer proxy settings" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h3></div></div></div><p>The Nix installer has special handling for these proxy-related
environment variables:
<code class="varname">http_proxy</code>, <code class="varname">https_proxy</code>,
<code class="varname">ftp_proxy</code>, <code class="varname">no_proxy</code>,
<code class="varname">HTTP_PROXY</code>, <code class="varname">HTTPS_PROXY</code>,
<code class="varname">FTP_PROXY</code>, <code class="varname">NO_PROXY</code>.
</p><p>If any of these variables are set when running the Nix installer,
then the installer will create an override file at
<code class="filename">/etc/systemd/system/nix-daemon.service.d/override.conf</code>
so <span class="command"><strong>nix-daemon</strong></span> will use them.
</p></section></section></section></div><section class="chapter"><div class="titlepage"><div><div><div class="page-header"><h1 id="ch-upgrading-nix" class="title">Chapter 8. Upgrading Nix<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-upgrading-nix" aria-label="Anchor link for: ch upgrading nix" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h1></div></div></div></div><p>
Multi-user Nix users on macOS can upgrade Nix by running:
<span class="command"><strong>sudo -i sh -c 'nix-channel --update &&
nix-env -iA nixpkgs.nix &&
launchctl remove org.nixos.nix-daemon &&
launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist'</strong></span>
</p><p>
Single-user installations of Nix should run this:
<span class="command"><strong>nix-channel --update; nix-env -iA nixpkgs.nix</strong></span>
</p></section><div class="part"><div class="titlepage"><div><div><div class="page-header"><h1 id="chap-package-management" class="title">Part III. Package Management<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#chap-package-management" aria-label="Anchor link for: chap package management" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h1></div></div></div></div><div class="partintro"><div></div><p>This chapter discusses how to do package management with Nix,
i.e., how to obtain, install, upgrade, and erase packages. This is
the “user’s” perspective of the Nix system — people
who want to <span class="emphasis"><em>create</em></span> packages should consult
<a class="xref" href="https://nixos.org/manual/nix/stable/#chap-writing-nix-expressions" title="Part IV. Writing Nix Expressions" shape="rect">Part IV, “Writing Nix Expressions”</a>.</p></div><section class="chapter"><div class="titlepage"><div><div><h2 id="ch-basic-package-mgmt" class="title">Chapter 9. Basic Package Management<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#ch-basic-package-mgmt" aria-label="Anchor link for: ch basic package mgmt" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>The main command for package management is <a class="link" href="https://nixos.org/manual/nix/stable/#sec-nix-env" title="nix-env" shape="rect"><span class="command"><strong>nix-env</strong></span></a>. You can use
it to install, upgrade, and erase packages, and to query what
packages are installed or are available for installation.</p><p>In Nix, different users can have different “views”
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 —
where “active” just means that it appears in a directory
in the user’s <code class="envar">PATH</code>. Such a view on the set of
installed applications is called a <span class="emphasis"><em>user
environment</em></span>, which is just a directory tree consisting of
symlinks to the files of the active applications. </p><p>Components are installed from a set of <span class="emphasis"><em>Nix
expressions</em></span> 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.)</p><p>You can manually download the latest version of Nixpkgs from
<a class="link" href="http://nixos.org/nixpkgs/download.html" target="_top" shape="rect">http://nixos.org/nixpkgs/download.html</a>. However,
it’s much more convenient to use the Nixpkgs
<span class="emphasis"><em>channel</em></span>, since it makes it easy to stay up to
date with new versions of Nixpkgs. (Channels are described in more
detail in <a class="xref" href="https://nixos.org/manual/nix/stable/#sec-channels" title="Chapter 12. Channels" shape="rect">Chapter 12, <em>Channels</em></a>.) Nixpkgs is automatically
added to your list of “subscribed” channels when you install
Nix. If this is not the case for some reason, you can add it as
follows:
</p><pre class="screen" xml:space="preserve">$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
</pre><p>
</p><div class="alert alert-info"><strong>Note:</strong> On NixOS, you’re automatically subscribed to a NixOS
channel corresponding to your NixOS major release
(e.g. <code class="uri">http://nixos.org/channels/nixos-14.12</code>). 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.</div><p>You can view the set of available packages in Nixpkgs:
</p><pre class="screen" xml:space="preserve">$ nix-env -qa
aterm-2.2
bash-3.0
binutils-2.15
bison-1.875d
blackdown-1.4.2
bzip2-1.0.2
…</pre><p>
The flag <code class="option">-q</code> specifies a query operation, and
<code class="option">-a</code> means that you want to show the “available” (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
<code class="option">-f</code> flag:
</p><pre class="screen" xml:space="preserve">$ nix-env -qaf <em class="replaceable"><code>/path/to/nixpkgs</code></em>
</pre><p>
where <em class="replaceable"><code>/path/to/nixpkgs</code></em> is where you’ve
unpacked or checked out Nixpkgs.</p><p>You can select specific packages by name:
</p><pre class="screen" xml:space="preserve">$ nix-env -qa firefox
firefox-34.0.5
firefox-with-plugins-34.0.5
</pre><p>
and using regular expressions:
</p><pre class="screen" xml:space="preserve">$ nix-env -qa 'firefox.*'
</pre><p>
</p><p>It is also possible to see the <span class="emphasis"><em>status</em></span> of
available packages, i.e., whether they are installed into the user
environment and/or present in the system:
</p><pre class="screen" xml:space="preserve">$ nix-env -qas
…
-PS bash-3.0
--S binutils-2.15
IPS bison-1.875d
…</pre><p>
The first character (<code class="literal">I</code>) indicates whether the
package is installed in your current user environment. The second
(<code class="literal">P</code>) 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 (<code class="literal">S</code>) indicates
whether there is a so-called <span class="emphasis"><em>substitute</em></span> for the
package, which is Nix’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.</p><p>You can install a package using <code class="literal">nix-env -i</code>.
For instance,
</p><pre class="screen" xml:space="preserve">$ nix-env -i subversion</pre><p>
will install the package called <code class="literal">subversion</code> (which
is, of course, the <a class="link" href="http://subversion.tigris.org/" target="_top" shape="rect">Subversion version
management system</a>).</p><div class="alert alert-info"><strong>Note:</strong> When you ask Nix to install a package, it will first try
to get it in pre-compiled form from a <span class="emphasis"><em>binary
cache</em></span>. By default, Nix will use the binary cache
<code class="uri">https://cache.nixos.org</code>; 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 <code class="literal">nix-env
-i subversion</code> 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
<code class="uri">https://cache.nixos.org</code>. 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.</div><p>Naturally, packages can also be uninstalled:
</p><pre class="screen" xml:space="preserve">$ nix-env -e subversion</pre><p>
</p><p>Upgrading to a new version is just as easy. If you have a new
release of Nix Packages, you can do:
</p><pre class="screen" xml:space="preserve">$ nix-env -u subversion</pre><p>
This will <span class="emphasis"><em>only</em></span> upgrade Subversion if there is a
“newer” 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’d expect of them). To just
unconditionally replace Subversion with whatever version is in the Nix
expressions, use <em class="parameter"><code>-i</code></em> instead of
<em class="parameter"><code>-u</code></em>; <em class="parameter"><code>-i</code></em> will remove
whatever version is already installed.</p><p>You can also upgrade all packages for which there are newer
versions:
</p><pre class="screen" xml:space="preserve">$ nix-env -u</pre><p>
</p><p>Sometimes it’s useful to be able to ask what
<span class="command"><strong>nix-env</strong></span> would do, without actually doing it. For
instance, to find out what packages would be upgraded by
<code class="literal">nix-env -u</code>, you can do
</p><pre class="screen" xml:space="preserve">$ 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'</pre><p>
</p></section><section class="chapter"><div class="titlepage"><div><div><h2 id="sec-profiles" class="title">Chapter 10. Profiles<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-profiles" aria-label="Anchor link for: sec profiles" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p>Profiles and user environments are Nix’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’s useful to know a bit about how Nix
works. In Nix, packages are stored in unique locations in the
<span class="emphasis"><em>Nix store</em></span> (typically,
<code class="filename">/nix/store</code>). For instance, a particular version
of the Subversion package might be stored in a directory
<code class="filename">/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3/</code>,
while another version might be stored in
<code class="filename">/nix/store/5mq2jcn36ldlmh93yj1n8s9c95pj7c5s-subversion-1.1.2</code>.
The long strings prefixed to the directory names are cryptographic
hashes<a href="https://nixos.org/manual/nix/stable/#ftn.idm140737322335088" class="footnote" id="idm140737322335088" shape="rect"><sup class="footnote">[1]</sup></a> of
<span class="emphasis"><em>all</em></span> inputs involved in building the package —
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’t interfere with each other. <a class="xref" href="https://nixos.org/manual/nix/stable/#fig-user-environments" title="Figure 10.1. User environments" shape="rect">Figure 10.1, “User environments”</a> shows a part of a typical Nix
store.</p><div class="figure"><a id="fig-user-environments" shape="rect"></a><p class="title"><strong>Figure 10.1. User environments</strong></p><div class="figure-contents"><div class="mediaobject"><img src="./Nix-Package-Manager-Guide-Version-2.3.10_files/user-environments.png" alt="User environments"></div></div></div><br class="figure-break" clear="none"><br><p>Of course, you wouldn’t want to type
</p><pre class="screen" xml:space="preserve">$ /nix/store/dpmvp969yhdq...-subversion-1.1.3/bin/svn</pre><p>
every time you want to run Subversion. Of course we could set up the
<code class="envar">PATH</code> environment variable to include the
<code class="filename">bin</code> directory of every package we want to use,
but this is not very convenient since changing <code class="envar">PATH</code>
doesn’t take effect for already existing processes. The solution Nix
uses is to create directory trees of symlinks to
<span class="emphasis"><em>activated</em></span> packages. These are called
<span class="emphasis"><em>user environments</em></span> and they are packages
themselves (though automatically generated by
<span class="command"><strong>nix-env</strong></span>), so they too reside in the Nix store. For
instance, in <a class="xref" href="https://nixos.org/manual/nix/stable/#fig-user-environments" title="Figure 10.1. User environments" shape="rect">Figure 10.1, “User environments”</a> the user
environment <code class="filename">/nix/store/0c1p5z4kda11...-user-env</code>
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
</p><pre class="screen" xml:space="preserve">$ nix-env -i subversion</pre><p>
on a set of Nix expressions that contained Subversion 1.1.2.</p><p>This doesn’t in itself solve the problem, of course; you
wouldn’t want to type
<code class="filename">/nix/store/0c1p5z4kda11...-user-env/bin/svn</code>
either. That’s why there are symlinks outside of the store that point
to the user environments in the store; for instance, the symlinks
<code class="filename">default-42-link</code> and
<code class="filename">default-43-link</code> in the example. These are called
<span class="emphasis"><em>generations</em></span> since every time you perform a
<span class="command"><strong>nix-env</strong></span> operation, a new user environment is
generated based on the current one. For instance, generation 43 was
created from generation 42 when we did
</p><pre class="screen" xml:space="preserve">$ nix-env -i subversion firefox</pre><p>
on a set of Nix expressions that contained Firefox and a new version
of Subversion.</p><p>Generations are grouped together into
<span class="emphasis"><em>profiles</em></span> so that different users don’t interfere
with each other if they don’t want to. For example:
</p><pre class="screen" xml:space="preserve">$ ls -l /nix/var/nix/profiles/
...
lrwxrwxrwx 1 eelco ... default-42-link -> /nix/store/0c1p5z4kda11...-user-env
lrwxrwxrwx 1 eelco ... default-43-link -> /nix/store/3aw2pdyx2jfc...-user-env
lrwxrwxrwx 1 eelco ... default -> default-43-link</pre><p>
This shows a profile called <code class="filename">default</code>. The file
<code class="filename">default</code> itself is actually a symlink that points
to the current generation. When we do a <span class="command"><strong>nix-env</strong></span>
operation, a new user environment and generation link are created
based on the current one, and finally the <code class="filename">default</code>
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’t interfere in
any way with old packages, since they are stored in different
locations in the Nix store.)</p><p>If you find that you want to undo a <span class="command"><strong>nix-env</strong></span>
operation, you can just do
</p><pre class="screen" xml:space="preserve">$ nix-env --rollback</pre><p>
which will just make the current generation link point at the previous
link. E.g., <code class="filename">default</code> would be made to point at
<code class="filename">default-42-link</code>. You can also switch to a
specific generation:
</p><pre class="screen" xml:space="preserve">$ nix-env --switch-generation 43</pre><p>
which in this example would roll forward to generation 43 again. You
can also see all available generations:
</p><pre class="screen" xml:space="preserve">$ nix-env --list-generations</pre><p>You generally wouldn’t have
<code class="filename">/nix/var/nix/profiles/<em class="replaceable"><code>some-profile</code></em>/bin</code>
in your <code class="envar">PATH</code>. Rather, there is a symlink
<code class="filename">~/.nix-profile</code> that points to your current
profile. This means that you should put
<code class="filename">~/.nix-profile/bin</code> in your <code class="envar">PATH</code>
(and indeed, that’s what the initialisation script
<code class="filename">/nix/etc/profile.d/nix.sh</code> does). This makes it
easier to switch to a different profile. You can do that using the
command <span class="command"><strong>nix-env --switch-profile</strong></span>:
</p><pre class="screen" xml:space="preserve">$ nix-env --switch-profile /nix/var/nix/profiles/my-profile
$ nix-env --switch-profile /nix/var/nix/profiles/default</pre><p>
These commands switch to the <code class="filename">my-profile</code> and
default profile, respectively. If the profile doesn’t exist, it will
be created automatically. You should be careful about storing a
profile in another location than the <code class="filename">profiles</code>
directory, since otherwise it might not be used as a root of the
garbage collector (see <a class="xref" href="https://nixos.org/manual/nix/stable/#sec-garbage-collection" title="Chapter 11. Garbage Collection" shape="rect">Chapter 11, <em>Garbage Collection</em></a>).</p><p>All <span class="command"><strong>nix-env</strong></span> operations work on the profile
pointed to by <span class="command"><strong>~/.nix-profile</strong></span>, but you can override
this using the <code class="option">--profile</code> option (abbreviation
<code class="option">-p</code>):
</p><pre class="screen" xml:space="preserve">$ nix-env -p /nix/var/nix/profiles/other-profile -i subversion</pre><p>
This will <span class="emphasis"><em>not</em></span> change the
<span class="command"><strong>~/.nix-profile</strong></span> symlink.</p><div class="footnotes"><br clear="none"><br><hr style="width:100; text-align:left;margin-left: 0"><div id="ftn.idm140737322335088" class="footnote"><p><a href="https://nixos.org/manual/nix/stable/#idm140737322335088" class="para" shape="rect"><sup class="para">[1] </sup></a>160-bit truncations of SHA-256 hashes encoded in
a base-32 notation, to be precise.</p></div></div></section><section class="chapter"><div class="titlepage"><div><div><h2 id="sec-garbage-collection" class="title">Chapter 11. Garbage Collection<a class="anchorjs-link " href="https://nixos.org/manual/nix/stable/#sec-garbage-collection" aria-label="Anchor link for: sec garbage collection" data-anchorjs-icon="" style="font-family: anchorjs-icons; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1; padding-left: 0.375em;"></a></h2></div></div></div><p><span class="command"><strong>nix-env</strong></span> operations such as upgrades
(<code class="option">-u</code>) and uninstall (<code class="option">-e</code>) 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 “deleted” packages.</p><p>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.</p><p>Note however that as long as old generations reference a
package, it will not be deleted. After all, we wouldn’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.</p><p>To delete all old (non-current) generations of your current
profile:
</p><pre class="screen" xml:space="preserve">$ nix-env --delete-generations old</pre><p>
Instead of <code class="literal">old</code> you can also specify a list of
generations, e.g.,
</p><pre class="screen" xml:space="preserve">$ nix-env --delete-generations 10 11 14</pre><p>
To delete all generations older than a specified number of days
(except the current generation), use the <code class="literal">d</code>
suffix. For example,
</p><pre class="screen" xml:space="preserve">$ nix-env --delete-generations 14d</pre><p>
deletes all generations older than two weeks.</p><p>After removing appropriate old generations you can run the
garbage collector as follows:
</p><pre class="screen" xml:space="preserve">$ nix-store --gc</pre><p>
The behaviour of the gargage collector is affected by the