Nix User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
Nix User’s Guide i Nix User’s Guide Ed. Version 1.3 Nix User’s Guide ii Copyright © 2004-2012 Eelco Dolstra Nix User’s Guide iii Contents 1 Introduction 1 1.1 About Nix . 1 1.1.1 Multiple versions . 1 1.1.2 Complete dependencies . 1 1.1.3 Multi-user support . 2 1.1.4 Atomic upgrades and rollbacks . 2 1.1.5 Garbage collection . 2 1.1.6 Functional package language . 2 1.1.7 Transparent source/binary deployment . 2 1.1.8 Binary patching . 3 1.1.9 Nix Packages collection . 3 1.1.10 Service deployment . 3 1.1.11 Portability . 3 1.1.12 NixOS . 3 1.2 About us . 3 1.3 About this manual . 3 1.4 License . 3 1.5 More information . 4 2 Quick Start 5 3 Installation 7 3.1 Supported platforms . 7 3.2 Installing a binary distribution . 7 3.3 Installing Nix from source . 8 3.3.1 Prerequisites . 8 3.3.2 Obtaining a source distribution . 8 3.3.3 Building Nix from source . 9 3.4 Security . 9 3.4.1 Single-user mode . 9 3.4.2 Multi-user mode . 9 Nix User’s Guide iv 3.4.2.1 Setting up the build users . 10 3.4.2.2 Nix store/database owned by root . 10 3.4.2.3 Nix store/database not owned by root . 11 3.4.2.4 Restricting access . 11 3.5 Using Nix . 11 4 Package Management 12 4.1 Basic package management . 12 4.2 Profiles . 14 4.3 Garbage collection . 15 4.3.1 Garbage collector roots . 16 4.4 Channels . 16 4.5 One-click installs . 17 4.6 Sharing packages between machines . 17 5 Writing Nix Expressions 19 5.1 A simple Nix expression . 19 5.1.1 The Nix expression . 19 5.1.2 The builder . 20 5.1.3 Composition . 21 5.1.4 Testing . 22 5.1.5 The generic builder . 23 5.2 The Nix expression language . 24 5.2.1 Values . 24 5.2.1.1 Simple values . 24 5.2.1.2 Lists . 25 5.2.1.3 Attribute sets . 26 5.2.2 Language constructs . 26 5.2.2.1 Recursive attribute sets . 26 5.2.2.2 Let-expressions . 27 5.2.2.3 Inheriting attributes . 27 5.2.2.4 Functions . 27 5.2.2.5 Conditionals . 28 5.2.2.6 Assertions . 28 5.2.2.7 With-expressions . 29 5.2.2.8 Comments . 30 5.2.3 Operators . 30 5.2.4 Derivations . 30 5.2.4.1 Advanced attributes . 32 5.2.5 Built-in functions . 34 5.3 The standard environment . 39 5.3.1 Customising the generic builder . 40 5.3.2 Debugging failed builds . 40 Nix User’s Guide v 6 Setting Up Distributed Builds 41 A Command Reference 43 A.1 Common options . 43 A.2 Common environment variables . 45 A.3 Main commands . 46 A.3.1 nix-env . 46 A.3.2 nix-instantiate . 55.