Advertisement
Guest User

Untitled

a guest
Jan 10th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 8.40 KB | None | 0 0
  1. \begin{chapter}[id=ch-about-nix]{About Nix}
  2.  
  3. Nix is a \emph{purely functional package manager}.  This means that it
  4. treats packages like values in purely functional programming languages
  5. such as Haskell — they are built by functions that don’t have
  6. side-effects, and they never change after they have been built.  Nix
  7. stores packages in the \emph{Nix store}, usually the directory
  8. \filename{/nix/store}, where each package has its own unique
  9. subdirectory such as
  10.  
  11.  \listing{/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-33.1/}
  12.  
  13. where \code{b6gvzjyb2pg0…} is a unique identifier for the package that
  14. captures all its dependencies (it’s a cryptographic hash of the
  15. package’s build dependency graph).  This enables many powerful
  16. features.
  17.  
  18.  
  19. \simplesect{Multiple versions}{
  20.  
  21. You can have multiple versions or variants of a package
  22. installed at the same time.  This is especially important when
  23. different applications have dependencies on different versions of the
  24. same package — it prevents the “DLL hell”.  Because of the hashing
  25. scheme, different versions of a package end up in different paths in
  26. the Nix store, so they don’t interfere with each other.
  27.  
  28. An important consequence is that operations like upgrading or
  29. uninstalling an application cannot break other applications, since
  30. these operations never “destructively” update or delete files that are
  31. used by other packages.
  32.  
  33. }
  34.  
  35. \simplesect{Complete dependencies}{
  36.  
  37. Nix helps you make sure that package dependency specifications are
  38. complete.  In general, when you’re making a package for a package
  39. management system like RPM, you have to specify for each package what
  40. its dependencies are, but there are no guarantees that this
  41. specification is complete.  If you forget a dependency, then the
  42. package will build and work correctly on \emph{your} machine if you
  43. have the dependency installed, but not on the end user's machine if
  44. it's not there.
  45.  
  46. Since Nix on the other hand doesn’t install packages in “global”
  47. locations like \filename{/usr/bin} but in package-specific
  48. directories, the risk of incomplete dependencies is greatly reduced.
  49. This is because tools such as compilers don’t search in per-packages
  50. directories such as
  51. \filename{/nix/store/5lbfaxb722zp…-openssl-0.9.8d/include}, so if a
  52. package builds correctly on your system, this is because you specified
  53. the dependency explicitly.
  54.  
  55. Once a package is built, runtime dependencies are found by scanning
  56. binaries for the hash parts of Nix store paths (such as
  57. \code{r8vvq9kq…}).  This sounds risky, but it works extremely well.
  58.  
  59. }
  60.  
  61. \simplesect{Multi-user support}{
  62.  
  63. Nix has multi-user support.  This means that non-privileged users can
  64. securely install software.  Each user can have a different
  65. \emph{profile}, a set of packages in the Nix store that appear in the
  66. user’s \envar{PATH}.  If a user installs a package that another user
  67. has already installed previously, the package won’t be built or
  68. downloaded a second time.  At the same time, it is not possible for
  69. one user to inject a Trojan horse into a package that might be used by
  70. another user.
  71.  
  72. }
  73.  
  74. \simplesect{Atomic upgrades and rollbacks}{
  75.  
  76. Since package management operations never overwrite packages in the
  77. Nix store but just add new versions in different paths, they are
  78. \emph{atomic}.  So during a package upgrade, there is no time window
  79. in which the package has some files from the old version and some
  80. files from the new version — which would be bad because a program
  81. might well crash if it’s started during that period.
  82.  
  83. And since packages aren’t overwritten, the old versions are still
  84. there after an upgrade.  This means that you can \emph{roll
  85. back} to the old version:
  86.  
  87.  \screen{
  88.  $ nix-env --upgrade <replaceable>some-packages</replaceable>
  89.  $ nix-env --rollback
  90.  }
  91.  
  92. }
  93.  
  94. \simplesect{Garbage collection}{
  95.  
  96. When you uninstall a package like this…
  97.  
  98.  \screen{$ nix-env --uninstall firefox}
  99. the package isn’t deleted from the system right away (after all, you
  100. might want to do a rollback, or it might be in the profiles of other
  101. users).  Instead, unused packages can be deleted safely by running the
  102. \emph{garbage collector}:
  103.  \screen{$ nix-collect-garbage}
  104.  
  105. This deletes all packages that aren’t in use by any user profile or by
  106. a currently running program.
  107.  
  108. }
  109.  
  110. \simplesect{Functional package language}{
  111.  
  112. Packages are built from \emph{Nix expressions},
  113. which is a simple functional language.  A Nix expression describes
  114. everything that goes into a package build action (a “derivation”):
  115. other packages, sources, the build script, environment variables for
  116. the build script, etc.  Nix tries very hard to ensure that Nix
  117. expressions are \emph{deterministic}: building a Nix
  118. expression twice should yield the same result.
  119.  
  120. Because it’s a functional language, it’s easy to support
  121. building variants of a package: turn the Nix expression into a
  122. function and call it any number of times with the appropriate
  123. arguments.  Due to the hashing scheme, variants don’t conflict with
  124. each other in the Nix store.
  125.  
  126. }
  127.  
  128. \simplesect{Transparent source/binary deployment}{
  129.  
  130. Nix expressions generally describe how to build a package from
  131. source, so an installation action like
  132.  
  133.  \screen{$ nix-env --install firefox}
  134. \emph{could} cause quite a bit of build activity, as not only Firefox
  135. but also all its dependencies (all the way up to the C library and the
  136. compiler) would have to built, at least if they are not already in the
  137. Nix store.  This is a \emph{source deployment model}.  For most users,
  138. building from source is not very pleasant as it takes far too long.
  139. However, Nix can automatically skip building from source and instead
  140. use a \emph{binary cache}, a web server that provides pre-built
  141. binaries. For instance, when asked to build
  142. \code{/nix/store/b6gvzjyb2pg0…-firefox-33.1} from source, Nix would
  143. first check if the file
  144. \uri{https://cache.nixos.org/b6gvzjyb2pg0….narinfo} exists, and if so,
  145. fetch the pre-built binary referenced from there; otherwise, it would
  146. fall back to building from source.
  147. }
  148. \#{\simplesect{Binary patching}{
  149. In addition to downloading binaries automatically if they’re
  150. available, Nix can download binary deltas that patch an existing
  151. package in the Nix store into a new version.  This speeds up
  152. upgrades.
  153. }}
  154. \simplesect{Nix Packages collection}{
  155. We provide a large set of Nix expressions containing hundreds of
  156. existing Unix packages, the \emph{Nix Packages
  157. collection} (Nixpkgs).
  158. }
  159. \simplesect{Managing build environments}{
  160. Nix is extremely useful for developers as it makes it easy to
  161. automatically set up the build environment for a package. Given a Nix
  162. expression that describes the dependencies of your package, the
  163. command \command{nix-shell} will build or download those dependencies
  164. if they’re not already in your Nix store, and then start a Bash shell
  165. in which all necessary environment variables (such as compiler search
  166. paths) are set.
  167. For example, the following command gets all dependencies of the Pan
  168. newsreader, as described by
  169. \link{https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix}{its
  170.  Nix expression}:
  171.  \screen{$ nix-shell '<nixpkgs>' -A pan}
  172.  
  173. You’re then dropped into a shell where you can edit, build and test
  174. the package:
  175.  
  176.  \screen{{{
  177.  [nix-shell]$ tar xf $src
  178.  [nix-shell]$ cd pan-*
  179.  [nix-shell]$ ./configure
  180.  [nix-shell]$ make
  181.  [nix-shell]$ ./pan/gui/pan
  182.  }}}
  183.  
  184. \#{
  185. Since Nix packages are reproducible and have complete dependency
  186. specifications, Nix makes an excellent basis for
  187. \link{https://nixos.org/hydra}{a continuous build system}.
  188. }
  189.  
  190. }
  191.  
  192. \simplesect{Portability}{
  193.  
  194. Nix runs on Linux and macOS.
  195.  
  196. }
  197.  
  198. \simplesect{NixOS}{
  199.  
  200. NixOS is a Linux distribution based on Nix.  It uses Nix not just for
  201. package management but also to manage the system configuration (e.g.,
  202. to build configuration files in \filename{/etc}).  This means, among
  203. other things, that it is easy to roll back the entire configuration of
  204. the system to an earlier state.  Also, users can install software
  205. without root privileges.  For more information and downloads, see the
  206. \link{http://nixos.org/}{NixOS homepage}.
  207.  
  208. }
  209.  
  210. \simplesect{License}{
  211.  
  212. Nix is released under the terms of the
  213. \link{http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html}{GNU
  214.  LGPLv2.1 or (at your option) any later version}.
  215.  
  216. }
  217.  
  218. \end{chapter}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement