Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6468f63994 | ||
|
|
9416202465 | ||
|
|
4941ba3413 | ||
|
|
7244b9b861 |
No files matched your search
@@ -1,17 +0,0 @@
|
|||||||
((c++-mode . (
|
|
||||||
(c-file-style . "k&r")
|
|
||||||
(c-basic-offset . 4)
|
|
||||||
(indent-tabs-mode . nil)
|
|
||||||
(tab-width . 4)
|
|
||||||
(show-trailing-whitespace . t)
|
|
||||||
(indicate-empty-lines . t)
|
|
||||||
(eval . (c-set-offset 'innamespace 0))
|
|
||||||
(eval . (c-set-offset 'defun-open 0))
|
|
||||||
(eval . (c-set-offset 'inline-open 0))
|
|
||||||
(eval . (c-set-offset 'arglist-intro '+))
|
|
||||||
(eval . (c-set-offset 'arglist-cont 0))
|
|
||||||
(eval . (c-set-offset 'arglist-cont-nonempty '+))
|
|
||||||
(eval . (c-set-offset 'substatement-open 0))
|
|
||||||
(eval . (c-set-offset 'access-label '-))
|
|
||||||
(eval . (c-set-offset 'inlambda 0))
|
|
||||||
)))
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# EditorConfig configuration for nix
|
|
||||||
# http://EditorConfig.org
|
|
||||||
|
|
||||||
# Top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
# Unix-style newlines with a newline ending every file, utf-8 charset
|
|
||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
charset = utf-8
|
|
||||||
|
|
||||||
# Match nix files, set indent to spaces with width of two
|
|
||||||
[*.nix]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
|
|
||||||
# Match c++/shell/perl, set indent to spaces with width of four
|
|
||||||
[*.{hpp,cc,hh,sh,pl}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
|
|
||||||
# Match diffs, avoid to trim trailing whitespace
|
|
||||||
[*.{diff,patch}]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
labels: bug
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
If you have a problem with a specific package or NixOS,
|
|
||||||
you probably want to file an issue at https://github.com/NixOS/nixpkgs/issues.
|
|
||||||
|
|
||||||
**Steps To Reproduce**
|
|
||||||
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**`nix-env --version` output**
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
|
|
||||||
Add any other context about the problem here.
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: improvement
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
name: "Test"
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
jobs:
|
|
||||||
tests:
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-18.04, macos]
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: cachix/install-nix-action@v8
|
|
||||||
#- run: nix flake check
|
|
||||||
- run: nix-build -A checks.$(if [[ `uname` = Linux ]]; then echo x86_64-linux; else echo x86_64-darwin; fi)
|
|
||||||
-125
@@ -1,125 +0,0 @@
|
|||||||
Makefile.config
|
|
||||||
perl/Makefile.config
|
|
||||||
|
|
||||||
# /
|
|
||||||
/aclocal.m4
|
|
||||||
/autom4te.cache
|
|
||||||
/precompiled-headers.h.gch
|
|
||||||
/precompiled-headers.h.pch
|
|
||||||
/config.*
|
|
||||||
/configure
|
|
||||||
/stamp-h1
|
|
||||||
/svn-revision
|
|
||||||
/libtool
|
|
||||||
|
|
||||||
/corepkgs/config.nix
|
|
||||||
|
|
||||||
# /corepkgs/channels/
|
|
||||||
/corepkgs/channels/unpack.sh
|
|
||||||
|
|
||||||
# /corepkgs/nar/
|
|
||||||
/corepkgs/nar/nar.sh
|
|
||||||
/corepkgs/nar/unnar.sh
|
|
||||||
|
|
||||||
# /doc/manual/
|
|
||||||
/doc/manual/manual.html
|
|
||||||
/doc/manual/manual.xmli
|
|
||||||
/doc/manual/manual.pdf
|
|
||||||
/doc/manual/manual.is-valid
|
|
||||||
/doc/manual/*.1
|
|
||||||
/doc/manual/*.5
|
|
||||||
/doc/manual/*.8
|
|
||||||
/doc/manual/version.txt
|
|
||||||
|
|
||||||
# /scripts/
|
|
||||||
/scripts/nix-profile.sh
|
|
||||||
/scripts/nix-copy-closure
|
|
||||||
/scripts/nix-reduce-build
|
|
||||||
/scripts/nix-http-export.cgi
|
|
||||||
/scripts/nix-profile-daemon.sh
|
|
||||||
|
|
||||||
# /src/libexpr/
|
|
||||||
/src/libexpr/lexer-tab.cc
|
|
||||||
/src/libexpr/lexer-tab.hh
|
|
||||||
/src/libexpr/parser-tab.cc
|
|
||||||
/src/libexpr/parser-tab.hh
|
|
||||||
/src/libexpr/parser-tab.output
|
|
||||||
/src/libexpr/nix.tbl
|
|
||||||
|
|
||||||
# /src/libstore/
|
|
||||||
*.gen.*
|
|
||||||
|
|
||||||
/src/nix/nix
|
|
||||||
|
|
||||||
# /src/nix-env/
|
|
||||||
/src/nix-env/nix-env
|
|
||||||
|
|
||||||
# /src/nix-instantiate/
|
|
||||||
/src/nix-instantiate/nix-instantiate
|
|
||||||
|
|
||||||
# /src/nix-store/
|
|
||||||
/src/nix-store/nix-store
|
|
||||||
|
|
||||||
/src/nix-prefetch-url/nix-prefetch-url
|
|
||||||
|
|
||||||
# /src/nix-daemon/
|
|
||||||
/src/nix-daemon/nix-daemon
|
|
||||||
|
|
||||||
/src/nix-collect-garbage/nix-collect-garbage
|
|
||||||
|
|
||||||
# /src/nix-channel/
|
|
||||||
/src/nix-channel/nix-channel
|
|
||||||
|
|
||||||
# /src/nix-build/
|
|
||||||
/src/nix-build/nix-build
|
|
||||||
|
|
||||||
/src/nix-copy-closure/nix-copy-closure
|
|
||||||
|
|
||||||
/src/error-demo/error-demo
|
|
||||||
|
|
||||||
/src/build-remote/build-remote
|
|
||||||
|
|
||||||
# /tests/
|
|
||||||
/tests/test-tmp
|
|
||||||
/tests/common.sh
|
|
||||||
/tests/dummy
|
|
||||||
/tests/result*
|
|
||||||
/tests/restricted-innocent
|
|
||||||
/tests/shell
|
|
||||||
/tests/shell.drv
|
|
||||||
/tests/config.nix
|
|
||||||
|
|
||||||
# /tests/lang/
|
|
||||||
/tests/lang/*.out
|
|
||||||
/tests/lang/*.out.xml
|
|
||||||
/tests/lang/*.ast
|
|
||||||
|
|
||||||
/perl/lib/Nix/Config.pm
|
|
||||||
/perl/lib/Nix/Store.cc
|
|
||||||
|
|
||||||
/misc/systemd/nix-daemon.service
|
|
||||||
/misc/systemd/nix-daemon.socket
|
|
||||||
/misc/upstart/nix-daemon.conf
|
|
||||||
|
|
||||||
/src/resolve-system-dependencies/resolve-system-dependencies
|
|
||||||
|
|
||||||
inst/
|
|
||||||
|
|
||||||
*.a
|
|
||||||
*.o
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
*.dll
|
|
||||||
*.exe
|
|
||||||
*.dep
|
|
||||||
*~
|
|
||||||
*.pc
|
|
||||||
*.plist
|
|
||||||
|
|
||||||
# GNU Global
|
|
||||||
GPATH
|
|
||||||
GRTAGS
|
|
||||||
GSYMS
|
|
||||||
GTAGS
|
|
||||||
|
|
||||||
nix-rust/target
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
The following people contributed to Nix, in alphabetical order:
|
||||||
|
|
||||||
|
Martin Bravenboer
|
||||||
|
Eelco Dolstra
|
||||||
|
Niels Janssen
|
||||||
|
Armijn Hemel
|
||||||
|
Rob Vermaas
|
||||||
|
Eelco Visser
|
||||||
File renamed without changes.
@@ -0,0 +1,229 @@
|
|||||||
|
Copyright 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
||||||
|
Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free documentation; the Free Software Foundation gives
|
||||||
|
unlimited permission to copy, distribute and modify it.
|
||||||
|
|
||||||
|
Basic Installation
|
||||||
|
==================
|
||||||
|
|
||||||
|
These are generic installation instructions.
|
||||||
|
|
||||||
|
The `configure' shell script attempts to guess correct values for
|
||||||
|
various system-dependent variables used during compilation. It uses
|
||||||
|
those values to create a `Makefile' in each directory of the package.
|
||||||
|
It may also create one or more `.h' files containing system-dependent
|
||||||
|
definitions. Finally, it creates a shell script `config.status' that
|
||||||
|
you can run in the future to recreate the current configuration, and a
|
||||||
|
file `config.log' containing compiler output (useful mainly for
|
||||||
|
debugging `configure').
|
||||||
|
|
||||||
|
It can also use an optional file (typically called `config.cache'
|
||||||
|
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||||
|
the results of its tests to speed up reconfiguring. (Caching is
|
||||||
|
disabled by default to prevent problems with accidental use of stale
|
||||||
|
cache files.)
|
||||||
|
|
||||||
|
If you need to do unusual things to compile the package, please try
|
||||||
|
to figure out how `configure' could check whether to do them, and mail
|
||||||
|
diffs or instructions to the address given in the `README' so they can
|
||||||
|
be considered for the next release. If you are using the cache, and at
|
||||||
|
some point `config.cache' contains results you don't want to keep, you
|
||||||
|
may remove or edit it.
|
||||||
|
|
||||||
|
The file `configure.ac' (or `configure.in') is used to create
|
||||||
|
`configure' by a program called `autoconf'. You only need
|
||||||
|
`configure.ac' if you want to change it or regenerate `configure' using
|
||||||
|
a newer version of `autoconf'.
|
||||||
|
|
||||||
|
The simplest way to compile this package is:
|
||||||
|
|
||||||
|
1. `cd' to the directory containing the package's source code and type
|
||||||
|
`./configure' to configure the package for your system. If you're
|
||||||
|
using `csh' on an old version of System V, you might need to type
|
||||||
|
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||||
|
`configure' itself.
|
||||||
|
|
||||||
|
Running `configure' takes awhile. While running, it prints some
|
||||||
|
messages telling which features it is checking for.
|
||||||
|
|
||||||
|
2. Type `make' to compile the package.
|
||||||
|
|
||||||
|
3. Optionally, type `make check' to run any self-tests that come with
|
||||||
|
the package.
|
||||||
|
|
||||||
|
4. Type `make install' to install the programs and any data files and
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
5. You can remove the program binaries and object files from the
|
||||||
|
source code directory by typing `make clean'. To also remove the
|
||||||
|
files that `configure' created (so you can compile the package for
|
||||||
|
a different kind of computer), type `make distclean'. There is
|
||||||
|
also a `make maintainer-clean' target, but that is intended mainly
|
||||||
|
for the package's developers. If you use it, you may have to get
|
||||||
|
all sorts of other programs in order to regenerate files that came
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
|
Compilers and Options
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Some systems require unusual options for compilation or linking that
|
||||||
|
the `configure' script does not know about. Run `./configure --help'
|
||||||
|
for details on some of the pertinent environment variables.
|
||||||
|
|
||||||
|
You can give `configure' initial values for configuration parameters
|
||||||
|
by setting variables in the command line or in the environment. Here
|
||||||
|
is an example:
|
||||||
|
|
||||||
|
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||||
|
|
||||||
|
*Note Defining Variables::, for more details.
|
||||||
|
|
||||||
|
Compiling For Multiple Architectures
|
||||||
|
====================================
|
||||||
|
|
||||||
|
You can compile the package for more than one kind of computer at the
|
||||||
|
same time, by placing the object files for each architecture in their
|
||||||
|
own directory. To do this, you must use a version of `make' that
|
||||||
|
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||||
|
directory where you want the object files and executables to go and run
|
||||||
|
the `configure' script. `configure' automatically checks for the
|
||||||
|
source code in the directory that `configure' is in and in `..'.
|
||||||
|
|
||||||
|
If you have to use a `make' that does not support the `VPATH'
|
||||||
|
variable, you have to compile the package for one architecture at a
|
||||||
|
time in the source code directory. After you have installed the
|
||||||
|
package for one architecture, use `make distclean' before reconfiguring
|
||||||
|
for another architecture.
|
||||||
|
|
||||||
|
Installation Names
|
||||||
|
==================
|
||||||
|
|
||||||
|
By default, `make install' will install the package's files in
|
||||||
|
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||||
|
installation prefix other than `/usr/local' by giving `configure' the
|
||||||
|
option `--prefix=PATH'.
|
||||||
|
|
||||||
|
You can specify separate installation prefixes for
|
||||||
|
architecture-specific files and architecture-independent files. If you
|
||||||
|
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||||
|
PATH as the prefix for installing programs and libraries.
|
||||||
|
Documentation and other data files will still use the regular prefix.
|
||||||
|
|
||||||
|
In addition, if you use an unusual directory layout you can give
|
||||||
|
options like `--bindir=PATH' to specify different values for particular
|
||||||
|
kinds of files. Run `configure --help' for a list of the directories
|
||||||
|
you can set and what kinds of files go in them.
|
||||||
|
|
||||||
|
If the package supports it, you can cause programs to be installed
|
||||||
|
with an extra prefix or suffix on their names by giving `configure' the
|
||||||
|
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||||
|
|
||||||
|
Optional Features
|
||||||
|
=================
|
||||||
|
|
||||||
|
Some packages pay attention to `--enable-FEATURE' options to
|
||||||
|
`configure', where FEATURE indicates an optional part of the package.
|
||||||
|
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||||
|
is something like `gnu-as' or `x' (for the X Window System). The
|
||||||
|
`README' should mention any `--enable-' and `--with-' options that the
|
||||||
|
package recognizes.
|
||||||
|
|
||||||
|
For packages that use the X Window System, `configure' can usually
|
||||||
|
find the X include and library files automatically, but if it doesn't,
|
||||||
|
you can use the `configure' options `--x-includes=DIR' and
|
||||||
|
`--x-libraries=DIR' to specify their locations.
|
||||||
|
|
||||||
|
Specifying the System Type
|
||||||
|
==========================
|
||||||
|
|
||||||
|
There may be some features `configure' cannot figure out
|
||||||
|
automatically, but needs to determine by the type of machine the package
|
||||||
|
will run on. Usually, assuming the package is built to be run on the
|
||||||
|
_same_ architectures, `configure' can figure that out, but if it prints
|
||||||
|
a message saying it cannot guess the machine type, give it the
|
||||||
|
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||||
|
type, such as `sun4', or a canonical name which has the form:
|
||||||
|
|
||||||
|
CPU-COMPANY-SYSTEM
|
||||||
|
|
||||||
|
where SYSTEM can have one of these forms:
|
||||||
|
|
||||||
|
OS KERNEL-OS
|
||||||
|
|
||||||
|
See the file `config.sub' for the possible values of each field. If
|
||||||
|
`config.sub' isn't included in this package, then this package doesn't
|
||||||
|
need to know the machine type.
|
||||||
|
|
||||||
|
If you are _building_ compiler tools for cross-compiling, you should
|
||||||
|
use the `--target=TYPE' option to select the type of system they will
|
||||||
|
produce code for.
|
||||||
|
|
||||||
|
If you want to _use_ a cross compiler, that generates code for a
|
||||||
|
platform different from the build platform, you should specify the
|
||||||
|
"host" platform (i.e., that on which the generated programs will
|
||||||
|
eventually be run) with `--host=TYPE'.
|
||||||
|
|
||||||
|
Sharing Defaults
|
||||||
|
================
|
||||||
|
|
||||||
|
If you want to set default values for `configure' scripts to share,
|
||||||
|
you can create a site shell script called `config.site' that gives
|
||||||
|
default values for variables like `CC', `cache_file', and `prefix'.
|
||||||
|
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||||
|
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||||
|
`CONFIG_SITE' environment variable to the location of the site script.
|
||||||
|
A warning: not all `configure' scripts look for a site script.
|
||||||
|
|
||||||
|
Defining Variables
|
||||||
|
==================
|
||||||
|
|
||||||
|
Variables not defined in a site shell script can be set in the
|
||||||
|
environment passed to `configure'. However, some packages may run
|
||||||
|
configure again during the build, and the customized values of these
|
||||||
|
variables may be lost. In order to avoid this problem, you should set
|
||||||
|
them in the `configure' command line, using `VAR=value'. For example:
|
||||||
|
|
||||||
|
./configure CC=/usr/local2/bin/gcc
|
||||||
|
|
||||||
|
will cause the specified gcc to be used as the C compiler (unless it is
|
||||||
|
overridden in the site shell script).
|
||||||
|
|
||||||
|
`configure' Invocation
|
||||||
|
======================
|
||||||
|
|
||||||
|
`configure' recognizes the following options to control how it
|
||||||
|
operates.
|
||||||
|
|
||||||
|
`--help'
|
||||||
|
`-h'
|
||||||
|
Print a summary of the options to `configure', and exit.
|
||||||
|
|
||||||
|
`--version'
|
||||||
|
`-V'
|
||||||
|
Print the version of Autoconf used to generate the `configure'
|
||||||
|
script, and exit.
|
||||||
|
|
||||||
|
`--cache-file=FILE'
|
||||||
|
Enable the cache: use and save the results of the tests in FILE,
|
||||||
|
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||||
|
disable caching.
|
||||||
|
|
||||||
|
`--config-cache'
|
||||||
|
`-C'
|
||||||
|
Alias for `--cache-file=config.cache'.
|
||||||
|
|
||||||
|
`--quiet'
|
||||||
|
`--silent'
|
||||||
|
`-q'
|
||||||
|
Do not print messages saying which checks are being made. To
|
||||||
|
suppress all normal output, redirect it to `/dev/null' (any error
|
||||||
|
messages will still be shown).
|
||||||
|
|
||||||
|
`--srcdir=DIR'
|
||||||
|
Look for the package's source code in directory DIR. Usually
|
||||||
|
`configure' can determine that directory automatically.
|
||||||
|
|
||||||
|
`configure' also accepts some other, not widely useful, options. Run
|
||||||
|
`configure --help' for more details.
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
makefiles = \
|
|
||||||
mk/precompiled-headers.mk \
|
|
||||||
local.mk \
|
|
||||||
nix-rust/local.mk \
|
|
||||||
src/libutil/local.mk \
|
|
||||||
src/libstore/local.mk \
|
|
||||||
src/libfetchers/local.mk \
|
|
||||||
src/libmain/local.mk \
|
|
||||||
src/libexpr/local.mk \
|
|
||||||
src/nix/local.mk \
|
|
||||||
src/resolve-system-dependencies/local.mk \
|
|
||||||
scripts/local.mk \
|
|
||||||
corepkgs/local.mk \
|
|
||||||
misc/bash/local.mk \
|
|
||||||
misc/systemd/local.mk \
|
|
||||||
misc/launchd/local.mk \
|
|
||||||
misc/upstart/local.mk \
|
|
||||||
doc/manual/local.mk \
|
|
||||||
tests/local.mk \
|
|
||||||
tests/plugins/local.mk
|
|
||||||
|
|
||||||
-include Makefile.config
|
|
||||||
|
|
||||||
OPTIMIZE = 1
|
|
||||||
|
|
||||||
ifeq ($(OPTIMIZE), 1)
|
|
||||||
GLOBAL_CXXFLAGS += -O3
|
|
||||||
else
|
|
||||||
GLOBAL_CXXFLAGS += -O0
|
|
||||||
endif
|
|
||||||
|
|
||||||
include mk/lib.mk
|
|
||||||
|
|
||||||
GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++17
|
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
SUBDIRS = externals src scripts corepkgs doc misc tests
|
||||||
|
EXTRA_DIST = substitute.mk nix.spec nix.spec.in bootstrap.sh \
|
||||||
|
nix.conf.example NEWS version
|
||||||
|
|
||||||
|
include ./substitute.mk
|
||||||
|
|
||||||
|
nix.spec: nix.spec.in
|
||||||
|
|
||||||
|
install-data-local: init-state
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix
|
||||||
|
$(INSTALL_DATA) $(srcdir)/nix.conf.example $(DESTDIR)$(sysconfdir)/nix
|
||||||
|
if ! test -e $(DESTDIR)$(sysconfdir)/nix/nix.conf; then \
|
||||||
|
$(INSTALL_DATA) $(srcdir)/nix.conf.example $(DESTDIR)$(sysconfdir)/nix/nix.conf; \
|
||||||
|
fi
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(docdir)
|
||||||
|
$(INSTALL_DATA) README $(DESTDIR)$(docdir)/
|
||||||
|
|
||||||
|
if INIT_STATE
|
||||||
|
|
||||||
|
# For setuid operation, you can enable the following:
|
||||||
|
# INIT_FLAGS = -g @NIX_GROUP@ -o @NIX_USER@
|
||||||
|
# GROUP_WRITABLE = -m 775
|
||||||
|
|
||||||
|
init-state:
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/db
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/log/nix
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/log/nix/drvs
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/profiles
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/gcroots
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/temproots
|
||||||
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/tmp
|
||||||
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/channels
|
||||||
|
ln -sfn $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/userpool
|
||||||
|
$(INSTALL) $(INIT_FLAGS) -m 1777 -d $(DESTDIR)$(storedir)
|
||||||
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/manifests
|
||||||
|
ln -sfn $(localstatedir)/nix/manifests $(DESTDIR)$(localstatedir)/nix/gcroots/manifests
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
init-state:
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
NEWS:
|
||||||
|
$(MAKE) -C doc/manual NEWS.txt
|
||||||
|
cp $(srcdir)/doc/manual/NEWS.txt NEWS
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
AR = @AR@
|
|
||||||
BDW_GC_LIBS = @BDW_GC_LIBS@
|
|
||||||
BUILD_SHARED_LIBS = @BUILD_SHARED_LIBS@
|
|
||||||
CC = @CC@
|
|
||||||
CFLAGS = @CFLAGS@
|
|
||||||
CXX = @CXX@
|
|
||||||
CXXFLAGS = @CXXFLAGS@
|
|
||||||
LDFLAGS = @LDFLAGS@
|
|
||||||
ENABLE_S3 = @ENABLE_S3@
|
|
||||||
HAVE_SODIUM = @HAVE_SODIUM@
|
|
||||||
HAVE_SECCOMP = @HAVE_SECCOMP@
|
|
||||||
BOOST_LDFLAGS = @BOOST_LDFLAGS@
|
|
||||||
LIBCURL_LIBS = @LIBCURL_LIBS@
|
|
||||||
OPENSSL_LIBS = @OPENSSL_LIBS@
|
|
||||||
PACKAGE_NAME = @PACKAGE_NAME@
|
|
||||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
|
||||||
SODIUM_LIBS = @SODIUM_LIBS@
|
|
||||||
LIBLZMA_LIBS = @LIBLZMA_LIBS@
|
|
||||||
SQLITE3_LIBS = @SQLITE3_LIBS@
|
|
||||||
LIBBROTLI_LIBS = @LIBBROTLI_LIBS@
|
|
||||||
LIBARCHIVE_LIBS = @LIBARCHIVE_LIBS@
|
|
||||||
EDITLINE_LIBS = @EDITLINE_LIBS@
|
|
||||||
bash = @bash@
|
|
||||||
bindir = @bindir@
|
|
||||||
lsof = @lsof@
|
|
||||||
datadir = @datadir@
|
|
||||||
datarootdir = @datarootdir@
|
|
||||||
docdir = @docdir@
|
|
||||||
exec_prefix = @exec_prefix@
|
|
||||||
includedir = @includedir@
|
|
||||||
libdir = @libdir@
|
|
||||||
libexecdir = @libexecdir@
|
|
||||||
localstatedir = @localstatedir@
|
|
||||||
mandir = @mandir@
|
|
||||||
pkglibdir = $(libdir)/$(PACKAGE_NAME)
|
|
||||||
prefix = @prefix@
|
|
||||||
sandbox_shell = @sandbox_shell@
|
|
||||||
storedir = @storedir@
|
|
||||||
sysconfdir = @sysconfdir@
|
|
||||||
system = @system@
|
|
||||||
doc_generate = @doc_generate@
|
|
||||||
xmllint = @xmllint@
|
|
||||||
xsltproc = @xsltproc@
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Nix is a purely functional package manager. For installation and
|
||||||
|
usage instructions, please read the manual, which can be found in
|
||||||
|
`docs/manual/manual.html', and additionally at the Nix website at
|
||||||
|
<http://nixos.org/>.
|
||||||
|
|
||||||
|
|
||||||
|
Acknowledgments
|
||||||
|
|
||||||
|
This product includes software developed by the OpenSSL Project for
|
||||||
|
use in the OpenSSL Toolkit (http://www.OpenSSL.org/).
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
# Nix
|
|
||||||
|
|
||||||
[](https://opencollective.com/nixos)
|
|
||||||
[](https://github.com/NixOS/nix/actions)
|
|
||||||
|
|
||||||
Nix is a powerful package manager for Linux and other Unix systems that makes package
|
|
||||||
management reliable and reproducible. Please refer to the [Nix manual](https://nixos.org/nix/manual)
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
On Linux and macOS the easiest way to Install Nix is to run the following shell command
|
|
||||||
(as a user other than root):
|
|
||||||
|
|
||||||
```
|
|
||||||
$ curl -L https://nixos.org/nix/install | sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Information on additional installation methods is available on the [Nix download page](https://nixos.org/download.html).
|
|
||||||
|
|
||||||
## Building And Developing
|
|
||||||
|
|
||||||
### Building Nix
|
|
||||||
|
|
||||||
You can build Nix using one of the targets provided by [release.nix](./release.nix):
|
|
||||||
|
|
||||||
```
|
|
||||||
$ nix-build ./release.nix -A build.aarch64-linux
|
|
||||||
$ nix-build ./release.nix -A build.x86_64-darwin
|
|
||||||
$ nix-build ./release.nix -A build.i686-linux
|
|
||||||
$ nix-build ./release.nix -A build.x86_64-linux
|
|
||||||
```
|
|
||||||
|
|
||||||
### Development Environment
|
|
||||||
|
|
||||||
You can use the provided `shell.nix` to get a working development environment:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ nix-shell
|
|
||||||
$ ./bootstrap.sh
|
|
||||||
$ ./configure
|
|
||||||
$ make
|
|
||||||
```
|
|
||||||
|
|
||||||
## Additional Resources
|
|
||||||
|
|
||||||
- [Nix manual](https://nixos.org/nix/manual)
|
|
||||||
- [Nix jobsets on hydra.nixos.org](https://hydra.nixos.org/project/nix)
|
|
||||||
- [NixOS Discourse](https://discourse.nixos.org/)
|
|
||||||
- [IRC - #nixos on freenode.net](irc://irc.freenode.net/#nixos)
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Nix is released under the [LGPL v2.1](./COPYING).
|
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:*
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value8
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:*
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value8
|
||||||
|
fun:*
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Addr4
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Addr8
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect_minor
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value8
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Addr4
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Addr8
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:*
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value8
|
||||||
|
fun:*
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:*
|
||||||
|
fun:*
|
||||||
|
fun:AT_collect
|
||||||
|
}
|
||||||
Executable
+252
@@ -0,0 +1,252 @@
|
|||||||
|
#! /usr/bin/perl -w -I /home/eelco/.nix-profile/lib/site_perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use XML::LibXML;
|
||||||
|
#use XML::Simple;
|
||||||
|
|
||||||
|
my $blacklistFN = shift @ARGV;
|
||||||
|
die unless defined $blacklistFN;
|
||||||
|
my $userEnv = shift @ARGV;
|
||||||
|
die unless defined $userEnv;
|
||||||
|
|
||||||
|
|
||||||
|
# Read the blacklist.
|
||||||
|
my $parser = XML::LibXML->new();
|
||||||
|
my $blacklist = $parser->parse_file($blacklistFN)->getDocumentElement;
|
||||||
|
|
||||||
|
#print $blacklist->toString() , "\n";
|
||||||
|
|
||||||
|
|
||||||
|
# Get all the elements of the user environment.
|
||||||
|
my $userEnvElems = `nix-store --query --references '$userEnv'`;
|
||||||
|
die "cannot query user environment elements" if $? != 0;
|
||||||
|
my @userEnvElems = split ' ', $userEnvElems;
|
||||||
|
|
||||||
|
|
||||||
|
my %storePathHashes;
|
||||||
|
|
||||||
|
|
||||||
|
sub getElemNodes {
|
||||||
|
my $node = shift;
|
||||||
|
my @elems = ();
|
||||||
|
foreach my $node ($node->getChildNodes) {
|
||||||
|
push @elems, $node if $node->nodeType == XML_ELEMENT_NODE;
|
||||||
|
}
|
||||||
|
return @elems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my %referencesCache;
|
||||||
|
sub getReferences {
|
||||||
|
my $path = shift;
|
||||||
|
return $referencesCache{$path} if defined $referencesCache{$path};
|
||||||
|
|
||||||
|
my $references = `nix-store --query --references '$path'`;
|
||||||
|
die "cannot query references" if $? != 0;
|
||||||
|
$referencesCache{$path} = [split ' ', $references];
|
||||||
|
|
||||||
|
return $referencesCache{$path};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my %attrsCache;
|
||||||
|
sub getAttr {
|
||||||
|
my $path = shift;
|
||||||
|
my $name = shift;
|
||||||
|
my $key = "$path/$name";
|
||||||
|
return $referencesCache{$key} if defined $referencesCache{$key};
|
||||||
|
|
||||||
|
my $value = `nix-store --query --binding '$name' '$path' 2> /dev/null`;
|
||||||
|
$value = "" if $? != 0; # !!!
|
||||||
|
chomp $value;
|
||||||
|
$referencesCache{$key} = $value;
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub evalCondition;
|
||||||
|
|
||||||
|
|
||||||
|
sub traverse {
|
||||||
|
my $done = shift;
|
||||||
|
my $set = shift;
|
||||||
|
my $path = shift;
|
||||||
|
my $stopCondition = shift;
|
||||||
|
|
||||||
|
return if defined $done->{$path};
|
||||||
|
$done->{$path} = 1;
|
||||||
|
$set->{$path} = 1;
|
||||||
|
|
||||||
|
# print " in $path\n";
|
||||||
|
|
||||||
|
if (!evalCondition({$path => 1}, $stopCondition)) {
|
||||||
|
# print " STOPPING in $path\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the requisites of the deriver.
|
||||||
|
|
||||||
|
foreach my $reference (@{getReferences $path}) {
|
||||||
|
traverse($done, $set, $reference, $stopCondition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub evalSet {
|
||||||
|
my $inSet = shift;
|
||||||
|
my $expr = shift;
|
||||||
|
my $name = $expr->getName;
|
||||||
|
|
||||||
|
if ($name eq "traverse") {
|
||||||
|
my $stopCondition = (getElemNodes $expr)[0];
|
||||||
|
my $done = { };
|
||||||
|
my $set = { };
|
||||||
|
foreach my $path (keys %{$inSet}) {
|
||||||
|
traverse($done, $set, $path, $stopCondition);
|
||||||
|
}
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
die "unknown element `$name'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Function for evaluating conditions.
|
||||||
|
sub evalCondition {
|
||||||
|
my $storePaths = shift;
|
||||||
|
my $condition = shift;
|
||||||
|
my $elemName = $condition->getName;
|
||||||
|
|
||||||
|
if ($elemName eq "containsSource") {
|
||||||
|
my $hash = $condition->attributes->getNamedItem("hash")->getValue;
|
||||||
|
foreach my $path (keys %{$storePathHashes{$hash}}) {
|
||||||
|
return 1 if defined $storePaths->{$path};
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "hasName") {
|
||||||
|
my $nameRE = $condition->attributes->getNamedItem("name")->getValue;
|
||||||
|
foreach my $path (keys %{$storePaths}) {
|
||||||
|
return 1 if $path =~ /$nameRE/;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "hasAttr") {
|
||||||
|
my $name = $condition->attributes->getNamedItem("name")->getValue;
|
||||||
|
my $valueRE = $condition->attributes->getNamedItem("value")->getValue;
|
||||||
|
foreach my $path (keys %{$storePaths}) {
|
||||||
|
if ($path =~ /\.drv$/) {
|
||||||
|
my $value = getAttr($path, $name);
|
||||||
|
# print " $path $name $value\n";
|
||||||
|
return 1 if $value =~ /$valueRE/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "and") {
|
||||||
|
my $result = 1;
|
||||||
|
foreach my $node (getElemNodes $condition) {
|
||||||
|
$result &= evalCondition($storePaths, $node);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "not") {
|
||||||
|
return !evalCondition($storePaths, (getElemNodes $condition)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "within") {
|
||||||
|
my @elems = getElemNodes $condition;
|
||||||
|
my $set = evalSet($storePaths, $elems[0]);
|
||||||
|
return evalCondition($set, $elems[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "true") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($elemName eq "false") {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
die "unknown element `$elemName'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub evalOr {
|
||||||
|
my $storePaths = shift;
|
||||||
|
my $nodes = shift;
|
||||||
|
|
||||||
|
my $result = 0;
|
||||||
|
foreach my $node (@{$nodes}) {
|
||||||
|
$result |= evalCondition($storePaths, $node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Iterate over all elements, check them.
|
||||||
|
foreach my $userEnvElem (@userEnvElems) {
|
||||||
|
|
||||||
|
# Get the deriver of this path.
|
||||||
|
my $deriver = `nix-store --query --deriver '$userEnvElem'`;
|
||||||
|
die "cannot query deriver" if $? != 0;
|
||||||
|
chomp $deriver;
|
||||||
|
|
||||||
|
if ($deriver eq "unknown-deriver") {
|
||||||
|
# print " deriver unknown, cannot check sources\n";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "CHECKING $userEnvElem\n";
|
||||||
|
|
||||||
|
|
||||||
|
# Get the requisites of the deriver.
|
||||||
|
# my $requisites = `nix-store --query --requisites --include-outputs '$deriver'`;
|
||||||
|
# die "cannot query requisites" if $? != 0;
|
||||||
|
# my @requisites = split ' ', $requisites;
|
||||||
|
|
||||||
|
|
||||||
|
# Get the hashes of the requisites.
|
||||||
|
# my $hashes = `nix-store --query --hash @requisites`;
|
||||||
|
# die "cannot query hashes" if $? != 0;
|
||||||
|
# my @hashes = split ' ', $hashes;
|
||||||
|
# for (my $i = 0; $i < scalar @requisites; $i++) {
|
||||||
|
# die unless $i < scalar @hashes;
|
||||||
|
# my $hash = $hashes[$i];
|
||||||
|
# $storePathHashes{$hash} = {} unless defined $storePathHashes{$hash};
|
||||||
|
# my $r = $storePathHashes{$hash}; # !!! fix
|
||||||
|
# $$r{$requisites[$i]} = 1;
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
# Evaluate each blacklist item.
|
||||||
|
foreach my $item ($blacklist->getChildrenByTagName("item")) {
|
||||||
|
my $itemId = $item->getAttributeNode("id")->getValue;
|
||||||
|
# print " CHECKING FOR $itemId\n";
|
||||||
|
|
||||||
|
my $condition = ($item->getChildrenByTagName("condition"))[0];
|
||||||
|
die unless $condition;
|
||||||
|
|
||||||
|
# Evaluate the condition.
|
||||||
|
my @elems = getElemNodes $condition;
|
||||||
|
if (evalOr({$deriver => 1}, \@elems)) {
|
||||||
|
# Oops, condition triggered.
|
||||||
|
my $reason = ($item->getChildrenByTagName("reason"))[0]->getChildNodes->to_literal;
|
||||||
|
$reason =~ s/\s+/ /g;
|
||||||
|
$reason =~ s/^\s+//g;
|
||||||
|
|
||||||
|
print " VULNERABLE TO `$itemId': $reason\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+5
-2
@@ -1,4 +1,7 @@
|
|||||||
#! /bin/sh -e
|
#! /bin/sh -e
|
||||||
rm -f aclocal.m4
|
|
||||||
mkdir -p config
|
mkdir -p config
|
||||||
exec autoreconf -vfi
|
libtoolize --copy
|
||||||
|
aclocal
|
||||||
|
autoheader
|
||||||
|
automake --add-missing --copy
|
||||||
|
autoconf
|
||||||
Vendored
-1486
File diff suppressed because it is too large.
Load diff
Vendored
-1818
File diff suppressed because it is too large.
Load diff
@@ -1,527 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# install - install a program, script, or datafile
|
|
||||||
|
|
||||||
scriptversion=2011-11-20.07; # UTC
|
|
||||||
|
|
||||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
|
||||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
|
||||||
# following copyright and license.
|
|
||||||
#
|
|
||||||
# Copyright (C) 1994 X Consortium
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to
|
|
||||||
# deal in the Software without restriction, including without limitation the
|
|
||||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
||||||
# sell copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be included in
|
|
||||||
# all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
||||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
|
||||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
#
|
|
||||||
# Except as contained in this notice, the name of the X Consortium shall not
|
|
||||||
# be used in advertising or otherwise to promote the sale, use or other deal-
|
|
||||||
# ings in this Software without prior written authorization from the X Consor-
|
|
||||||
# tium.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# FSF changes to this file are in the public domain.
|
|
||||||
#
|
|
||||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
|
||||||
# 'make' implicit rules from creating a file called install from it
|
|
||||||
# when there is no Makefile.
|
|
||||||
#
|
|
||||||
# This script is compatible with the BSD install script, but was written
|
|
||||||
# from scratch.
|
|
||||||
|
|
||||||
nl='
|
|
||||||
'
|
|
||||||
IFS=" "" $nl"
|
|
||||||
|
|
||||||
# set DOITPROG to echo to test this script
|
|
||||||
|
|
||||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
|
||||||
doit=${DOITPROG-}
|
|
||||||
if test -z "$doit"; then
|
|
||||||
doit_exec=exec
|
|
||||||
else
|
|
||||||
doit_exec=$doit
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Put in absolute file names if you don't have them in your path;
|
|
||||||
# or use environment vars.
|
|
||||||
|
|
||||||
chgrpprog=${CHGRPPROG-chgrp}
|
|
||||||
chmodprog=${CHMODPROG-chmod}
|
|
||||||
chownprog=${CHOWNPROG-chown}
|
|
||||||
cmpprog=${CMPPROG-cmp}
|
|
||||||
cpprog=${CPPROG-cp}
|
|
||||||
mkdirprog=${MKDIRPROG-mkdir}
|
|
||||||
mvprog=${MVPROG-mv}
|
|
||||||
rmprog=${RMPROG-rm}
|
|
||||||
stripprog=${STRIPPROG-strip}
|
|
||||||
|
|
||||||
posix_glob='?'
|
|
||||||
initialize_posix_glob='
|
|
||||||
test "$posix_glob" != "?" || {
|
|
||||||
if (set -f) 2>/dev/null; then
|
|
||||||
posix_glob=
|
|
||||||
else
|
|
||||||
posix_glob=:
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
'
|
|
||||||
|
|
||||||
posix_mkdir=
|
|
||||||
|
|
||||||
# Desired mode of installed file.
|
|
||||||
mode=0755
|
|
||||||
|
|
||||||
chgrpcmd=
|
|
||||||
chmodcmd=$chmodprog
|
|
||||||
chowncmd=
|
|
||||||
mvcmd=$mvprog
|
|
||||||
rmcmd="$rmprog -f"
|
|
||||||
stripcmd=
|
|
||||||
|
|
||||||
src=
|
|
||||||
dst=
|
|
||||||
dir_arg=
|
|
||||||
dst_arg=
|
|
||||||
|
|
||||||
copy_on_change=false
|
|
||||||
no_target_directory=
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
|
||||||
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
|
||||||
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
|
||||||
or: $0 [OPTION]... -d DIRECTORIES...
|
|
||||||
|
|
||||||
In the 1st form, copy SRCFILE to DSTFILE.
|
|
||||||
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
|
||||||
In the 4th, create DIRECTORIES.
|
|
||||||
|
|
||||||
Options:
|
|
||||||
--help display this help and exit.
|
|
||||||
--version display version info and exit.
|
|
||||||
|
|
||||||
-c (ignored)
|
|
||||||
-C install only if different (preserve the last data modification time)
|
|
||||||
-d create directories instead of installing files.
|
|
||||||
-g GROUP $chgrpprog installed files to GROUP.
|
|
||||||
-m MODE $chmodprog installed files to MODE.
|
|
||||||
-o USER $chownprog installed files to USER.
|
|
||||||
-s $stripprog installed files.
|
|
||||||
-t DIRECTORY install into DIRECTORY.
|
|
||||||
-T report an error if DSTFILE is a directory.
|
|
||||||
|
|
||||||
Environment variables override the default commands:
|
|
||||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
|
||||||
RMPROG STRIPPROG
|
|
||||||
"
|
|
||||||
|
|
||||||
while test $# -ne 0; do
|
|
||||||
case $1 in
|
|
||||||
-c) ;;
|
|
||||||
|
|
||||||
-C) copy_on_change=true;;
|
|
||||||
|
|
||||||
-d) dir_arg=true;;
|
|
||||||
|
|
||||||
-g) chgrpcmd="$chgrpprog $2"
|
|
||||||
shift;;
|
|
||||||
|
|
||||||
--help) echo "$usage"; exit $?;;
|
|
||||||
|
|
||||||
-m) mode=$2
|
|
||||||
case $mode in
|
|
||||||
*' '* | *' '* | *'
|
|
||||||
'* | *'*'* | *'?'* | *'['*)
|
|
||||||
echo "$0: invalid mode: $mode" >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift;;
|
|
||||||
|
|
||||||
-o) chowncmd="$chownprog $2"
|
|
||||||
shift;;
|
|
||||||
|
|
||||||
-s) stripcmd=$stripprog;;
|
|
||||||
|
|
||||||
-t) dst_arg=$2
|
|
||||||
# Protect names problematic for 'test' and other utilities.
|
|
||||||
case $dst_arg in
|
|
||||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
|
||||||
esac
|
|
||||||
shift;;
|
|
||||||
|
|
||||||
-T) no_target_directory=true;;
|
|
||||||
|
|
||||||
--version) echo "$0 $scriptversion"; exit $?;;
|
|
||||||
|
|
||||||
--) shift
|
|
||||||
break;;
|
|
||||||
|
|
||||||
-*) echo "$0: invalid option: $1" >&2
|
|
||||||
exit 1;;
|
|
||||||
|
|
||||||
*) break;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
|
||||||
# When -d is used, all remaining arguments are directories to create.
|
|
||||||
# When -t is used, the destination is already specified.
|
|
||||||
# Otherwise, the last argument is the destination. Remove it from $@.
|
|
||||||
for arg
|
|
||||||
do
|
|
||||||
if test -n "$dst_arg"; then
|
|
||||||
# $@ is not empty: it contains at least $arg.
|
|
||||||
set fnord "$@" "$dst_arg"
|
|
||||||
shift # fnord
|
|
||||||
fi
|
|
||||||
shift # arg
|
|
||||||
dst_arg=$arg
|
|
||||||
# Protect names problematic for 'test' and other utilities.
|
|
||||||
case $dst_arg in
|
|
||||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test $# -eq 0; then
|
|
||||||
if test -z "$dir_arg"; then
|
|
||||||
echo "$0: no input file specified." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# It's OK to call 'install-sh -d' without argument.
|
|
||||||
# This can happen when creating conditional directories.
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -z "$dir_arg"; then
|
|
||||||
do_exit='(exit $ret); exit $ret'
|
|
||||||
trap "ret=129; $do_exit" 1
|
|
||||||
trap "ret=130; $do_exit" 2
|
|
||||||
trap "ret=141; $do_exit" 13
|
|
||||||
trap "ret=143; $do_exit" 15
|
|
||||||
|
|
||||||
# Set umask so as not to create temps with too-generous modes.
|
|
||||||
# However, 'strip' requires both read and write access to temps.
|
|
||||||
case $mode in
|
|
||||||
# Optimize common cases.
|
|
||||||
*644) cp_umask=133;;
|
|
||||||
*755) cp_umask=22;;
|
|
||||||
|
|
||||||
*[0-7])
|
|
||||||
if test -z "$stripcmd"; then
|
|
||||||
u_plus_rw=
|
|
||||||
else
|
|
||||||
u_plus_rw='% 200'
|
|
||||||
fi
|
|
||||||
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
|
||||||
*)
|
|
||||||
if test -z "$stripcmd"; then
|
|
||||||
u_plus_rw=
|
|
||||||
else
|
|
||||||
u_plus_rw=,u+rw
|
|
||||||
fi
|
|
||||||
cp_umask=$mode$u_plus_rw;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
for src
|
|
||||||
do
|
|
||||||
# Protect names problematic for 'test' and other utilities.
|
|
||||||
case $src in
|
|
||||||
-* | [=\(\)!]) src=./$src;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if test -n "$dir_arg"; then
|
|
||||||
dst=$src
|
|
||||||
dstdir=$dst
|
|
||||||
test -d "$dstdir"
|
|
||||||
dstdir_status=$?
|
|
||||||
else
|
|
||||||
|
|
||||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
|
||||||
# might cause directories to be created, which would be especially bad
|
|
||||||
# if $src (and thus $dsttmp) contains '*'.
|
|
||||||
if test ! -f "$src" && test ! -d "$src"; then
|
|
||||||
echo "$0: $src does not exist." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -z "$dst_arg"; then
|
|
||||||
echo "$0: no destination specified." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
dst=$dst_arg
|
|
||||||
|
|
||||||
# If destination is a directory, append the input filename; won't work
|
|
||||||
# if double slashes aren't ignored.
|
|
||||||
if test -d "$dst"; then
|
|
||||||
if test -n "$no_target_directory"; then
|
|
||||||
echo "$0: $dst_arg: Is a directory" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
dstdir=$dst
|
|
||||||
dst=$dstdir/`basename "$src"`
|
|
||||||
dstdir_status=0
|
|
||||||
else
|
|
||||||
# Prefer dirname, but fall back on a substitute if dirname fails.
|
|
||||||
dstdir=`
|
|
||||||
(dirname "$dst") 2>/dev/null ||
|
|
||||||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
|
|
||||||
X"$dst" : 'X\(//\)[^/]' \| \
|
|
||||||
X"$dst" : 'X\(//\)$' \| \
|
|
||||||
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
|
|
||||||
echo X"$dst" |
|
|
||||||
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
|
|
||||||
s//\1/
|
|
||||||
q
|
|
||||||
}
|
|
||||||
/^X\(\/\/\)[^/].*/{
|
|
||||||
s//\1/
|
|
||||||
q
|
|
||||||
}
|
|
||||||
/^X\(\/\/\)$/{
|
|
||||||
s//\1/
|
|
||||||
q
|
|
||||||
}
|
|
||||||
/^X\(\/\).*/{
|
|
||||||
s//\1/
|
|
||||||
q
|
|
||||||
}
|
|
||||||
s/.*/./; q'
|
|
||||||
`
|
|
||||||
|
|
||||||
test -d "$dstdir"
|
|
||||||
dstdir_status=$?
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
obsolete_mkdir_used=false
|
|
||||||
|
|
||||||
if test $dstdir_status != 0; then
|
|
||||||
case $posix_mkdir in
|
|
||||||
'')
|
|
||||||
# Create intermediate dirs using mode 755 as modified by the umask.
|
|
||||||
# This is like FreeBSD 'install' as of 1997-10-28.
|
|
||||||
umask=`umask`
|
|
||||||
case $stripcmd.$umask in
|
|
||||||
# Optimize common cases.
|
|
||||||
*[2367][2367]) mkdir_umask=$umask;;
|
|
||||||
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
|
|
||||||
|
|
||||||
*[0-7])
|
|
||||||
mkdir_umask=`expr $umask + 22 \
|
|
||||||
- $umask % 100 % 40 + $umask % 20 \
|
|
||||||
- $umask % 10 % 4 + $umask % 2
|
|
||||||
`;;
|
|
||||||
*) mkdir_umask=$umask,go-w;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# With -d, create the new directory with the user-specified mode.
|
|
||||||
# Otherwise, rely on $mkdir_umask.
|
|
||||||
if test -n "$dir_arg"; then
|
|
||||||
mkdir_mode=-m$mode
|
|
||||||
else
|
|
||||||
mkdir_mode=
|
|
||||||
fi
|
|
||||||
|
|
||||||
posix_mkdir=false
|
|
||||||
case $umask in
|
|
||||||
*[123567][0-7][0-7])
|
|
||||||
# POSIX mkdir -p sets u+wx bits regardless of umask, which
|
|
||||||
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
|
||||||
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
|
|
||||||
|
|
||||||
if (umask $mkdir_umask &&
|
|
||||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
if test -z "$dir_arg" || {
|
|
||||||
# Check for POSIX incompatibilities with -m.
|
|
||||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
|
||||||
# other-writable bit of parent directory when it shouldn't.
|
|
||||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
|
||||||
ls_ld_tmpdir=`ls -ld "$tmpdir"`
|
|
||||||
case $ls_ld_tmpdir in
|
|
||||||
d????-?r-*) different_mode=700;;
|
|
||||||
d????-?--*) different_mode=755;;
|
|
||||||
*) false;;
|
|
||||||
esac &&
|
|
||||||
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
|
|
||||||
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
|
|
||||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
then posix_mkdir=:
|
|
||||||
fi
|
|
||||||
rmdir "$tmpdir/d" "$tmpdir"
|
|
||||||
else
|
|
||||||
# Remove any dirs left behind by ancient mkdir implementations.
|
|
||||||
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
|
|
||||||
fi
|
|
||||||
trap '' 0;;
|
|
||||||
esac;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if
|
|
||||||
$posix_mkdir && (
|
|
||||||
umask $mkdir_umask &&
|
|
||||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
|
||||||
)
|
|
||||||
then :
|
|
||||||
else
|
|
||||||
|
|
||||||
# The umask is ridiculous, or mkdir does not conform to POSIX,
|
|
||||||
# or it failed possibly due to a race condition. Create the
|
|
||||||
# directory the slow way, step by step, checking for races as we go.
|
|
||||||
|
|
||||||
case $dstdir in
|
|
||||||
/*) prefix='/';;
|
|
||||||
[-=\(\)!]*) prefix='./';;
|
|
||||||
*) prefix='';;
|
|
||||||
esac
|
|
||||||
|
|
||||||
eval "$initialize_posix_glob"
|
|
||||||
|
|
||||||
oIFS=$IFS
|
|
||||||
IFS=/
|
|
||||||
$posix_glob set -f
|
|
||||||
set fnord $dstdir
|
|
||||||
shift
|
|
||||||
$posix_glob set +f
|
|
||||||
IFS=$oIFS
|
|
||||||
|
|
||||||
prefixes=
|
|
||||||
|
|
||||||
for d
|
|
||||||
do
|
|
||||||
test X"$d" = X && continue
|
|
||||||
|
|
||||||
prefix=$prefix$d
|
|
||||||
if test -d "$prefix"; then
|
|
||||||
prefixes=
|
|
||||||
else
|
|
||||||
if $posix_mkdir; then
|
|
||||||
(umask=$mkdir_umask &&
|
|
||||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
|
||||||
# Don't fail if two instances are running concurrently.
|
|
||||||
test -d "$prefix" || exit 1
|
|
||||||
else
|
|
||||||
case $prefix in
|
|
||||||
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
|
||||||
*) qprefix=$prefix;;
|
|
||||||
esac
|
|
||||||
prefixes="$prefixes '$qprefix'"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
prefix=$prefix/
|
|
||||||
done
|
|
||||||
|
|
||||||
if test -n "$prefixes"; then
|
|
||||||
# Don't fail if two instances are running concurrently.
|
|
||||||
(umask $mkdir_umask &&
|
|
||||||
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
|
||||||
test -d "$dstdir" || exit 1
|
|
||||||
obsolete_mkdir_used=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -n "$dir_arg"; then
|
|
||||||
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
|
||||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
|
||||||
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
|
||||||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
|
||||||
else
|
|
||||||
|
|
||||||
# Make a couple of temp file names in the proper directory.
|
|
||||||
dsttmp=$dstdir/_inst.$$_
|
|
||||||
rmtmp=$dstdir/_rm.$$_
|
|
||||||
|
|
||||||
# Trap to clean up those temp files at exit.
|
|
||||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
|
||||||
|
|
||||||
# Copy the file name to the temp name.
|
|
||||||
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
|
|
||||||
|
|
||||||
# and set any options; do chmod last to preserve setuid bits.
|
|
||||||
#
|
|
||||||
# If any of these fail, we abort the whole thing. If we want to
|
|
||||||
# ignore errors from any of these, just make sure not to ignore
|
|
||||||
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
|
||||||
#
|
|
||||||
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
|
||||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
|
||||||
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
|
||||||
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
|
||||||
|
|
||||||
# If -C, don't bother to copy if it wouldn't change the file.
|
|
||||||
if $copy_on_change &&
|
|
||||||
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
|
||||||
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
|
||||||
|
|
||||||
eval "$initialize_posix_glob" &&
|
|
||||||
$posix_glob set -f &&
|
|
||||||
set X $old && old=:$2:$4:$5:$6 &&
|
|
||||||
set X $new && new=:$2:$4:$5:$6 &&
|
|
||||||
$posix_glob set +f &&
|
|
||||||
|
|
||||||
test "$old" = "$new" &&
|
|
||||||
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
rm -f "$dsttmp"
|
|
||||||
else
|
|
||||||
# Rename the file to the real destination.
|
|
||||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
|
||||||
|
|
||||||
# The rename failed, perhaps because mv can't rename something else
|
|
||||||
# to itself, or perhaps because mv is so ancient that it does not
|
|
||||||
# support -f.
|
|
||||||
{
|
|
||||||
# Now remove or move aside any old file at destination location.
|
|
||||||
# We try this two ways since rm can't unlink itself on some
|
|
||||||
# systems and the destination file might be busy for other
|
|
||||||
# reasons. In this case, the final cleanup might fail but the new
|
|
||||||
# file should still install successfully.
|
|
||||||
{
|
|
||||||
test ! -f "$dst" ||
|
|
||||||
$doit $rmcmd -f "$dst" 2>/dev/null ||
|
|
||||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
|
||||||
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
|
|
||||||
} ||
|
|
||||||
{ echo "$0: cannot unlink or rename $dst" >&2
|
|
||||||
(exit 1); exit 1
|
|
||||||
}
|
|
||||||
} &&
|
|
||||||
|
|
||||||
# Now rename the file to the real destination.
|
|
||||||
$doit $mvcmd "$dsttmp" "$dst"
|
|
||||||
}
|
|
||||||
fi || exit 1
|
|
||||||
|
|
||||||
trap '' 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Local variables:
|
|
||||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
|
||||||
# time-stamp-start: "scriptversion="
|
|
||||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
|
||||||
# time-stamp-time-zone: "UTC"
|
|
||||||
# time-stamp-end: "; # UTC"
|
|
||||||
# End:
|
|
||||||
+233
-221
@@ -1,37 +1,34 @@
|
|||||||
AC_INIT(nix, m4_esyscmd([bash -c "echo -n $(cat ./.version)$VERSION_SUFFIX"]))
|
AC_INIT(nix, m4_esyscmd([echo -n $(cat ./version)$VERSION_SUFFIX]))
|
||||||
AC_CONFIG_MACRO_DIRS([m4])
|
AC_CONFIG_SRCDIR(README)
|
||||||
AC_CONFIG_SRCDIR(README.md)
|
|
||||||
AC_CONFIG_AUX_DIR(config)
|
AC_CONFIG_AUX_DIR(config)
|
||||||
|
AM_INIT_AUTOMAKE([dist-bzip2 foreign])
|
||||||
|
|
||||||
|
AC_DEFINE_UNQUOTED(NIX_VERSION, ["$VERSION"], [Nix version.])
|
||||||
|
|
||||||
|
AC_CANONICAL_HOST
|
||||||
|
|
||||||
AC_PROG_SED
|
|
||||||
|
|
||||||
# Construct a Nix system name (like "i686-linux").
|
# Construct a Nix system name (like "i686-linux").
|
||||||
AC_CANONICAL_HOST
|
|
||||||
AC_MSG_CHECKING([for the canonical Nix system name])
|
AC_MSG_CHECKING([for the canonical Nix system name])
|
||||||
|
cpu_name=$(uname -p | tr 'A-Z ' 'a-z_')
|
||||||
|
machine_name=$(uname -m | tr 'A-Z ' 'a-z_')
|
||||||
|
|
||||||
AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
|
case $machine_name in
|
||||||
[Platform identifier (e.g., `i686-linux').]),
|
i*86)
|
||||||
[system=$withval],
|
machine_name=i686
|
||||||
[case "$host_cpu" in
|
;;
|
||||||
i*86)
|
x86_64)
|
||||||
machine_name="i686";;
|
machine_name=x86_64
|
||||||
amd64)
|
;;
|
||||||
machine_name="x86_64";;
|
ppc)
|
||||||
armv6|armv7)
|
machine_name=powerpc
|
||||||
machine_name="${host_cpu}l";;
|
;;
|
||||||
*)
|
*)
|
||||||
machine_name="$host_cpu";;
|
if test "$cpu_name" != "unknown"; then
|
||||||
esac
|
machine_name=$cpu_name
|
||||||
|
fi
|
||||||
case "$host_os" in
|
;;
|
||||||
linux-gnu*|linux-musl*)
|
esac
|
||||||
# For backward compatibility, strip the `-gnu' part.
|
|
||||||
system="$machine_name-linux";;
|
|
||||||
*)
|
|
||||||
# Strip the version number from names such as `gnu0.3',
|
|
||||||
# `darwin10.2.0', etc.
|
|
||||||
system="$machine_name-`echo $host_os | "$SED" -e's/@<:@0-9.@:>@*$//g'`";;
|
|
||||||
esac])
|
|
||||||
|
|
||||||
sys_name=$(uname -s | tr 'A-Z ' 'a-z_')
|
sys_name=$(uname -s | tr 'A-Z ' 'a-z_')
|
||||||
|
|
||||||
@@ -41,33 +38,58 @@ case $sys_name in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
|
||||||
|
[Platform identifier (e.g., `i686-linux').]),
|
||||||
|
system=$withval, system="${machine_name}-${sys_name}")
|
||||||
AC_MSG_RESULT($system)
|
AC_MSG_RESULT($system)
|
||||||
AC_SUBST(system)
|
AC_SUBST(system)
|
||||||
AC_DEFINE_UNQUOTED(SYSTEM, ["$system"], [platform identifier ('cpu-os')])
|
AC_DEFINE_UNQUOTED(SYSTEM, ["$system"], [platform identifier (`cpu-os')])
|
||||||
|
|
||||||
|
|
||||||
# State should be stored in /nix/var, unless the user overrides it explicitly.
|
# State should be stored in /nix/var, unless the user overrides it explicitly.
|
||||||
test "$localstatedir" = '${prefix}/var' && localstatedir=/nix/var
|
test "$localstatedir" = '${prefix}/var' && localstatedir=/nix/var
|
||||||
|
|
||||||
|
|
||||||
CFLAGS=
|
# Whether to produce a statically linked binary. On Cygwin, this is
|
||||||
CXXFLAGS=
|
# the default: dynamically linking against the ATerm DLL does work,
|
||||||
|
# except that it requires the ATerm "lib" directory to be in $PATH, as
|
||||||
|
# Windows doesn't have anything like an RPATH embedded in executable.
|
||||||
|
# Since this is kind of annoying, we use static libraries for now.
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(static-nix, AC_HELP_STRING([--enable-static-nix],
|
||||||
|
[produce statically linked binaries]),
|
||||||
|
static_nix=$enableval, static_nix=no)
|
||||||
|
|
||||||
|
if test "$sys_name" = cygwin; then
|
||||||
|
static_nix=yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$static_nix" = yes; then
|
||||||
|
AC_DISABLE_SHARED
|
||||||
|
AC_ENABLE_STATIC
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Windows-specific stuff.
|
||||||
|
if test "$sys_name" = "cygwin"; then
|
||||||
|
# We cannot delete open files.
|
||||||
|
AC_DEFINE(CANNOT_DELETE_OPEN_FILES, 1, [Whether it is impossible to delete open files.])
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_PROG_CXX
|
AC_PROG_CXX
|
||||||
AC_PROG_CPP
|
|
||||||
|
|
||||||
AC_CHECK_TOOL([AR], [ar])
|
|
||||||
|
# We are going to use libtool.
|
||||||
|
AC_DISABLE_STATIC
|
||||||
|
AC_ENABLE_SHARED
|
||||||
|
AC_PROG_LIBTOOL
|
||||||
|
|
||||||
|
|
||||||
# Use 64-bit file system calls so that we can support files > 2 GiB.
|
# Use 64-bit file system calls so that we can support files > 2 GiB.
|
||||||
AC_SYS_LARGEFILE
|
CFLAGS="-D_FILE_OFFSET_BITS=64 $CFLAGS"
|
||||||
|
CXXFLAGS="-D_FILE_OFFSET_BITS=64 $CXXFLAGS"
|
||||||
|
|
||||||
# Solaris-specific stuff.
|
|
||||||
AC_STRUCT_DIRENT_D_TYPE
|
|
||||||
if test "$sys_name" = sunos; then
|
|
||||||
# Solaris requires -lsocket -lnsl for network functions
|
|
||||||
LIBS="-lsocket -lnsl $LIBS"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Check for pubsetbuf.
|
# Check for pubsetbuf.
|
||||||
@@ -82,32 +104,29 @@ static char buf[1024];]],
|
|||||||
AC_LANG_POP(C++)
|
AC_LANG_POP(C++)
|
||||||
|
|
||||||
|
|
||||||
AC_CHECK_FUNCS([statvfs pipe2])
|
# Check for chroot support (requires chroot() and bind mounts).
|
||||||
|
AC_CHECK_FUNCS([chroot])
|
||||||
|
AC_CHECK_FUNCS([unshare])
|
||||||
# Check for lutimes, optionally used for changing the mtime of
|
AC_CHECK_HEADERS([sched.h], [], [], [])
|
||||||
# symlinks.
|
AC_CHECK_HEADERS([sys/param.h], [], [], [])
|
||||||
AC_CHECK_FUNCS([lutimes])
|
AC_CHECK_HEADERS([sys/mount.h], [], [],
|
||||||
|
[#ifdef HAVE_SYS_PARAM_H
|
||||||
|
# include <sys/param.h>
|
||||||
# Check whether the store optimiser can optimise symlinks.
|
# endif
|
||||||
AC_MSG_CHECKING([whether it is possible to create a link to a symlink])
|
])
|
||||||
ln -s bla tmp_link
|
|
||||||
if ln tmp_link tmp_link2 2> /dev/null; then
|
|
||||||
AC_MSG_RESULT(yes)
|
|
||||||
AC_DEFINE(CAN_LINK_SYMLINK, 1, [Whether link() works on symlinks.])
|
|
||||||
else
|
|
||||||
AC_MSG_RESULT(no)
|
|
||||||
fi
|
|
||||||
rm -f tmp_link tmp_link2
|
|
||||||
|
|
||||||
|
|
||||||
# Check for <locale>.
|
# Check for <locale>.
|
||||||
AC_LANG_PUSH(C++)
|
AC_LANG_PUSH(C++)
|
||||||
AC_CHECK_HEADERS([locale])
|
AC_CHECK_HEADERS([locale], [], [], [])
|
||||||
AC_LANG_POP(C++)
|
AC_LANG_POP(C++)
|
||||||
|
|
||||||
|
|
||||||
|
# Check whether we have the personality() syscall, which allows us to
|
||||||
|
# do i686-linux builds on x86_64-linux machines.
|
||||||
|
AC_CHECK_HEADERS([sys/personality.h])
|
||||||
|
|
||||||
|
|
||||||
AC_DEFUN([NEED_PROG],
|
AC_DEFUN([NEED_PROG],
|
||||||
[
|
[
|
||||||
AC_PATH_PROG($1, $2)
|
AC_PATH_PROG($1, $2)
|
||||||
@@ -116,162 +135,145 @@ if test -z "$$1"; then
|
|||||||
fi
|
fi
|
||||||
])
|
])
|
||||||
|
|
||||||
|
NEED_PROG(curl, curl)
|
||||||
NEED_PROG(bash, bash)
|
NEED_PROG(bash, bash)
|
||||||
|
NEED_PROG(patch, patch)
|
||||||
AC_PATH_PROG(xmllint, xmllint, false)
|
AC_PATH_PROG(xmllint, xmllint, false)
|
||||||
AC_PATH_PROG(xsltproc, xsltproc, false)
|
AC_PATH_PROG(xsltproc, xsltproc, false)
|
||||||
|
AC_PATH_PROG(jing, jing, false) # needed because xmllint --relaxng seems broken
|
||||||
|
AC_PATH_PROG(w3m, w3m, false)
|
||||||
AC_PATH_PROG(flex, flex, false)
|
AC_PATH_PROG(flex, flex, false)
|
||||||
AC_PATH_PROG(bison, bison, false)
|
AC_PATH_PROG(bison, bison, false)
|
||||||
|
NEED_PROG(perl, perl)
|
||||||
|
NEED_PROG(tar, tar)
|
||||||
AC_PATH_PROG(dot, dot)
|
AC_PATH_PROG(dot, dot)
|
||||||
AC_PATH_PROG(lsof, lsof, lsof)
|
AC_PATH_PROG(dblatex, dblatex)
|
||||||
NEED_PROG(jq, jq)
|
AC_PATH_PROG(gzip, gzip)
|
||||||
|
|
||||||
|
AC_PATH_PROG(openssl_prog, openssl, openssl) # if not found, call openssl in $PATH
|
||||||
|
AC_SUBST(openssl_prog)
|
||||||
|
AC_DEFINE_UNQUOTED(OPENSSL_PATH, ["$openssl_prog"], [Path of the OpenSSL binary])
|
||||||
|
|
||||||
AC_SUBST(coreutils, [$(dirname $(type -p cat))])
|
# Test that Perl has the open/fork feature (Perl 5.8.0 and beyond).
|
||||||
|
AC_MSG_CHECKING([whether Perl is recent enough])
|
||||||
|
if ! $perl -e 'open(FOO, "-|", "true"); while (<FOO>) { print; }; close FOO or die;'; then
|
||||||
|
AC_MSG_RESULT(no)
|
||||||
|
AC_MSG_ERROR([Your Perl version is too old. Nix requires Perl 5.8.0 or newer.])
|
||||||
|
fi
|
||||||
|
AC_MSG_RESULT(yes)
|
||||||
|
|
||||||
|
NEED_PROG(cat, cat)
|
||||||
|
NEED_PROG(tr, tr)
|
||||||
|
AC_ARG_WITH(coreutils-bin, AC_HELP_STRING([--with-coreutils-bin=PATH],
|
||||||
|
[path of cat, mkdir, etc.]),
|
||||||
|
coreutils=$withval, coreutils=$(dirname $cat))
|
||||||
|
AC_SUBST(coreutils)
|
||||||
|
|
||||||
|
AC_ARG_WITH(docbook-rng, AC_HELP_STRING([--with-docbook-rng=PATH],
|
||||||
|
[path of the DocBook RelaxNG schema]),
|
||||||
|
docbookrng=$withval, docbookrng=/docbook-rng-missing)
|
||||||
|
AC_SUBST(docbookrng)
|
||||||
|
|
||||||
|
AC_ARG_WITH(docbook-xsl, AC_HELP_STRING([--with-docbook-xsl=PATH],
|
||||||
|
[path of the DocBook XSL stylesheets]),
|
||||||
|
docbookxsl=$withval, docbookxsl=/docbook-xsl-missing)
|
||||||
|
AC_SUBST(docbookxsl)
|
||||||
|
|
||||||
|
AC_ARG_WITH(xml-flags, AC_HELP_STRING([--with-xml-flags=FLAGS],
|
||||||
|
[extra flags to be passed to xmllint and xsltproc]),
|
||||||
|
xmlflags=$withval, xmlflags=)
|
||||||
|
AC_SUBST(xmlflags)
|
||||||
|
|
||||||
AC_ARG_WITH(store-dir, AC_HELP_STRING([--with-store-dir=PATH],
|
AC_ARG_WITH(store-dir, AC_HELP_STRING([--with-store-dir=PATH],
|
||||||
[path of the Nix store (defaults to /nix/store)]),
|
[path of the Nix store]),
|
||||||
storedir=$withval, storedir='/nix/store')
|
storedir=$withval, storedir='/nix/store')
|
||||||
AC_SUBST(storedir)
|
AC_SUBST(storedir)
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(old-db-compat, AC_HELP_STRING([--disable-old-db-compat],
|
||||||
|
[disable support for converting from old Berkeley DB-based Nix stores]),
|
||||||
|
old_db_compat=$enableval, old_db_compat=yes)
|
||||||
|
AM_CONDITIONAL(OLD_DB_COMPAT, test "$old_db_compat" = "yes")
|
||||||
|
|
||||||
# Look for boost, a required dependency.
|
AC_ARG_WITH(bdb, AC_HELP_STRING([--with-bdb=PATH],
|
||||||
# Note that AX_BOOST_BASE only exports *CPP* BOOST_CPPFLAGS, no CXX flags,
|
[prefix of Berkeley DB (for Nix <= 0.11 compatibility)]),
|
||||||
# and CPPFLAGS are not passed to the C++ compiler automatically.
|
bdb=$withval, bdb=)
|
||||||
# Thus we append the returned CPPFLAGS to the CXXFLAGS here.
|
AM_CONDITIONAL(HAVE_BDB, test -n "$bdb")
|
||||||
AX_BOOST_BASE([1.66], [CXXFLAGS="$BOOST_CPPFLAGS $CXXFLAGS"], [AC_MSG_ERROR([Nix requires boost.])])
|
if test -z "$bdb"; then
|
||||||
# For unknown reasons, setting this directly in the ACTION-IF-FOUND above
|
bdb_lib='-L${top_builddir}/externals/inst-bdb/lib -ldb_cxx'
|
||||||
# ends up with LDFLAGS being empty, so we set it afterwards.
|
bdb_include='-I${top_builddir}/externals/inst-bdb/include'
|
||||||
LDFLAGS="$BOOST_LDFLAGS $LDFLAGS"
|
|
||||||
|
|
||||||
# On some platforms, new-style atomics need a helper library
|
|
||||||
AC_MSG_CHECKING(whether -latomic is needed)
|
|
||||||
AC_LINK_IFELSE([AC_LANG_SOURCE([[
|
|
||||||
#include <stdint.h>
|
|
||||||
uint64_t v;
|
|
||||||
int main() {
|
|
||||||
return (int)__atomic_load_n(&v, __ATOMIC_ACQUIRE);
|
|
||||||
}]])], GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC=no, GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC=yes)
|
|
||||||
AC_MSG_RESULT($GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC)
|
|
||||||
if test "x$GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC" = xyes; then
|
|
||||||
LIBS="-latomic $LIBS"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG
|
|
||||||
|
|
||||||
AC_ARG_ENABLE(shared, AC_HELP_STRING([--enable-shared],
|
|
||||||
[Build shared libraries for Nix [default=yes]]),
|
|
||||||
shared=$enableval, shared=yes)
|
|
||||||
if test "$shared" = yes; then
|
|
||||||
AC_SUBST(BUILD_SHARED_LIBS, 1, [Whether to build shared libraries.])
|
|
||||||
else
|
else
|
||||||
AC_SUBST(BUILD_SHARED_LIBS, 0, [Whether to build shared libraries.])
|
bdb_lib="-L$bdb/lib -ldb_cxx"
|
||||||
PKG_CONFIG="$PKG_CONFIG --static"
|
bdb_include="-I$bdb/include"
|
||||||
fi
|
fi
|
||||||
|
if test "$old_db_compat" = "no"; then
|
||||||
# Look for OpenSSL, a required dependency. FIXME: this is only (maybe)
|
bdb_lib=
|
||||||
# used by S3BinaryCacheStore.
|
bdb_include=
|
||||||
PKG_CHECK_MODULES([OPENSSL], [libcrypto], [CXXFLAGS="$OPENSSL_CFLAGS $CXXFLAGS"])
|
|
||||||
|
|
||||||
|
|
||||||
# Look for libbz2, a required dependency.
|
|
||||||
AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [true],
|
|
||||||
[AC_MSG_ERROR([Nix requires libbz2, which is part of bzip2. See https://web.archive.org/web/20180624184756/http://www.bzip.org/.])])
|
|
||||||
AC_CHECK_HEADERS([bzlib.h], [true],
|
|
||||||
[AC_MSG_ERROR([Nix requires libbz2, which is part of bzip2. See https://web.archive.org/web/20180624184756/http://www.bzip.org/.])])
|
|
||||||
# Checks for libarchive
|
|
||||||
PKG_CHECK_MODULES([LIBARCHIVE], [libarchive >= 3.1.2], [CXXFLAGS="$LIBARCHIVE_CFLAGS $CXXFLAGS"])
|
|
||||||
|
|
||||||
# Look for SQLite, a required dependency.
|
|
||||||
PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19], [CXXFLAGS="$SQLITE3_CFLAGS $CXXFLAGS"])
|
|
||||||
|
|
||||||
# Look for libcurl, a required dependency.
|
|
||||||
PKG_CHECK_MODULES([LIBCURL], [libcurl], [CXXFLAGS="$LIBCURL_CFLAGS $CXXFLAGS"])
|
|
||||||
|
|
||||||
# Look for editline, a required dependency.
|
|
||||||
# The the libeditline.pc file was added only in libeditline >= 1.15.2,
|
|
||||||
# see https://github.com/troglobit/editline/commit/0a8f2ef4203c3a4a4726b9dd1336869cd0da8607,
|
|
||||||
# but e.g. Ubuntu 16.04 has an older version, so we fall back to searching for
|
|
||||||
# editline.h when the pkg-config approach fails.
|
|
||||||
PKG_CHECK_MODULES([EDITLINE], [libeditline], [CXXFLAGS="$EDITLINE_CFLAGS $CXXFLAGS"], [
|
|
||||||
AC_CHECK_HEADERS([editline.h], [true],
|
|
||||||
[AC_MSG_ERROR([Nix requires libeditline; it was found neither via pkg-config nor its normal header.])])
|
|
||||||
AC_SEARCH_LIBS([readline read_history], [editline], [],
|
|
||||||
[AC_MSG_ERROR([Nix requires libeditline; it was not found via pkg-config, but via its header, but required functions do not work. Maybe it is too old? >= 1.14 is required.])])
|
|
||||||
])
|
|
||||||
|
|
||||||
# Look for libsodium, an optional dependency.
|
|
||||||
PKG_CHECK_MODULES([SODIUM], [libsodium],
|
|
||||||
[AC_DEFINE([HAVE_SODIUM], [1], [Whether to use libsodium for cryptography.])
|
|
||||||
CXXFLAGS="$SODIUM_CFLAGS $CXXFLAGS"
|
|
||||||
have_sodium=1], [have_sodium=])
|
|
||||||
AC_SUBST(HAVE_SODIUM, [$have_sodium])
|
|
||||||
|
|
||||||
# Look for liblzma, a required dependency.
|
|
||||||
PKG_CHECK_MODULES([LIBLZMA], [liblzma], [CXXFLAGS="$LIBLZMA_CFLAGS $CXXFLAGS"])
|
|
||||||
AC_CHECK_LIB([lzma], [lzma_stream_encoder_mt],
|
|
||||||
[AC_DEFINE([HAVE_LZMA_MT], [1], [xz multithreaded compression support])])
|
|
||||||
|
|
||||||
# Look for zlib, a required dependency.
|
|
||||||
PKG_CHECK_MODULES([ZLIB], [zlib], [CXXFLAGS="$ZLIB_CFLAGS $CXXFLAGS"])
|
|
||||||
AC_CHECK_HEADER([zlib.h],[:],[AC_MSG_ERROR([could not find the zlib.h header])])
|
|
||||||
LDFLAGS="-lz $LDFLAGS"
|
|
||||||
|
|
||||||
# Look for libbrotli{enc,dec}.
|
|
||||||
PKG_CHECK_MODULES([LIBBROTLI], [libbrotlienc libbrotlidec], [CXXFLAGS="$LIBBROTLI_CFLAGS $CXXFLAGS"])
|
|
||||||
|
|
||||||
|
|
||||||
# Look for libseccomp, required for Linux sandboxing.
|
|
||||||
if test "$sys_name" = linux; then
|
|
||||||
AC_ARG_ENABLE([seccomp-sandboxing],
|
|
||||||
AC_HELP_STRING([--disable-seccomp-sandboxing],
|
|
||||||
[Don't build support for seccomp sandboxing (only recommended if your arch doesn't support libseccomp yet!)]
|
|
||||||
))
|
|
||||||
if test "x$enable_seccomp_sandboxing" != "xno"; then
|
|
||||||
PKG_CHECK_MODULES([LIBSECCOMP], [libseccomp],
|
|
||||||
[CXXFLAGS="$LIBSECCOMP_CFLAGS $CXXFLAGS"])
|
|
||||||
have_seccomp=1
|
|
||||||
AC_DEFINE([HAVE_SECCOMP], [1], [Whether seccomp is available and should be used for sandboxing.])
|
|
||||||
else
|
|
||||||
have_seccomp=
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
have_seccomp=
|
AC_DEFINE(OLD_DB_COMPAT, 1, [Whether to support converting from old Berkeley DB-based Nix stores.])
|
||||||
fi
|
fi
|
||||||
AC_SUBST(HAVE_SECCOMP, [$have_seccomp])
|
AC_SUBST(bdb_lib)
|
||||||
|
AC_SUBST(bdb_include)
|
||||||
|
|
||||||
|
AC_ARG_WITH(aterm, AC_HELP_STRING([--with-aterm=PATH],
|
||||||
|
[prefix of CWI ATerm library]),
|
||||||
|
aterm=$withval, aterm=)
|
||||||
|
AM_CONDITIONAL(HAVE_ATERM, test -n "$aterm")
|
||||||
|
if test -z "$aterm"; then
|
||||||
|
aterm_lib='-L${top_builddir}/externals/inst-aterm/lib -lATerm'
|
||||||
|
aterm_include='-I${top_builddir}/externals/inst-aterm/include'
|
||||||
|
aterm_bin='${top_builddir}/externals/inst-aterm/bin'
|
||||||
|
else
|
||||||
|
aterm_lib="-L$aterm/lib -lATerm"
|
||||||
|
aterm_include="-I$aterm/include"
|
||||||
|
aterm_bin="$aterm/bin"
|
||||||
|
fi
|
||||||
|
AC_SUBST(aterm_lib)
|
||||||
|
AC_SUBST(aterm_include)
|
||||||
|
AC_SUBST(aterm_bin)
|
||||||
|
|
||||||
# Look for aws-cpp-sdk-s3.
|
AC_ARG_WITH(openssl, AC_HELP_STRING([--with-openssl=PATH],
|
||||||
AC_LANG_PUSH(C++)
|
[prefix of the OpenSSL library]),
|
||||||
AC_CHECK_HEADERS([aws/s3/S3Client.h],
|
openssl=$withval, openssl=)
|
||||||
[AC_DEFINE([ENABLE_S3], [1], [Whether to enable S3 support via aws-sdk-cpp.])
|
AM_CONDITIONAL(HAVE_OPENSSL, test -n "$openssl")
|
||||||
enable_s3=1], [enable_s3=])
|
if test -n "$openssl"; then
|
||||||
AC_SUBST(ENABLE_S3, [$enable_s3])
|
LDFLAGS="-L$openssl/lib -lcrypto $LDFLAGS"
|
||||||
AC_LANG_POP(C++)
|
CFLAGS="-I$openssl/include $CFLAGS"
|
||||||
|
CXXFLAGS="-I$openssl/include $CXXFLAGS"
|
||||||
if test -n "$enable_s3"; then
|
AC_DEFINE(HAVE_OPENSSL, 1, [Whether to use OpenSSL.])
|
||||||
declare -a aws_version_tokens=($(printf '#include <aws/core/VersionConfig.h>\nAWS_SDK_VERSION_STRING' | $CPP $CPPFLAGS - | grep -v '^#.*' | sed 's/"//g' | tr '.' ' '))
|
|
||||||
AC_DEFINE_UNQUOTED([AWS_VERSION_MAJOR], ${aws_version_tokens@<:@0@:>@}, [Major version of aws-sdk-cpp.])
|
|
||||||
AC_DEFINE_UNQUOTED([AWS_VERSION_MINOR], ${aws_version_tokens@<:@1@:>@}, [Minor version of aws-sdk-cpp.])
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_WITH(bzip2, AC_HELP_STRING([--with-bzip2=PATH],
|
||||||
# Whether to use the Boehm garbage collector.
|
[prefix of bzip2]),
|
||||||
AC_ARG_ENABLE(gc, AC_HELP_STRING([--enable-gc],
|
bzip2=$withval, bzip2=)
|
||||||
[enable garbage collection in the Nix expression evaluator (requires Boehm GC) [default=yes]]),
|
AM_CONDITIONAL(HAVE_BZIP2, test -n "$bzip2")
|
||||||
gc=$enableval, gc=yes)
|
if test -z "$bzip2"; then
|
||||||
if test "$gc" = yes; then
|
# Headers and libraries will be used from the temporary installation
|
||||||
PKG_CHECK_MODULES([BDW_GC], [bdw-gc])
|
# in externals/inst-bzip2.
|
||||||
CXXFLAGS="$BDW_GC_CFLAGS $CXXFLAGS"
|
bzip2_lib='-L${top_builddir}/externals/inst-bzip2/lib -lbz2'
|
||||||
AC_DEFINE(HAVE_BOEHMGC, 1, [Whether to use the Boehm garbage collector.])
|
bzip2_include='-I${top_builddir}/externals/inst-bzip2/include'
|
||||||
fi
|
# The binary will be copied to $libexecdir.
|
||||||
|
bzip2_bin='${libexecdir}/nix'
|
||||||
|
# But for testing, we have to use the temporary copy :-(
|
||||||
|
bzip2_bin_test='${top_builddir}/externals/inst-bzip2/bin'
|
||||||
|
else
|
||||||
|
bzip2_lib="-L$bzip2/lib -lbz2"
|
||||||
|
bzip2_include="-I$bzip2/include"
|
||||||
|
bzip2_bin="$bzip2/bin"
|
||||||
|
bzip2_bin_test="$bzip2/bin"
|
||||||
|
fi
|
||||||
|
AC_SUBST(bzip2_lib)
|
||||||
|
AC_SUBST(bzip2_include)
|
||||||
|
AC_SUBST(bzip2_bin)
|
||||||
|
AC_SUBST(bzip2_bin_test)
|
||||||
|
|
||||||
|
|
||||||
# documentation generation switch
|
AC_CHECK_LIB(pthread, pthread_mutex_init)
|
||||||
AC_ARG_ENABLE(doc-gen, AC_HELP_STRING([--disable-doc-gen],
|
|
||||||
[disable documentation generation]),
|
|
||||||
doc_generate=$enableval, doc_generate=yes)
|
AC_ARG_ENABLE(init-state, AC_HELP_STRING([--disable-init-state],
|
||||||
AC_SUBST(doc_generate)
|
[do not initialise DB etc. in `make install']),
|
||||||
|
init_state=$enableval, init_state=yes)
|
||||||
|
AM_CONDITIONAL(INIT_STATE, test "$init_state" = "yes")
|
||||||
|
|
||||||
|
|
||||||
# Setuid installations.
|
# Setuid installations.
|
||||||
@@ -279,43 +281,53 @@ AC_CHECK_FUNCS([setresuid setreuid lchown])
|
|||||||
|
|
||||||
|
|
||||||
# Nice to have, but not essential.
|
# Nice to have, but not essential.
|
||||||
AC_CHECK_FUNCS([strsignal posix_fallocate sysconf])
|
AC_CHECK_FUNCS([strsignal])
|
||||||
|
AC_CHECK_FUNCS([posix_fallocate])
|
||||||
|
|
||||||
|
|
||||||
# This is needed if bzip2 is a static library, and the Nix libraries
|
# This is needed if ATerm, Berkeley DB or bzip2 are static libraries,
|
||||||
# are dynamic.
|
# and the Nix libraries are dynamic.
|
||||||
if test "$(uname)" = "Darwin"; then
|
if test "$(uname)" = "Darwin"; then
|
||||||
LDFLAGS="-all_load $LDFLAGS"
|
LDFLAGS="-all_load $LDFLAGS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Do we have GNU tar?
|
if test "$static_nix" = yes; then
|
||||||
AC_MSG_CHECKING([if you have a recent GNU tar])
|
# `-all-static' has to be added at the end of configure, because
|
||||||
if $tar --version 2> /dev/null | grep -q GNU && tar cvf /dev/null --warning=no-timestamp ./config.log > /dev/null; then
|
# the C compiler doesn't know about -all-static (it's filtered out
|
||||||
AC_MSG_RESULT(yes)
|
# by libtool, but configure doesn't use libtool).
|
||||||
tarFlags="--warning=no-timestamp"
|
LDFLAGS="-all-static $LDFLAGS"
|
||||||
else
|
|
||||||
AC_MSG_RESULT(no)
|
|
||||||
fi
|
fi
|
||||||
AC_SUBST(tarFlags)
|
|
||||||
|
|
||||||
|
|
||||||
AC_ARG_WITH(sandbox-shell, AC_HELP_STRING([--with-sandbox-shell=PATH],
|
AM_CONFIG_HEADER([config.h])
|
||||||
[path of a statically-linked shell to use as /bin/sh in sandboxes]),
|
AC_CONFIG_FILES([Makefile
|
||||||
sandbox_shell=$withval)
|
externals/Makefile
|
||||||
AC_SUBST(sandbox_shell)
|
src/Makefile
|
||||||
|
src/bin2c/Makefile
|
||||||
# Expand all variables in config.status.
|
src/boost/Makefile
|
||||||
test "$prefix" = NONE && prefix=$ac_default_prefix
|
src/boost/format/Makefile
|
||||||
test "$exec_prefix" = NONE && exec_prefix='${prefix}'
|
src/libutil/Makefile
|
||||||
for name in $ac_subst_vars; do
|
src/libstore/Makefile
|
||||||
declare $name="$(eval echo "${!name}")"
|
src/libmain/Makefile
|
||||||
declare $name="$(eval echo "${!name}")"
|
src/nix-store/Makefile
|
||||||
declare $name="$(eval echo "${!name}")"
|
src/nix-hash/Makefile
|
||||||
done
|
src/libexpr/Makefile
|
||||||
|
src/nix-instantiate/Makefile
|
||||||
rm -f Makefile.config
|
src/nix-env/Makefile
|
||||||
|
src/nix-worker/Makefile
|
||||||
AC_CONFIG_HEADER([config.h])
|
src/nix-setuid-helper/Makefile
|
||||||
AC_CONFIG_FILES([])
|
src/nix-log2xml/Makefile
|
||||||
|
src/bsdiff-4.3/Makefile
|
||||||
|
scripts/Makefile
|
||||||
|
corepkgs/Makefile
|
||||||
|
corepkgs/nar/Makefile
|
||||||
|
corepkgs/buildenv/Makefile
|
||||||
|
corepkgs/channels/Makefile
|
||||||
|
doc/Makefile
|
||||||
|
doc/manual/Makefile
|
||||||
|
misc/Makefile
|
||||||
|
misc/emacs/Makefile
|
||||||
|
tests/Makefile
|
||||||
|
])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#!/usr/bin/env nix-shell
|
|
||||||
#!nix-shell -i python3 -p python3 --pure
|
|
||||||
|
|
||||||
# To be used with `--trace-function-calls` and `flamegraph.pl`.
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
#
|
|
||||||
# nix-instantiate --trace-function-calls '<nixpkgs>' -A hello 2> nix-function-calls.trace
|
|
||||||
# ./contrib/stack-collapse.py nix-function-calls.trace > nix-function-calls.folded
|
|
||||||
# nix-shell -p flamegraph --run "flamegraph.pl nix-function-calls.folded > nix-function-calls.svg"
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from pprint import pprint
|
|
||||||
import fileinput
|
|
||||||
|
|
||||||
stack = []
|
|
||||||
timestack = []
|
|
||||||
|
|
||||||
for line in fileinput.input():
|
|
||||||
components = line.strip().split(" ", 2)
|
|
||||||
if components[0] != "function-trace":
|
|
||||||
continue
|
|
||||||
|
|
||||||
direction = components[1]
|
|
||||||
components = components[2].rsplit(" ", 2)
|
|
||||||
|
|
||||||
loc = components[0]
|
|
||||||
_at = components[1]
|
|
||||||
time = int(components[2])
|
|
||||||
|
|
||||||
if direction == "entered":
|
|
||||||
stack.append(loc)
|
|
||||||
timestack.append(time)
|
|
||||||
elif direction == "exited":
|
|
||||||
dur = time - timestack.pop()
|
|
||||||
vst = ";".join(stack)
|
|
||||||
print(f"{vst} {dur}")
|
|
||||||
stack.pop()
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
SUBDIRS = nar buildenv channels
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
all-local: builder.pl
|
||||||
|
|
||||||
|
install-exec-local:
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/buildenv
|
||||||
|
$(INSTALL_DATA) $(srcdir)/default.nix $(DESTDIR)$(datadir)/nix/corepkgs/buildenv
|
||||||
|
$(INSTALL_PROGRAM) builder.pl $(DESTDIR)$(datadir)/nix/corepkgs/buildenv
|
||||||
|
|
||||||
|
include ../../substitute.mk
|
||||||
|
|
||||||
|
EXTRA_DIST = default.nix builder.pl.in
|
||||||
Executable
+163
@@ -0,0 +1,163 @@
|
|||||||
|
#! @perl@ -w
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Cwd;
|
||||||
|
use IO::Handle;
|
||||||
|
|
||||||
|
STDOUT->autoflush(1);
|
||||||
|
|
||||||
|
my $out = $ENV{"out"};
|
||||||
|
mkdir "$out", 0755 || die "error creating $out";
|
||||||
|
|
||||||
|
|
||||||
|
my $symlinks = 0;
|
||||||
|
|
||||||
|
my %priorities;
|
||||||
|
|
||||||
|
|
||||||
|
# For each activated package, create symlinks.
|
||||||
|
|
||||||
|
sub createLinks {
|
||||||
|
my $srcDir = shift;
|
||||||
|
my $dstDir = shift;
|
||||||
|
my $priority = shift;
|
||||||
|
|
||||||
|
my @srcFiles = glob("$srcDir/*");
|
||||||
|
|
||||||
|
foreach my $srcFile (@srcFiles) {
|
||||||
|
my $baseName = $srcFile;
|
||||||
|
$baseName =~ s/^.*\///g; # strip directory
|
||||||
|
my $dstFile = "$dstDir/$baseName";
|
||||||
|
|
||||||
|
# Urgh, hacky...
|
||||||
|
if ($srcFile =~ /\/propagated-build-inputs$/ ||
|
||||||
|
$srcFile =~ /\/nix-support$/ ||
|
||||||
|
$srcFile =~ /\/perllocal.pod$/ ||
|
||||||
|
$srcFile =~ /\/info\/dir$/ ||
|
||||||
|
$srcFile =~ /\/log$/)
|
||||||
|
{
|
||||||
|
# Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif (-d $srcFile) {
|
||||||
|
|
||||||
|
lstat $dstFile;
|
||||||
|
|
||||||
|
if (-d _) {
|
||||||
|
createLinks($srcFile, $dstFile, $priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif (-l _) {
|
||||||
|
my $target = readlink $dstFile or die;
|
||||||
|
if (!-d $target) {
|
||||||
|
die "collission between directory `$srcFile' and non-directory `$target'";
|
||||||
|
}
|
||||||
|
unlink $dstFile or die "error unlinking `$dstFile': $!";
|
||||||
|
mkdir $dstFile, 0755 ||
|
||||||
|
die "error creating directory `$dstFile': $!";
|
||||||
|
createLinks($target, $dstFile, $priorities{$dstFile});
|
||||||
|
createLinks($srcFile, $dstFile, $priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
symlink($srcFile, $dstFile) ||
|
||||||
|
die "error creating link `$dstFile': $!";
|
||||||
|
$priorities{$dstFile} = $priority;
|
||||||
|
$symlinks++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
if (-l $dstFile) {
|
||||||
|
my $target = readlink $dstFile;
|
||||||
|
my $prevPriority = $priorities{$dstFile};
|
||||||
|
die ( "Collission between `$srcFile' and `$target'. "
|
||||||
|
. "Suggested solution: use `nix-env --set-flag "
|
||||||
|
. "priority NUMBER PKGNAME' to change the priority of "
|
||||||
|
. "one of the conflicting packages.\n" )
|
||||||
|
if $prevPriority == $priority;
|
||||||
|
next if $prevPriority < $priority;
|
||||||
|
unlink $dstFile or die;
|
||||||
|
}
|
||||||
|
|
||||||
|
symlink($srcFile, $dstFile) ||
|
||||||
|
die "error creating link `$dstFile': $!";
|
||||||
|
$priorities{$dstFile} = $priority;
|
||||||
|
$symlinks++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my %done;
|
||||||
|
my %postponed;
|
||||||
|
|
||||||
|
sub addPkg;
|
||||||
|
sub addPkg {
|
||||||
|
my $pkgDir = shift;
|
||||||
|
my $priority = shift;
|
||||||
|
|
||||||
|
return if (defined $done{$pkgDir});
|
||||||
|
$done{$pkgDir} = 1;
|
||||||
|
|
||||||
|
# print "symlinking $pkgDir\n";
|
||||||
|
createLinks("$pkgDir", "$out", $priority);
|
||||||
|
|
||||||
|
my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
|
||||||
|
if (-e $propagatedFN) {
|
||||||
|
open PROP, "<$propagatedFN" or die;
|
||||||
|
my $propagated = <PROP>;
|
||||||
|
close PROP;
|
||||||
|
my @propagated = split ' ', $propagated;
|
||||||
|
foreach my $p (@propagated) {
|
||||||
|
$postponed{$p} = 1 unless defined $done{$p};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Convert the stuff we get from the environment back into a coherent
|
||||||
|
# data type.
|
||||||
|
my @paths = split ' ', $ENV{"paths"};
|
||||||
|
my @active = split ' ', $ENV{"active"};
|
||||||
|
my @priority = split ' ', $ENV{"priority"};
|
||||||
|
|
||||||
|
die if scalar @paths != scalar @active;
|
||||||
|
die if scalar @paths != scalar @priority;
|
||||||
|
|
||||||
|
my %pkgs;
|
||||||
|
|
||||||
|
for (my $n = 0; $n < scalar @paths; $n++) {
|
||||||
|
$pkgs{$paths[$n]} =
|
||||||
|
{ active => $active[$n]
|
||||||
|
, priority => $priority[$n] };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Symlink to the packages that have been installed explicitly by the
|
||||||
|
# user.
|
||||||
|
foreach my $pkg (sort (keys %pkgs)) {
|
||||||
|
#print $pkg, " ", $pkgs{$pkg}->{priority}, "\n";
|
||||||
|
addPkg($pkg, $pkgs{$pkg}->{priority}) if $pkgs{$pkg}->{active} ne "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Symlink to the packages that have been "propagated" by packages
|
||||||
|
# installed by the user (i.e., package X declares that it want Y
|
||||||
|
# installed as well). We do these later because they have a lower
|
||||||
|
# priority in case of collisions.
|
||||||
|
my $priorityCounter = 1000; # don't care about collisions
|
||||||
|
while (scalar(keys %postponed) > 0) {
|
||||||
|
my @pkgDirs = keys %postponed;
|
||||||
|
%postponed = ();
|
||||||
|
foreach my $pkgDir (sort @pkgDirs) {
|
||||||
|
addPkg($pkgDir, $priorityCounter++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print STDERR "created $symlinks symlinks in user environment\n";
|
||||||
|
|
||||||
|
|
||||||
|
symlink($ENV{"manifest"}, "$out/manifest") or die "cannot create manifest";
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{system, derivations, manifest}:
|
||||||
|
|
||||||
|
derivation {
|
||||||
|
name = "user-environment";
|
||||||
|
system = system;
|
||||||
|
builder = ./builder.pl;
|
||||||
|
|
||||||
|
manifest = manifest;
|
||||||
|
|
||||||
|
# !!! grmbl, need structured data for passing this in a clean way.
|
||||||
|
paths = derivations;
|
||||||
|
active = map (x: if x ? meta && x.meta ? active then x.meta.active else "true") derivations;
|
||||||
|
priority = map (x: if x ? meta && x.meta ? priority then x.meta.priority else "5") derivations;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
all-local: unpack.sh
|
||||||
|
|
||||||
|
install-exec-local:
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/channels
|
||||||
|
$(INSTALL_DATA) $(srcdir)/unpack.nix $(DESTDIR)$(datadir)/nix/corepkgs/channels
|
||||||
|
$(INSTALL_PROGRAM) unpack.sh $(DESTDIR)$(datadir)/nix/corepkgs/channels
|
||||||
|
|
||||||
|
include ../../substitute.mk
|
||||||
|
|
||||||
|
EXTRA_DIST = unpack.nix unpack.sh.in
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{system, inputs}:
|
||||||
|
|
||||||
|
derivation {
|
||||||
|
name = "channels";
|
||||||
|
builder = ./unpack.sh;
|
||||||
|
inherit system inputs;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#! @shell@ -e
|
||||||
|
|
||||||
|
@coreutils@/mkdir $out
|
||||||
|
@coreutils@/mkdir $out/tmp
|
||||||
|
cd $out/tmp
|
||||||
|
|
||||||
|
inputs=($inputs)
|
||||||
|
for ((n = 0; n < ${#inputs[*]}; n += 2)); do
|
||||||
|
channelName=${inputs[n]}
|
||||||
|
channelTarball=${inputs[n+1]}
|
||||||
|
|
||||||
|
echo "unpacking channel $channelName"
|
||||||
|
|
||||||
|
@bunzip2@ < $channelTarball | @tar@ xf -
|
||||||
|
|
||||||
|
if test -e */channel-name; then
|
||||||
|
channelName="$(@coreutils@/cat */channel-name)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
nr=1
|
||||||
|
attrName=$(echo $channelName | @tr@ -- '- ' '__')
|
||||||
|
dirName=$attrName
|
||||||
|
while test -e ../$dirName; do
|
||||||
|
nr=$((nr+1))
|
||||||
|
dirName=$attrName-$nr
|
||||||
|
done
|
||||||
|
|
||||||
|
@coreutils@/mv * ../$dirName # !!! hacky
|
||||||
|
done
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
@coreutils@/rmdir tmp
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# FIXME: remove this file?
|
|
||||||
let
|
|
||||||
fromEnv = var: def:
|
|
||||||
let val = builtins.getEnv var; in
|
|
||||||
if val != "" then val else def;
|
|
||||||
in rec {
|
|
||||||
nixBinDir = fromEnv "NIX_BIN_DIR" "@bindir@";
|
|
||||||
nixPrefix = "@prefix@";
|
|
||||||
nixLibexecDir = fromEnv "NIX_LIBEXEC_DIR" "@libexecdir@";
|
|
||||||
nixLocalstateDir = "@localstatedir@";
|
|
||||||
nixSysconfDir = "@sysconfdir@";
|
|
||||||
nixStoreDir = fromEnv "NIX_STORE_DIR" "@storedir@";
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/* This is the implementation of the ‘derivation’ builtin function.
|
|
||||||
It's actually a wrapper around the ‘derivationStrict’ primop. */
|
|
||||||
|
|
||||||
drvAttrs @ { outputs ? [ "out" ], ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
strict = derivationStrict drvAttrs;
|
|
||||||
|
|
||||||
commonAttrs = drvAttrs // (builtins.listToAttrs outputsList) //
|
|
||||||
{ all = map (x: x.value) outputsList;
|
|
||||||
inherit drvAttrs;
|
|
||||||
};
|
|
||||||
|
|
||||||
outputToAttrListElement = outputName:
|
|
||||||
{ name = outputName;
|
|
||||||
value = commonAttrs // {
|
|
||||||
outPath = builtins.getAttr outputName strict;
|
|
||||||
drvPath = strict.drvPath;
|
|
||||||
type = "derivation";
|
|
||||||
inherit outputName;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
outputsList = map outputToAttrListElement outputs;
|
|
||||||
|
|
||||||
in (builtins.head outputsList).value
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
{ system ? "" # obsolete
|
|
||||||
, url
|
|
||||||
, hash ? "" # an SRI ash
|
|
||||||
|
|
||||||
# Legacy hash specification
|
|
||||||
, md5 ? "", sha1 ? "", sha256 ? "", sha512 ? ""
|
|
||||||
, outputHash ?
|
|
||||||
if hash != "" then hash else if sha512 != "" then sha512 else if sha1 != "" then sha1 else if md5 != "" then md5 else sha256
|
|
||||||
, outputHashAlgo ?
|
|
||||||
if hash != "" then "" else if sha512 != "" then "sha512" else if sha1 != "" then "sha1" else if md5 != "" then "md5" else "sha256"
|
|
||||||
|
|
||||||
, executable ? false
|
|
||||||
, unpack ? false
|
|
||||||
, name ? baseNameOf (toString url)
|
|
||||||
}:
|
|
||||||
|
|
||||||
derivation {
|
|
||||||
builder = "builtin:fetchurl";
|
|
||||||
|
|
||||||
# New-style output content requirements.
|
|
||||||
inherit outputHashAlgo outputHash;
|
|
||||||
outputHashMode = if unpack || executable then "recursive" else "flat";
|
|
||||||
|
|
||||||
inherit name url executable unpack;
|
|
||||||
|
|
||||||
system = "builtin";
|
|
||||||
|
|
||||||
# No need to double the amount of network traffic
|
|
||||||
preferLocalBuild = true;
|
|
||||||
|
|
||||||
impureEnvVars = [
|
|
||||||
# We borrow these environment variables from the caller to allow
|
|
||||||
# easy proxy configuration. This is impure, but a fixed-output
|
|
||||||
# derivation like fetchurl is allowed to do so since its result is
|
|
||||||
# by definition pure.
|
|
||||||
"http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
|
|
||||||
];
|
|
||||||
|
|
||||||
# To make "nix-prefetch-url" work.
|
|
||||||
urls = [ url ];
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
corepkgs_FILES = \
|
|
||||||
unpack-channel.nix \
|
|
||||||
derivation.nix \
|
|
||||||
fetchurl.nix
|
|
||||||
|
|
||||||
$(foreach file,config.nix $(corepkgs_FILES),$(eval $(call install-data-in,$(d)/$(file),$(datadir)/nix/corepkgs)))
|
|
||||||
|
|
||||||
template-files += $(d)/config.nix
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
all-local: nar.sh
|
||||||
|
|
||||||
|
install-exec-local:
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/nar
|
||||||
|
$(INSTALL_DATA) $(srcdir)/nar.nix $(DESTDIR)$(datadir)/nix/corepkgs/nar
|
||||||
|
$(INSTALL_PROGRAM) nar.sh $(DESTDIR)$(datadir)/nix/corepkgs/nar
|
||||||
|
|
||||||
|
include ../../substitute.mk
|
||||||
|
|
||||||
|
EXTRA_DIST = nar.nix nar.sh.in
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{system, storePath, hashAlgo}:
|
||||||
|
|
||||||
|
derivation {
|
||||||
|
name = "nar";
|
||||||
|
builder = ./nar.sh;
|
||||||
|
inherit system storePath hashAlgo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#! @shell@ -e
|
||||||
|
|
||||||
|
echo "packing $storePath into $out..."
|
||||||
|
@coreutils@/mkdir $out
|
||||||
|
dst=$out/tmp.nar.bz2
|
||||||
|
@bindir@/nix-store --dump "$storePath" > tmp
|
||||||
|
|
||||||
|
@bzip2@ < tmp > $dst
|
||||||
|
|
||||||
|
@bindir@/nix-hash -vvvvv --flat --type $hashAlgo --base32 tmp > $out/nar-hash
|
||||||
|
|
||||||
|
@bindir@/nix-hash --flat --type $hashAlgo --base32 $dst > $out/narbz2-hash
|
||||||
|
|
||||||
|
@coreutils@/mv $out/tmp.nar.bz2 $out/$(@coreutils@/cat $out/narbz2-hash).nar.bz2
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{ name, channelName, src }:
|
|
||||||
|
|
||||||
derivation {
|
|
||||||
builder = "builtin:unpack-channel";
|
|
||||||
|
|
||||||
system = "builtin";
|
|
||||||
|
|
||||||
inherit name channelName src;
|
|
||||||
|
|
||||||
# No point in doing this remotely.
|
|
||||||
preferLocalBuild = true;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(import (fetchTarball https://github.com/edolstra/flake-compat/archive/master.tar.gz) {
|
|
||||||
src = builtins.fetchGit ./.;
|
|
||||||
}).defaultNix
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
SUBDIRS = manual
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
To produce a `stable' release from the trunk:
|
||||||
|
|
||||||
|
-1. Update the release notes; make sure that the release date is
|
||||||
|
correct.
|
||||||
|
|
||||||
|
0. Make sure that the trunk builds in the release supervisor.
|
||||||
|
|
||||||
|
1. Branch the trunk, e.g., `svn cp .../trunk
|
||||||
|
.../branches/0.5-release'.
|
||||||
|
|
||||||
|
2. Switch to the branch, e.g., `svn switch .../branches/0.5-release'.
|
||||||
|
|
||||||
|
3. In `configure.ac', change `STABLE=0' into `STABLE=1' and commit.
|
||||||
|
|
||||||
|
4. In the release supervisor, add a one-time job to build
|
||||||
|
`.../branches/0.5-release'.
|
||||||
|
|
||||||
|
5. Make sure that the release succeeds.
|
||||||
|
|
||||||
|
6. Move the branch to a tag, e.g., `svn mv .../branches/0.5-release
|
||||||
|
.../tags/0.5'.
|
||||||
|
|
||||||
|
Note that the branch should not be used for maintenance; it should
|
||||||
|
be deleted after the release has been created. A maintenance
|
||||||
|
branch (e.g., `.../branches/0.5') should be created from the
|
||||||
|
original revision of the trunk (since maintenance releases should
|
||||||
|
also be tested first; hence, we cannot have `STABLE=1'). The same
|
||||||
|
procedure can then be followed to produce maintenance releases;
|
||||||
|
just substitute `.../branches/VERSION' for the trunk.
|
||||||
|
|
||||||
|
7. Switch back to the trunk.
|
||||||
|
|
||||||
|
8. Bump the version number in `configure.ac' (in AC_INIT).
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
XMLLINT = $(xmllint) $(xmlflags)
|
||||||
|
XSLTPROC = $(xsltproc) $(xmlflags) \
|
||||||
|
--param section.autolabel 1 \
|
||||||
|
--param section.label.includes.component.label 1 \
|
||||||
|
--param html.stylesheet \'style.css\' \
|
||||||
|
--param xref.with.number.and.title 1 \
|
||||||
|
--param toc.section.depth 3 \
|
||||||
|
--param admon.style \'\' \
|
||||||
|
--param callout.graphics.extension \'.gif\'
|
||||||
|
|
||||||
|
# Note: we use GIF for now, since the PNGs shipped with Docbook aren't
|
||||||
|
# transparent.
|
||||||
|
|
||||||
|
man1_MANS = nix-env.1 nix-build.1 nix-store.1 nix-instantiate.1 \
|
||||||
|
nix-collect-garbage.1 nix-push.1 nix-pull.1 \
|
||||||
|
nix-prefetch-url.1 nix-channel.1 \
|
||||||
|
nix-install-package.1 nix-hash.1 nix-copy-closure.1
|
||||||
|
|
||||||
|
man8_MANS = nix-worker.8
|
||||||
|
|
||||||
|
FIGURES = figures/user-environments.png
|
||||||
|
|
||||||
|
MANUAL_SRCS = manual.xml introduction.xml installation.xml \
|
||||||
|
package-management.xml writing-nix-expressions.xml builtins.xml \
|
||||||
|
build-farm.xml \
|
||||||
|
$(man1_MANS:.1=.xml) $(man8_MANS:.8=.xml) \
|
||||||
|
troubleshooting.xml bugs.xml opt-common.xml opt-common-syn.xml \
|
||||||
|
env-common.xml quick-start.xml nix-lang-ref.xml glossary.xml \
|
||||||
|
conf-file.xml release-notes.xml \
|
||||||
|
style.css images
|
||||||
|
|
||||||
|
manual.is-valid: $(MANUAL_SRCS) version.txt
|
||||||
|
# $(XMLLINT) --xinclude $< | $(XMLLINT) --noout --nonet --relaxng $(docbookrng)/docbook.rng -
|
||||||
|
if test "$(jing)" != "false"; then \
|
||||||
|
$(XMLLINT) --xinclude $< | $(jing) $(docbookrng)/docbook.rng /dev/fd/0; \
|
||||||
|
else \
|
||||||
|
echo "Not validating."; \
|
||||||
|
fi
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
version.txt:
|
||||||
|
echo -n $(VERSION) > version.txt
|
||||||
|
|
||||||
|
man $(MANS): $(MANUAL_SRCS) manual.is-valid
|
||||||
|
$(XSLTPROC) --nonet --xinclude $(docbookxsl)/manpages/docbook.xsl manual.xml
|
||||||
|
|
||||||
|
manual.html: $(MANUAL_SRCS) manual.is-valid images
|
||||||
|
$(XSLTPROC) --nonet --xinclude --output manual.html \
|
||||||
|
$(docbookxsl)/html/docbook.xsl manual.xml
|
||||||
|
|
||||||
|
manual.pdf: $(MANUAL_SRCS) manual.is-valid images
|
||||||
|
if test "$(dblatex)" != ""; then \
|
||||||
|
$(dblatex) manual.xml; \
|
||||||
|
else \
|
||||||
|
echo "Please install dblatex and rerun configure."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
NEWS_OPTS = \
|
||||||
|
--stringparam generate.toc "article nop" \
|
||||||
|
--stringparam section.autolabel.max.depth 0 \
|
||||||
|
--stringparam header.rule 0
|
||||||
|
|
||||||
|
NEWS.html: release-notes.xml
|
||||||
|
$(XSLTPROC) --nonet --xinclude --output $@ $(NEWS_OPTS) \
|
||||||
|
$(docbookxsl)/html/docbook.xsl release-notes.xml
|
||||||
|
|
||||||
|
NEWS.txt: release-notes.xml
|
||||||
|
$(XSLTPROC) --nonet --xinclude quote-literals.xsl release-notes.xml | \
|
||||||
|
$(XSLTPROC) --nonet --output $@.tmp.html $(NEWS_OPTS) \
|
||||||
|
$(docbookxsl)/html/docbook.xsl -
|
||||||
|
LANG=en_US $(w3m) -dump $@.tmp.html > $@
|
||||||
|
rm $@.tmp.html
|
||||||
|
|
||||||
|
|
||||||
|
all-local: manual.html NEWS.html NEWS.txt
|
||||||
|
|
||||||
|
install-data-local: manual.html
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(docdir)/manual
|
||||||
|
$(INSTALL_DATA) manual.html $(DESTDIR)$(docdir)/manual
|
||||||
|
ln -sf manual.html $(DESTDIR)$(docdir)/manual/index.html
|
||||||
|
$(INSTALL_DATA) style.css $(DESTDIR)$(docdir)/manual
|
||||||
|
cp -r images $(DESTDIR)$(docdir)/manual/images
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(docdir)/manual/figures
|
||||||
|
$(INSTALL_DATA) $(FIGURES) $(DESTDIR)$(docdir)/manual/figures
|
||||||
|
$(INSTALL) -d $(DESTDIR)$(docdir)/release-notes
|
||||||
|
$(INSTALL_DATA) NEWS.html $(DESTDIR)$(docdir)/release-notes/index.html
|
||||||
|
$(INSTALL_DATA) style.css $(DESTDIR)$(docdir)/release-notes/
|
||||||
|
|
||||||
|
images:
|
||||||
|
mkdir images
|
||||||
|
# cp $(docbookxsl)/images/*.gif images
|
||||||
|
mkdir images/callouts
|
||||||
|
cp $(docbookxsl)/images/callouts/*.gif images/callouts
|
||||||
|
chmod -R +w images
|
||||||
|
|
||||||
|
KEEP = manual.html manual.is-valid version.txt $(MANS) NEWS.html NEWS.txt
|
||||||
|
|
||||||
|
EXTRA_DIST = $(MANUAL_SRCS) $(FIGURES) $(KEEP)
|
||||||
|
|
||||||
|
DISTCLEANFILES = $(KEEP)
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<part xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
xml:id="part-advanced-topics"
|
|
||||||
version="5.0">
|
|
||||||
|
|
||||||
<title>Advanced Topics</title>
|
|
||||||
|
|
||||||
<xi:include href="distributed-builds.xml" />
|
|
||||||
<xi:include href="cores-vs-jobs.xml" />
|
|
||||||
<xi:include href="diff-hook.xml" />
|
|
||||||
<xi:include href="post-build-hook.xml" />
|
|
||||||
|
|
||||||
</part>
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="chap-tuning-cores-and-jobs">
|
|
||||||
|
|
||||||
<title>Tuning Cores and Jobs</title>
|
|
||||||
|
|
||||||
<para>Nix has two relevant settings with regards to how your CPU cores
|
|
||||||
will be utilized: <xref linkend="conf-cores" /> and
|
|
||||||
<xref linkend="conf-max-jobs" />. This chapter will talk about what
|
|
||||||
they are, how they interact, and their configuration trade-offs.</para>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
<varlistentry>
|
|
||||||
<term><xref linkend="conf-max-jobs" /></term>
|
|
||||||
<listitem><para>
|
|
||||||
Dictates how many separate derivations will be built at the same
|
|
||||||
time. If you set this to zero, the local machine will do no
|
|
||||||
builds. Nix will still substitute from binary caches, and build
|
|
||||||
remotely if remote builders are configured.
|
|
||||||
</para></listitem>
|
|
||||||
</varlistentry>
|
|
||||||
<varlistentry>
|
|
||||||
<term><xref linkend="conf-cores" /></term>
|
|
||||||
<listitem><para>
|
|
||||||
Suggests how many cores each derivation should use. Similar to
|
|
||||||
<command>make -j</command>.
|
|
||||||
</para></listitem>
|
|
||||||
</varlistentry>
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
<para>The <xref linkend="conf-cores" /> setting determines the value of
|
|
||||||
<envar>NIX_BUILD_CORES</envar>. <envar>NIX_BUILD_CORES</envar> is equal
|
|
||||||
to <xref linkend="conf-cores" />, unless <xref linkend="conf-cores" />
|
|
||||||
equals <literal>0</literal>, in which case <envar>NIX_BUILD_CORES</envar>
|
|
||||||
will be the total number of cores in the system.</para>
|
|
||||||
|
|
||||||
<para>The maximum number of consumed cores is a simple multiplication,
|
|
||||||
<xref linkend="conf-max-jobs" /> * <envar>NIX_BUILD_CORES</envar>.</para>
|
|
||||||
|
|
||||||
<para>The balance on how to set these two independent variables depends
|
|
||||||
upon each builder's workload and hardware. Here are a few example
|
|
||||||
scenarios on a machine with 24 cores:</para>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<caption>Balancing 24 Build Cores</caption>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th><xref linkend="conf-max-jobs" /></th>
|
|
||||||
<th><xref linkend="conf-cores" /></th>
|
|
||||||
<th><envar>NIX_BUILD_CORES</envar></th>
|
|
||||||
<th>Maximum Processes</th>
|
|
||||||
<th>Result</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>1</td>
|
|
||||||
<td>24</td>
|
|
||||||
<td>24</td>
|
|
||||||
<td>24</td>
|
|
||||||
<td>
|
|
||||||
One derivation will be built at a time, each one can use 24
|
|
||||||
cores. Undersold if a job can’t use 24 cores.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>4</td>
|
|
||||||
<td>6</td>
|
|
||||||
<td>6</td>
|
|
||||||
<td>24</td>
|
|
||||||
<td>
|
|
||||||
Four derivations will be built at once, each given access to
|
|
||||||
six cores.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>12</td>
|
|
||||||
<td>6</td>
|
|
||||||
<td>6</td>
|
|
||||||
<td>72</td>
|
|
||||||
<td>
|
|
||||||
12 derivations will be built at once, each given access to six
|
|
||||||
cores. This configuration is over-sold. If all 12 derivations
|
|
||||||
being built simultaneously try to use all six cores, the
|
|
||||||
machine's performance will be degraded due to extensive context
|
|
||||||
switching between the 12 builds.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>24</td>
|
|
||||||
<td>1</td>
|
|
||||||
<td>1</td>
|
|
||||||
<td>24</td>
|
|
||||||
<td>
|
|
||||||
24 derivations can build at the same time, each using a single
|
|
||||||
core. Never oversold, but derivations which require many cores
|
|
||||||
will be very slow to compile.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>24</td>
|
|
||||||
<td>0</td>
|
|
||||||
<td>24</td>
|
|
||||||
<td>576</td>
|
|
||||||
<td>
|
|
||||||
24 derivations can build at the same time, each using all the
|
|
||||||
available cores of the machine. Very likely to be oversold,
|
|
||||||
and very likely to suffer context switches.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<para>It is up to the derivations' build script to respect
|
|
||||||
host's requested cores-per-build by following the value of the
|
|
||||||
<envar>NIX_BUILD_CORES</envar> environment variable.</para>
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
xml:id="chap-diff-hook"
|
|
||||||
version="5.0"
|
|
||||||
>
|
|
||||||
|
|
||||||
<title>Verifying Build Reproducibility with <option linkend="conf-diff-hook">diff-hook</option></title>
|
|
||||||
|
|
||||||
<subtitle>Check build reproducibility by running builds multiple times
|
|
||||||
and comparing their results.</subtitle>
|
|
||||||
|
|
||||||
<para>Specify a program with Nix's <xref linkend="conf-diff-hook" /> to
|
|
||||||
compare build results when two builds produce different results. Note:
|
|
||||||
this hook is only executed if the results are not the same, this hook
|
|
||||||
is not used for determining if the results are the same.</para>
|
|
||||||
|
|
||||||
<para>For purposes of demonstration, we'll use the following Nix file,
|
|
||||||
<filename>deterministic.nix</filename> for testing:</para>
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let
|
|
||||||
inherit (import <nixpkgs> {}) runCommand;
|
|
||||||
in {
|
|
||||||
stable = runCommand "stable" {} ''
|
|
||||||
touch $out
|
|
||||||
'';
|
|
||||||
|
|
||||||
unstable = runCommand "unstable" {} ''
|
|
||||||
echo $RANDOM > $out
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
<para>Additionally, <filename>nix.conf</filename> contains:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
diff-hook = /etc/nix/my-diff-hook
|
|
||||||
run-diff-hook = true
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
where <filename>/etc/nix/my-diff-hook</filename> is an executable
|
|
||||||
file containing:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#!/bin/sh
|
|
||||||
exec >&2
|
|
||||||
echo "For derivation $3:"
|
|
||||||
/run/current-system/sw/bin/diff -r "$1" "$2"
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The diff hook is executed by the same user and group who ran the
|
|
||||||
build. However, the diff hook does not have write access to the store
|
|
||||||
path just built.</para>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>
|
|
||||||
Spot-Checking Build Determinism
|
|
||||||
</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Verify a path which already exists in the Nix store by passing
|
|
||||||
<option>--check</option> to the build command.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>If the build passes and is deterministic, Nix will exit with a
|
|
||||||
status code of 0:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-build ./deterministic.nix -A stable
|
|
||||||
these derivations will be built:
|
|
||||||
/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv
|
|
||||||
building '/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv'...
|
|
||||||
/nix/store/yyxlzw3vqaas7wfp04g0b1xg51f2czgq-stable
|
|
||||||
|
|
||||||
$ nix-build ./deterministic.nix -A stable --check
|
|
||||||
checking outputs of '/nix/store/z98fasz2jqy9gs0xbvdj939p27jwda38-stable.drv'...
|
|
||||||
/nix/store/yyxlzw3vqaas7wfp04g0b1xg51f2czgq-stable
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>If the build is not deterministic, Nix will exit with a status
|
|
||||||
code of 1:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-build ./deterministic.nix -A unstable
|
|
||||||
these derivations will be built:
|
|
||||||
/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv
|
|
||||||
building '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'...
|
|
||||||
/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable
|
|
||||||
|
|
||||||
$ nix-build ./deterministic.nix -A unstable --check
|
|
||||||
checking outputs of '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'...
|
|
||||||
error: derivation '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv' may not be deterministic: output '/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable' differs
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>In the Nix daemon's log, we will now see:
|
|
||||||
<screen>
|
|
||||||
For derivation /nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv:
|
|
||||||
1c1
|
|
||||||
< 8108
|
|
||||||
---
|
|
||||||
> 30204
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Using <option>--check</option> with <option>--keep-failed</option>
|
|
||||||
will cause Nix to keep the second build's output in a special,
|
|
||||||
<literal>.check</literal> path:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-build ./deterministic.nix -A unstable --check --keep-failed
|
|
||||||
checking outputs of '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv'...
|
|
||||||
note: keeping build directory '/tmp/nix-build-unstable.drv-0'
|
|
||||||
error: derivation '/nix/store/cgl13lbj1w368r5z8gywipl1ifli7dhk-unstable.drv' may not be deterministic: output '/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable' differs from '/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable.check'
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>In particular, notice the
|
|
||||||
<literal>/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable.check</literal>
|
|
||||||
output. Nix has copied the build results to that directory where you
|
|
||||||
can examine it.</para>
|
|
||||||
|
|
||||||
<note xml:id="check-dirs-are-unregistered">
|
|
||||||
<title><literal>.check</literal> paths are not registered store paths</title>
|
|
||||||
|
|
||||||
<para>Check paths are not protected against garbage collection,
|
|
||||||
and this path will be deleted on the next garbage collection.</para>
|
|
||||||
|
|
||||||
<para>The path is guaranteed to be alive for the duration of
|
|
||||||
<xref linkend="conf-diff-hook" />'s execution, but may be deleted
|
|
||||||
any time after.</para>
|
|
||||||
|
|
||||||
<para>If the comparison is performed as part of automated tooling,
|
|
||||||
please use the diff-hook or author your tooling to handle the case
|
|
||||||
where the build was not deterministic and also a check path does
|
|
||||||
not exist.</para>
|
|
||||||
</note>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
<option>--check</option> is only usable if the derivation has
|
|
||||||
been built on the system already. If the derivation has not been
|
|
||||||
built Nix will fail with the error:
|
|
||||||
<screen>
|
|
||||||
error: some outputs of '/nix/store/hzi1h60z2qf0nb85iwnpvrai3j2w7rr6-unstable.drv' are not valid, so checking is not possible
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
Run the build without <option>--check</option>, and then try with
|
|
||||||
<option>--check</option> again.
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>
|
|
||||||
Automatic and Optionally Enforced Determinism Verification
|
|
||||||
</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Automatically verify every build at build time by executing the
|
|
||||||
build multiple times.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Setting <xref linkend="conf-repeat" /> and
|
|
||||||
<xref linkend="conf-enforce-determinism" /> in your
|
|
||||||
<filename>nix.conf</filename> permits the automated verification
|
|
||||||
of every build Nix performs.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
The following configuration will run each build three times, and
|
|
||||||
will require the build to be deterministic:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
enforce-determinism = true
|
|
||||||
repeat = 2
|
|
||||||
</programlisting>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Setting <xref linkend="conf-enforce-determinism" /> to false as in
|
|
||||||
the following configuration will run the build multiple times,
|
|
||||||
execute the build hook, but will allow the build to succeed even
|
|
||||||
if it does not build reproducibly:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
enforce-determinism = false
|
|
||||||
repeat = 1
|
|
||||||
</programlisting>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
An example output of this configuration:
|
|
||||||
<screen>
|
|
||||||
$ nix-build ./test.nix -A unstable
|
|
||||||
these derivations will be built:
|
|
||||||
/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv
|
|
||||||
building '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' (round 1/2)...
|
|
||||||
building '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' (round 2/2)...
|
|
||||||
output '/nix/store/6xg356v9gl03hpbbg8gws77n19qanh02-unstable' of '/nix/store/ch6llwpr2h8c3jmnf3f2ghkhx59aa97f-unstable.drv' differs from '/nix/store/6xg356v9gl03hpbbg8gws77n19qanh02-unstable.check' from previous round
|
|
||||||
/nix/store/6xg356v9gl03hpbbg8gws77n19qanh02-unstable
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
</chapter>
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='chap-distributed-builds'>
|
|
||||||
|
|
||||||
<title>Remote Builds</title>
|
|
||||||
|
|
||||||
<para>Nix supports remote builds, where a local Nix installation can
|
|
||||||
forward Nix builds to other machines. This allows multiple builds to
|
|
||||||
be performed in parallel and allows Nix to perform multi-platform
|
|
||||||
builds in a semi-transparent way. For instance, if you perform a
|
|
||||||
build for a <literal>x86_64-darwin</literal> on an
|
|
||||||
<literal>i686-linux</literal> machine, Nix can automatically forward
|
|
||||||
the build to a <literal>x86_64-darwin</literal> machine, if
|
|
||||||
available.</para>
|
|
||||||
|
|
||||||
<para>To forward a build to a remote machine, it’s required that the
|
|
||||||
remote machine is accessible via SSH and that it has Nix
|
|
||||||
installed. You can test whether connecting to the remote Nix instance
|
|
||||||
works, e.g.
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix ping-store --store ssh://mac
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
will try to connect to the machine named <literal>mac</literal>. It is
|
|
||||||
possible to specify an SSH identity file as part of the remote store
|
|
||||||
URI, e.g.
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix ping-store --store ssh://mac?ssh-key=/home/alice/my-key
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
Since builds should be non-interactive, the key should not have a
|
|
||||||
passphrase. Alternatively, you can load identities ahead of time into
|
|
||||||
<command>ssh-agent</command> or <command>gpg-agent</command>.</para>
|
|
||||||
|
|
||||||
<para>If you get the error
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
bash: nix-store: command not found
|
|
||||||
error: cannot connect to 'mac'
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
then you need to ensure that the <envar>PATH</envar> of
|
|
||||||
non-interactive login shells contains Nix.</para>
|
|
||||||
|
|
||||||
<warning><para>If you are building via the Nix daemon, it is the Nix
|
|
||||||
daemon user account (that is, <literal>root</literal>) that should
|
|
||||||
have SSH access to the remote machine. If you can’t or don’t want to
|
|
||||||
configure <literal>root</literal> to be able to access to remote
|
|
||||||
machine, you can use a private Nix store instead by passing
|
|
||||||
e.g. <literal>--store ~/my-nix</literal>.</para></warning>
|
|
||||||
|
|
||||||
<para>The list of remote machines can be specified on the command line
|
|
||||||
or in the Nix configuration file. The former is convenient for
|
|
||||||
testing. For example, the following command allows you to build a
|
|
||||||
derivation for <literal>x86_64-darwin</literal> on a Linux machine:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ uname
|
|
||||||
Linux
|
|
||||||
|
|
||||||
$ nix build \
|
|
||||||
'(with import <nixpkgs> { system = "x86_64-darwin"; }; runCommand "foo" {} "uname > $out")' \
|
|
||||||
--builders 'ssh://mac x86_64-darwin'
|
|
||||||
[1/0/1 built, 0.0 MiB DL] building foo on ssh://mac
|
|
||||||
|
|
||||||
$ cat ./result
|
|
||||||
Darwin
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
It is possible to specify multiple builders separated by a semicolon
|
|
||||||
or a newline, e.g.
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
--builders 'ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd'
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Each machine specification consists of the following elements,
|
|
||||||
separated by spaces. Only the first element is required.
|
|
||||||
To leave a field at its default, set it to <literal>-</literal>.
|
|
||||||
|
|
||||||
<orderedlist>
|
|
||||||
|
|
||||||
<listitem><para>The URI of the remote store in the format
|
|
||||||
<literal>ssh://[<replaceable>username</replaceable>@]<replaceable>hostname</replaceable></literal>,
|
|
||||||
e.g. <literal>ssh://nix@mac</literal> or
|
|
||||||
<literal>ssh://mac</literal>. For backward compatibility,
|
|
||||||
<literal>ssh://</literal> may be omitted. The hostname may be an
|
|
||||||
alias defined in your
|
|
||||||
<filename>~/.ssh/config</filename>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A comma-separated list of Nix platform type
|
|
||||||
identifiers, such as <literal>x86_64-darwin</literal>. It is
|
|
||||||
possible for a machine to support multiple platform types, e.g.,
|
|
||||||
<literal>i686-linux,x86_64-linux</literal>. If omitted, this
|
|
||||||
defaults to the local platform type.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The SSH identity file to be used to log in to the
|
|
||||||
remote machine. If omitted, SSH will use its regular
|
|
||||||
identities.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The maximum number of builds that Nix will execute
|
|
||||||
in parallel on the machine. Typically this should be equal to the
|
|
||||||
number of CPU cores. For instance, the machine
|
|
||||||
<literal>itchy</literal> in the example will execute up to 8 builds
|
|
||||||
in parallel.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The “speed factor”, indicating the relative speed of
|
|
||||||
the machine. If there are multiple machines of the right type, Nix
|
|
||||||
will prefer the fastest, taking load into account.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A comma-separated list of <emphasis>supported
|
|
||||||
features</emphasis>. If a derivation has the
|
|
||||||
<varname>requiredSystemFeatures</varname> attribute, then Nix will
|
|
||||||
only perform the derivation on a machine that has the specified
|
|
||||||
features. For instance, the attribute
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
requiredSystemFeatures = [ "kvm" ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
will cause the build to be performed on a machine that has the
|
|
||||||
<literal>kvm</literal> feature.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A comma-separated list of <emphasis>mandatory
|
|
||||||
features</emphasis>. A machine will only be used to build a
|
|
||||||
derivation if all of the machine’s mandatory features appear in the
|
|
||||||
derivation’s <varname>requiredSystemFeatures</varname>
|
|
||||||
attribute..</para></listitem>
|
|
||||||
|
|
||||||
</orderedlist>
|
|
||||||
|
|
||||||
For example, the machine specification
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
nix@scratchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy_auto 8 1 kvm
|
|
||||||
nix@itchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy_auto 8 2
|
|
||||||
nix@poochie.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy_auto 1 2 kvm benchmark
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
specifies several machines that can perform
|
|
||||||
<literal>i686-linux</literal> builds. However,
|
|
||||||
<literal>poochie</literal> will only do builds that have the attribute
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
requiredSystemFeatures = [ "benchmark" ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
requiredSystemFeatures = [ "benchmark" "kvm" ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
<literal>itchy</literal> cannot do builds that require
|
|
||||||
<literal>kvm</literal>, but <literal>scratchy</literal> does support
|
|
||||||
such builds. For regular builds, <literal>itchy</literal> will be
|
|
||||||
preferred over <literal>scratchy</literal> because it has a higher
|
|
||||||
speed factor.</para>
|
|
||||||
|
|
||||||
<para>Remote builders can also be configured in
|
|
||||||
<filename>nix.conf</filename>, e.g.
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
builders = ssh://mac x86_64-darwin ; ssh://beastie x86_64-freebsd
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
Finally, remote builders can be configured in a separate configuration
|
|
||||||
file included in <option>builders</option> via the syntax
|
|
||||||
<literal>@<replaceable>file</replaceable></literal>. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
builders = @/etc/nix/machines
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
causes the list of machines in <filename>/etc/nix/machines</filename>
|
|
||||||
to be included. (This is the default.)</para>
|
|
||||||
|
|
||||||
<para>If you want the builders to use caches, you likely want to set
|
|
||||||
the option <link linkend='conf-builders-use-substitutes'><literal>builders-use-substitutes</literal></link>
|
|
||||||
in your local <filename>nix.conf</filename>.</para>
|
|
||||||
|
|
||||||
<para>To build only on remote builders and disable building on the local machine,
|
|
||||||
you can use the option <option>--max-jobs 0</option>.</para>
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
xml:id="chap-post-build-hook"
|
|
||||||
version="5.0"
|
|
||||||
>
|
|
||||||
|
|
||||||
<title>Using the <option linkend="conf-post-build-hook">post-build-hook</option></title>
|
|
||||||
<subtitle>Uploading to an S3-compatible binary cache after each build</subtitle>
|
|
||||||
|
|
||||||
|
|
||||||
<section xml:id="chap-post-build-hook-caveats">
|
|
||||||
<title>Implementation Caveats</title>
|
|
||||||
<para>Here we use the post-build hook to upload to a binary cache.
|
|
||||||
This is a simple and working example, but it is not suitable for all
|
|
||||||
use cases.</para>
|
|
||||||
|
|
||||||
<para>The post build hook program runs after each executed build,
|
|
||||||
and blocks the build loop. The build loop exits if the hook program
|
|
||||||
fails.</para>
|
|
||||||
|
|
||||||
<para>Concretely, this implementation will make Nix slow or unusable
|
|
||||||
when the internet is slow or unreliable.</para>
|
|
||||||
|
|
||||||
<para>A more advanced implementation might pass the store paths to a
|
|
||||||
user-supplied daemon or queue for processing the store paths outside
|
|
||||||
of the build loop.</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>Prerequisites</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
This tutorial assumes you have configured an S3-compatible binary cache
|
|
||||||
according to the instructions at
|
|
||||||
<xref linkend="ssec-s3-substituter-authenticated-writes" />, and
|
|
||||||
that the <literal>root</literal> user's default AWS profile can
|
|
||||||
upload to the bucket.
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>Set up a Signing Key</title>
|
|
||||||
<para>Use <command>nix-store --generate-binary-cache-key</command> to
|
|
||||||
create our public and private signing keys. We will sign paths
|
|
||||||
with the private key, and distribute the public key for verifying
|
|
||||||
the authenticity of the paths.</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
# nix-store --generate-binary-cache-key example-nix-cache-1 /etc/nix/key.private /etc/nix/key.public
|
|
||||||
# cat /etc/nix/key.public
|
|
||||||
example-nix-cache-1:1/cKDz3QCCOmwcztD2eV6Coggp6rqc9DGjWv7C0G+rM=
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>Then, add the public key and the cache URL to your
|
|
||||||
<filename>nix.conf</filename>'s <xref linkend="conf-trusted-public-keys" />
|
|
||||||
and <xref linkend="conf-substituters" /> like:</para>
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
substituters = https://cache.nixos.org/ s3://example-nix-cache
|
|
||||||
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= example-nix-cache-1:1/cKDz3QCCOmwcztD2eV6Coggp6rqc9DGjWv7C0G+rM=
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
<para>we will restart the Nix daemon a later step.</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>Implementing the build hook</title>
|
|
||||||
<para>Write the following script to
|
|
||||||
<filename>/etc/nix/upload-to-cache.sh</filename>:
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
set -f # disable globbing
|
|
||||||
export IFS=' '
|
|
||||||
|
|
||||||
echo "Signing paths" $OUT_PATHS
|
|
||||||
nix sign-paths --key-file /etc/nix/key.private $OUT_PATHS
|
|
||||||
echo "Uploading paths" $OUT_PATHS
|
|
||||||
exec nix copy --to 's3://example-nix-cache' $OUT_PATHS
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
<note>
|
|
||||||
<title>Should <literal>$OUT_PATHS</literal> be quoted?</title>
|
|
||||||
<para>
|
|
||||||
The <literal>$OUT_PATHS</literal> variable is a space-separated
|
|
||||||
list of Nix store paths. In this case, we expect and want the
|
|
||||||
shell to perform word splitting to make each output path its
|
|
||||||
own argument to <command>nix sign-paths</command>. Nix guarantees
|
|
||||||
the paths will not contain any spaces, however a store path
|
|
||||||
might contain glob characters. The <command>set -f</command>
|
|
||||||
disables globbing in the shell.
|
|
||||||
</para>
|
|
||||||
</note>
|
|
||||||
<para>
|
|
||||||
Then make sure the hook program is executable by the <literal>root</literal> user:
|
|
||||||
<screen>
|
|
||||||
# chmod +x /etc/nix/upload-to-cache.sh
|
|
||||||
</screen></para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>Updating Nix Configuration</title>
|
|
||||||
|
|
||||||
<para>Edit <filename>/etc/nix/nix.conf</filename> to run our hook,
|
|
||||||
by adding the following configuration snippet at the end:</para>
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
post-build-hook = /etc/nix/upload-to-cache.sh
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
<para>Then, restart the <command>nix-daemon</command>.</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<title>Testing</title>
|
|
||||||
|
|
||||||
<para>Build any derivation, for example:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-build -E '(import <nixpkgs> {}).writeText "example" (builtins.toString builtins.currentTime)'
|
|
||||||
these derivations will be built:
|
|
||||||
/nix/store/s4pnfbkalzy5qz57qs6yybna8wylkig6-example.drv
|
|
||||||
building '/nix/store/s4pnfbkalzy5qz57qs6yybna8wylkig6-example.drv'...
|
|
||||||
running post-build-hook '/home/grahamc/projects/github.com/NixOS/nix/post-hook.sh'...
|
|
||||||
post-build-hook: Signing paths /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
|
|
||||||
post-build-hook: Uploading paths /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
|
|
||||||
/nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>Then delete the path from the store, and try substituting it from the binary cache:</para>
|
|
||||||
<screen>
|
|
||||||
$ rm ./result
|
|
||||||
$ nix-store --delete /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>Now, copy the path back from the cache:</para>
|
|
||||||
<screen>
|
|
||||||
$ nix store --realize /nix/store/ibcyipq5gf91838ldx40mjsp0b8w9n18-example
|
|
||||||
copying path '/nix/store/m8bmqwrch6l3h8s0k3d673xpmipcdpsa-example from 's3://example-nix-cache'...
|
|
||||||
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
|
|
||||||
/nix/store/m8bmqwrch6l3h8s0k3d673xpmipcdpsa-example
|
|
||||||
</screen>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<title>Conclusion</title>
|
|
||||||
<para>
|
|
||||||
We now have a Nix installation configured to automatically sign and
|
|
||||||
upload every local build to a remote binary cache.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Before deploying this to production, be sure to consider the
|
|
||||||
implementation caveats in <xref linkend="chap-post-build-hook-caveats" />.
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
</chapter>
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<appendix xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
|
||||||
|
<title>Bugs / To-Do</title>
|
||||||
|
|
||||||
|
|
||||||
|
<itemizedlist>
|
||||||
|
|
||||||
|
<listitem><para>The man-pages generated from the DocBook documentation
|
||||||
|
are ugly.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>Generations properly form a tree. E.g., if after
|
||||||
|
switching to generation 39, we perform an installation action, a
|
||||||
|
generation 43 is created which is a descendant of 39, not 42. So a
|
||||||
|
rollback from 43 ought to go back to 39. This is not currently
|
||||||
|
implemented; generations form a linear sequence.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>For security, <command>nix-push</command> manifests
|
||||||
|
should be digitally signed, and <command>nix-pull</command> should
|
||||||
|
verify the signatures. The actual NAR archives in the cache do not
|
||||||
|
need to be signed, since the manifest contains cryptographic hashes of
|
||||||
|
these files (and <filename>fetchurl.nix</filename> checks
|
||||||
|
them).</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>It would be useful to have an option in
|
||||||
|
<command>nix-env --delete-generations</command> to remove non-current
|
||||||
|
generations older than a certain age.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>There should be a flexible way to change the user
|
||||||
|
environment builder. Currently, you have to replace
|
||||||
|
<filename><replaceable>prefix</replaceable>/share/nix/corepkgs/buildenv/builder.pl</filename>,
|
||||||
|
which is hard-coded into <command>nix-env</command>. Also, the
|
||||||
|
default builder should be more powerful. For instance, there should
|
||||||
|
be some way to specify priorities to resolve
|
||||||
|
collisions.</para></listitem>
|
||||||
|
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
|
</appendix>
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xml:id='chap-build-farm'>
|
||||||
|
|
||||||
|
<title>Setting up a Build Farm</title>
|
||||||
|
|
||||||
|
|
||||||
|
<para>This chapter provides some sketchy information on how to set up
|
||||||
|
a Nix-based build farm. Nix is particularly suited as a basis for a
|
||||||
|
build farm, since:
|
||||||
|
|
||||||
|
<itemizedlist>
|
||||||
|
|
||||||
|
<listitem><para>Nix supports distributed builds: a local Nix
|
||||||
|
installation can forward Nix builds to other machines over the
|
||||||
|
network. This allows multiple builds to be performed in parallel
|
||||||
|
(thus improving performance), but more in importantly, it allows Nix
|
||||||
|
to perform multi-platform builds in a semi-transparent way. For
|
||||||
|
instance, if you perform a build for a
|
||||||
|
<literal>powerpc-darwin</literal> on an
|
||||||
|
<literal>i686-linux</literal> machine, Nix can automatically forward
|
||||||
|
the build to a <literal>powerpc-darwin</literal> machine, if
|
||||||
|
available.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The Nix expression language is ideal for describing
|
||||||
|
build jobs, plus all their dependencies. For instance, if your
|
||||||
|
package has some dependency, you don't have to manually install it
|
||||||
|
on all the machines in the build farm; they will be built
|
||||||
|
automatically.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>Proper release management requires that builds (if
|
||||||
|
deployed) are traceable: it should be possible to figure out from
|
||||||
|
exactly what sources they were built, in what configuration, etc.;
|
||||||
|
and it should be possible to reproduce the build, if necessary. Nix
|
||||||
|
makes this possible since Nix's hashing scheme uniquely identifies
|
||||||
|
builds, and Nix expressions are self-contained.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>Nix will only rebuild things that have actually
|
||||||
|
changed. For instance, if the sources of a package haven't changed
|
||||||
|
between runs of the build farm, the package won't be rebuilt (unless
|
||||||
|
it was garbage-collected). Also, dependencies typically don't
|
||||||
|
change very often, so they only need to be built
|
||||||
|
once.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The results of a Nix build farm can be made
|
||||||
|
available through a channel, so successful builds can be deployed to
|
||||||
|
users immediately.</para></listitem>
|
||||||
|
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Overview</title>
|
||||||
|
|
||||||
|
<para>TODO</para>
|
||||||
|
|
||||||
|
<para>The sources of the Nix build farm are at <link
|
||||||
|
xlink:href='https://svn.nixos.org/repos/nix/release/trunk'/>.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section xml:id='sec-distributed-builds'><title>Setting up distributed builds</title>
|
||||||
|
|
||||||
|
<para>You can enable distributed builds by setting the environment
|
||||||
|
variable <envar>NIX_BUILD_HOOK</envar> to point to a program that Nix
|
||||||
|
will call whenever it wants to build a derivation. The build hook
|
||||||
|
(typically a shell or Perl script) can decline the build, in which Nix
|
||||||
|
will perform it in the usual way if possible, or it can accept it, in
|
||||||
|
which case it is responsible for somehow getting the inputs of the
|
||||||
|
build to another machine, doing the build there, and getting the
|
||||||
|
results back. The details of the build hook protocol are described in
|
||||||
|
the documentation of the <link
|
||||||
|
linkend="envar-build-hook"><envar>NIX_BUILD_HOOK</envar>
|
||||||
|
variable</link>.</para>
|
||||||
|
|
||||||
|
<example xml:id='ex-remote-systems'><title>Remote machine configuration:
|
||||||
|
<filename>remote-systems.conf</filename></title>
|
||||||
|
<programlisting>
|
||||||
|
nix@mcflurry.labs.cs.uu.nl powerpc-darwin /home/nix/.ssh/id_quarterpounder_auto 2
|
||||||
|
nix@scratchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy_auto 1
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
|
||||||
|
<para>An example build hook can be found in the Nix build farm
|
||||||
|
sources: <link
|
||||||
|
xlink:href='https://svn.nixos.org/repos/nix/release/trunk/common/distributed/build-remote.pl'
|
||||||
|
/>. It should be suitable for most purposes, with maybe some minor
|
||||||
|
adjustments. It uses <command>ssh</command> and
|
||||||
|
<command>rsync</command> to copy the build inputs and outputs and
|
||||||
|
perform the remote build. You should define a list of available build
|
||||||
|
machines and set the environment variable
|
||||||
|
<envar>REMOTE_SYSTEMS</envar> to point to it. An example
|
||||||
|
configuration is shown in <xref linkend='ex-remote-systems' />. Each
|
||||||
|
line in the file specifies a machine, with the following bits of
|
||||||
|
information:
|
||||||
|
|
||||||
|
<orderedlist>
|
||||||
|
|
||||||
|
<listitem><para>The name of the remote machine, with optionally the
|
||||||
|
user under which the remote build should be performed. This is
|
||||||
|
actually passed as an argument to <command>ssh</command>, so it can
|
||||||
|
be an alias defined in your
|
||||||
|
<filename>~/.ssh/config</filename>.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The Nix platform type identifier, such as
|
||||||
|
<literal>powerpc-darwin</literal>.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The SSH private key to be used to log in to the
|
||||||
|
remote machine. Since builds should be non-interactive, this key
|
||||||
|
should not have a passphrase!</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The maximum <quote>load</quote> of the remote
|
||||||
|
machine. This is just the maximum number of jobs that
|
||||||
|
<filename>build-remote.pl</filename> will execute in parallel on the
|
||||||
|
machine. Typically this should be equal to the number of
|
||||||
|
CPUs.</para></listitem>
|
||||||
|
|
||||||
|
</orderedlist>
|
||||||
|
|
||||||
|
You should also set up the environment variable
|
||||||
|
<envar>CURRENT_LOAD</envar> to point at a file that
|
||||||
|
<filename>build-remote.pl</filename> uses to remember how many jobs it
|
||||||
|
is currently executing remotely. It doesn't look at the actual load
|
||||||
|
on the remote machine, so if you have multiple instances of Nix
|
||||||
|
running, they should use the same <envar>CURRENT_LOAD</envar>
|
||||||
|
file<footnote><para>Although there are probably some race conditions
|
||||||
|
in the script right now.</para></footnote>. Maybe in the future
|
||||||
|
<filename>build-remote.pl</filename> will look at the actual remote
|
||||||
|
load. The load file should exist, so you should just create it as an
|
||||||
|
empty file initially.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
</chapter>
|
||||||
@@ -0,0 +1,841 @@
|
|||||||
|
<section xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xml:id='ssec-builtins'>
|
||||||
|
|
||||||
|
<title>Built-in functions</title>
|
||||||
|
|
||||||
|
|
||||||
|
<para>This section lists the functions and constants built into the
|
||||||
|
Nix expression evaluator. (The built-in function
|
||||||
|
<function>derivation</function> is discussed above.) Some built-ins,
|
||||||
|
such as <function>derivation</function>, are always in scope of every
|
||||||
|
Nix expression; you can just access them right away. But to prevent
|
||||||
|
polluting the namespace too much, most built-ins are not in scope.
|
||||||
|
Instead, you can access them through the <varname>builtins</varname>
|
||||||
|
built-in value, which is an attribute set that contains all built-in
|
||||||
|
functions and values. For instance, <function>derivation</function>
|
||||||
|
is also available as <function>builtins.derivation</function>.</para>
|
||||||
|
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>abort</function> <replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Abort Nix expression evaluation, print error
|
||||||
|
message <replaceable>s</replaceable>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.add</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the sum of the integers
|
||||||
|
<replaceable>e1</replaceable> and
|
||||||
|
<replaceable>e2</replaceable>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.attrNames</function>
|
||||||
|
<replaceable>attrs</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the names of the attributes in the
|
||||||
|
attribute set <replaceable>attrs</replaceable> in a sorted list.
|
||||||
|
For instance, <literal>builtins.attrNames {y = 1; x =
|
||||||
|
"foo";}</literal> evaluates to <literal>["x" "y"]</literal>.
|
||||||
|
There is no built-in function <function>attrValues</function>, but
|
||||||
|
you can easily define it yourself:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
attrValues = attrs: map (name: builtins.getAttr name attrs) (builtins.attrNames attrs);</programlisting>
|
||||||
|
|
||||||
|
</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>baseNameOf</function> <replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the <emphasis>base name</emphasis> of the
|
||||||
|
string <replaceable>s</replaceable>, that is, everything following
|
||||||
|
the final slash in the string. This is similar to the GNU
|
||||||
|
<command>basename</command> command.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><varname>builtins</varname></term>
|
||||||
|
|
||||||
|
<listitem><para>The attribute set <varname>builtins</varname>
|
||||||
|
contains all the built-in functions and values. You can use
|
||||||
|
<varname>builtins</varname> to test for the availability of
|
||||||
|
features in the Nix installation, e.g.,
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
if builtins ? getEnv then builtins.getEnv "PATH" else ""</programlisting>
|
||||||
|
|
||||||
|
This allows a Nix expression to fall back gracefully on older Nix
|
||||||
|
installations that don’t have the desired built-in
|
||||||
|
function.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.compareVersions</function>
|
||||||
|
<replaceable>s1</replaceable> <replaceable>s2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Compare two strings representing versions and
|
||||||
|
return <literal>-1</literal> if version
|
||||||
|
<replaceable>s1</replaceable> is older than version
|
||||||
|
<replaceable>s2</replaceable>, <literal>0</literal> if they are
|
||||||
|
the same, and <literal>1</literal> if
|
||||||
|
<replaceable>s1</replaceable> is newer than
|
||||||
|
<replaceable>s2</replaceable>. The version comparison algorithm
|
||||||
|
is the same as the one used by <link
|
||||||
|
linkend="ssec-version-comparisons"><command>nix-env
|
||||||
|
-u</command></link>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry
|
||||||
|
xml:id='builtin-currentSystem'><term><varname>builtins.currentSystem</varname></term>
|
||||||
|
|
||||||
|
<listitem><para>The built-in value <varname>currentSystem</varname>
|
||||||
|
evaluates to the Nix platform identifier for the Nix installation
|
||||||
|
on which the expression is being evaluated, such as
|
||||||
|
<literal>"i686-linux"</literal> or
|
||||||
|
<literal>"powerpc-darwin"</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<varlistentry><term><function>currentTime</function></term>
|
||||||
|
|
||||||
|
<listitem><para>The built-in value <varname>currentTime</varname>
|
||||||
|
returns the current system time in seconds since 00:00:00 1/1/1970
|
||||||
|
UTC. Due to the evaluation model of Nix expressions
|
||||||
|
(<emphasis>maximal laziness</emphasis>), it always yields the same
|
||||||
|
value within an execution of Nix.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<varlistentry><term><function>dependencyClosure</function></term>
|
||||||
|
|
||||||
|
<listitem><para>TODO</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>derivation</function>
|
||||||
|
<replaceable>attrs</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para><function>derivation</function> is described in
|
||||||
|
<xref linkend='ssec-derivation' />.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>dirOf</function> <replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the directory part of the string
|
||||||
|
<replaceable>s</replaceable>, that is, everything before the final
|
||||||
|
slash in the string. This is similar to the GNU
|
||||||
|
<command>dirname</command> command.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.div</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the quotient of the integers
|
||||||
|
<replaceable>e1</replaceable> and
|
||||||
|
<replaceable>e2</replaceable>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.filterSource</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
|
||||||
|
<para>This function allows you to copy sources into the Nix
|
||||||
|
store while filtering certain files. For instance, suppose that
|
||||||
|
you want to use the directory <filename>source-dir</filename> as
|
||||||
|
an input to a Nix expression, e.g.
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
...
|
||||||
|
src = ./source-dir;
|
||||||
|
}
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
However, if <filename>source-dir</filename> is a Subversion
|
||||||
|
working copy, then all those annoying <filename>.svn</filename>
|
||||||
|
subdirectories will also be copied to the store. Worse, the
|
||||||
|
contents of those directories may change a lot, causing lots of
|
||||||
|
spurious rebuilds. With <function>filterSource</function> you
|
||||||
|
can filter out the <filename>.svn</filename> directories:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
src = builtins.filterSource
|
||||||
|
(path: type: type != "directory" || baseNameOf path != ".svn")
|
||||||
|
./source-dir;
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>Thus, the first argument <replaceable>e1</replaceable>
|
||||||
|
must be a predicate function that is called for each regular
|
||||||
|
file, directory or symlink in the source tree
|
||||||
|
<replaceable>e2</replaceable>. If the function returns
|
||||||
|
<literal>true</literal>, the file is copied to the Nix store,
|
||||||
|
otherwise it is omitted. The function is called with two
|
||||||
|
arguments. The first is the full path of the file. The second
|
||||||
|
is a string that identifies the type of the file, which is
|
||||||
|
either <literal>"regular"</literal>,
|
||||||
|
<literal>"directory"</literal>, <literal>"symlink"</literal> or
|
||||||
|
<literal>"unknown"</literal> (for other kinds of files such as
|
||||||
|
device nodes or fifos — but note that those cannot be copied to
|
||||||
|
the Nix store, so if the predicate returns
|
||||||
|
<literal>true</literal> for them, the copy will fail).</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.getAttr</function>
|
||||||
|
<replaceable>s</replaceable> <replaceable>attrs</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para><function>getAttr</function> returns the attribute
|
||||||
|
named <replaceable>s</replaceable> from the attribute set
|
||||||
|
<replaceable>attrs</replaceable>. Evaluation aborts if the
|
||||||
|
attribute doesn’t exist. This is a dynamic version of the
|
||||||
|
<literal>.</literal> operator, since <replaceable>s</replaceable>
|
||||||
|
is an expression rather than an identifier.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.getEnv</function>
|
||||||
|
<replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para><function>getEnv</function> returns the value of
|
||||||
|
the environment variable <replaceable>s</replaceable>, or an empty
|
||||||
|
string if the variable doesn’t exist. This function should be
|
||||||
|
used with care, as it can introduce all sorts of nasty environment
|
||||||
|
dependencies in your Nix expression.</para>
|
||||||
|
|
||||||
|
<para><function>getEnv</function> is used in Nix Packages to
|
||||||
|
locate the file <filename>~/.nixpkgs/config.nix</filename>, which
|
||||||
|
contains user-local settings for Nix Packages. (That is, it does
|
||||||
|
a <literal>getEnv "HOME"</literal> to locate the user’s home
|
||||||
|
directory.)</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.hasAttr</function>
|
||||||
|
<replaceable>s</replaceable> <replaceable>attrs</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para><function>hasAttr</function> returns
|
||||||
|
<literal>true</literal> if the attribute set
|
||||||
|
<replaceable>attrs</replaceable> has an attribute named
|
||||||
|
<replaceable>s</replaceable>, and <literal>false</literal>
|
||||||
|
otherwise. This is a dynamic version of the <literal>?</literal>
|
||||||
|
operator, since <replaceable>s</replaceable> is an expression
|
||||||
|
rather than an identifier.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.head</function>
|
||||||
|
<replaceable>list</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the first element of a list; abort
|
||||||
|
evaluation if the argument isn’t a list or is an empty list. You
|
||||||
|
can test whether a list is empty by comparing it with
|
||||||
|
<literal>[]</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>import</function>
|
||||||
|
<replaceable>path</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Load, parse and return the Nix expression in the
|
||||||
|
file <replaceable>path</replaceable>. Evaluation aborts if the
|
||||||
|
file doesn’t exist or contains an incorrect Nix
|
||||||
|
expression. <function>import</function> implements Nix’s module
|
||||||
|
system: you can put any Nix expression (such as an attribute set
|
||||||
|
or a function) in a separate file, and use it from Nix expressions
|
||||||
|
in other files.</para>
|
||||||
|
|
||||||
|
<para>A Nix expression loaded by <function>import</function> must
|
||||||
|
not contain any <emphasis>free variables</emphasis> (identifiers
|
||||||
|
that are not defined in the Nix expression itself and are not
|
||||||
|
built-in). Therefore, it cannot refer to variables that are in
|
||||||
|
scope at the call site. For instance, if you have a calling
|
||||||
|
expression
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
rec {
|
||||||
|
x = 123;
|
||||||
|
y = import ./foo.nix;
|
||||||
|
}</programlisting>
|
||||||
|
|
||||||
|
then the following <filename>foo.nix</filename> will give an
|
||||||
|
error:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
x + 456</programlisting>
|
||||||
|
|
||||||
|
since <varname>x</varname> is not in scope in
|
||||||
|
<filename>foo.nix</filename>. If you want <varname>x</varname>
|
||||||
|
to be available in <filename>foo.nix</filename>, you should pass
|
||||||
|
it as a function argument:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
rec {
|
||||||
|
x = 123;
|
||||||
|
y = import ./foo.nix x;
|
||||||
|
}</programlisting>
|
||||||
|
|
||||||
|
and
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
x: x + 456</programlisting>
|
||||||
|
|
||||||
|
(The function argument doesn’t have to be called
|
||||||
|
<varname>x</varname> in <filename>foo.nix</filename>; any name
|
||||||
|
would work.)</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.isAttrs</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to an attribute set, and
|
||||||
|
<literal>false</literal> otherwise.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.isList</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to a list, and
|
||||||
|
<literal>false</literal> otherwise.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.isFunction</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to a function, and
|
||||||
|
<literal>false</literal> otherwise.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.isString</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to a string, and
|
||||||
|
<literal>false</literal> otherwise.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.isInt</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to a int, and
|
||||||
|
<literal>false</literal> otherwise.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.isBool</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to a bool, and
|
||||||
|
<literal>false</literal> otherwise.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>isNull</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if
|
||||||
|
<replaceable>e</replaceable> evaluates to <literal>null</literal>,
|
||||||
|
and <literal>false</literal> otherwise.</para>
|
||||||
|
|
||||||
|
<warning><para>This function is <emphasis>deprecated</emphasis>;
|
||||||
|
just write <literal>e == null</literal> instead.</para></warning>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.length</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the length of the list
|
||||||
|
<replaceable>e</replaceable>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.lessThan</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if the integer
|
||||||
|
<replaceable>e1</replaceable> is less than the integer
|
||||||
|
<replaceable>e2</replaceable>, and <literal>false</literal>
|
||||||
|
otherwise. Evaluation aborts if either
|
||||||
|
<replaceable>e1</replaceable> or <replaceable>e2</replaceable>
|
||||||
|
does not evaluate to an integer.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.listToAttrs</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Construct an attribute set from a list specifying
|
||||||
|
the names and values of each attribute. Each element of the list
|
||||||
|
should be an attribute set consisting of a string-valued attribute
|
||||||
|
<varname>name</varname> specifying the name of the attribute, and
|
||||||
|
an attribute <varname>value</varname> specifying its value.
|
||||||
|
Example:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
builtins.listToAttrs [
|
||||||
|
{name = "foo"; value = 123;}
|
||||||
|
{name = "bar"; value = 456;}
|
||||||
|
]
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
evaluates to
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
{ foo = 123; bar = 456; }
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><function>map</function>
|
||||||
|
<replaceable>f</replaceable> <replaceable>list</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Apply the function <replaceable>f</replaceable> to
|
||||||
|
each element in the list <replaceable>list</replaceable>. For
|
||||||
|
example,
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
map (x: "foo" + x) ["bar" "bla" "abc"]</programlisting>
|
||||||
|
|
||||||
|
evaluates to <literal>["foobar" "foobla"
|
||||||
|
"fooabc"]</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.mul</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the product of the integers
|
||||||
|
<replaceable>e1</replaceable> and
|
||||||
|
<replaceable>e2</replaceable>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.parseDrvName</function>
|
||||||
|
<replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Split the string <replaceable>s</replaceable> into
|
||||||
|
a package name and version. The package name is everything up to
|
||||||
|
but not including the first dash followed by a digit, and the
|
||||||
|
version is everything following that dash. The result is returned
|
||||||
|
in an attribute set <literal>{name, version}</literal>. Thus,
|
||||||
|
<literal>builtins.parseDrvName "nix-0.12pre12876"</literal>
|
||||||
|
returns <literal>{name = "nix"; version =
|
||||||
|
"0.12pre12876";}</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.pathExists</function>
|
||||||
|
<replaceable>path</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return <literal>true</literal> if the path
|
||||||
|
<replaceable>path</replaceable> exists, and
|
||||||
|
<literal>false</literal> otherwise. One application of this
|
||||||
|
function is to conditionally include a Nix expression containing
|
||||||
|
user configuration:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
let
|
||||||
|
fileName = builtins.getEnv "CONFIG_FILE";
|
||||||
|
config =
|
||||||
|
if fileName != "" && builtins.pathExists (builtins.toPath fileName)
|
||||||
|
then import (builtins.toPath fileName)
|
||||||
|
else { someSetting = false; }; <lineannotation># default configuration</lineannotation>
|
||||||
|
in config.someSetting</programlisting>
|
||||||
|
|
||||||
|
(Note that <envar>CONFIG_FILE</envar> must be an absolute path for
|
||||||
|
this to work.)</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<varlistentry><term><function>relativise</function></term>
|
||||||
|
|
||||||
|
<listitem><para>TODO</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.readFile</function>
|
||||||
|
<replaceable>path</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the contents of the file
|
||||||
|
<replaceable>path</replaceable> as a string.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>removeAttrs</function>
|
||||||
|
<replaceable>attrs</replaceable> <replaceable>list</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Remove the attributes listed in
|
||||||
|
<replaceable>list</replaceable> from the attribute set
|
||||||
|
<replaceable>attrs</replaceable>. The attributes don’t have to
|
||||||
|
exist in <replaceable>attrs</replaceable>. For instance,
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
removeAttrs { x = 1; y = 2; z = 3; } ["a" "x" "z"]</screen>
|
||||||
|
|
||||||
|
evaluates to <literal>{y = 2;}</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.stringLength</function>
|
||||||
|
<replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the length of the string
|
||||||
|
<replaceable>e</replaceable>. If <replaceable>e</replaceable> is
|
||||||
|
not a string, evaluation is aborted.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.sub</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the difference between the integers
|
||||||
|
<replaceable>e1</replaceable> and
|
||||||
|
<replaceable>e2</replaceable>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.substring</function>
|
||||||
|
<replaceable>start</replaceable> <replaceable>len</replaceable>
|
||||||
|
<replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the substring of
|
||||||
|
<replaceable>s</replaceable> from character position
|
||||||
|
<replaceable>start</replaceable> (zero-based) up to but not
|
||||||
|
including <replaceable>start + len</replaceable>. If
|
||||||
|
<replaceable>start</replaceable> is greater than the length of the
|
||||||
|
string, an empty string is returned, and if <replaceable>start +
|
||||||
|
len</replaceable> lies beyond the end of the string, only the
|
||||||
|
substring up to the end of the string is returned.
|
||||||
|
<replaceable>start</replaceable> must be
|
||||||
|
non-negative.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.tail</function>
|
||||||
|
<replaceable>list</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the second to last elements of a list;
|
||||||
|
abort evaluation if the argument isn’t a list or is an empty
|
||||||
|
list.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>throw</function>
|
||||||
|
<replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Throw an error message
|
||||||
|
<replaceable>s</replaceable>. This usually aborts Nix expression
|
||||||
|
evaluation, but in <command>nix-env -qa</command> and other
|
||||||
|
commands that try to evaluate a set of derivations to get
|
||||||
|
information about those derivations, a derivation that throws an
|
||||||
|
error is silently skipped (which is not the case for
|
||||||
|
<function>abort</function>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry
|
||||||
|
xml:id='builtin-toFile'><term><function>builtins.toFile</function>
|
||||||
|
<replaceable>name</replaceable> <replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Store the string <replaceable>s</replaceable> in a
|
||||||
|
file in the Nix store and return its path. The file has suffix
|
||||||
|
<replaceable>name</replaceable>. This file can be used as an
|
||||||
|
input to derivations. One application is to write builders
|
||||||
|
“inline”. For instance, the following Nix expression combines
|
||||||
|
<xref linkend='ex-hello-nix' /> and <xref
|
||||||
|
linkend='ex-hello-builder' /> into one file:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
{stdenv, fetchurl, perl}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "hello-2.1.1";
|
||||||
|
|
||||||
|
builder = builtins.toFile "builder.sh" "
|
||||||
|
source $stdenv/setup
|
||||||
|
|
||||||
|
PATH=$perl/bin:$PATH
|
||||||
|
|
||||||
|
tar xvfz $src
|
||||||
|
cd hello-*
|
||||||
|
./configure --prefix=$out
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
";
|
||||||
|
|
||||||
|
src = fetchurl {
|
||||||
|
url = http://nix.cs.uu.nl/dist/tarballs/hello-2.1.1.tar.gz;
|
||||||
|
md5 = "70c9ccf9fac07f762c24f2df2290784d";
|
||||||
|
};
|
||||||
|
inherit perl;
|
||||||
|
}</programlisting>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>It is even possible for one file to refer to another, e.g.,
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
builder = let
|
||||||
|
configFile = builtins.toFile "foo.conf" "
|
||||||
|
# This is some dummy configuration file.
|
||||||
|
<replaceable>...</replaceable>
|
||||||
|
";
|
||||||
|
in builtins.toFile "builder.sh" "
|
||||||
|
source $stdenv/setup
|
||||||
|
<replaceable>...</replaceable>
|
||||||
|
cp ${configFile} $out/etc/foo.conf
|
||||||
|
";</programlisting>
|
||||||
|
|
||||||
|
Note that <literal>${configFile}</literal> is an antiquotation
|
||||||
|
(see <xref linkend='ssec-values' />), so the result of the
|
||||||
|
expression <literal>configFile</literal> (i.e., a path like
|
||||||
|
<filename>/nix/store/m7p7jfny445k...-foo.conf</filename>) will be
|
||||||
|
spliced into the resulting string.</para>
|
||||||
|
|
||||||
|
<para>It is however <emphasis>not</emphasis> allowed to have files
|
||||||
|
mutually referring to each other, like so:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
let
|
||||||
|
foo = builtins.toFile "foo" "...${bar}...";
|
||||||
|
bar = builtins.toFile "bar" "...${foo}...";
|
||||||
|
in foo</programlisting>
|
||||||
|
|
||||||
|
This is not allowed because it would cause a cyclic dependency in
|
||||||
|
the computation of the cryptographic hashes for
|
||||||
|
<varname>foo</varname> and <varname>bar</varname>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.toPath</function> <replaceable>s</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Convert the string value
|
||||||
|
<replaceable>s</replaceable> into a path value. The string
|
||||||
|
<replaceable>s</replaceable> must represent an absolute path
|
||||||
|
(i.e., must start with <literal>/</literal>). The path need not
|
||||||
|
exist. The resulting path is canonicalised, e.g.,
|
||||||
|
<literal>builtins.toPath "//foo/xyzzy/../bar/"</literal> returns
|
||||||
|
<literal>/foo/bar</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>toString</function> <replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Convert the expression
|
||||||
|
<replaceable>e</replaceable> to a string.
|
||||||
|
<replaceable>e</replaceable> can be a string (in which case
|
||||||
|
<function>toString</function> is a no-op) or a path (e.g.,
|
||||||
|
<literal>toString /foo/bar</literal> yields
|
||||||
|
<literal>"/foo/bar"</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id='builtin-toXML'><term><function>builtins.toXML</function> <replaceable>e</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return a string containing an XML representation
|
||||||
|
of <replaceable>e</replaceable>. The main application for
|
||||||
|
<function>toXML</function> is to communicate information with the
|
||||||
|
builder in a more structured format than plain environment
|
||||||
|
variables.</para>
|
||||||
|
|
||||||
|
<!-- TODO: more formally describe the schema of the XML
|
||||||
|
representation -->
|
||||||
|
|
||||||
|
<para><xref linkend='ex-toxml' /> shows an example where this is
|
||||||
|
the case. The builder is supposed to generate the configuration
|
||||||
|
file for a <link xlink:href='http://jetty.mortbay.org/'>Jetty
|
||||||
|
servlet container</link>. A servlet container contains a number
|
||||||
|
of servlets (<filename>*.war</filename> files) each exported under
|
||||||
|
a specific URI prefix. So the servlet configuration is a list of
|
||||||
|
attribute sets containing the <varname>path</varname> and
|
||||||
|
<varname>war</varname> of the servlet (<xref
|
||||||
|
linkend='ex-toxml-co-servlets' />). This kind of information is
|
||||||
|
difficult to communicate with the normal method of passing
|
||||||
|
information through an environment variable, which just
|
||||||
|
concatenates everything together into a string (which might just
|
||||||
|
work in this case, but wouldn’t work if fields are optional or
|
||||||
|
contain lists themselves). Instead the Nix expression is
|
||||||
|
converted to an XML representation with
|
||||||
|
<function>toXML</function>, which is unambiguous and can easily be
|
||||||
|
processed with the appropriate tools. For instance, in the
|
||||||
|
example an XSLT stylesheet (<xref linkend='ex-toxml-co-stylesheet'
|
||||||
|
/>) is applied to it (<xref linkend='ex-toxml-co-apply' />) to
|
||||||
|
generate the XML configuration file for the Jetty server. The XML
|
||||||
|
representation produced from <xref linkend='ex-toxml-co-servlets'
|
||||||
|
/> by <function>toXML</function> is shown in <xref
|
||||||
|
linkend='ex-toxml-result' />.</para>
|
||||||
|
|
||||||
|
<para>Note that <xref linkend='ex-toxml' /> uses the <function
|
||||||
|
linkend='builtin-toFile'>toFile</function> built-in to write the
|
||||||
|
builder and the stylesheet “inline” in the Nix expression. The
|
||||||
|
path of the stylesheet is spliced into the builder at
|
||||||
|
<literal>xsltproc ${stylesheet}
|
||||||
|
<replaceable>...</replaceable></literal>.</para>
|
||||||
|
|
||||||
|
<example xml:id='ex-toxml'><title>Passing information to a builder
|
||||||
|
using <function>toXML</function></title>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[
|
||||||
|
{stdenv, fetchurl, libxslt, jira, uberwiki}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation (rec {
|
||||||
|
name = "web-server";
|
||||||
|
|
||||||
|
buildInputs = [libxslt];
|
||||||
|
|
||||||
|
builder = builtins.toFile "builder.sh" "
|
||||||
|
source $stdenv/setup
|
||||||
|
mkdir $out
|
||||||
|
echo $servlets | xsltproc ${stylesheet} - > $out/server-conf.xml]]> <co xml:id='ex-toxml-co-apply' /> <![CDATA[
|
||||||
|
";
|
||||||
|
|
||||||
|
stylesheet = builtins.toFile "stylesheet.xsl"]]> <co xml:id='ex-toxml-co-stylesheet' /> <![CDATA[
|
||||||
|
"<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
|
||||||
|
<xsl:template match='/'>
|
||||||
|
<Configure>
|
||||||
|
<xsl:for-each select='/expr/list/attrs'>
|
||||||
|
<Call name='addWebApplication'>
|
||||||
|
<Arg><xsl:value-of select=\"attr[@name = 'path']/string/@value\" /></Arg>
|
||||||
|
<Arg><xsl:value-of select=\"attr[@name = 'war']/path/@value\" /></Arg>
|
||||||
|
</Call>
|
||||||
|
</xsl:for-each>
|
||||||
|
</Configure>
|
||||||
|
</xsl:template>
|
||||||
|
</xsl:stylesheet>
|
||||||
|
";
|
||||||
|
|
||||||
|
servlets = builtins.toXML []]> <co xml:id='ex-toxml-co-servlets' /> <![CDATA[
|
||||||
|
{ path = "/bugtracker"; war = jira + "/lib/atlassian-jira.war"; }
|
||||||
|
{ path = "/wiki"; war = uberwiki + "/uberwiki.war"; }
|
||||||
|
];
|
||||||
|
})]]></programlisting>
|
||||||
|
|
||||||
|
</example>
|
||||||
|
|
||||||
|
<example xml:id='ex-toxml-result'><title>XML representation produced by
|
||||||
|
<function>toXML</function></title>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<expr>
|
||||||
|
<list>
|
||||||
|
<attrs>
|
||||||
|
<attr name="path">
|
||||||
|
<string value="/bugtracker" />
|
||||||
|
</attr>
|
||||||
|
<attr name="war">
|
||||||
|
<path value="/nix/store/d1jh9pasa7k2...-jira/lib/atlassian-jira.war" />
|
||||||
|
</attr>
|
||||||
|
</attrs>
|
||||||
|
<attrs>
|
||||||
|
<attr name="path">
|
||||||
|
<string value="/wiki" />
|
||||||
|
</attr>
|
||||||
|
<attr name="war">
|
||||||
|
<path value="/nix/store/y6423b1yi4sx...-uberwiki/uberwiki.war" />
|
||||||
|
</attr>
|
||||||
|
</attrs>
|
||||||
|
</list>
|
||||||
|
</expr>]]></programlisting>
|
||||||
|
|
||||||
|
</example>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.trace</function>
|
||||||
|
<replaceable>e1</replaceable> <replaceable>e2</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Evaluate <replaceable>e1</replaceable> and print its
|
||||||
|
abstract syntax representation on standard error. Then return
|
||||||
|
<replaceable>e2</replaceable>. This function is useful for
|
||||||
|
debugging.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<part xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='part-command-ref'>
|
|
||||||
|
|
||||||
<title>Command Reference</title>
|
|
||||||
|
|
||||||
<partintro>
|
|
||||||
<para>This section lists commands and options that you can use when you
|
|
||||||
work with Nix.</para>
|
|
||||||
</partintro>
|
|
||||||
|
|
||||||
<xi:include href="opt-common.xml" />
|
|
||||||
<xi:include href="env-common.xml" />
|
|
||||||
<xi:include href="main-commands.xml" />
|
|
||||||
<xi:include href="utilities.xml" />
|
|
||||||
<xi:include href="files.xml" />
|
|
||||||
|
|
||||||
</part>
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,209 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-common-env">
|
|
||||||
|
|
||||||
<title>Common Environment Variables</title>
|
|
||||||
|
|
||||||
|
|
||||||
<para>Most Nix commands interpret the following environment variables:</para>
|
|
||||||
|
|
||||||
<variablelist xml:id="env-common">
|
|
||||||
|
|
||||||
<varlistentry><term><envar>IN_NIX_SHELL</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Indicator that tells if the current environment was set up by
|
|
||||||
<command>nix-shell</command>. Since Nix 2.0 the values are
|
|
||||||
<literal>"pure"</literal> and <literal>"impure"</literal></para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry xml:id="env-NIX_PATH"><term><envar>NIX_PATH</envar></term>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
|
|
||||||
<para>A colon-separated list of directories used to look up Nix
|
|
||||||
expressions enclosed in angle brackets (i.e.,
|
|
||||||
<literal><<replaceable>path</replaceable>></literal>). For
|
|
||||||
instance, the value
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
/home/eelco/Dev:/etc/nixos</screen>
|
|
||||||
|
|
||||||
will cause Nix to look for paths relative to
|
|
||||||
<filename>/home/eelco/Dev</filename> and
|
|
||||||
<filename>/etc/nixos</filename>, in this order. It is also
|
|
||||||
possible to match paths against a prefix. For example, the value
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos</screen>
|
|
||||||
|
|
||||||
will cause Nix to search for
|
|
||||||
<literal><nixpkgs/<replaceable>path</replaceable>></literal> in
|
|
||||||
<filename>/home/eelco/Dev/nixpkgs-branch/<replaceable>path</replaceable></filename>
|
|
||||||
and
|
|
||||||
<filename>/etc/nixos/nixpkgs/<replaceable>path</replaceable></filename>.</para>
|
|
||||||
|
|
||||||
<para>If a path in the Nix search path starts with
|
|
||||||
<literal>http://</literal> or <literal>https://</literal>, it is
|
|
||||||
interpreted as the URL of a tarball that will be downloaded and
|
|
||||||
unpacked to a temporary location. The tarball must consist of a
|
|
||||||
single top-level directory. For example, setting
|
|
||||||
<envar>NIX_PATH</envar> to
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-15.09.tar.gz</screen>
|
|
||||||
|
|
||||||
tells Nix to download the latest revision in the Nixpkgs/NixOS
|
|
||||||
15.09 channel.</para>
|
|
||||||
|
|
||||||
<para>A following shorthand can be used to refer to the official channels:
|
|
||||||
|
|
||||||
<screen>nixpkgs=channel:nixos-15.09</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The search path can be extended using the <option
|
|
||||||
linkend="opt-I">-I</option> option, which takes precedence over
|
|
||||||
<envar>NIX_PATH</envar>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
|
|
||||||
<para>Normally, the Nix store directory (typically
|
|
||||||
<filename>/nix/store</filename>) is not allowed to contain any
|
|
||||||
symlink components. This is to prevent “impure” builds. Builders
|
|
||||||
sometimes “canonicalise” paths by resolving all symlink components.
|
|
||||||
Thus, builds on different machines (with
|
|
||||||
<filename>/nix/store</filename> resolving to different locations)
|
|
||||||
could yield different results. This is generally not a problem,
|
|
||||||
except when builds are deployed to machines where
|
|
||||||
<filename>/nix/store</filename> resolves differently. If you are
|
|
||||||
sure that you’re not going to do that, you can set
|
|
||||||
<envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>
|
|
||||||
|
|
||||||
<para>Note that if you’re symlinking the Nix store so that you can
|
|
||||||
put it on another file system than the root file system, on Linux
|
|
||||||
you’re better off using <literal>bind</literal> mount points, e.g.,
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ mkdir /nix
|
|
||||||
$ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|
||||||
|
|
||||||
Consult the <citerefentry><refentrytitle>mount</refentrytitle>
|
|
||||||
<manvolnum>8</manvolnum></citerefentry> manual page for details.</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_STORE_DIR</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Overrides the location of the Nix store (default
|
|
||||||
<filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_DATA_DIR</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Overrides the location of the Nix static data
|
|
||||||
directory (default
|
|
||||||
<filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_LOG_DIR</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Overrides the location of the Nix log directory
|
|
||||||
(default <filename><replaceable>prefix</replaceable>/var/log/nix</filename>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_STATE_DIR</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Overrides the location of the Nix state directory
|
|
||||||
(default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_CONF_DIR</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Overrides the location of the system Nix configuration
|
|
||||||
directory (default
|
|
||||||
<filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_USER_CONF_FILES</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Overrides the location of the user Nix configuration files
|
|
||||||
to load from (defaults to the XDG spec locations). The variable is treated
|
|
||||||
as a list separated by the <literal>:</literal> token.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><envar>TMPDIR</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Use the specified directory to store temporary
|
|
||||||
files. In particular, this includes temporary build directories;
|
|
||||||
these can take up substantial amounts of disk space. The default is
|
|
||||||
<filename>/tmp</filename>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>This variable should be set to
|
|
||||||
<literal>daemon</literal> if you want to use the Nix daemon to
|
|
||||||
execute Nix operations. This is necessary in <link
|
|
||||||
linkend="ssec-multi-user">multi-user Nix installations</link>.
|
|
||||||
If the Nix daemon's Unix socket is at some non-standard path,
|
|
||||||
this variable should be set to <literal>unix://path/to/socket</literal>.
|
|
||||||
Otherwise, it should be left unset.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_SHOW_STATS</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>If set to <literal>1</literal>, Nix will print some
|
|
||||||
evaluation statistics, such as the number of values
|
|
||||||
allocated.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_COUNT_CALLS</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>If set to <literal>1</literal>, Nix will print how
|
|
||||||
often functions were called during Nix expression evaluation. This
|
|
||||||
is useful for profiling your Nix expressions.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><envar>GC_INITIAL_HEAP_SIZE</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>If Nix has been configured to use the Boehm garbage
|
|
||||||
collector, this variable sets the initial size of the heap in bytes.
|
|
||||||
It defaults to 384 MiB. Setting it to a low value reduces memory
|
|
||||||
consumption, but will increase runtime due to the overhead of
|
|
||||||
garbage collection.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='ch-files'>
|
|
||||||
|
|
||||||
<title>Files</title>
|
|
||||||
|
|
||||||
<para>This section lists configuration files that you can use when you
|
|
||||||
work with Nix.</para>
|
|
||||||
|
|
||||||
<xi:include href="conf-file.xml" />
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='ch-main-commands'>
|
|
||||||
|
|
||||||
<title>Main Commands</title>
|
|
||||||
|
|
||||||
<para>This section lists commands and options that you can use when you
|
|
||||||
work with Nix.</para>
|
|
||||||
|
|
||||||
<xi:include href="nix-env.xml" />
|
|
||||||
<xi:include href="nix-build.xml" />
|
|
||||||
<xi:include href="nix-shell.xml" />
|
|
||||||
<xi:include href="nix-store.xml" />
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,181 +0,0 @@
|
|||||||
<refentry xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-nix-channel">
|
|
||||||
|
|
||||||
<refmeta>
|
|
||||||
<refentrytitle>nix-channel</refentrytitle>
|
|
||||||
<manvolnum>1</manvolnum>
|
|
||||||
<refmiscinfo class="source">Nix</refmiscinfo>
|
|
||||||
<refmiscinfo class="version"><xi:include href="../version.txt" parse="text"/></refmiscinfo>
|
|
||||||
</refmeta>
|
|
||||||
|
|
||||||
<refnamediv>
|
|
||||||
<refname>nix-channel</refname>
|
|
||||||
<refpurpose>manage Nix channels</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-channel</command>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--add</option> <replaceable>url</replaceable> <arg choice='opt'><replaceable>name</replaceable></arg></arg>
|
|
||||||
<arg choice='plain'><option>--remove</option> <replaceable>name</replaceable></arg>
|
|
||||||
<arg choice='plain'><option>--list</option></arg>
|
|
||||||
<arg choice='plain'><option>--update</option> <arg rep='repeat'><replaceable>names</replaceable></arg></arg>
|
|
||||||
<arg choice='plain'><option>--rollback</option> <arg choice='opt'><replaceable>generation</replaceable></arg></arg>
|
|
||||||
</group>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>A Nix channel is a mechanism that allows you to automatically
|
|
||||||
stay up-to-date with a set of pre-built Nix expressions. A Nix
|
|
||||||
channel is just a URL that points to a place containing a set of Nix
|
|
||||||
expressions. <phrase condition="manual">See also <xref
|
|
||||||
linkend="sec-channels" />.</phrase></para>
|
|
||||||
|
|
||||||
<para>To see the list of official NixOS channels, visit <link
|
|
||||||
xlink:href="https://nixos.org/channels" />.</para>
|
|
||||||
|
|
||||||
<para>This command has the following operations:
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--add</option> <replaceable>url</replaceable> [<replaceable>name</replaceable>]</term>
|
|
||||||
|
|
||||||
<listitem><para>Adds a channel named
|
|
||||||
<replaceable>name</replaceable> with URL
|
|
||||||
<replaceable>url</replaceable> to the list of subscribed channels.
|
|
||||||
If <replaceable>name</replaceable> is omitted, it defaults to the
|
|
||||||
last component of <replaceable>url</replaceable>, with the
|
|
||||||
suffixes <literal>-stable</literal> or
|
|
||||||
<literal>-unstable</literal> removed.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--remove</option> <replaceable>name</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Removes the channel named
|
|
||||||
<replaceable>name</replaceable> from the list of subscribed
|
|
||||||
channels.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--list</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Prints the names and URLs of all subscribed
|
|
||||||
channels on standard output.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--update</option> [<replaceable>names</replaceable>…]</term>
|
|
||||||
|
|
||||||
<listitem><para>Downloads the Nix expressions of all subscribed
|
|
||||||
channels (or only those included in
|
|
||||||
<replaceable>names</replaceable> if specified) and makes them the
|
|
||||||
default for <command>nix-env</command> operations (by symlinking
|
|
||||||
them from the directory
|
|
||||||
<filename>~/.nix-defexpr</filename>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--rollback</option> [<replaceable>generation</replaceable>]</term>
|
|
||||||
|
|
||||||
<listitem><para>Reverts the previous call to <command>nix-channel
|
|
||||||
--update</command>. Optionally, you can specify a specific channel
|
|
||||||
generation number to restore.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Note that <option>--add</option> does not automatically perform
|
|
||||||
an update.</para>
|
|
||||||
|
|
||||||
<para>The list of subscribed channels is stored in
|
|
||||||
<filename>~/.nix-channels</filename>.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Examples</title>
|
|
||||||
|
|
||||||
<para>To subscribe to the Nixpkgs channel and install the GNU Hello package:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
|
|
||||||
$ nix-channel --update
|
|
||||||
$ nix-env -iA nixpkgs.hello</screen>
|
|
||||||
|
|
||||||
<para>You can revert channel updates using <option>--rollback</option>:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
|
|
||||||
"14.04.527.0e935f1"
|
|
||||||
|
|
||||||
$ nix-channel --rollback
|
|
||||||
switching from generation 483 to 482
|
|
||||||
|
|
||||||
$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
|
|
||||||
"14.04.526.dbadfad"
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Files</title>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><filename>/nix/var/nix/profiles/per-user/<replaceable>username</replaceable>/channels</filename></term>
|
|
||||||
|
|
||||||
<listitem><para><command>nix-channel</command> uses a
|
|
||||||
<command>nix-env</command> profile to keep track of previous
|
|
||||||
versions of the subscribed channels. Every time you run
|
|
||||||
<command>nix-channel --update</command>, a new channel generation
|
|
||||||
(that is, a symlink to the channel Nix expressions in the Nix store)
|
|
||||||
is created. This enables <command>nix-channel --rollback</command>
|
|
||||||
to revert to previous versions.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><filename>~/.nix-defexpr/channels</filename></term>
|
|
||||||
|
|
||||||
<listitem><para>This is a symlink to
|
|
||||||
<filename>/nix/var/nix/profiles/per-user/<replaceable>username</replaceable>/channels</filename>. It
|
|
||||||
ensures that <command>nix-env</command> can find your channels. In
|
|
||||||
a multi-user installation, you may also have
|
|
||||||
<filename>~/.nix-defexpr/channels_root</filename>, which links to
|
|
||||||
the channels of the root user.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Channel format</title>
|
|
||||||
|
|
||||||
<para>A channel URL should point to a directory containing the
|
|
||||||
following files:</para>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><filename>nixexprs.tar.xz</filename></term>
|
|
||||||
|
|
||||||
<listitem><para>A tarball containing Nix expressions and files
|
|
||||||
referenced by them (such as build scripts and patches). At the
|
|
||||||
top level, the tarball should contain a single directory. That
|
|
||||||
directory must contain a file <filename>default.nix</filename>
|
|
||||||
that serves as the channel’s “entry point”.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
</refentry>
|
|
||||||
@@ -1,266 +0,0 @@
|
|||||||
<refentry xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-nix-instantiate">
|
|
||||||
|
|
||||||
<refmeta>
|
|
||||||
<refentrytitle>nix-instantiate</refentrytitle>
|
|
||||||
<manvolnum>1</manvolnum>
|
|
||||||
<refmiscinfo class="source">Nix</refmiscinfo>
|
|
||||||
<refmiscinfo class="version"><xi:include href="../version.txt" parse="text"/></refmiscinfo>
|
|
||||||
</refmeta>
|
|
||||||
|
|
||||||
<refnamediv>
|
|
||||||
<refname>nix-instantiate</refname>
|
|
||||||
<refpurpose>instantiate store derivations from Nix expressions</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-instantiate</command>
|
|
||||||
<group>
|
|
||||||
<arg choice='plain'><option>--parse</option></arg>
|
|
||||||
<arg choice='plain'>
|
|
||||||
<option>--eval</option>
|
|
||||||
<arg><option>--strict</option></arg>
|
|
||||||
<arg><option>--json</option></arg>
|
|
||||||
<arg><option>--xml</option></arg>
|
|
||||||
</arg>
|
|
||||||
</group>
|
|
||||||
<arg><option>--read-write-mode</option></arg>
|
|
||||||
<arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--attr</option></arg>
|
|
||||||
<arg choice='plain'><option>-A</option></arg>
|
|
||||||
</group>
|
|
||||||
<replaceable>attrPath</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg><option>--add-root</option> <replaceable>path</replaceable></arg>
|
|
||||||
<arg><option>--indirect</option></arg>
|
|
||||||
<group>
|
|
||||||
<arg choice='plain'><option>--expr</option></arg>
|
|
||||||
<arg choice='plain'><option>-E</option></arg>
|
|
||||||
</group>
|
|
||||||
<arg choice='plain' rep='repeat'><replaceable>files</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-instantiate</command>
|
|
||||||
<arg choice='plain'><option>--find-file</option></arg>
|
|
||||||
<arg choice='plain' rep='repeat'><replaceable>files</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The command <command>nix-instantiate</command> generates <link
|
|
||||||
linkend="gloss-derivation">store derivations</link> from (high-level)
|
|
||||||
Nix expressions. It evaluates the Nix expressions in each of
|
|
||||||
<replaceable>files</replaceable> (which defaults to
|
|
||||||
<replaceable>./default.nix</replaceable>). Each top-level expression
|
|
||||||
should evaluate to a derivation, a list of derivations, or a set of
|
|
||||||
derivations. The paths of the resulting store derivations are printed
|
|
||||||
on standard output.</para>
|
|
||||||
|
|
||||||
<para>If <replaceable>files</replaceable> is the character
|
|
||||||
<literal>-</literal>, then a Nix expression will be read from standard
|
|
||||||
input.</para>
|
|
||||||
|
|
||||||
<para condition="manual">See also <xref linkend="sec-common-options"
|
|
||||||
/> for a list of common options.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Options</title>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry>
|
|
||||||
<term><option>--add-root</option> <replaceable>path</replaceable></term>
|
|
||||||
<term><option>--indirect</option></term>
|
|
||||||
|
|
||||||
<listitem><para>See the <link linkend="opt-add-root">corresponding
|
|
||||||
options</link> in <command>nix-store</command>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--parse</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Just parse the input files, and print their
|
|
||||||
abstract syntax trees on standard output in ATerm
|
|
||||||
format.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--eval</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Just parse and evaluate the input files, and print
|
|
||||||
the resulting values on standard output. No instantiation of
|
|
||||||
store derivations takes place.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--find-file</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Look up the given files in Nix’s search path (as
|
|
||||||
specified by the <envar linkend="env-NIX_PATH">NIX_PATH</envar>
|
|
||||||
environment variable). If found, print the corresponding absolute
|
|
||||||
paths on standard output. For instance, if
|
|
||||||
<envar>NIX_PATH</envar> is
|
|
||||||
<literal>nixpkgs=/home/alice/nixpkgs</literal>, then
|
|
||||||
<literal>nix-instantiate --find-file nixpkgs/default.nix</literal>
|
|
||||||
will print
|
|
||||||
<literal>/home/alice/nixpkgs/default.nix</literal>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--strict</option></term>
|
|
||||||
|
|
||||||
<listitem><para>When used with <option>--eval</option>,
|
|
||||||
recursively evaluate list elements and attributes. Normally, such
|
|
||||||
sub-expressions are left unevaluated (since the Nix expression
|
|
||||||
language is lazy).</para>
|
|
||||||
|
|
||||||
<warning><para>This option can cause non-termination, because lazy
|
|
||||||
data structures can be infinitely large.</para></warning>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--json</option></term>
|
|
||||||
|
|
||||||
<listitem><para>When used with <option>--eval</option>, print the resulting
|
|
||||||
value as an JSON representation of the abstract syntax tree rather
|
|
||||||
than as an ATerm.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--xml</option></term>
|
|
||||||
|
|
||||||
<listitem><para>When used with <option>--eval</option>, print the resulting
|
|
||||||
value as an XML representation of the abstract syntax tree rather than as
|
|
||||||
an ATerm. The schema is the same as that used by the <link
|
|
||||||
linkend="builtin-toXML"><function>toXML</function> built-in</link>.
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--read-write-mode</option></term>
|
|
||||||
|
|
||||||
<listitem><para>When used with <option>--eval</option>, perform
|
|
||||||
evaluation in read/write mode so nix language features that
|
|
||||||
require it will still work (at the cost of needing to do
|
|
||||||
instantiation of every evaluated derivation). If this option is
|
|
||||||
not enabled, there may be uninstantiated store paths in the final
|
|
||||||
output.</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
<variablelist condition="manpage">
|
|
||||||
<xi:include href="opt-common.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(//db:variablelist[@xml:id='opt-common']/*)" />
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Examples</title>
|
|
||||||
|
|
||||||
<para>Instantiating store derivations from a Nix expression, and
|
|
||||||
building them using <command>nix-store</command>:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate test.nix <lineannotation>(instantiate)</lineannotation>
|
|
||||||
/nix/store/cigxbmvy6dzix98dxxh9b6shg7ar5bvs-perl-BerkeleyDB-0.26.drv
|
|
||||||
|
|
||||||
$ nix-store -r $(nix-instantiate test.nix) <lineannotation>(build)</lineannotation>
|
|
||||||
<replaceable>...</replaceable>
|
|
||||||
/nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26 <lineannotation>(output path)</lineannotation>
|
|
||||||
|
|
||||||
$ ls -l /nix/store/qhqk4n8ci095g3sdp93x7rgwyh9rdvgk-perl-BerkeleyDB-0.26
|
|
||||||
dr-xr-xr-x 2 eelco users 4096 1970-01-01 01:00 lib
|
|
||||||
...</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>You can also give a Nix expression on the command line:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate -E 'with import <nixpkgs> { }; hello'
|
|
||||||
/nix/store/j8s4zyv75a724q38cb0r87rlczaiag4y-hello-2.8.drv
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
This is equivalent to:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate '<nixpkgs>' -A hello
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Parsing and evaluating Nix expressions:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate --parse -E '1 + 2'
|
|
||||||
1 + 2
|
|
||||||
|
|
||||||
$ nix-instantiate --eval -E '1 + 2'
|
|
||||||
3
|
|
||||||
|
|
||||||
$ nix-instantiate --eval --xml -E '1 + 2'
|
|
||||||
<![CDATA[<?xml version='1.0' encoding='utf-8'?>
|
|
||||||
<expr>
|
|
||||||
<int value="3" />
|
|
||||||
</expr>]]></screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The difference between non-strict and strict evaluation:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate --eval --xml -E 'rec { x = "foo"; y = x; }'
|
|
||||||
<replaceable>...</replaceable><![CDATA[
|
|
||||||
<attr name="x">
|
|
||||||
<string value="foo" />
|
|
||||||
</attr>
|
|
||||||
<attr name="y">
|
|
||||||
<unevaluated />
|
|
||||||
</attr>]]>
|
|
||||||
<replaceable>...</replaceable></screen>
|
|
||||||
|
|
||||||
Note that <varname>y</varname> is left unevaluated (the XML
|
|
||||||
representation doesn’t attempt to show non-normal forms).
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-instantiate --eval --xml --strict -E 'rec { x = "foo"; y = x; }'
|
|
||||||
<replaceable>...</replaceable><![CDATA[
|
|
||||||
<attr name="x">
|
|
||||||
<string value="foo" />
|
|
||||||
</attr>
|
|
||||||
<attr name="y">
|
|
||||||
<string value="foo" />
|
|
||||||
</attr>]]>
|
|
||||||
<replaceable>...</replaceable></screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection condition="manpage"><title>Environment variables</title>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
<xi:include href="env-common.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(//db:variablelist[@xml:id='env-common']/*)" />
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refentry>
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
<refentry xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-nix-prefetch-url">
|
|
||||||
|
|
||||||
<refmeta>
|
|
||||||
<refentrytitle>nix-prefetch-url</refentrytitle>
|
|
||||||
<manvolnum>1</manvolnum>
|
|
||||||
<refmiscinfo class="source">Nix</refmiscinfo>
|
|
||||||
<refmiscinfo class="version"><xi:include href="../version.txt" parse="text"/></refmiscinfo>
|
|
||||||
</refmeta>
|
|
||||||
|
|
||||||
<refnamediv>
|
|
||||||
<refname>nix-prefetch-url</refname>
|
|
||||||
<refpurpose>copy a file from a URL into the store and print its hash</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-prefetch-url</command>
|
|
||||||
<arg><option>--version</option></arg>
|
|
||||||
<arg><option>--type</option> <replaceable>hashAlgo</replaceable></arg>
|
|
||||||
<arg><option>--print-path</option></arg>
|
|
||||||
<arg><option>--unpack</option></arg>
|
|
||||||
<arg><option>--name</option> <replaceable>name</replaceable></arg>
|
|
||||||
<arg choice='plain'><replaceable>url</replaceable></arg>
|
|
||||||
<arg><replaceable>hash</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The command <command>nix-prefetch-url</command> downloads the
|
|
||||||
file referenced by the URL <replaceable>url</replaceable>, prints its
|
|
||||||
cryptographic hash, and copies it into the Nix store. The file name
|
|
||||||
in the store is
|
|
||||||
<filename><replaceable>hash</replaceable>-<replaceable>baseName</replaceable></filename>,
|
|
||||||
where <replaceable>baseName</replaceable> is everything following the
|
|
||||||
final slash in <replaceable>url</replaceable>.</para>
|
|
||||||
|
|
||||||
<para>This command is just a convenience for Nix expression writers.
|
|
||||||
Often a Nix expression fetches some source distribution from the
|
|
||||||
network using the <literal>fetchurl</literal> expression contained in
|
|
||||||
Nixpkgs. However, <literal>fetchurl</literal> requires a
|
|
||||||
cryptographic hash. If you don't know the hash, you would have to
|
|
||||||
download the file first, and then <literal>fetchurl</literal> would
|
|
||||||
download it again when you build your Nix expression. Since
|
|
||||||
<literal>fetchurl</literal> uses the same name for the downloaded file
|
|
||||||
as <command>nix-prefetch-url</command>, the redundant download can be
|
|
||||||
avoided.</para>
|
|
||||||
|
|
||||||
<para>If <replaceable>hash</replaceable> is specified, then a download
|
|
||||||
is not performed if the Nix store already contains a file with the
|
|
||||||
same hash and base name. Otherwise, the file is downloaded, and an
|
|
||||||
error is signaled if the actual hash of the file does not match the
|
|
||||||
specified hash.</para>
|
|
||||||
|
|
||||||
<para>This command prints the hash on standard output. Additionally,
|
|
||||||
if the option <option>--print-path</option> is used, the path of the
|
|
||||||
downloaded file in the Nix store is also printed.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Options</title>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--type</option> <replaceable>hashAlgo</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Use the specified cryptographic hash algorithm,
|
|
||||||
which can be one of <literal>md5</literal>,
|
|
||||||
<literal>sha1</literal>, and
|
|
||||||
<literal>sha256</literal>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--print-path</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Print the store path of the downloaded file on
|
|
||||||
standard output.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--unpack</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Unpack the archive (which must be a tarball or zip
|
|
||||||
file) and add the result to the Nix store. The resulting hash can
|
|
||||||
be used with functions such as Nixpkgs’s
|
|
||||||
<varname>fetchzip</varname> or
|
|
||||||
<varname>fetchFromGitHub</varname>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--name</option> <replaceable>name</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Override the name of the file in the Nix store. By
|
|
||||||
default, this is
|
|
||||||
<literal><replaceable>hash</replaceable>-<replaceable>basename</replaceable></literal>,
|
|
||||||
where <replaceable>basename</replaceable> is the last component of
|
|
||||||
<replaceable>url</replaceable>. Overriding the name is necessary
|
|
||||||
when <replaceable>basename</replaceable> contains characters that
|
|
||||||
are not allowed in Nix store paths.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Examples</title>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-prefetch-url ftp://ftp.gnu.org/pub/gnu/hello/hello-2.10.tar.gz
|
|
||||||
0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
|
|
||||||
|
|
||||||
$ nix-prefetch-url --print-path mirror://gnu/hello/hello-2.10.tar.gz
|
|
||||||
0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
|
|
||||||
/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz
|
|
||||||
|
|
||||||
$ nix-prefetch-url --unpack --print-path https://github.com/NixOS/patchelf/archive/0.8.tar.gz
|
|
||||||
079agjlv0hrv7fxnx9ngipx14gyncbkllxrp9cccnh3a50fxcmy7
|
|
||||||
/nix/store/19zrmhm3m40xxaw81c8cqm6aljgrnwj2-0.8.tar.gz
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refentry>
|
|
||||||
@@ -1,411 +0,0 @@
|
|||||||
<refentry xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-nix-shell">
|
|
||||||
|
|
||||||
<refmeta>
|
|
||||||
<refentrytitle>nix-shell</refentrytitle>
|
|
||||||
<manvolnum>1</manvolnum>
|
|
||||||
<refmiscinfo class="source">Nix</refmiscinfo>
|
|
||||||
<refmiscinfo class="version"><xi:include href="../version.txt" parse="text"/></refmiscinfo>
|
|
||||||
</refmeta>
|
|
||||||
|
|
||||||
<refnamediv>
|
|
||||||
<refname>nix-shell</refname>
|
|
||||||
<refpurpose>start an interactive shell based on a Nix expression</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-shell</command>
|
|
||||||
<arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
|
||||||
<arg><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--attr</option></arg>
|
|
||||||
<arg choice='plain'><option>-A</option></arg>
|
|
||||||
</group>
|
|
||||||
<replaceable>attrPath</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg><option>--command</option> <replaceable>cmd</replaceable></arg>
|
|
||||||
<arg><option>--run</option> <replaceable>cmd</replaceable></arg>
|
|
||||||
<arg><option>--exclude</option> <replaceable>regexp</replaceable></arg>
|
|
||||||
<arg><option>--pure</option></arg>
|
|
||||||
<arg><option>--keep</option> <replaceable>name</replaceable></arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--packages</option></arg>
|
|
||||||
<arg choice='plain'><option>-p</option></arg>
|
|
||||||
</group>
|
|
||||||
<arg choice='plain' rep='repeat'>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice="plain"><replaceable>packages</replaceable></arg>
|
|
||||||
<arg choice="plain"><replaceable>expressions</replaceable></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
</arg>
|
|
||||||
<arg><replaceable>path</replaceable></arg>
|
|
||||||
</group>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The command <command>nix-shell</command> will build the
|
|
||||||
dependencies of the specified derivation, but not the derivation
|
|
||||||
itself. It will then start an interactive shell in which all
|
|
||||||
environment variables defined by the derivation
|
|
||||||
<replaceable>path</replaceable> have been set to their corresponding
|
|
||||||
values, and the script <literal>$stdenv/setup</literal> has been
|
|
||||||
sourced. This is useful for reproducing the environment of a
|
|
||||||
derivation for development.</para>
|
|
||||||
|
|
||||||
<para>If <replaceable>path</replaceable> is not given,
|
|
||||||
<command>nix-shell</command> defaults to
|
|
||||||
<filename>shell.nix</filename> if it exists, and
|
|
||||||
<filename>default.nix</filename> otherwise.</para>
|
|
||||||
|
|
||||||
<para>If <replaceable>path</replaceable> starts with
|
|
||||||
<literal>http://</literal> or <literal>https://</literal>, it is
|
|
||||||
interpreted as the URL of a tarball that will be downloaded and
|
|
||||||
unpacked to a temporary location. The tarball must include a single
|
|
||||||
top-level directory containing at least a file named
|
|
||||||
<filename>default.nix</filename>.</para>
|
|
||||||
|
|
||||||
<para>If the derivation defines the variable
|
|
||||||
<varname>shellHook</varname>, it will be evaluated after
|
|
||||||
<literal>$stdenv/setup</literal> has been sourced. Since this hook is
|
|
||||||
not executed by regular Nix builds, it allows you to perform
|
|
||||||
initialisation specific to <command>nix-shell</command>. For example,
|
|
||||||
the derivation attribute
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
shellHook =
|
|
||||||
''
|
|
||||||
echo "Hello shell"
|
|
||||||
'';
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
will cause <command>nix-shell</command> to print <literal>Hello shell</literal>.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Options</title>
|
|
||||||
|
|
||||||
<para>All options not listed here are passed to <command>nix-store
|
|
||||||
--realise</command>, except for <option>--arg</option> and
|
|
||||||
<option>--attr</option> / <option>-A</option> which are passed to
|
|
||||||
<command>nix-instantiate</command>. <phrase condition="manual">See
|
|
||||||
also <xref linkend="sec-common-options" />.</phrase></para>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--command</option> <replaceable>cmd</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>In the environment of the derivation, run the
|
|
||||||
shell command <replaceable>cmd</replaceable>. This command is
|
|
||||||
executed in an interactive shell. (Use <option>--run</option> to
|
|
||||||
use a non-interactive shell instead.) However, a call to
|
|
||||||
<literal>exit</literal> is implicitly added to the command, so the
|
|
||||||
shell will exit after running the command. To prevent this, add
|
|
||||||
<literal>return</literal> at the end; e.g. <literal>--command
|
|
||||||
"echo Hello; return"</literal> will print <literal>Hello</literal>
|
|
||||||
and then drop you into the interactive shell. This can be useful
|
|
||||||
for doing any additional initialisation.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--run</option> <replaceable>cmd</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Like <option>--command</option>, but executes the
|
|
||||||
command in a non-interactive shell. This means (among other
|
|
||||||
things) that if you hit Ctrl-C while the command is running, the
|
|
||||||
shell exits.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--exclude</option> <replaceable>regexp</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Do not build any dependencies whose store path
|
|
||||||
matches the regular expression <replaceable>regexp</replaceable>.
|
|
||||||
This option may be specified multiple times.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--pure</option></term>
|
|
||||||
|
|
||||||
<listitem><para>If this flag is specified, the environment is
|
|
||||||
almost entirely cleared before the interactive shell is started,
|
|
||||||
so you get an environment that more closely corresponds to the
|
|
||||||
“real” Nix build. A few variables, in particular
|
|
||||||
<envar>HOME</envar>, <envar>USER</envar> and
|
|
||||||
<envar>DISPLAY</envar>, are retained. Note that
|
|
||||||
<filename>~/.bashrc</filename> and (depending on your Bash
|
|
||||||
installation) <filename>/etc/bashrc</filename> are still sourced,
|
|
||||||
so any variables set there will affect the interactive
|
|
||||||
shell.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--packages</option> / <option>-p</option> <replaceable>packages</replaceable>…</term>
|
|
||||||
|
|
||||||
<listitem><para>Set up an environment in which the specified
|
|
||||||
packages are present. The command line arguments are interpreted
|
|
||||||
as attribute names inside the Nix Packages collection. Thus,
|
|
||||||
<literal>nix-shell -p libjpeg openjdk</literal> will start a shell
|
|
||||||
in which the packages denoted by the attribute names
|
|
||||||
<varname>libjpeg</varname> and <varname>openjdk</varname> are
|
|
||||||
present.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>-i</option> <replaceable>interpreter</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>The chained script interpreter to be invoked by
|
|
||||||
<command>nix-shell</command>. Only applicable in
|
|
||||||
<literal>#!</literal>-scripts (described <link
|
|
||||||
linkend="ssec-nix-shell-shebang">below</link>).</para>
|
|
||||||
|
|
||||||
</listitem></varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--keep</option> <replaceable>name</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>When a <option>--pure</option> shell is started,
|
|
||||||
keep the listed environment variables.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
<para>The following common options are supported:</para>
|
|
||||||
|
|
||||||
<variablelist condition="manpage">
|
|
||||||
<xi:include href="opt-common.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(//db:variablelist[@xml:id='opt-common']/*)" />
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Environment variables</title>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><envar>NIX_BUILD_SHELL</envar></term>
|
|
||||||
|
|
||||||
<listitem><para>Shell used to start the interactive environment.
|
|
||||||
Defaults to the <command>bash</command> found in <envar>PATH</envar>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Examples</title>
|
|
||||||
|
|
||||||
<para>To build the dependencies of the package Pan, and start an
|
|
||||||
interactive shell in which to build it:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell '<nixpkgs>' -A pan
|
|
||||||
[nix-shell]$ unpackPhase
|
|
||||||
[nix-shell]$ cd pan-*
|
|
||||||
[nix-shell]$ configurePhase
|
|
||||||
[nix-shell]$ buildPhase
|
|
||||||
[nix-shell]$ ./pan/gui/pan
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
To clear the environment first, and do some additional automatic
|
|
||||||
initialisation of the interactive shell:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell '<nixpkgs>' -A pan --pure \
|
|
||||||
--command 'export NIX_DEBUG=1; export NIX_CORES=8; return'
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
Nix expressions can also be given on the command line using the
|
|
||||||
<command>-E</command> and <command>-p</command> flags.
|
|
||||||
For instance, the following starts a shell containing the packages
|
|
||||||
<literal>sqlite</literal> and <literal>libX11</literal>:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell -E 'with import <nixpkgs> { }; runCommand "dummy" { buildInputs = [ sqlite xorg.libX11 ]; } ""'
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
A shorter way to do the same is:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell -p sqlite xorg.libX11
|
|
||||||
[nix-shell]$ echo $NIX_LDFLAGS
|
|
||||||
… -L/nix/store/j1zg5v…-sqlite-3.8.0.2/lib -L/nix/store/0gmcz9…-libX11-1.6.1/lib …
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
Note that <command>-p</command> accepts multiple full nix expressions that
|
|
||||||
are valid in the <literal>buildInputs = [ ... ]</literal> shown above,
|
|
||||||
not only package names. So the following is also legal:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell -p sqlite 'git.override { withManual = false; }'
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
The <command>-p</command> flag looks up Nixpkgs in the Nix search
|
|
||||||
path. You can override it by passing <option>-I</option> or setting
|
|
||||||
<envar>NIX_PATH</envar>. For example, the following gives you a shell
|
|
||||||
containing the Pan package from a specific revision of Nixpkgs:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell -p pan -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/8a3eea054838b55aca962c3fbde9c83c102b8bf2.tar.gz
|
|
||||||
|
|
||||||
[nix-shell:~]$ pan --version
|
|
||||||
Pan 0.139
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection xml:id="ssec-nix-shell-shebang"><title>Use as a <literal>#!</literal>-interpreter</title>
|
|
||||||
|
|
||||||
<para>You can use <command>nix-shell</command> as a script interpreter
|
|
||||||
to allow scripts written in arbitrary languages to obtain their own
|
|
||||||
dependencies via Nix. This is done by starting the script with the
|
|
||||||
following lines:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#! /usr/bin/env nix-shell
|
|
||||||
#! nix-shell -i <replaceable>real-interpreter</replaceable> -p <replaceable>packages</replaceable>
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
where <replaceable>real-interpreter</replaceable> is the “real” script
|
|
||||||
interpreter that will be invoked by <command>nix-shell</command> after
|
|
||||||
it has obtained the dependencies and initialised the environment, and
|
|
||||||
<replaceable>packages</replaceable> are the attribute names of the
|
|
||||||
dependencies in Nixpkgs.</para>
|
|
||||||
|
|
||||||
<para>The lines starting with <literal>#! nix-shell</literal> specify
|
|
||||||
<command>nix-shell</command> options (see above). Note that you cannot
|
|
||||||
write <literal>#! /usr/bin/env nix-shell -i ...</literal> because
|
|
||||||
many operating systems only allow one argument in
|
|
||||||
<literal>#!</literal> lines.</para>
|
|
||||||
|
|
||||||
<para>For example, here is a Python script that depends on Python and
|
|
||||||
the <literal>prettytable</literal> package:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#! /usr/bin/env nix-shell
|
|
||||||
#! nix-shell -i python -p python pythonPackages.prettytable
|
|
||||||
|
|
||||||
import prettytable
|
|
||||||
|
|
||||||
# Print a simple table.
|
|
||||||
t = prettytable.PrettyTable(["N", "N^2"])
|
|
||||||
for n in range(1, 10): t.add_row([n, n * n])
|
|
||||||
print t
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Similarly, the following is a Perl script that specifies that it
|
|
||||||
requires Perl and the <literal>HTML::TokeParser::Simple</literal> and
|
|
||||||
<literal>LWP</literal> packages:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#! /usr/bin/env nix-shell
|
|
||||||
#! nix-shell -i perl -p perl perlPackages.HTMLTokeParserSimple perlPackages.LWP
|
|
||||||
|
|
||||||
use HTML::TokeParser::Simple;
|
|
||||||
|
|
||||||
# Fetch nixos.org and print all hrefs.
|
|
||||||
my $p = HTML::TokeParser::Simple->new(url => 'http://nixos.org/');
|
|
||||||
|
|
||||||
while (my $token = $p->get_tag("a")) {
|
|
||||||
my $href = $token->get_attr("href");
|
|
||||||
print "$href\n" if $href;
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Sometimes you need to pass a simple Nix expression to customize
|
|
||||||
a package like Terraform:
|
|
||||||
|
|
||||||
<programlisting><![CDATA[
|
|
||||||
#! /usr/bin/env nix-shell
|
|
||||||
#! nix-shell -i bash -p "terraform.withPlugins (plugins: [ plugins.openstack ])"
|
|
||||||
|
|
||||||
terraform apply
|
|
||||||
]]></programlisting>
|
|
||||||
|
|
||||||
<note><para>You must use double quotes (<literal>"</literal>) when
|
|
||||||
passing a simple Nix expression in a nix-shell shebang.</para></note>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Finally, using the merging of multiple nix-shell shebangs the
|
|
||||||
following Haskell script uses a specific branch of Nixpkgs/NixOS (the
|
|
||||||
18.03 stable branch):
|
|
||||||
|
|
||||||
<programlisting><![CDATA[
|
|
||||||
#! /usr/bin/env nix-shell
|
|
||||||
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages (ps: [ps.HTTP ps.tagsoup])"
|
|
||||||
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.03.tar.gz
|
|
||||||
|
|
||||||
import Network.HTTP
|
|
||||||
import Text.HTML.TagSoup
|
|
||||||
|
|
||||||
-- Fetch nixos.org and print all hrefs.
|
|
||||||
main = do
|
|
||||||
resp <- Network.HTTP.simpleHTTP (getRequest "http://nixos.org/")
|
|
||||||
body <- getResponseBody resp
|
|
||||||
let tags = filter (isTagOpenName "a") $ parseTags body
|
|
||||||
let tags' = map (fromAttrib "href") tags
|
|
||||||
mapM_ putStrLn $ filter (/= "") tags'
|
|
||||||
]]></programlisting>
|
|
||||||
|
|
||||||
If you want to be even more precise, you can specify a specific
|
|
||||||
revision of Nixpkgs:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/0672315759b3e15e2121365f067c1c8c56bb4722.tar.gz
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The examples above all used <option>-p</option> to get
|
|
||||||
dependencies from Nixpkgs. You can also use a Nix expression to build
|
|
||||||
your own dependencies. For example, the Python example could have been
|
|
||||||
written as:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
#! /usr/bin/env nix-shell
|
|
||||||
#! nix-shell deps.nix -i python
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
where the file <filename>deps.nix</filename> in the same directory
|
|
||||||
as the <literal>#!</literal>-script contains:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
with import <nixpkgs> {};
|
|
||||||
|
|
||||||
runCommand "dummy" { buildInputs = [ python pythonPackages.prettytable ]; } ""
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection condition="manpage"><title>Environment variables</title>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
<xi:include href="env-common.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(//db:variablelist[@xml:id='env-common']/*)" />
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refentry>
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<nop xmlns="http://docbook.org/ns/docbook">
|
|
||||||
|
|
||||||
<arg><option>--help</option></arg>
|
|
||||||
<arg><option>--version</option></arg>
|
|
||||||
<arg rep='repeat'>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--verbose</option></arg>
|
|
||||||
<arg choice='plain'><option>-v</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<arg choice='plain'><option>--quiet</option></arg>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='plain'>
|
|
||||||
<arg choice='plain'><option>--no-build-output</option></arg>
|
|
||||||
<arg choice='plain'><option>-Q</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--max-jobs</option></arg>
|
|
||||||
<arg choice='plain'><option>-j</option></arg>
|
|
||||||
</group>
|
|
||||||
<replaceable>number</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<option>--cores</option>
|
|
||||||
<replaceable>number</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<option>--max-silent-time</option>
|
|
||||||
<replaceable>number</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<option>--timeout</option>
|
|
||||||
<replaceable>number</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='plain'>
|
|
||||||
<arg choice='plain'><option>--keep-going</option></arg>
|
|
||||||
<arg choice='plain'><option>-k</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='plain'>
|
|
||||||
<arg choice='plain'><option>--keep-failed</option></arg>
|
|
||||||
<arg choice='plain'><option>-K</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
<arg><option>--fallback</option></arg>
|
|
||||||
<arg><option>--readonly-mode</option></arg>
|
|
||||||
<arg>
|
|
||||||
<option>-I</option>
|
|
||||||
<replaceable>path</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg>
|
|
||||||
<option>--option</option>
|
|
||||||
<replaceable>name</replaceable>
|
|
||||||
<replaceable>value</replaceable>
|
|
||||||
</arg>
|
|
||||||
<sbr />
|
|
||||||
|
|
||||||
</nop>
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='ch-utilities'>
|
|
||||||
|
|
||||||
<title>Utilities</title>
|
|
||||||
|
|
||||||
<para>This section lists utilities that you can use when you
|
|
||||||
work with Nix.</para>
|
|
||||||
|
|
||||||
<xi:include href="nix-channel.xml" />
|
|
||||||
<xi:include href="nix-collect-garbage.xml" />
|
|
||||||
<xi:include href="nix-copy-closure.xml" />
|
|
||||||
<xi:include href="nix-daemon.xml" />
|
|
||||||
<xi:include href="nix-hash.xml" />
|
|
||||||
<xi:include href="nix-instantiate.xml" />
|
|
||||||
<xi:include href="nix-prefetch-url.xml" />
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
<section xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xml:id="sec-conf-file">
|
||||||
|
|
||||||
|
<title>Nix configuration file</title>
|
||||||
|
|
||||||
|
|
||||||
|
<para>A number of persistent settings of Nix are stored in the file
|
||||||
|
<filename><replaceable>prefix</replaceable>/etc/nix/nix.conf</filename>.
|
||||||
|
This file is a list of <literal><replaceable>name</replaceable> =
|
||||||
|
<replaceable>value</replaceable></literal> pairs, one per line.
|
||||||
|
Comments start with a <literal>#</literal> character. An example
|
||||||
|
configuration file is shown in <xref linkend="ex-nix-conf" />.</para>
|
||||||
|
|
||||||
|
<example xml:id='ex-nix-conf'><title>Nix configuration file</title>
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
gc-keep-outputs = true # Nice for developers
|
||||||
|
gc-keep-derivations = true # Idem
|
||||||
|
env-keep-derivations = false
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
|
||||||
|
<para>The following variables are currently available:
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-gc-keep-outputs"><term><literal>gc-keep-outputs</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>If <literal>true</literal>, the garbage collector
|
||||||
|
will keep the outputs of non-garbage derivations. If
|
||||||
|
<literal>false</literal> (default), outputs will be deleted unless
|
||||||
|
they are GC roots themselves (or reachable from other roots).</para>
|
||||||
|
|
||||||
|
<para>In general, outputs must be registered as roots separately.
|
||||||
|
However, even if the output of a derivation is registered as a
|
||||||
|
root, the collector will still delete store paths that are used
|
||||||
|
only at build time (e.g., the C compiler, or source tarballs
|
||||||
|
downloaded from the network). To prevent it from doing so, set
|
||||||
|
this option to <literal>true</literal>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-gc-keep-derivations"><term><literal>gc-keep-derivations</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>If <literal>true</literal> (default), the garbage
|
||||||
|
collector will keep the derivations from which non-garbage store
|
||||||
|
paths were built. If <literal>false</literal>, they will be
|
||||||
|
deleted unless explicitly registered as a root (or reachable from
|
||||||
|
other roots).</para>
|
||||||
|
|
||||||
|
<para>Keeping derivation around is useful for querying and
|
||||||
|
traceability (e.g., it allows you to ask with what dependencies or
|
||||||
|
options a store path was built), so by default this option is on.
|
||||||
|
Turn it off to safe a bit of disk space (or a lot if
|
||||||
|
<literal>gc-keep-outputs</literal> is also turned on).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><literal>env-keep-derivations</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>If <literal>false</literal> (default), derivations
|
||||||
|
are not stored in Nix user environments. That is, the derivation
|
||||||
|
any build-time-only dependencies may be garbage-collected.</para>
|
||||||
|
|
||||||
|
<para>If <literal>true</literal>, when you add a Nix derivation to
|
||||||
|
a user environment, the path of the derivation is stored in the
|
||||||
|
user environment. Thus, the derivation will not be
|
||||||
|
garbage-collected until the user environment generation is deleted
|
||||||
|
(<command>nix-env --delete-generations</command>). To prevent
|
||||||
|
build-time-only dependencies from being collected, you should also
|
||||||
|
turn on <literal>gc-keep-outputs</literal>.</para>
|
||||||
|
|
||||||
|
<para>The difference between this option and
|
||||||
|
<literal>gc-keep-derivations</literal> is that this one is
|
||||||
|
“sticky”: it applies to any user environment created while this
|
||||||
|
option was enabled, while <literal>gc-keep-derivations</literal>
|
||||||
|
only applies at the moment the garbage collector is
|
||||||
|
run.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-build-max-jobs"><term><literal>build-max-jobs</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>This option defines the maximum number of jobs
|
||||||
|
that Nix will try to build in parallel. The default is
|
||||||
|
<literal>1</literal>. You should generally set it to the number
|
||||||
|
of CPUs in your system (e.g., <literal>2</literal> on a Athlon 64
|
||||||
|
X2). It can be overriden using the <option
|
||||||
|
linkend='opt-max-jobs'>--max-jobs</option> (<option>-j</option>)
|
||||||
|
command line switch.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-build-max-silent-time"><term><literal>build-max-silent-time</literal></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
|
||||||
|
<para>This option defines the maximum number of seconds that a
|
||||||
|
builder can go without producing any data on standard output or
|
||||||
|
standard error. This is useful (for instance in a automated
|
||||||
|
build system) to catch builds that are stuck in an infinite
|
||||||
|
loop, or to catch remote builds that are hanging due to network
|
||||||
|
problems. It can be overriden using the <option
|
||||||
|
linkend="opt-max-silent-time">--max-silent-time</option> command
|
||||||
|
line switch.</para>
|
||||||
|
|
||||||
|
<para>The value <literal>0</literal> means that there is no
|
||||||
|
timeout. This is also the default.</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-build-users-group"><term><literal>build-users-group</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>This options specifies the Unix group containing
|
||||||
|
the Nix build user accounts. In multi-user Nix installations,
|
||||||
|
builds should not be performed by the Nix account since that would
|
||||||
|
allow users to arbitrarily modify the Nix store and database by
|
||||||
|
supplying specially crafted builders; and they cannot be performed
|
||||||
|
by the calling user since that would allow him/her to influence
|
||||||
|
the build result.</para>
|
||||||
|
|
||||||
|
<para>Therefore, if this option is non-empty and specifies a valid
|
||||||
|
group, builds will be performed under the user accounts that are a
|
||||||
|
member of the group specified here (as listed in
|
||||||
|
<filename>/etc/group</filename>). Those user accounts should not
|
||||||
|
be used for any other purpose!</para>
|
||||||
|
|
||||||
|
<para>Nix will never run two builds under the same user account at
|
||||||
|
the same time. This is to prevent an obvious security hole: a
|
||||||
|
malicious user writing a Nix expression that modifies the build
|
||||||
|
result of a legitimate Nix expression being built by another user.
|
||||||
|
Therefore it is good to have as many Nix build user accounts as
|
||||||
|
you can spare. (Remember: uids are cheap.)</para>
|
||||||
|
|
||||||
|
<para>The build users should have permission to create files in
|
||||||
|
the Nix store, but not delete them. Therefore,
|
||||||
|
<filename>/nix/store</filename> should be owned by the Nix
|
||||||
|
account, its group should be the group specified here, and its
|
||||||
|
mode should be <literal>1775</literal>.</para>
|
||||||
|
|
||||||
|
<para>If the build users group is empty, builds will be performed
|
||||||
|
under the uid of the Nix process (that is, the uid of the caller
|
||||||
|
if <envar>NIX_REMOTE</envar> is empty, the uid under which the Nix
|
||||||
|
daemon runs if <envar>NIX_REMOTE</envar> is
|
||||||
|
<literal>daemon</literal>, or the uid that owns the setuid
|
||||||
|
<command>nix-worker</command> program if <envar>NIX_REMOTE</envar>
|
||||||
|
is <literal>slave</literal>). Obviously, this should not be used
|
||||||
|
in multi-user settings with untrusted users.</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><literal>build-use-chroot</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>If set to <literal>true</literal>, builds will be
|
||||||
|
performed in a <emphasis>chroot environment</emphasis>, i.e., the
|
||||||
|
build will be isolated from the normal file system hierarchy and
|
||||||
|
will only see the Nix store, the temporary build directory, and
|
||||||
|
the directories configured with the <link
|
||||||
|
linkend='conf-build-chroot-dirs'><literal>build-chroot-dirs</literal>
|
||||||
|
option</link> (such as <filename>/proc</filename> and
|
||||||
|
<filename>/dev</filename>). This is useful to prevent undeclared
|
||||||
|
dependencies on files in directories such as
|
||||||
|
<filename>/usr/bin</filename>.</para>
|
||||||
|
|
||||||
|
<para>The use of a chroot requires that Nix is run as root (but
|
||||||
|
you can still use the <link
|
||||||
|
linkend='conf-build-users-group'>“build users” feature</link> to
|
||||||
|
perform builds under different users than root). Currently,
|
||||||
|
chroot builds only work on Linux because Nix uses “bind mounts” to
|
||||||
|
make the Nix store and other directories available inside the
|
||||||
|
chroot.</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-build-chroot-dirs"><term><literal>build-chroot-dirs</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>When builds are performed in a chroot environment,
|
||||||
|
Nix will mount (using <command>mount --bind</command> on Linux)
|
||||||
|
some directories from the normal file system hierarchy inside the
|
||||||
|
chroot. These are the Nix store, the temporary build directory
|
||||||
|
(usually
|
||||||
|
<filename>/tmp/nix-<replaceable>pid</replaceable>-<replaceable>number</replaceable></filename>)
|
||||||
|
and the directories listed here. The default is <literal>dev
|
||||||
|
/proc</literal>. Files in <filename>/dev</filename> (such as
|
||||||
|
<filename>/dev/null</filename>) are needed by many builds, and
|
||||||
|
some files in <filename>/proc</filename> may also be needed
|
||||||
|
occasionally.</para>
|
||||||
|
|
||||||
|
<para>The value used on NixOS is
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
build-use-chroot = /dev /proc /bin</programlisting>
|
||||||
|
|
||||||
|
to make the <filename>/bin/sh</filename> symlink available (which
|
||||||
|
is still needed by many builders).</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><literal>system</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>This option specifies the canonical Nix system
|
||||||
|
name of the current installation, such as
|
||||||
|
<literal>i686-linux</literal> or
|
||||||
|
<literal>powerpc-darwin</literal>. Nix can only build derivations
|
||||||
|
whose <literal>system</literal> attribute equals the value
|
||||||
|
specified here. In general, it never makes sense to modify this
|
||||||
|
value from its default, since you can use it to ‘lie’ about the
|
||||||
|
platform you are building on (e.g., perform a Mac OS build on a
|
||||||
|
Linux machine; the result would obviously be wrong). It only
|
||||||
|
makes sense if the Nix binaries can run on multiple platforms,
|
||||||
|
e.g., ‘universal binaries’ that run on <literal>powerpc-darwin</literal> and
|
||||||
|
<literal>i686-darwin</literal>.</para>
|
||||||
|
|
||||||
|
<para>It defaults to the canonical Nix system name detected by
|
||||||
|
<filename>configure</filename> at build time.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,278 @@
|
|||||||
|
<section xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xml:id="sec-common-env">
|
||||||
|
|
||||||
|
<title>Common environment variables</title>
|
||||||
|
|
||||||
|
|
||||||
|
<para>Most Nix commands interpret the following environment variables:</para>
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_IGNORE_SYMLINK_STORE</envar></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
|
||||||
|
<para>Normally, the Nix store directory (typically
|
||||||
|
<filename>/nix/store</filename>) is not allowed to contain any
|
||||||
|
symlink components. This is to prevent “impure” builds. Builders
|
||||||
|
sometimes “canonicalise” paths by resolving all symlink components.
|
||||||
|
Thus, builds on different machines (with
|
||||||
|
<filename>/nix/store</filename> resolving to different locations)
|
||||||
|
could yield different results. This is generally not a problem,
|
||||||
|
except when builds are deployed to machines where
|
||||||
|
<filename>/nix/store</filename> resolves differently. If you are
|
||||||
|
sure that you’re not going to do that, you can set
|
||||||
|
<envar>NIX_IGNORE_SYMLINK_STORE</envar> to <envar>1</envar>.</para>
|
||||||
|
|
||||||
|
<para>Note that if you’re symlinking the Nix store so that you can
|
||||||
|
put it on another file system than the root file system, on Linux
|
||||||
|
you’re better off using <literal>bind</literal> mount points, e.g.,
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ mkdir /nix
|
||||||
|
$ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
||||||
|
|
||||||
|
Consult the <citerefentry><refentrytitle>mount</refentrytitle>
|
||||||
|
<manvolnum>8</manvolnum></citerefentry> manual page for details.</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_STORE_DIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Overrides the location of the Nix store (default
|
||||||
|
<filename><replaceable>prefix</replaceable>/store</filename>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_DATA_DIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Overrides the location of the Nix static data
|
||||||
|
directory (default
|
||||||
|
<filename><replaceable>prefix</replaceable>/share</filename>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_LOG_DIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Overrides the location of the Nix log directory
|
||||||
|
(default <filename><replaceable>prefix</replaceable>/log/nix</filename>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_STATE_DIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Overrides the location of the Nix state directory
|
||||||
|
(default <filename><replaceable>prefix</replaceable>/var/nix</filename>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_DB_DIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Overrides the location of the Nix database (default
|
||||||
|
<filename><replaceable>$NIX_STATE_DIR</replaceable>/db</filename>, i.e.,
|
||||||
|
<filename><replaceable>prefix</replaceable>/var/nix/db</filename>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_CONF_DIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Overrides the location of the Nix configuration
|
||||||
|
directory (default
|
||||||
|
<filename><replaceable>prefix</replaceable>/etc/nix</filename>).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>NIX_LOG_TYPE</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Equivalent to the <link
|
||||||
|
linkend="opt-log-type"><option>--log-type</option>
|
||||||
|
option</link>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><envar>TMPDIR</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>Use the specified directory to store temporary
|
||||||
|
files. In particular, this includes temporary build directories;
|
||||||
|
these can take up substantial amounts of disk space. The default is
|
||||||
|
<filename>/tmp</filename>.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="envar-build-hook"><term><envar>NIX_BUILD_HOOK</envar></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
|
||||||
|
<para>Specifies the location of the <emphasis>build hook</emphasis>,
|
||||||
|
which is a program (typically some script) that Nix will call
|
||||||
|
whenever it wants to build a derivation. This is used to implement
|
||||||
|
distributed builds (see <xref linkend="sec-distributed-builds"
|
||||||
|
/>). The protocol by which the calling Nix process and the build
|
||||||
|
hook communicate is as follows.</para>
|
||||||
|
|
||||||
|
<para>The build hook is called with the following command-line
|
||||||
|
arguments:
|
||||||
|
|
||||||
|
<orderedlist>
|
||||||
|
|
||||||
|
<listitem><para>A boolean value <literal>0</literal> or
|
||||||
|
<literal>1</literal> specifying whether Nix can locally execute
|
||||||
|
more builds, as per the <link
|
||||||
|
linkend="opt-max-jobs"><option>--max-jobs</option> option</link>.
|
||||||
|
The purpose of this argument is to allow the hook to not have to
|
||||||
|
maintain bookkeeping for the local machine.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The Nix platform identifier for the local machine
|
||||||
|
(e.g., <literal>i686-linux</literal>).</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The Nix platform identifier for the derivation,
|
||||||
|
i.e., its <link linkend="attr-system"><varname>system</varname>
|
||||||
|
attribute</link>.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>The store path of the derivation.</para></listitem>
|
||||||
|
|
||||||
|
</orderedlist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>On the basis of this information, and whatever persistent
|
||||||
|
state the build hook keeps about other machines and their current
|
||||||
|
load, it has to decide what to do with the build. It should print
|
||||||
|
out on standard error one of the following responses (terminated by
|
||||||
|
a newline, <literal>"\n"</literal>):
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
|
||||||
|
<varlistentry><term><literal># decline</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>The build hook is not willing or able to perform
|
||||||
|
the build; the calling Nix process should do the build itself,
|
||||||
|
if possible.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><literal># postpone</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>The build hook cannot perform the build now, but
|
||||||
|
can do so in the future (e.g., because all available build slots
|
||||||
|
on remote machines are in use). The calling Nix process should
|
||||||
|
postpone this build until at least one currently running build
|
||||||
|
has terminated.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><literal># accept</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>The build hook has accepted the
|
||||||
|
build.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>After sending <literal># accept</literal>, the hook should
|
||||||
|
read one line from standard input, which will be the string
|
||||||
|
<literal>okay</literal>. It can then proceed with the build.
|
||||||
|
Before sending <literal>okay</literal>, Nix will store in the hook’s
|
||||||
|
current directory a number of text files that contain information
|
||||||
|
about the derivation:
|
||||||
|
|
||||||
|
<variablelist>
|
||||||
|
|
||||||
|
<varlistentry><term><filename>inputs</filename></term>
|
||||||
|
|
||||||
|
<listitem><para>The set of store paths that are inputs to the
|
||||||
|
build process (one per line). These have to be copied
|
||||||
|
<emphasis>to</emphasis> the remote machine (in addition to the
|
||||||
|
store derivation itself).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><filename>outputs</filename></term>
|
||||||
|
|
||||||
|
<listitem><para>The set of store paths that are outputs of the
|
||||||
|
derivation (one per line). These have to be copied
|
||||||
|
<emphasis>from</emphasis> the remote machine if the build
|
||||||
|
succeeds.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><filename>references</filename></term>
|
||||||
|
|
||||||
|
<listitem><para>The reference graph of the inputs, in the format
|
||||||
|
accepted by the command <command>nix-store
|
||||||
|
--register-validity</command>. It is necessary to run this
|
||||||
|
command on the remote machine after copying the inputs to inform
|
||||||
|
Nix on the remote machine that the inputs are valid
|
||||||
|
paths.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>The hook should copy the inputs to the remote machine,
|
||||||
|
register the validity of the inputs, perform the remote build, and
|
||||||
|
copy the outputs back to the local machine. An exit code other than
|
||||||
|
<literal>0</literal> indicates that the hook has failed. An exit
|
||||||
|
code equal to 100 means that the remote build failed (as opposed to,
|
||||||
|
e.g., a network error).</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="envar-remote"><term><envar>NIX_REMOTE</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>This variable should be set to
|
||||||
|
<literal>daemon</literal> if you want to use the Nix daemon to
|
||||||
|
executed Nix operations, which is necessary in <link
|
||||||
|
linkend="ssec-multi-user">multi-user Nix installations</link>.
|
||||||
|
Otherwise, it should be left unset.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="envar-other-stores"><term><envar>NIX_OTHER_STORES</envar></term>
|
||||||
|
|
||||||
|
<listitem><para>This variable contains the paths of remote Nix
|
||||||
|
installations from whichs paths can be copied, separated by colons.
|
||||||
|
See <xref linkend="sec-sharing-packages" /> for details. Each path
|
||||||
|
should be the <filename>/nix</filename> directory of a remote Nix
|
||||||
|
installation (i.e., not the <filename>/nix/store</filename>
|
||||||
|
directory). The paths are subject to globbing, so you can set it so
|
||||||
|
something like <literal>/var/run/nix/remote-stores/*/nix</literal>
|
||||||
|
and mount multiple remote filesystems in
|
||||||
|
<literal>/var/run/nix/remote-stores</literal>.</para>
|
||||||
|
|
||||||
|
<para>Note that if you’re building through the <link
|
||||||
|
linkend="sec-nix-worker">Nix daemon</link>, the only setting for
|
||||||
|
this variable that matters is the one that the
|
||||||
|
<command>nix-worker</command> process uses. So if you want to
|
||||||
|
change it, you have to restart the daemon.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
</section>
|
||||||
@@ -1,351 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-advanced-attributes">
|
|
||||||
|
|
||||||
<title>Advanced Attributes</title>
|
|
||||||
|
|
||||||
<para>Derivations can declare some infrequently used optional
|
|
||||||
attributes.</para>
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-allowedReferences"><term><varname>allowedReferences</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>The optional attribute
|
|
||||||
<varname>allowedReferences</varname> specifies a list of legal
|
|
||||||
references (dependencies) of the output of the builder. For
|
|
||||||
example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
allowedReferences = [];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
enforces that the output of a derivation cannot have any runtime
|
|
||||||
dependencies on its inputs. To allow an output to have a runtime
|
|
||||||
dependency on itself, use <literal>"out"</literal> as a list item.
|
|
||||||
This is used in NixOS to check that generated files such as
|
|
||||||
initial ramdisks for booting Linux don’t have accidental
|
|
||||||
dependencies on other paths in the Nix store.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-allowedRequisites"><term><varname>allowedRequisites</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>This attribute is similar to
|
|
||||||
<varname>allowedReferences</varname>, but it specifies the legal
|
|
||||||
requisites of the whole closure, so all the dependencies
|
|
||||||
recursively. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
allowedRequisites = [ foobar ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
enforces that the output of a derivation cannot have any other
|
|
||||||
runtime dependency than <varname>foobar</varname>, and in addition
|
|
||||||
it enforces that <varname>foobar</varname> itself doesn't
|
|
||||||
introduce any other dependency itself.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-disallowedReferences"><term><varname>disallowedReferences</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>The optional attribute
|
|
||||||
<varname>disallowedReferences</varname> specifies a list of illegal
|
|
||||||
references (dependencies) of the output of the builder. For
|
|
||||||
example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
disallowedReferences = [ foo ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
enforces that the output of a derivation cannot have a direct runtime
|
|
||||||
dependencies on the derivation <varname>foo</varname>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-disallowedRequisites"><term><varname>disallowedRequisites</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>This attribute is similar to
|
|
||||||
<varname>disallowedReferences</varname>, but it specifies illegal
|
|
||||||
requisites for the whole closure, so all the dependencies
|
|
||||||
recursively. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
disallowedRequisites = [ foobar ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
enforces that the output of a derivation cannot have any
|
|
||||||
runtime dependency on <varname>foobar</varname> or any other derivation
|
|
||||||
depending recursively on <varname>foobar</varname>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-exportReferencesGraph"><term><varname>exportReferencesGraph</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>This attribute allows builders access to the
|
|
||||||
references graph of their inputs. The attribute is a list of
|
|
||||||
inputs in the Nix store whose references graph the builder needs
|
|
||||||
to know. The value of this attribute should be a list of pairs
|
|
||||||
<literal>[ <replaceable>name1</replaceable>
|
|
||||||
<replaceable>path1</replaceable> <replaceable>name2</replaceable>
|
|
||||||
<replaceable>path2</replaceable> <replaceable>...</replaceable>
|
|
||||||
]</literal>. The references graph of each
|
|
||||||
<replaceable>pathN</replaceable> will be stored in a text file
|
|
||||||
<replaceable>nameN</replaceable> in the temporary build directory.
|
|
||||||
The text files have the format used by <command>nix-store
|
|
||||||
--register-validity</command> (with the deriver fields left
|
|
||||||
empty). For example, when the following derivation is built:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
derivation {
|
|
||||||
...
|
|
||||||
exportReferencesGraph = [ "libfoo-graph" libfoo ];
|
|
||||||
};
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
the references graph of <literal>libfoo</literal> is placed in the
|
|
||||||
file <filename>libfoo-graph</filename> in the temporary build
|
|
||||||
directory.</para>
|
|
||||||
|
|
||||||
<para><varname>exportReferencesGraph</varname> is useful for
|
|
||||||
builders that want to do something with the closure of a store
|
|
||||||
path. Examples include the builders in NixOS that generate the
|
|
||||||
initial ramdisk for booting Linux (a <command>cpio</command>
|
|
||||||
archive containing the closure of the boot script) and the
|
|
||||||
ISO-9660 image for the installation CD (which is populated with a
|
|
||||||
Nix store containing the closure of a bootable NixOS
|
|
||||||
configuration).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-impureEnvVars"><term><varname>impureEnvVars</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>This attribute allows you to specify a list of
|
|
||||||
environment variables that should be passed from the environment
|
|
||||||
of the calling user to the builder. Usually, the environment is
|
|
||||||
cleared completely when the builder is executed, but with this
|
|
||||||
attribute you can allow specific environment variables to be
|
|
||||||
passed unmodified. For example, <function>fetchurl</function> in
|
|
||||||
Nixpkgs has the line
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
impureEnvVars = [ "http_proxy" "https_proxy" <replaceable>...</replaceable> ];
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
to make it use the proxy server configuration specified by the
|
|
||||||
user in the environment variables <envar>http_proxy</envar> and
|
|
||||||
friends.</para>
|
|
||||||
|
|
||||||
<para>This attribute is only allowed in <link
|
|
||||||
linkend="fixed-output-drvs">fixed-output derivations</link>, where
|
|
||||||
impurities such as these are okay since (the hash of) the output
|
|
||||||
is known in advance. It is ignored for all other
|
|
||||||
derivations.</para>
|
|
||||||
|
|
||||||
<warning><para><varname>impureEnvVars</varname> implementation takes
|
|
||||||
environment variables from the current builder process. When a daemon is
|
|
||||||
building its environmental variables are used. Without the daemon, the
|
|
||||||
environmental variables come from the environment of the
|
|
||||||
<command>nix-build</command>.</para></warning></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="fixed-output-drvs">
|
|
||||||
<term xml:id="adv-attr-outputHash"><varname>outputHash</varname></term>
|
|
||||||
<term xml:id="adv-attr-outputHashAlgo"><varname>outputHashAlgo</varname></term>
|
|
||||||
<term xml:id="adv-attr-outputHashMode"><varname>outputHashMode</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>These attributes declare that the derivation is a
|
|
||||||
so-called <emphasis>fixed-output derivation</emphasis>, which
|
|
||||||
means that a cryptographic hash of the output is already known in
|
|
||||||
advance. When the build of a fixed-output derivation finishes,
|
|
||||||
Nix computes the cryptographic hash of the output and compares it
|
|
||||||
to the hash declared with these attributes. If there is a
|
|
||||||
mismatch, the build fails.</para>
|
|
||||||
|
|
||||||
<para>The rationale for fixed-output derivations is derivations
|
|
||||||
such as those produced by the <function>fetchurl</function>
|
|
||||||
function. This function downloads a file from a given URL. To
|
|
||||||
ensure that the downloaded file has not been modified, the caller
|
|
||||||
must also specify a cryptographic hash of the file. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
fetchurl {
|
|
||||||
url = http://ftp.gnu.org/pub/gnu/hello/hello-2.1.1.tar.gz;
|
|
||||||
sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
It sometimes happens that the URL of the file changes, e.g.,
|
|
||||||
because servers are reorganised or no longer available. We then
|
|
||||||
must update the call to <function>fetchurl</function>, e.g.,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
fetchurl {
|
|
||||||
url = ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz;
|
|
||||||
sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
If a <function>fetchurl</function> derivation was treated like a
|
|
||||||
normal derivation, the output paths of the derivation and
|
|
||||||
<emphasis>all derivations depending on it</emphasis> would change.
|
|
||||||
For instance, if we were to change the URL of the Glibc source
|
|
||||||
distribution in Nixpkgs (a package on which almost all other
|
|
||||||
packages depend) massive rebuilds would be needed. This is
|
|
||||||
unfortunate for a change which we know cannot have a real effect
|
|
||||||
as it propagates upwards through the dependency graph.</para>
|
|
||||||
|
|
||||||
<para>For fixed-output derivations, on the other hand, the name of
|
|
||||||
the output path only depends on the <varname>outputHash*</varname>
|
|
||||||
and <varname>name</varname> attributes, while all other attributes
|
|
||||||
are ignored for the purpose of computing the output path. (The
|
|
||||||
<varname>name</varname> attribute is included because it is part
|
|
||||||
of the path.)</para>
|
|
||||||
|
|
||||||
<para>As an example, here is the (simplified) Nix expression for
|
|
||||||
<varname>fetchurl</varname>:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ stdenv, curl }: # The <command>curl</command> program is used for downloading.
|
|
||||||
|
|
||||||
{ url, sha256 }:
|
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
|
||||||
name = baseNameOf (toString url);
|
|
||||||
builder = ./builder.sh;
|
|
||||||
buildInputs = [ curl ];
|
|
||||||
|
|
||||||
# This is a fixed-output derivation; the output must be a regular
|
|
||||||
# file with SHA256 hash <varname>sha256</varname>.
|
|
||||||
outputHashMode = "flat";
|
|
||||||
outputHashAlgo = "sha256";
|
|
||||||
outputHash = sha256;
|
|
||||||
|
|
||||||
inherit url;
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The <varname>outputHashAlgo</varname> attribute specifies
|
|
||||||
the hash algorithm used to compute the hash. It can currently be
|
|
||||||
<literal>"sha1"</literal>, <literal>"sha256"</literal> or
|
|
||||||
<literal>"sha512"</literal>.</para>
|
|
||||||
|
|
||||||
<para>The <varname>outputHashMode</varname> attribute determines
|
|
||||||
how the hash is computed. It must be one of the following two
|
|
||||||
values:
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><literal>"flat"</literal></term>
|
|
||||||
|
|
||||||
<listitem><para>The output must be a non-executable regular
|
|
||||||
file. If it isn’t, the build fails. The hash is simply
|
|
||||||
computed over the contents of that file (so it’s equal to what
|
|
||||||
Unix commands like <command>sha256sum</command> or
|
|
||||||
<command>sha1sum</command> produce).</para>
|
|
||||||
|
|
||||||
<para>This is the default.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><literal>"recursive"</literal></term>
|
|
||||||
|
|
||||||
<listitem><para>The hash is computed over the NAR archive dump
|
|
||||||
of the output (i.e., the result of <link
|
|
||||||
linkend="refsec-nix-store-dump"><command>nix-store
|
|
||||||
--dump</command></link>). In this case, the output can be
|
|
||||||
anything, including a directory tree.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The <varname>outputHash</varname> attribute, finally, must
|
|
||||||
be a string containing the hash in either hexadecimal or base-32
|
|
||||||
notation. (See the <link
|
|
||||||
linkend="sec-nix-hash"><command>nix-hash</command> command</link>
|
|
||||||
for information about converting to and from base-32
|
|
||||||
notation.)</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-passAsFile"><term><varname>passAsFile</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>A list of names of attributes that should be
|
|
||||||
passed via files rather than environment variables. For example,
|
|
||||||
if you have
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
passAsFile = ["big"];
|
|
||||||
big = "a very long string";
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
then when the builder runs, the environment variable
|
|
||||||
<envar>bigPath</envar> will contain the absolute path to a
|
|
||||||
temporary file containing <literal>a very long
|
|
||||||
string</literal>. That is, for any attribute
|
|
||||||
<replaceable>x</replaceable> listed in
|
|
||||||
<varname>passAsFile</varname>, Nix will pass an environment
|
|
||||||
variable <envar><replaceable>x</replaceable>Path</envar> holding
|
|
||||||
the path of the file containing the value of attribute
|
|
||||||
<replaceable>x</replaceable>. This is useful when you need to pass
|
|
||||||
large strings to a builder, since most operating systems impose a
|
|
||||||
limit on the size of the environment (typically, a few hundred
|
|
||||||
kilobyte).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-preferLocalBuild"><term><varname>preferLocalBuild</varname></term>
|
|
||||||
|
|
||||||
<listitem><para>If this attribute is set to
|
|
||||||
<literal>true</literal> and <link
|
|
||||||
linkend="chap-distributed-builds">distributed building is
|
|
||||||
enabled</link>, then, if possible, the derivaton will be built
|
|
||||||
locally instead of forwarded to a remote machine. This is
|
|
||||||
appropriate for trivial builders where the cost of doing a
|
|
||||||
download or remote build would exceed the cost of building
|
|
||||||
locally.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="adv-attr-allowSubstitutes"><term><varname>allowSubstitutes</varname></term>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>If this attribute is set to
|
|
||||||
<literal>false</literal>, then Nix will always build this
|
|
||||||
derivation; it will not try to substitute its outputs. This is
|
|
||||||
useful for very trivial derivations (such as
|
|
||||||
<function>writeText</function> in Nixpkgs) that are cheaper to
|
|
||||||
build than to substitute from a binary cache.</para>
|
|
||||||
|
|
||||||
<note><para>You need to have a builder configured which satisfies
|
|
||||||
the derivation’s <literal>system</literal> attribute, since the
|
|
||||||
derivation cannot be substituted. Thus it is usually a good idea
|
|
||||||
to align <literal>system</literal> with
|
|
||||||
<literal>builtins.currentSystem</literal> when setting
|
|
||||||
<literal>allowSubstitutes</literal> to <literal>false</literal>.
|
|
||||||
For most trivial derivations this should be the case.
|
|
||||||
</para></note>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='sec-arguments'>
|
|
||||||
|
|
||||||
<title>Arguments and Variables</title>
|
|
||||||
|
|
||||||
<example xml:id='ex-hello-composition'>
|
|
||||||
|
|
||||||
<title>Composing GNU Hello
|
|
||||||
(<filename>all-packages.nix</filename>)</title>
|
|
||||||
<programlisting>
|
|
||||||
...
|
|
||||||
|
|
||||||
rec { <co xml:id='ex-hello-composition-co-1' />
|
|
||||||
|
|
||||||
hello = import ../applications/misc/hello/ex-1 <co xml:id='ex-hello-composition-co-2' /> { <co xml:id='ex-hello-composition-co-3' />
|
|
||||||
inherit fetchurl stdenv perl;
|
|
||||||
};
|
|
||||||
|
|
||||||
perl = import ../development/interpreters/perl { <co xml:id='ex-hello-composition-co-4' />
|
|
||||||
inherit fetchurl stdenv;
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchurl = import ../build-support/fetchurl {
|
|
||||||
inherit stdenv; ...
|
|
||||||
};
|
|
||||||
|
|
||||||
stdenv = ...;
|
|
||||||
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para>The Nix expression in <xref linkend='ex-hello-nix' /> is a
|
|
||||||
function; it is missing some arguments that have to be filled in
|
|
||||||
somewhere. In the Nix Packages collection this is done in the file
|
|
||||||
<filename>pkgs/top-level/all-packages.nix</filename>, where all
|
|
||||||
Nix expressions for packages are imported and called with the
|
|
||||||
appropriate arguments. <xref linkend='ex-hello-composition' /> shows
|
|
||||||
some fragments of
|
|
||||||
<filename>all-packages.nix</filename>.</para>
|
|
||||||
|
|
||||||
<calloutlist>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-composition-co-1'>
|
|
||||||
|
|
||||||
<para>This file defines a set of attributes, all of which are
|
|
||||||
concrete derivations (i.e., not functions). In fact, we define a
|
|
||||||
<emphasis>mutually recursive</emphasis> set of attributes. That
|
|
||||||
is, the attributes can refer to each other. This is precisely
|
|
||||||
what we want since we want to <quote>plug</quote> the
|
|
||||||
various packages into each other.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-composition-co-2'>
|
|
||||||
|
|
||||||
<para>Here we <emphasis>import</emphasis> the Nix expression for
|
|
||||||
GNU Hello. The import operation just loads and returns the
|
|
||||||
specified Nix expression. In fact, we could just have put the
|
|
||||||
contents of <xref linkend='ex-hello-nix' /> in
|
|
||||||
<filename>all-packages.nix</filename> at this point. That
|
|
||||||
would be completely equivalent, but it would make the file rather
|
|
||||||
bulky.</para>
|
|
||||||
|
|
||||||
<para>Note that we refer to
|
|
||||||
<filename>../applications/misc/hello/ex-1</filename>, not
|
|
||||||
<filename>../applications/misc/hello/ex-1/default.nix</filename>.
|
|
||||||
When you try to import a directory, Nix automatically appends
|
|
||||||
<filename>/default.nix</filename> to the file name.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-composition-co-3'>
|
|
||||||
|
|
||||||
<para>This is where the actual composition takes place. Here we
|
|
||||||
<emphasis>call</emphasis> the function imported from
|
|
||||||
<filename>../applications/misc/hello/ex-1</filename> with a set
|
|
||||||
containing the things that the function expects, namely
|
|
||||||
<varname>fetchurl</varname>, <varname>stdenv</varname>, and
|
|
||||||
<varname>perl</varname>. We use inherit again to use the
|
|
||||||
attributes defined in the surrounding scope (we could also have
|
|
||||||
written <literal>fetchurl = fetchurl;</literal>, etc.).</para>
|
|
||||||
|
|
||||||
<para>The result of this function call is an actual derivation
|
|
||||||
that can be built by Nix (since when we fill in the arguments of
|
|
||||||
the function, what we get is its body, which is the call to
|
|
||||||
<varname>stdenv.mkDerivation</varname> in <xref
|
|
||||||
linkend='ex-hello-nix' />).</para>
|
|
||||||
|
|
||||||
<note><para>Nixpkgs has a convenience function
|
|
||||||
<function>callPackage</function> that imports and calls a
|
|
||||||
function, filling in any missing arguments by passing the
|
|
||||||
corresponding attribute from the Nixpkgs set, like this:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
hello = callPackage ../applications/misc/hello/ex-1 { };
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
If necessary, you can set or override arguments:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
hello = callPackage ../applications/misc/hello/ex-1 { stdenv = myStdenv; };
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para></note>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-composition-co-4'>
|
|
||||||
|
|
||||||
<para>Likewise, we have to instantiate Perl,
|
|
||||||
<varname>fetchurl</varname>, and the standard environment.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
</calloutlist>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='sec-build-script'>
|
|
||||||
|
|
||||||
<title>Build Script</title>
|
|
||||||
|
|
||||||
<example xml:id='ex-hello-builder'><title>Build script for GNU Hello
|
|
||||||
(<filename>builder.sh</filename>)</title>
|
|
||||||
<programlisting>
|
|
||||||
source $stdenv/setup <co xml:id='ex-hello-builder-co-1' />
|
|
||||||
|
|
||||||
PATH=$perl/bin:$PATH <co xml:id='ex-hello-builder-co-2' />
|
|
||||||
|
|
||||||
tar xvfz $src <co xml:id='ex-hello-builder-co-3' />
|
|
||||||
cd hello-*
|
|
||||||
./configure --prefix=$out <co xml:id='ex-hello-builder-co-4' />
|
|
||||||
make <co xml:id='ex-hello-builder-co-5' />
|
|
||||||
make install</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para><xref linkend='ex-hello-builder' /> shows the builder referenced
|
|
||||||
from Hello's Nix expression (stored in
|
|
||||||
<filename>pkgs/applications/misc/hello/ex-1/builder.sh</filename>).
|
|
||||||
The builder can actually be made a lot shorter by using the
|
|
||||||
<emphasis>generic builder</emphasis> functions provided by
|
|
||||||
<varname>stdenv</varname>, but here we write out the build steps to
|
|
||||||
elucidate what a builder does. It performs the following
|
|
||||||
steps:</para>
|
|
||||||
|
|
||||||
<calloutlist>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-1'>
|
|
||||||
|
|
||||||
<para>When Nix runs a builder, it initially completely clears the
|
|
||||||
environment (except for the attributes declared in the
|
|
||||||
derivation). For instance, the <envar>PATH</envar> variable is
|
|
||||||
empty<footnote><para>Actually, it's initialised to
|
|
||||||
<filename>/path-not-set</filename> to prevent Bash from setting it
|
|
||||||
to a default value.</para></footnote>. This is done to prevent
|
|
||||||
undeclared inputs from being used in the build process. If for
|
|
||||||
example the <envar>PATH</envar> contained
|
|
||||||
<filename>/usr/bin</filename>, then you might accidentally use
|
|
||||||
<filename>/usr/bin/gcc</filename>.</para>
|
|
||||||
|
|
||||||
<para>So the first step is to set up the environment. This is
|
|
||||||
done by calling the <filename>setup</filename> script of the
|
|
||||||
standard environment. The environment variable
|
|
||||||
<envar>stdenv</envar> points to the location of the standard
|
|
||||||
environment being used. (It wasn't specified explicitly as an
|
|
||||||
attribute in <xref linkend='ex-hello-nix' />, but
|
|
||||||
<varname>mkDerivation</varname> adds it automatically.)</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-2'>
|
|
||||||
|
|
||||||
<para>Since Hello needs Perl, we have to make sure that Perl is in
|
|
||||||
the <envar>PATH</envar>. The <envar>perl</envar> environment
|
|
||||||
variable points to the location of the Perl package (since it
|
|
||||||
was passed in as an attribute to the derivation), so
|
|
||||||
<filename><replaceable>$perl</replaceable>/bin</filename> is the
|
|
||||||
directory containing the Perl interpreter.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-3'>
|
|
||||||
|
|
||||||
<para>Now we have to unpack the sources. The
|
|
||||||
<varname>src</varname> attribute was bound to the result of
|
|
||||||
fetching the Hello source tarball from the network, so the
|
|
||||||
<envar>src</envar> environment variable points to the location in
|
|
||||||
the Nix store to which the tarball was downloaded. After
|
|
||||||
unpacking, we <command>cd</command> to the resulting source
|
|
||||||
directory.</para>
|
|
||||||
|
|
||||||
<para>The whole build is performed in a temporary directory
|
|
||||||
created in <varname>/tmp</varname>, by the way. This directory is
|
|
||||||
removed after the builder finishes, so there is no need to clean
|
|
||||||
up the sources afterwards. Also, the temporary directory is
|
|
||||||
always newly created, so you don't have to worry about files from
|
|
||||||
previous builds interfering with the current build.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-4'>
|
|
||||||
|
|
||||||
<para>GNU Hello is a typical Autoconf-based package, so we first
|
|
||||||
have to run its <filename>configure</filename> script. In Nix
|
|
||||||
every package is stored in a separate location in the Nix store,
|
|
||||||
for instance
|
|
||||||
<filename>/nix/store/9a54ba97fb71b65fda531012d0443ce2-hello-2.1.1</filename>.
|
|
||||||
Nix computes this path by cryptographically hashing all attributes
|
|
||||||
of the derivation. The path is passed to the builder through the
|
|
||||||
<envar>out</envar> environment variable. So here we give
|
|
||||||
<filename>configure</filename> the parameter
|
|
||||||
<literal>--prefix=$out</literal> to cause Hello to be installed in
|
|
||||||
the expected location.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-5'>
|
|
||||||
|
|
||||||
<para>Finally we build Hello (<literal>make</literal>) and install
|
|
||||||
it into the location specified by <envar>out</envar>
|
|
||||||
(<literal>make install</literal>).</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
</calloutlist>
|
|
||||||
|
|
||||||
<para>If you are wondering about the absence of error checking on the
|
|
||||||
result of various commands called in the builder: this is because the
|
|
||||||
shell script is evaluated with Bash's <option>-e</option> option,
|
|
||||||
which causes the script to be aborted if any command fails without an
|
|
||||||
error check.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='sec-builder-syntax'>
|
|
||||||
|
|
||||||
<title>Builder Syntax</title>
|
|
||||||
|
|
||||||
<example xml:id='ex-hello-builder'><title>Build script for GNU Hello
|
|
||||||
(<filename>builder.sh</filename>)</title>
|
|
||||||
<programlisting>
|
|
||||||
source $stdenv/setup <co xml:id='ex-hello-builder-co-1' />
|
|
||||||
|
|
||||||
PATH=$perl/bin:$PATH <co xml:id='ex-hello-builder-co-2' />
|
|
||||||
|
|
||||||
tar xvfz $src <co xml:id='ex-hello-builder-co-3' />
|
|
||||||
cd hello-*
|
|
||||||
./configure --prefix=$out <co xml:id='ex-hello-builder-co-4' />
|
|
||||||
make <co xml:id='ex-hello-builder-co-5' />
|
|
||||||
make install</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para><xref linkend='ex-hello-builder' /> shows the builder referenced
|
|
||||||
from Hello's Nix expression (stored in
|
|
||||||
<filename>pkgs/applications/misc/hello/ex-1/builder.sh</filename>).
|
|
||||||
The builder can actually be made a lot shorter by using the
|
|
||||||
<emphasis>generic builder</emphasis> functions provided by
|
|
||||||
<varname>stdenv</varname>, but here we write out the build steps to
|
|
||||||
elucidate what a builder does. It performs the following
|
|
||||||
steps:</para>
|
|
||||||
|
|
||||||
<calloutlist>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-1'>
|
|
||||||
|
|
||||||
<para>When Nix runs a builder, it initially completely clears the
|
|
||||||
environment (except for the attributes declared in the
|
|
||||||
derivation). For instance, the <envar>PATH</envar> variable is
|
|
||||||
empty<footnote><para>Actually, it's initialised to
|
|
||||||
<filename>/path-not-set</filename> to prevent Bash from setting it
|
|
||||||
to a default value.</para></footnote>. This is done to prevent
|
|
||||||
undeclared inputs from being used in the build process. If for
|
|
||||||
example the <envar>PATH</envar> contained
|
|
||||||
<filename>/usr/bin</filename>, then you might accidentally use
|
|
||||||
<filename>/usr/bin/gcc</filename>.</para>
|
|
||||||
|
|
||||||
<para>So the first step is to set up the environment. This is
|
|
||||||
done by calling the <filename>setup</filename> script of the
|
|
||||||
standard environment. The environment variable
|
|
||||||
<envar>stdenv</envar> points to the location of the standard
|
|
||||||
environment being used. (It wasn't specified explicitly as an
|
|
||||||
attribute in <xref linkend='ex-hello-nix' />, but
|
|
||||||
<varname>mkDerivation</varname> adds it automatically.)</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-2'>
|
|
||||||
|
|
||||||
<para>Since Hello needs Perl, we have to make sure that Perl is in
|
|
||||||
the <envar>PATH</envar>. The <envar>perl</envar> environment
|
|
||||||
variable points to the location of the Perl package (since it
|
|
||||||
was passed in as an attribute to the derivation), so
|
|
||||||
<filename><replaceable>$perl</replaceable>/bin</filename> is the
|
|
||||||
directory containing the Perl interpreter.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-3'>
|
|
||||||
|
|
||||||
<para>Now we have to unpack the sources. The
|
|
||||||
<varname>src</varname> attribute was bound to the result of
|
|
||||||
fetching the Hello source tarball from the network, so the
|
|
||||||
<envar>src</envar> environment variable points to the location in
|
|
||||||
the Nix store to which the tarball was downloaded. After
|
|
||||||
unpacking, we <command>cd</command> to the resulting source
|
|
||||||
directory.</para>
|
|
||||||
|
|
||||||
<para>The whole build is performed in a temporary directory
|
|
||||||
created in <varname>/tmp</varname>, by the way. This directory is
|
|
||||||
removed after the builder finishes, so there is no need to clean
|
|
||||||
up the sources afterwards. Also, the temporary directory is
|
|
||||||
always newly created, so you don't have to worry about files from
|
|
||||||
previous builds interfering with the current build.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-4'>
|
|
||||||
|
|
||||||
<para>GNU Hello is a typical Autoconf-based package, so we first
|
|
||||||
have to run its <filename>configure</filename> script. In Nix
|
|
||||||
every package is stored in a separate location in the Nix store,
|
|
||||||
for instance
|
|
||||||
<filename>/nix/store/9a54ba97fb71b65fda531012d0443ce2-hello-2.1.1</filename>.
|
|
||||||
Nix computes this path by cryptographically hashing all attributes
|
|
||||||
of the derivation. The path is passed to the builder through the
|
|
||||||
<envar>out</envar> environment variable. So here we give
|
|
||||||
<filename>configure</filename> the parameter
|
|
||||||
<literal>--prefix=$out</literal> to cause Hello to be installed in
|
|
||||||
the expected location.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder-co-5'>
|
|
||||||
|
|
||||||
<para>Finally we build Hello (<literal>make</literal>) and install
|
|
||||||
it into the location specified by <envar>out</envar>
|
|
||||||
(<literal>make install</literal>).</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
</calloutlist>
|
|
||||||
|
|
||||||
<para>If you are wondering about the absence of error checking on the
|
|
||||||
result of various commands called in the builder: this is because the
|
|
||||||
shell script is evaluated with Bash's <option>-e</option> option,
|
|
||||||
which causes the script to be aborted if any command fails without an
|
|
||||||
error check.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,211 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ssec-derivation">
|
|
||||||
|
|
||||||
<title>Derivations</title>
|
|
||||||
|
|
||||||
<para>The most important built-in function is
|
|
||||||
<function>derivation</function>, which is used to describe a single
|
|
||||||
derivation (a build action). It takes as input a set, the attributes
|
|
||||||
of which specify the inputs of the build.</para>
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem xml:id="attr-system"><para>There must be an attribute named
|
|
||||||
<varname>system</varname> whose value must be a string specifying a
|
|
||||||
Nix platform identifier, such as <literal>"i686-linux"</literal> or
|
|
||||||
<literal>"x86_64-darwin"</literal><footnote><para>To figure out
|
|
||||||
your platform identifier, look at the line <quote>Checking for the
|
|
||||||
canonical Nix system name</quote> in the output of Nix's
|
|
||||||
<filename>configure</filename> script.</para></footnote> The build
|
|
||||||
can only be performed on a machine and operating system matching the
|
|
||||||
platform identifier. (Nix can automatically forward builds for
|
|
||||||
other platforms by forwarding them to other machines; see <xref
|
|
||||||
linkend='chap-distributed-builds' />.)</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>There must be an attribute named
|
|
||||||
<varname>name</varname> whose value must be a string. This is used
|
|
||||||
as a symbolic name for the package by <command>nix-env</command>,
|
|
||||||
and it is appended to the output paths of the
|
|
||||||
derivation.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>There must be an attribute named
|
|
||||||
<varname>builder</varname> that identifies the program that is
|
|
||||||
executed to perform the build. It can be either a derivation or a
|
|
||||||
source (a local file reference, e.g.,
|
|
||||||
<filename>./builder.sh</filename>).</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Every attribute is passed as an environment variable
|
|
||||||
to the builder. Attribute values are translated to environment
|
|
||||||
variables as follows:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para>Strings and numbers are just passed
|
|
||||||
verbatim.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A <emphasis>path</emphasis> (e.g.,
|
|
||||||
<filename>../foo/sources.tar</filename>) causes the referenced
|
|
||||||
file to be copied to the store; its location in the store is put
|
|
||||||
in the environment variable. The idea is that all sources
|
|
||||||
should reside in the Nix store, since all inputs to a derivation
|
|
||||||
should reside in the Nix store.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A <emphasis>derivation</emphasis> causes that
|
|
||||||
derivation to be built prior to the present derivation; its
|
|
||||||
default output path is put in the environment
|
|
||||||
variable.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Lists of the previous types are also allowed.
|
|
||||||
They are simply concatenated, separated by
|
|
||||||
spaces.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><literal>true</literal> is passed as the string
|
|
||||||
<literal>1</literal>, <literal>false</literal> and
|
|
||||||
<literal>null</literal> are passed as an empty string.
|
|
||||||
</para></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The optional attribute <varname>args</varname>
|
|
||||||
specifies command-line arguments to be passed to the builder. It
|
|
||||||
should be a list.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The optional attribute <varname>outputs</varname>
|
|
||||||
specifies a list of symbolic outputs of the derivation. By default,
|
|
||||||
a derivation produces a single output path, denoted as
|
|
||||||
<literal>out</literal>. However, derivations can produce multiple
|
|
||||||
output paths. This is useful because it allows outputs to be
|
|
||||||
downloaded or garbage-collected separately. For instance, imagine a
|
|
||||||
library package that provides a dynamic library, header files, and
|
|
||||||
documentation. A program that links against the library doesn’t
|
|
||||||
need the header files and documentation at runtime, and it doesn’t
|
|
||||||
need the documentation at build time. Thus, the library package
|
|
||||||
could specify:
|
|
||||||
<programlisting>
|
|
||||||
outputs = [ "lib" "headers" "doc" ];
|
|
||||||
</programlisting>
|
|
||||||
This will cause Nix to pass environment variables
|
|
||||||
<literal>lib</literal>, <literal>headers</literal> and
|
|
||||||
<literal>doc</literal> to the builder containing the intended store
|
|
||||||
paths of each output. The builder would typically do something like
|
|
||||||
<programlisting>
|
|
||||||
./configure --libdir=$lib/lib --includedir=$headers/include --docdir=$doc/share/doc
|
|
||||||
</programlisting>
|
|
||||||
for an Autoconf-style package. You can refer to each output of a
|
|
||||||
derivation by selecting it as an attribute, e.g.
|
|
||||||
<programlisting>
|
|
||||||
buildInputs = [ pkg.lib pkg.headers ];
|
|
||||||
</programlisting>
|
|
||||||
The first element of <varname>outputs</varname> determines the
|
|
||||||
<emphasis>default output</emphasis>. Thus, you could also write
|
|
||||||
<programlisting>
|
|
||||||
buildInputs = [ pkg pkg.headers ];
|
|
||||||
</programlisting>
|
|
||||||
since <literal>pkg</literal> is equivalent to
|
|
||||||
<literal>pkg.lib</literal>.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
<para>The function <function>mkDerivation</function> in the Nixpkgs
|
|
||||||
standard environment is a wrapper around
|
|
||||||
<function>derivation</function> that adds a default value for
|
|
||||||
<varname>system</varname> and always uses Bash as the builder, to
|
|
||||||
which the supplied builder is passed as a command-line argument. See
|
|
||||||
the Nixpkgs manual for details.</para>
|
|
||||||
|
|
||||||
<para>The builder is executed as follows:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para>A temporary directory is created under the directory
|
|
||||||
specified by <envar>TMPDIR</envar> (default
|
|
||||||
<filename>/tmp</filename>) where the build will take place. The
|
|
||||||
current directory is changed to this directory.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The environment is cleared and set to the derivation
|
|
||||||
attributes, as specified above.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>In addition, the following variables are set:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para><envar>NIX_BUILD_TOP</envar> contains the path of
|
|
||||||
the temporary directory for this build.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Also, <envar>TMPDIR</envar>,
|
|
||||||
<envar>TEMPDIR</envar>, <envar>TMP</envar>, <envar>TEMP</envar>
|
|
||||||
are set to point to the temporary directory. This is to prevent
|
|
||||||
the builder from accidentally writing temporary files anywhere
|
|
||||||
else. Doing so might cause interference by other
|
|
||||||
processes.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><envar>PATH</envar> is set to
|
|
||||||
<filename>/path-not-set</filename> to prevent shells from
|
|
||||||
initialising it to their built-in default value.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><envar>HOME</envar> is set to
|
|
||||||
<filename>/homeless-shelter</filename> to prevent programs from
|
|
||||||
using <filename>/etc/passwd</filename> or the like to find the
|
|
||||||
user's home directory, which could cause impurity. Usually, when
|
|
||||||
<envar>HOME</envar> is set, it is used as the location of the home
|
|
||||||
directory, even if it points to a non-existent
|
|
||||||
path.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><envar>NIX_STORE</envar> is set to the path of the
|
|
||||||
top-level Nix store directory (typically,
|
|
||||||
<filename>/nix/store</filename>).</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>For each output declared in
|
|
||||||
<varname>outputs</varname>, the corresponding environment variable
|
|
||||||
is set to point to the intended path in the Nix store for that
|
|
||||||
output. Each output path is a concatenation of the cryptographic
|
|
||||||
hash of all build inputs, the <varname>name</varname> attribute
|
|
||||||
and the output name. (The output name is omitted if it’s
|
|
||||||
<literal>out</literal>.)</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>If an output path already exists, it is removed.
|
|
||||||
Also, locks are acquired to prevent multiple Nix instances from
|
|
||||||
performing the same build at the same time.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A log of the combined standard output and error is
|
|
||||||
written to <filename>/nix/var/log/nix</filename>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The builder is executed with the arguments specified
|
|
||||||
by the attribute <varname>args</varname>. If it exits with exit
|
|
||||||
code 0, it is considered to have succeeded.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The temporary directory is removed (unless the
|
|
||||||
<option>-K</option> option was specified).</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>If the build was successful, Nix scans each output
|
|
||||||
path for references to input paths by looking for the hash parts of
|
|
||||||
the input paths. Since these are potential runtime dependencies,
|
|
||||||
Nix registers them as dependencies of the output
|
|
||||||
paths.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>After the build, Nix sets the last-modified
|
|
||||||
timestamp on all files in the build result to 1 (00:00:01 1/1/1970
|
|
||||||
UTC), sets the group to the default group, and sets the mode of the
|
|
||||||
file to 0444 or 0555 (i.e., read-only, with execute permission
|
|
||||||
enabled if the file was originally executable). Note that possible
|
|
||||||
<literal>setuid</literal> and <literal>setgid</literal> bits are
|
|
||||||
cleared. Setuid and setgid programs are not currently supported by
|
|
||||||
Nix. This is because the Nix archives used in deployment have no
|
|
||||||
concept of ownership information, and because it makes the build
|
|
||||||
result dependent on the user performing the build.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<xi:include href="advanced-attributes.xml" />
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-expression-language">
|
|
||||||
|
|
||||||
<title>Nix Expression Language</title>
|
|
||||||
|
|
||||||
<para>The Nix expression language is a pure, lazy, functional
|
|
||||||
language. Purity means that operations in the language don't have
|
|
||||||
side-effects (for instance, there is no variable assignment).
|
|
||||||
Laziness means that arguments to functions are evaluated only when
|
|
||||||
they are needed. Functional means that functions are
|
|
||||||
<quote>normal</quote> values that can be passed around and manipulated
|
|
||||||
in interesting ways. The language is not a full-featured, general
|
|
||||||
purpose language. Its main job is to describe packages,
|
|
||||||
compositions of packages, and the variability within
|
|
||||||
packages.</para>
|
|
||||||
|
|
||||||
<para>This section presents the various features of the
|
|
||||||
language.</para>
|
|
||||||
|
|
||||||
<xi:include href="language-values.xml" />
|
|
||||||
<xi:include href="language-constructs.xml" />
|
|
||||||
<xi:include href="language-operators.xml" />
|
|
||||||
<xi:include href="derivations.xml" />
|
|
||||||
<xi:include href="builtins.xml" />
|
|
||||||
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='sec-expression-syntax'>
|
|
||||||
|
|
||||||
<title>Expression Syntax</title>
|
|
||||||
|
|
||||||
<example xml:id='ex-hello-nix'><title>Nix expression for GNU Hello
|
|
||||||
(<filename>default.nix</filename>)</title>
|
|
||||||
<programlisting>
|
|
||||||
{ stdenv, fetchurl, perl }: <co xml:id='ex-hello-nix-co-1' />
|
|
||||||
|
|
||||||
stdenv.mkDerivation { <co xml:id='ex-hello-nix-co-2' />
|
|
||||||
name = "hello-2.1.1"; <co xml:id='ex-hello-nix-co-3' />
|
|
||||||
builder = ./builder.sh; <co xml:id='ex-hello-nix-co-4' />
|
|
||||||
src = fetchurl { <co xml:id='ex-hello-nix-co-5' />
|
|
||||||
url = ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz;
|
|
||||||
sha256 = "1md7jsfd8pa45z73bz1kszpp01yw6x5ljkjk2hx7wl800any6465";
|
|
||||||
};
|
|
||||||
inherit perl; <co xml:id='ex-hello-nix-co-6' />
|
|
||||||
}</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para><xref linkend='ex-hello-nix' /> shows a Nix expression for GNU
|
|
||||||
Hello. It's actually already in the Nix Packages collection in
|
|
||||||
<filename>pkgs/applications/misc/hello/ex-1/default.nix</filename>.
|
|
||||||
It is customary to place each package in a separate directory and call
|
|
||||||
the single Nix expression in that directory
|
|
||||||
<filename>default.nix</filename>. The file has the following elements
|
|
||||||
(referenced from the figure by number):
|
|
||||||
|
|
||||||
<calloutlist>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-nix-co-1'>
|
|
||||||
|
|
||||||
<para>This states that the expression is a
|
|
||||||
<emphasis>function</emphasis> that expects to be called with three
|
|
||||||
arguments: <varname>stdenv</varname>, <varname>fetchurl</varname>,
|
|
||||||
and <varname>perl</varname>. They are needed to build Hello, but
|
|
||||||
we don't know how to build them here; that's why they are function
|
|
||||||
arguments. <varname>stdenv</varname> is a package that is used
|
|
||||||
by almost all Nix Packages packages; it provides a
|
|
||||||
<quote>standard</quote> environment consisting of the things you
|
|
||||||
would expect in a basic Unix environment: a C/C++ compiler (GCC,
|
|
||||||
to be precise), the Bash shell, fundamental Unix tools such as
|
|
||||||
<command>cp</command>, <command>grep</command>,
|
|
||||||
<command>tar</command>, etc. <varname>fetchurl</varname> is a
|
|
||||||
function that downloads files. <varname>perl</varname> is the
|
|
||||||
Perl interpreter.</para>
|
|
||||||
|
|
||||||
<para>Nix functions generally have the form <literal>{ x, y, ...,
|
|
||||||
z }: e</literal> where <varname>x</varname>, <varname>y</varname>,
|
|
||||||
etc. are the names of the expected arguments, and where
|
|
||||||
<replaceable>e</replaceable> is the body of the function. So
|
|
||||||
here, the entire remainder of the file is the body of the
|
|
||||||
function; when given the required arguments, the body should
|
|
||||||
describe how to build an instance of the Hello package.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-nix-co-2'>
|
|
||||||
|
|
||||||
<para>So we have to build a package. Building something from
|
|
||||||
other stuff is called a <emphasis>derivation</emphasis> in Nix (as
|
|
||||||
opposed to sources, which are built by humans instead of
|
|
||||||
computers). We perform a derivation by calling
|
|
||||||
<varname>stdenv.mkDerivation</varname>.
|
|
||||||
<varname>mkDerivation</varname> is a function provided by
|
|
||||||
<varname>stdenv</varname> that builds a package from a set of
|
|
||||||
<emphasis>attributes</emphasis>. A set is just a list of
|
|
||||||
key/value pairs where each key is a string and each value is an
|
|
||||||
arbitrary Nix expression. They take the general form <literal>{
|
|
||||||
<replaceable>name1</replaceable> =
|
|
||||||
<replaceable>expr1</replaceable>; <replaceable>...</replaceable>
|
|
||||||
<replaceable>nameN</replaceable> =
|
|
||||||
<replaceable>exprN</replaceable>; }</literal>.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-nix-co-3'>
|
|
||||||
|
|
||||||
<para>The attribute <varname>name</varname> specifies the symbolic
|
|
||||||
name and version of the package. Nix doesn't really care about
|
|
||||||
these things, but they are used by for instance <command>nix-env
|
|
||||||
-q</command> to show a <quote>human-readable</quote> name for
|
|
||||||
packages. This attribute is required by
|
|
||||||
<varname>mkDerivation</varname>.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-nix-co-4'>
|
|
||||||
|
|
||||||
<para>The attribute <varname>builder</varname> specifies the
|
|
||||||
builder. This attribute can sometimes be omitted, in which case
|
|
||||||
<varname>mkDerivation</varname> will fill in a default builder
|
|
||||||
(which does a <literal>configure; make; make install</literal>, in
|
|
||||||
essence). Hello is sufficiently simple that the default builder
|
|
||||||
would suffice, but in this case, we will show an actual builder
|
|
||||||
for educational purposes. The value
|
|
||||||
<command>./builder.sh</command> refers to the shell script shown
|
|
||||||
in <xref linkend='ex-hello-builder' />, discussed below.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-nix-co-5'>
|
|
||||||
|
|
||||||
<para>The builder has to know what the sources of the package
|
|
||||||
are. Here, the attribute <varname>src</varname> is bound to the
|
|
||||||
result of a call to the <command>fetchurl</command> function.
|
|
||||||
Given a URL and a SHA-256 hash of the expected contents of the file
|
|
||||||
at that URL, this function builds a derivation that downloads the
|
|
||||||
file and checks its hash. So the sources are a dependency that
|
|
||||||
like all other dependencies is built before Hello itself is
|
|
||||||
built.</para>
|
|
||||||
|
|
||||||
<para>Instead of <varname>src</varname> any other name could have
|
|
||||||
been used, and in fact there can be any number of sources (bound
|
|
||||||
to different attributes). However, <varname>src</varname> is
|
|
||||||
customary, and it's also expected by the default builder (which we
|
|
||||||
don't use in this example).</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-nix-co-6'>
|
|
||||||
|
|
||||||
<para>Since the derivation requires Perl, we have to pass the
|
|
||||||
value of the <varname>perl</varname> function argument to the
|
|
||||||
builder. All attributes in the set are actually passed as
|
|
||||||
environment variables to the builder, so declaring an attribute
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
perl = perl;</programlisting>
|
|
||||||
|
|
||||||
will do the trick: it binds an attribute <varname>perl</varname>
|
|
||||||
to the function argument which also happens to be called
|
|
||||||
<varname>perl</varname>. However, it looks a bit silly, so there
|
|
||||||
is a shorter syntax. The <literal>inherit</literal> keyword
|
|
||||||
causes the specified attributes to be bound to whatever variables
|
|
||||||
with the same name happen to be in scope.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
</calloutlist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='sec-generic-builder'>
|
|
||||||
|
|
||||||
<title>Generic Builder Syntax</title>
|
|
||||||
|
|
||||||
<para>Recall from <xref linkend='ex-hello-builder' /> that the builder
|
|
||||||
looked something like this:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
PATH=$perl/bin:$PATH
|
|
||||||
tar xvfz $src
|
|
||||||
cd hello-*
|
|
||||||
./configure --prefix=$out
|
|
||||||
make
|
|
||||||
make install</programlisting>
|
|
||||||
|
|
||||||
The builders for almost all Unix packages look like this — set up some
|
|
||||||
environment variables, unpack the sources, configure, build, and
|
|
||||||
install. For this reason the standard environment provides some Bash
|
|
||||||
functions that automate the build process. A builder using the
|
|
||||||
generic build facilities in shown in <xref linkend='ex-hello-builder2'
|
|
||||||
/>.</para>
|
|
||||||
|
|
||||||
<example xml:id='ex-hello-builder2'><title>Build script using the generic
|
|
||||||
build functions</title>
|
|
||||||
<programlisting>
|
|
||||||
buildInputs="$perl" <co xml:id='ex-hello-builder2-co-1' />
|
|
||||||
|
|
||||||
source $stdenv/setup <co xml:id='ex-hello-builder2-co-2' />
|
|
||||||
|
|
||||||
genericBuild <co xml:id='ex-hello-builder2-co-3' /></programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<calloutlist>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder2-co-1'>
|
|
||||||
|
|
||||||
<para>The <envar>buildInputs</envar> variable tells
|
|
||||||
<filename>setup</filename> to use the indicated packages as
|
|
||||||
<quote>inputs</quote>. This means that if a package provides a
|
|
||||||
<filename>bin</filename> subdirectory, it's added to
|
|
||||||
<envar>PATH</envar>; if it has a <filename>include</filename>
|
|
||||||
subdirectory, it's added to GCC's header search path; and so
|
|
||||||
on.<footnote><para>How does it work? <filename>setup</filename>
|
|
||||||
tries to source the file
|
|
||||||
<filename><replaceable>pkg</replaceable>/nix-support/setup-hook</filename>
|
|
||||||
of all dependencies. These “setup hooks” can then set up whatever
|
|
||||||
environment variables they want; for instance, the setup hook for
|
|
||||||
Perl sets the <envar>PERL5LIB</envar> environment variable to
|
|
||||||
contain the <filename>lib/site_perl</filename> directories of all
|
|
||||||
inputs.</para></footnote>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder2-co-2'>
|
|
||||||
|
|
||||||
<para>The function <function>genericBuild</function> is defined in
|
|
||||||
the file <literal>$stdenv/setup</literal>.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-hello-builder2-co-3'>
|
|
||||||
|
|
||||||
<para>The final step calls the shell function
|
|
||||||
<function>genericBuild</function>, which performs the steps that
|
|
||||||
were done explicitly in <xref linkend='ex-hello-builder' />. The
|
|
||||||
generic builder is smart enough to figure out whether to unpack
|
|
||||||
the sources using <command>gzip</command>,
|
|
||||||
<command>bzip2</command>, etc. It can be customised in many ways;
|
|
||||||
see the Nixpkgs manual for details.</para>
|
|
||||||
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
</calloutlist>
|
|
||||||
|
|
||||||
<para>Discerning readers will note that the
|
|
||||||
<envar>buildInputs</envar> could just as well have been set in the Nix
|
|
||||||
expression, like this:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
buildInputs = [ perl ];</programlisting>
|
|
||||||
|
|
||||||
The <varname>perl</varname> attribute can then be removed, and the
|
|
||||||
builder becomes even shorter:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
source $stdenv/setup
|
|
||||||
genericBuild</programlisting>
|
|
||||||
|
|
||||||
In fact, <varname>mkDerivation</varname> provides a default builder
|
|
||||||
that looks exactly like that, so it is actually possible to omit the
|
|
||||||
builder for Hello entirely.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,409 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-constructs">
|
|
||||||
|
|
||||||
<title>Language Constructs</title>
|
|
||||||
|
|
||||||
<simplesect><title>Recursive sets</title>
|
|
||||||
|
|
||||||
<para>Recursive sets are just normal sets, but the attributes can
|
|
||||||
refer to each other. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
rec {
|
|
||||||
x = y;
|
|
||||||
y = 123;
|
|
||||||
}.x
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
evaluates to <literal>123</literal>. Note that without
|
|
||||||
<literal>rec</literal> the binding <literal>x = y;</literal> would
|
|
||||||
refer to the variable <varname>y</varname> in the surrounding scope,
|
|
||||||
if one exists, and would be invalid if no such variable exists. That
|
|
||||||
is, in a normal (non-recursive) set, attributes are not added to the
|
|
||||||
lexical scope; in a recursive set, they are.</para>
|
|
||||||
|
|
||||||
<para>Recursive sets of course introduce the danger of infinite
|
|
||||||
recursion. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
rec {
|
|
||||||
x = y;
|
|
||||||
y = x;
|
|
||||||
}.x</programlisting>
|
|
||||||
|
|
||||||
does not terminate<footnote><para>Actually, Nix detects infinite
|
|
||||||
recursion in this case and aborts (<quote>infinite recursion
|
|
||||||
encountered</quote>).</para></footnote>.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect xml:id="sect-let-expressions"><title>Let-expressions</title>
|
|
||||||
|
|
||||||
<para>A let-expression allows you to define local variables for an
|
|
||||||
expression. For instance,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let
|
|
||||||
x = "foo";
|
|
||||||
y = "bar";
|
|
||||||
in x + y</programlisting>
|
|
||||||
|
|
||||||
evaluates to <literal>"foobar"</literal>.
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Inheriting attributes</title>
|
|
||||||
|
|
||||||
<para>When defining a set or in a let-expression it is often convenient to copy variables
|
|
||||||
from the surrounding lexical scope (e.g., when you want to propagate
|
|
||||||
attributes). This can be shortened using the
|
|
||||||
<literal>inherit</literal> keyword. For instance,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let x = 123; in
|
|
||||||
{ inherit x;
|
|
||||||
y = 456;
|
|
||||||
}</programlisting>
|
|
||||||
|
|
||||||
is equivalent to
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let x = 123; in
|
|
||||||
{ x = x;
|
|
||||||
y = 456;
|
|
||||||
}</programlisting>
|
|
||||||
|
|
||||||
and both evaluate to <literal>{ x = 123; y = 456; }</literal>. (Note that
|
|
||||||
this works because <varname>x</varname> is added to the lexical scope
|
|
||||||
by the <literal>let</literal> construct.) It is also possible to
|
|
||||||
inherit attributes from another set. For instance, in this fragment
|
|
||||||
from <filename>all-packages.nix</filename>,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
graphviz = (import ../tools/graphics/graphviz) {
|
|
||||||
inherit fetchurl stdenv libpng libjpeg expat x11 yacc;
|
|
||||||
inherit (xlibs) libXaw;
|
|
||||||
};
|
|
||||||
|
|
||||||
xlibs = {
|
|
||||||
libX11 = ...;
|
|
||||||
libXaw = ...;
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
libpng = ...;
|
|
||||||
libjpg = ...;
|
|
||||||
...</programlisting>
|
|
||||||
|
|
||||||
the set used in the function call to the function defined in
|
|
||||||
<filename>../tools/graphics/graphviz</filename> inherits a number of
|
|
||||||
variables from the surrounding scope (<varname>fetchurl</varname>
|
|
||||||
... <varname>yacc</varname>), but also inherits
|
|
||||||
<varname>libXaw</varname> (the X Athena Widgets) from the
|
|
||||||
<varname>xlibs</varname> (X11 client-side libraries) set.</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Summarizing the fragment
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
...
|
|
||||||
inherit x y z;
|
|
||||||
inherit (src-set) a b c;
|
|
||||||
...</programlisting>
|
|
||||||
|
|
||||||
is equivalent to
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
...
|
|
||||||
x = x; y = y; z = z;
|
|
||||||
a = src-set.a; b = src-set.b; c = src-set.c;
|
|
||||||
...</programlisting>
|
|
||||||
|
|
||||||
when used while defining local variables in a let-expression or
|
|
||||||
while defining a set.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect xml:id="ss-functions"><title>Functions</title>
|
|
||||||
|
|
||||||
<para>Functions have the following form:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
<replaceable>pattern</replaceable>: <replaceable>body</replaceable></programlisting>
|
|
||||||
|
|
||||||
The pattern specifies what the argument of the function must look
|
|
||||||
like, and binds variables in the body to (parts of) the
|
|
||||||
argument. There are three kinds of patterns:</para>
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>If a pattern is a single identifier, then the
|
|
||||||
function matches any argument. Example:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let negate = x: !x;
|
|
||||||
concat = x: y: x + y;
|
|
||||||
in if negate true then concat "foo" "bar" else ""</programlisting>
|
|
||||||
|
|
||||||
Note that <function>concat</function> is a function that takes one
|
|
||||||
argument and returns a function that takes another argument. This
|
|
||||||
allows partial parameterisation (i.e., only filling some of the
|
|
||||||
arguments of a function); e.g.,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
map (concat "foo") [ "bar" "bla" "abc" ]</programlisting>
|
|
||||||
|
|
||||||
evaluates to <literal>[ "foobar" "foobla"
|
|
||||||
"fooabc" ]</literal>.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>A <emphasis>set pattern</emphasis> of the form
|
|
||||||
<literal>{ name1, name2, …, nameN }</literal> matches a set
|
|
||||||
containing the listed attributes, and binds the values of those
|
|
||||||
attributes to variables in the function body. For example, the
|
|
||||||
function
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ x, y, z }: z + y + x</programlisting>
|
|
||||||
|
|
||||||
can only be called with a set containing exactly the attributes
|
|
||||||
<varname>x</varname>, <varname>y</varname> and
|
|
||||||
<varname>z</varname>. No other attributes are allowed. If you want
|
|
||||||
to allow additional arguments, you can use an ellipsis
|
|
||||||
(<literal>...</literal>):
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ x, y, z, ... }: z + y + x</programlisting>
|
|
||||||
|
|
||||||
This works on any set that contains at least the three named
|
|
||||||
attributes.</para>
|
|
||||||
|
|
||||||
<para>It is possible to provide <emphasis>default values</emphasis>
|
|
||||||
for attributes, in which case they are allowed to be missing. A
|
|
||||||
default value is specified by writing
|
|
||||||
<literal><replaceable>name</replaceable> ?
|
|
||||||
<replaceable>e</replaceable></literal>, where
|
|
||||||
<replaceable>e</replaceable> is an arbitrary expression. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ x, y ? "foo", z ? "bar" }: z + y + x</programlisting>
|
|
||||||
|
|
||||||
specifies a function that only requires an attribute named
|
|
||||||
<varname>x</varname>, but optionally accepts <varname>y</varname>
|
|
||||||
and <varname>z</varname>.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>An <literal>@</literal>-pattern provides a means of referring
|
|
||||||
to the whole value being matched:
|
|
||||||
|
|
||||||
<programlisting> args@{ x, y, z, ... }: z + y + x + args.a</programlisting>
|
|
||||||
|
|
||||||
but can also be written as:
|
|
||||||
|
|
||||||
<programlisting> { x, y, z, ... } @ args: z + y + x + args.a</programlisting>
|
|
||||||
|
|
||||||
Here <varname>args</varname> is bound to the entire argument, which
|
|
||||||
is further matched against the pattern <literal>{ x, y, z,
|
|
||||||
... }</literal>. <literal>@</literal>-pattern makes mainly sense with an
|
|
||||||
ellipsis(<literal>...</literal>) as you can access attribute names as
|
|
||||||
<literal>a</literal>, using <literal>args.a</literal>, which was given as an
|
|
||||||
additional attribute to the function.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<warning>
|
|
||||||
<para>
|
|
||||||
The <literal>args@</literal> expression is bound to the argument passed to the function which
|
|
||||||
means that attributes with defaults that aren't explicitly specified in the function call
|
|
||||||
won't cause an evaluation error, but won't exist in <literal>args</literal>.
|
|
||||||
</para>
|
|
||||||
<para>
|
|
||||||
For instance
|
|
||||||
<programlisting>
|
|
||||||
let
|
|
||||||
function = args@{ a ? 23, ... }: args;
|
|
||||||
in
|
|
||||||
function {}
|
|
||||||
</programlisting>
|
|
||||||
will evaluate to an empty attribute set.
|
|
||||||
</para>
|
|
||||||
</warning></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
<para>Note that functions do not have names. If you want to give them
|
|
||||||
a name, you can bind them to an attribute, e.g.,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let concat = { x, y }: x + y;
|
|
||||||
in concat { x = "foo"; y = "bar"; }</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Conditionals</title>
|
|
||||||
|
|
||||||
<para>Conditionals look like this:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
if <replaceable>e1</replaceable> then <replaceable>e2</replaceable> else <replaceable>e3</replaceable></programlisting>
|
|
||||||
|
|
||||||
where <replaceable>e1</replaceable> is an expression that should
|
|
||||||
evaluate to a Boolean value (<literal>true</literal> or
|
|
||||||
<literal>false</literal>).</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Assertions</title>
|
|
||||||
|
|
||||||
<para>Assertions are generally used to check that certain requirements
|
|
||||||
on or between features and dependencies hold. They look like this:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
assert <replaceable>e1</replaceable>; <replaceable>e2</replaceable></programlisting>
|
|
||||||
|
|
||||||
where <replaceable>e1</replaceable> is an expression that should
|
|
||||||
evaluate to a Boolean value. If it evaluates to
|
|
||||||
<literal>true</literal>, <replaceable>e2</replaceable> is returned;
|
|
||||||
otherwise expression evaluation is aborted and a backtrace is printed.</para>
|
|
||||||
|
|
||||||
<example xml:id='ex-subversion-nix'><title>Nix expression for Subversion</title>
|
|
||||||
<programlisting>
|
|
||||||
{ localServer ? false
|
|
||||||
, httpServer ? false
|
|
||||||
, sslSupport ? false
|
|
||||||
, pythonBindings ? false
|
|
||||||
, javaSwigBindings ? false
|
|
||||||
, javahlBindings ? false
|
|
||||||
, stdenv, fetchurl
|
|
||||||
, openssl ? null, httpd ? null, db4 ? null, expat, swig ? null, j2sdk ? null
|
|
||||||
}:
|
|
||||||
|
|
||||||
assert localServer -> db4 != null; <co xml:id='ex-subversion-nix-co-1' />
|
|
||||||
assert httpServer -> httpd != null && httpd.expat == expat; <co xml:id='ex-subversion-nix-co-2' />
|
|
||||||
assert sslSupport -> openssl != null && (httpServer -> httpd.openssl == openssl); <co xml:id='ex-subversion-nix-co-3' />
|
|
||||||
assert pythonBindings -> swig != null && swig.pythonSupport;
|
|
||||||
assert javaSwigBindings -> swig != null && swig.javaSupport;
|
|
||||||
assert javahlBindings -> j2sdk != null;
|
|
||||||
|
|
||||||
stdenv.mkDerivation {
|
|
||||||
name = "subversion-1.1.1";
|
|
||||||
...
|
|
||||||
openssl = if sslSupport then openssl else null; <co xml:id='ex-subversion-nix-co-4' />
|
|
||||||
...
|
|
||||||
}</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para><xref linkend='ex-subversion-nix' /> show how assertions are
|
|
||||||
used in the Nix expression for Subversion.</para>
|
|
||||||
|
|
||||||
<calloutlist>
|
|
||||||
|
|
||||||
<callout arearefs='ex-subversion-nix-co-1'>
|
|
||||||
<para>This assertion states that if Subversion is to have support
|
|
||||||
for local repositories, then Berkeley DB is needed. So if the
|
|
||||||
Subversion function is called with the
|
|
||||||
<varname>localServer</varname> argument set to
|
|
||||||
<literal>true</literal> but the <varname>db4</varname> argument
|
|
||||||
set to <literal>null</literal>, then the evaluation fails.</para>
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-subversion-nix-co-2'>
|
|
||||||
<para>This is a more subtle condition: if Subversion is built with
|
|
||||||
Apache (<literal>httpServer</literal>) support, then the Expat
|
|
||||||
library (an XML library) used by Subversion should be same as the
|
|
||||||
one used by Apache. This is because in this configuration
|
|
||||||
Subversion code ends up being linked with Apache code, and if the
|
|
||||||
Expat libraries do not match, a build- or runtime link error or
|
|
||||||
incompatibility might occur.</para>
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-subversion-nix-co-3'>
|
|
||||||
<para>This assertion says that in order for Subversion to have SSL
|
|
||||||
support (so that it can access <literal>https</literal> URLs), an
|
|
||||||
OpenSSL library must be passed. Additionally, it says that
|
|
||||||
<emphasis>if</emphasis> Apache support is enabled, then Apache's
|
|
||||||
OpenSSL should match Subversion's. (Note that if Apache support
|
|
||||||
is not enabled, we don't care about Apache's OpenSSL.)</para>
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
<callout arearefs='ex-subversion-nix-co-4'>
|
|
||||||
<para>The conditional here is not really related to assertions,
|
|
||||||
but is worth pointing out: it ensures that if SSL support is
|
|
||||||
disabled, then the Subversion derivation is not dependent on
|
|
||||||
OpenSSL, even if a non-<literal>null</literal> value was passed.
|
|
||||||
This prevents an unnecessary rebuild of Subversion if OpenSSL
|
|
||||||
changes.</para>
|
|
||||||
</callout>
|
|
||||||
|
|
||||||
</calloutlist>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>With-expressions</title>
|
|
||||||
|
|
||||||
<para>A <emphasis>with-expression</emphasis>,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
with <replaceable>e1</replaceable>; <replaceable>e2</replaceable></programlisting>
|
|
||||||
|
|
||||||
introduces the set <replaceable>e1</replaceable> into the lexical
|
|
||||||
scope of the expression <replaceable>e2</replaceable>. For instance,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let as = { x = "foo"; y = "bar"; };
|
|
||||||
in with as; x + y</programlisting>
|
|
||||||
|
|
||||||
evaluates to <literal>"foobar"</literal> since the
|
|
||||||
<literal>with</literal> adds the <varname>x</varname> and
|
|
||||||
<varname>y</varname> attributes of <varname>as</varname> to the
|
|
||||||
lexical scope in the expression <literal>x + y</literal>. The most
|
|
||||||
common use of <literal>with</literal> is in conjunction with the
|
|
||||||
<function>import</function> function. E.g.,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
with (import ./definitions.nix); ...</programlisting>
|
|
||||||
|
|
||||||
makes all attributes defined in the file
|
|
||||||
<filename>definitions.nix</filename> available as if they were defined
|
|
||||||
locally in a <literal>let</literal>-expression.</para>
|
|
||||||
|
|
||||||
<para>The bindings introduced by <literal>with</literal> do not shadow bindings
|
|
||||||
introduced by other means, e.g.
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let a = 3; in with { a = 1; }; let a = 4; in with { a = 2; }; ...</programlisting>
|
|
||||||
|
|
||||||
establishes the same scope as
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let a = 1; in let a = 2; in let a = 3; in let a = 4; in ...</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Comments</title>
|
|
||||||
|
|
||||||
<para>Comments can be single-line, started with a <literal>#</literal>
|
|
||||||
character, or inline/multi-line, enclosed within <literal>/*
|
|
||||||
... */</literal>.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-language-operators">
|
|
||||||
|
|
||||||
<title>Operators</title>
|
|
||||||
|
|
||||||
<para><xref linkend='table-operators' /> lists the operators in the
|
|
||||||
Nix expression language, in order of precedence (from strongest to
|
|
||||||
weakest binding).</para>
|
|
||||||
|
|
||||||
<table xml:id='table-operators'>
|
|
||||||
<title>Operators</title>
|
|
||||||
<tgroup cols='3'>
|
|
||||||
<thead>
|
|
||||||
<row>
|
|
||||||
<entry>Name</entry>
|
|
||||||
<entry>Syntax</entry>
|
|
||||||
<entry>Associativity</entry>
|
|
||||||
<entry>Description</entry>
|
|
||||||
<entry>Precedence</entry>
|
|
||||||
</row>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<row>
|
|
||||||
<entry>Select</entry>
|
|
||||||
<entry><replaceable>e</replaceable> <literal>.</literal>
|
|
||||||
<replaceable>attrpath</replaceable>
|
|
||||||
[ <literal>or</literal> <replaceable>def</replaceable> ]
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Select attribute denoted by the attribute path
|
|
||||||
<replaceable>attrpath</replaceable> from set
|
|
||||||
<replaceable>e</replaceable>. (An attribute path is a
|
|
||||||
dot-separated list of attribute names.) If the attribute
|
|
||||||
doesn’t exist, return <replaceable>def</replaceable> if
|
|
||||||
provided, otherwise abort evaluation.</entry>
|
|
||||||
<entry>1</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Application</entry>
|
|
||||||
<entry><replaceable>e1</replaceable> <replaceable>e2</replaceable></entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Call function <replaceable>e1</replaceable> with
|
|
||||||
argument <replaceable>e2</replaceable>.</entry>
|
|
||||||
<entry>2</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Arithmetic Negation</entry>
|
|
||||||
<entry><literal>-</literal> <replaceable>e</replaceable></entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Arithmetic negation.</entry>
|
|
||||||
<entry>3</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Has Attribute</entry>
|
|
||||||
<entry><replaceable>e</replaceable> <literal>?</literal>
|
|
||||||
<replaceable>attrpath</replaceable></entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Test whether set <replaceable>e</replaceable> contains
|
|
||||||
the attribute denoted by <replaceable>attrpath</replaceable>;
|
|
||||||
return <literal>true</literal> or
|
|
||||||
<literal>false</literal>.</entry>
|
|
||||||
<entry>4</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>List Concatenation</entry>
|
|
||||||
<entry><replaceable>e1</replaceable> <literal>++</literal> <replaceable>e2</replaceable></entry>
|
|
||||||
<entry>right</entry>
|
|
||||||
<entry>List concatenation.</entry>
|
|
||||||
<entry>5</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Multiplication</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>*</literal> <replaceable>e2</replaceable>,
|
|
||||||
</entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Arithmetic multiplication.</entry>
|
|
||||||
<entry>6</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Division</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>/</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Arithmetic division.</entry>
|
|
||||||
<entry>6</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Addition</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>+</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Arithmetic addition.</entry>
|
|
||||||
<entry>7</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Subtraction</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>-</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Arithmetic subtraction.</entry>
|
|
||||||
<entry>7</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>String Concatenation</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>string1</replaceable> <literal>+</literal> <replaceable>string2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>String concatenation.</entry>
|
|
||||||
<entry>7</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Not</entry>
|
|
||||||
<entry><literal>!</literal> <replaceable>e</replaceable></entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Boolean negation.</entry>
|
|
||||||
<entry>8</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Update</entry>
|
|
||||||
<entry><replaceable>e1</replaceable> <literal>//</literal>
|
|
||||||
<replaceable>e2</replaceable></entry>
|
|
||||||
<entry>right</entry>
|
|
||||||
<entry>Return a set consisting of the attributes in
|
|
||||||
<replaceable>e1</replaceable> and
|
|
||||||
<replaceable>e2</replaceable> (with the latter taking
|
|
||||||
precedence over the former in case of equally named
|
|
||||||
attributes).</entry>
|
|
||||||
<entry>9</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Less Than</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal><</literal> <replaceable>e2</replaceable>,
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Arithmetic comparison.</entry>
|
|
||||||
<entry>10</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Less Than or Equal To</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal><=</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Arithmetic comparison.</entry>
|
|
||||||
<entry>10</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Greater Than</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>></literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Arithmetic comparison.</entry>
|
|
||||||
<entry>10</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Greater Than or Equal To</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>>=</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Arithmetic comparison.</entry>
|
|
||||||
<entry>10</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Equality</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>==</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Equality.</entry>
|
|
||||||
<entry>11</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Inequality</entry>
|
|
||||||
<entry>
|
|
||||||
<replaceable>e1</replaceable> <literal>!=</literal> <replaceable>e2</replaceable>
|
|
||||||
</entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Inequality.</entry>
|
|
||||||
<entry>11</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Logical AND</entry>
|
|
||||||
<entry><replaceable>e1</replaceable> <literal>&&</literal>
|
|
||||||
<replaceable>e2</replaceable></entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Logical AND.</entry>
|
|
||||||
<entry>12</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Logical OR</entry>
|
|
||||||
<entry><replaceable>e1</replaceable> <literal>||</literal>
|
|
||||||
<replaceable>e2</replaceable></entry>
|
|
||||||
<entry>left</entry>
|
|
||||||
<entry>Logical OR.</entry>
|
|
||||||
<entry>13</entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry>Logical Implication</entry>
|
|
||||||
<entry><replaceable>e1</replaceable> <literal>-></literal>
|
|
||||||
<replaceable>e2</replaceable></entry>
|
|
||||||
<entry>none</entry>
|
|
||||||
<entry>Logical implication (equivalent to
|
|
||||||
<literal>!<replaceable>e1</replaceable> ||
|
|
||||||
<replaceable>e2</replaceable></literal>).</entry>
|
|
||||||
<entry>14</entry>
|
|
||||||
</row>
|
|
||||||
</tbody>
|
|
||||||
</tgroup>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,313 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='ssec-values'>
|
|
||||||
|
|
||||||
<title>Values</title>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Simple Values</title>
|
|
||||||
|
|
||||||
<para>Nix has the following basic data types:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
|
|
||||||
<para><emphasis>Strings</emphasis> can be written in three
|
|
||||||
ways.</para>
|
|
||||||
|
|
||||||
<para>The most common way is to enclose the string between double
|
|
||||||
quotes, e.g., <literal>"foo bar"</literal>. Strings can span
|
|
||||||
multiple lines. The special characters <literal>"</literal> and
|
|
||||||
<literal>\</literal> and the character sequence
|
|
||||||
<literal>${</literal> must be escaped by prefixing them with a
|
|
||||||
backslash (<literal>\</literal>). Newlines, carriage returns and
|
|
||||||
tabs can be written as <literal>\n</literal>,
|
|
||||||
<literal>\r</literal> and <literal>\t</literal>,
|
|
||||||
respectively.</para>
|
|
||||||
|
|
||||||
<para>You can include the result of an expression into a string by
|
|
||||||
enclosing it in
|
|
||||||
<literal>${<replaceable>...</replaceable>}</literal>, a feature
|
|
||||||
known as <emphasis>antiquotation</emphasis>. The enclosed
|
|
||||||
expression must evaluate to something that can be coerced into a
|
|
||||||
string (meaning that it must be a string, a path, or a
|
|
||||||
derivation). For instance, rather than writing
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
"--with-freetype2-library=" + freetype + "/lib"</programlisting>
|
|
||||||
|
|
||||||
(where <varname>freetype</varname> is a derivation), you can
|
|
||||||
instead write the more natural
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
"--with-freetype2-library=${freetype}/lib"</programlisting>
|
|
||||||
|
|
||||||
The latter is automatically translated to the former. A more
|
|
||||||
complicated example (from the Nix expression for <link
|
|
||||||
xlink:href='http://www.trolltech.com/products/qt'>Qt</link>):
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
configureFlags = "
|
|
||||||
-system-zlib -system-libpng -system-libjpeg
|
|
||||||
${if openglSupport then "-dlopen-opengl
|
|
||||||
-L${mesa}/lib -I${mesa}/include
|
|
||||||
-L${libXmu}/lib -I${libXmu}/include" else ""}
|
|
||||||
${if threadSupport then "-thread" else "-no-thread"}
|
|
||||||
";</programlisting>
|
|
||||||
|
|
||||||
Note that Nix expressions and strings can be arbitrarily nested;
|
|
||||||
in this case the outer string contains various antiquotations that
|
|
||||||
themselves contain strings (e.g., <literal>"-thread"</literal>),
|
|
||||||
some of which in turn contain expressions (e.g.,
|
|
||||||
<literal>${mesa}</literal>).</para>
|
|
||||||
|
|
||||||
<para>The second way to write string literals is as an
|
|
||||||
<emphasis>indented string</emphasis>, which is enclosed between
|
|
||||||
pairs of <emphasis>double single-quotes</emphasis>, like so:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
''
|
|
||||||
This is the first line.
|
|
||||||
This is the second line.
|
|
||||||
This is the third line.
|
|
||||||
''</programlisting>
|
|
||||||
|
|
||||||
This kind of string literal intelligently strips indentation from
|
|
||||||
the start of each line. To be precise, it strips from each line a
|
|
||||||
number of spaces equal to the minimal indentation of the string as
|
|
||||||
a whole (disregarding the indentation of empty lines). For
|
|
||||||
instance, the first and second line are indented two space, while
|
|
||||||
the third line is indented four spaces. Thus, two spaces are
|
|
||||||
stripped from each line, so the resulting string is
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
"This is the first line.\nThis is the second line.\n This is the third line.\n"</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Note that the whitespace and newline following the opening
|
|
||||||
<literal>''</literal> is ignored if there is no non-whitespace
|
|
||||||
text on the initial line.</para>
|
|
||||||
|
|
||||||
<para>Antiquotation
|
|
||||||
(<literal>${<replaceable>expr</replaceable>}</literal>) is
|
|
||||||
supported in indented strings.</para>
|
|
||||||
|
|
||||||
<para>Since <literal>${</literal> and <literal>''</literal> have
|
|
||||||
special meaning in indented strings, you need a way to quote them.
|
|
||||||
<literal>$</literal> can be escaped by prefixing it with
|
|
||||||
<literal>''</literal> (that is, two single quotes), i.e.,
|
|
||||||
<literal>''$</literal>. <literal>''</literal> can be escaped by
|
|
||||||
prefixing it with <literal>'</literal>, i.e.,
|
|
||||||
<literal>'''</literal>. <literal>$</literal> removes any special meaning
|
|
||||||
from the following <literal>$</literal>. Linefeed, carriage-return and tab
|
|
||||||
characters can be written as <literal>''\n</literal>,
|
|
||||||
<literal>''\r</literal>, <literal>''\t</literal>, and <literal>''\</literal>
|
|
||||||
escapes any other character.
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Indented strings are primarily useful in that they allow
|
|
||||||
multi-line string literals to follow the indentation of the
|
|
||||||
enclosing Nix expression, and that less escaping is typically
|
|
||||||
necessary for strings representing languages such as shell scripts
|
|
||||||
and configuration files because <literal>''</literal> is much less
|
|
||||||
common than <literal>"</literal>. Example:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
stdenv.mkDerivation {
|
|
||||||
<replaceable>...</replaceable>
|
|
||||||
postInstall =
|
|
||||||
''
|
|
||||||
mkdir $out/bin $out/etc
|
|
||||||
cp foo $out/bin
|
|
||||||
echo "Hello World" > $out/etc/foo.conf
|
|
||||||
${if enableBar then "cp bar $out/bin" else ""}
|
|
||||||
'';
|
|
||||||
<replaceable>...</replaceable>
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Finally, as a convenience, <emphasis>URIs</emphasis> as
|
|
||||||
defined in appendix B of <link
|
|
||||||
xlink:href='http://www.ietf.org/rfc/rfc2396.txt'>RFC 2396</link>
|
|
||||||
can be written <emphasis>as is</emphasis>, without quotes. For
|
|
||||||
instance, the string
|
|
||||||
<literal>"http://example.org/foo.tar.bz2"</literal>
|
|
||||||
can also be written as
|
|
||||||
<literal>http://example.org/foo.tar.bz2</literal>.</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem><para>Numbers, which can be <emphasis>integers</emphasis> (like
|
|
||||||
<literal>123</literal>) or <emphasis>floating point</emphasis> (like
|
|
||||||
<literal>123.43</literal> or <literal>.27e13</literal>).</para>
|
|
||||||
|
|
||||||
<para>Numbers are type-compatible: pure integer operations will always
|
|
||||||
return integers, whereas any operation involving at least one floating point
|
|
||||||
number will have a floating point number as a result.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><emphasis>Paths</emphasis>, e.g.,
|
|
||||||
<filename>/bin/sh</filename> or <filename>./builder.sh</filename>.
|
|
||||||
A path must contain at least one slash to be recognised as such; for
|
|
||||||
instance, <filename>builder.sh</filename> is not a
|
|
||||||
path<footnote><para>It's parsed as an expression that selects the
|
|
||||||
attribute <varname>sh</varname> from the variable
|
|
||||||
<varname>builder</varname>.</para></footnote>. If the file name is
|
|
||||||
relative, i.e., if it does not begin with a slash, it is made
|
|
||||||
absolute at parse time relative to the directory of the Nix
|
|
||||||
expression that contained it. For instance, if a Nix expression in
|
|
||||||
<filename>/foo/bar/bla.nix</filename> refers to
|
|
||||||
<filename>../xyzzy/fnord.nix</filename>, the absolute path is
|
|
||||||
<filename>/foo/xyzzy/fnord.nix</filename>.</para>
|
|
||||||
|
|
||||||
<para>If the first component of a path is a <literal>~</literal>,
|
|
||||||
it is interpreted as if the rest of the path were relative to the
|
|
||||||
user's home directory. e.g. <filename>~/foo</filename> would be
|
|
||||||
equivalent to <filename>/home/edolstra/foo</filename> for a user
|
|
||||||
whose home directory is <filename>/home/edolstra</filename>.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Paths can also be specified between angle brackets, e.g.
|
|
||||||
<literal><nixpkgs></literal>. This means that the directories
|
|
||||||
listed in the environment variable
|
|
||||||
<envar linkend="env-NIX_PATH">NIX_PATH</envar> will be searched
|
|
||||||
for the given file or directory name.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem><para><emphasis>Booleans</emphasis> with values
|
|
||||||
<literal>true</literal> and
|
|
||||||
<literal>false</literal>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The null value, denoted as
|
|
||||||
<literal>null</literal>.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Lists</title>
|
|
||||||
|
|
||||||
<para>Lists are formed by enclosing a whitespace-separated list of
|
|
||||||
values between square brackets. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
[ 123 ./foo.nix "abc" (f { x = y; }) ]</programlisting>
|
|
||||||
|
|
||||||
defines a list of four elements, the last being the result of a call
|
|
||||||
to the function <varname>f</varname>. Note that function calls have
|
|
||||||
to be enclosed in parentheses. If they had been omitted, e.g.,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
[ 123 ./foo.nix "abc" f { x = y; } ]</programlisting>
|
|
||||||
|
|
||||||
the result would be a list of five elements, the fourth one being a
|
|
||||||
function and the fifth being a set.</para>
|
|
||||||
|
|
||||||
<para>Note that lists are only lazy in values, and they are strict in length.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Sets</title>
|
|
||||||
|
|
||||||
<para>Sets are really the core of the language, since ultimately the
|
|
||||||
Nix language is all about creating derivations, which are really just
|
|
||||||
sets of attributes to be passed to build scripts.</para>
|
|
||||||
|
|
||||||
<para>Sets are just a list of name/value pairs (called
|
|
||||||
<emphasis>attributes</emphasis>) enclosed in curly brackets, where
|
|
||||||
each value is an arbitrary expression terminated by a semicolon. For
|
|
||||||
example:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ x = 123;
|
|
||||||
text = "Hello";
|
|
||||||
y = f { bla = 456; };
|
|
||||||
}</programlisting>
|
|
||||||
|
|
||||||
This defines a set with attributes named <varname>x</varname>,
|
|
||||||
<varname>text</varname>, <varname>y</varname>. The order of the
|
|
||||||
attributes is irrelevant. An attribute name may only occur
|
|
||||||
once.</para>
|
|
||||||
|
|
||||||
<para>Attributes can be selected from a set using the
|
|
||||||
<literal>.</literal> operator. For instance,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ a = "Foo"; b = "Bar"; }.a</programlisting>
|
|
||||||
|
|
||||||
evaluates to <literal>"Foo"</literal>. It is possible to provide a
|
|
||||||
default value in an attribute selection using the
|
|
||||||
<literal>or</literal> keyword. For example,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ a = "Foo"; b = "Bar"; }.c or "Xyzzy"</programlisting>
|
|
||||||
|
|
||||||
will evaluate to <literal>"Xyzzy"</literal> because there is no
|
|
||||||
<varname>c</varname> attribute in the set.</para>
|
|
||||||
|
|
||||||
<para>You can use arbitrary double-quoted strings as attribute
|
|
||||||
names:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ "foo ${bar}" = 123; "nix-1.0" = 456; }."foo ${bar}"
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
This will evaluate to <literal>123</literal> (Assuming
|
|
||||||
<literal>bar</literal> is antiquotable). In the case where an
|
|
||||||
attribute name is just a single antiquotation, the quotes can be
|
|
||||||
dropped:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ foo = 123; }.${bar} or 456 </programlisting>
|
|
||||||
|
|
||||||
This will evaluate to <literal>123</literal> if
|
|
||||||
<literal>bar</literal> evaluates to <literal>"foo"</literal> when
|
|
||||||
coerced to a string and <literal>456</literal> otherwise (again
|
|
||||||
assuming <literal>bar</literal> is antiquotable).</para>
|
|
||||||
|
|
||||||
<para>In the special case where an attribute name inside of a set declaration
|
|
||||||
evaluates to <literal>null</literal> (which is normally an error, as
|
|
||||||
<literal>null</literal> is not antiquotable), that attribute is simply not
|
|
||||||
added to the set:
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{ ${if foo then "bar" else null} = true; }</programlisting>
|
|
||||||
|
|
||||||
This will evaluate to <literal>{}</literal> if <literal>foo</literal>
|
|
||||||
evaluates to <literal>false</literal>.</para>
|
|
||||||
|
|
||||||
<para>A set that has a <literal>__functor</literal> attribute whose value
|
|
||||||
is callable (i.e. is itself a function or a set with a
|
|
||||||
<literal>__functor</literal> attribute whose value is callable) can be
|
|
||||||
applied as if it were a function, with the set itself passed in first
|
|
||||||
, e.g.,
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
let add = { __functor = self: x: x + self.x; };
|
|
||||||
inc = add // { x = 1; };
|
|
||||||
in inc 1
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
evaluates to <literal>2</literal>. This can be used to attach metadata to a
|
|
||||||
function without the caller needing to treat it specially, or to implement
|
|
||||||
a form of object-oriented programming, for example.
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='sec-building-simple'>
|
|
||||||
|
|
||||||
<title>Building and Testing</title>
|
|
||||||
|
|
||||||
<para>You can now try to build Hello. Of course, you could do
|
|
||||||
<literal>nix-env -i hello</literal>, but you may not want to install a
|
|
||||||
possibly broken package just yet. The best way to test the package is by
|
|
||||||
using the command <command linkend="sec-nix-build">nix-build</command>,
|
|
||||||
which builds a Nix expression and creates a symlink named
|
|
||||||
<filename>result</filename> in the current directory:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-build -A hello
|
|
||||||
building path `/nix/store/632d2b22514d...-hello-2.1.1'
|
|
||||||
hello-2.1.1/
|
|
||||||
hello-2.1.1/intl/
|
|
||||||
hello-2.1.1/intl/ChangeLog
|
|
||||||
<replaceable>...</replaceable>
|
|
||||||
|
|
||||||
$ ls -l result
|
|
||||||
lrwxrwxrwx ... 2006-09-29 10:43 result -> /nix/store/632d2b22514d...-hello-2.1.1
|
|
||||||
|
|
||||||
$ ./result/bin/hello
|
|
||||||
Hello, world!</screen>
|
|
||||||
|
|
||||||
The <link linkend='opt-attr'><option>-A</option></link> option selects
|
|
||||||
the <literal>hello</literal> attribute. This is faster than using the
|
|
||||||
symbolic package name specified by the <literal>name</literal>
|
|
||||||
attribute (which also happens to be <literal>hello</literal>) and is
|
|
||||||
unambiguous (there can be multiple packages with the symbolic name
|
|
||||||
<literal>hello</literal>, but there can be only one attribute in a set
|
|
||||||
named <literal>hello</literal>).</para>
|
|
||||||
|
|
||||||
<para><command>nix-build</command> registers the
|
|
||||||
<filename>./result</filename> symlink as a garbage collection root, so
|
|
||||||
unless and until you delete the <filename>./result</filename> symlink,
|
|
||||||
the output of the build will be safely kept on your system. You can
|
|
||||||
use <command>nix-build</command>’s <option
|
|
||||||
linkend='opt-out-link'>-o</option> switch to give the symlink another
|
|
||||||
name.</para>
|
|
||||||
|
|
||||||
<para>Nix has transactional semantics. Once a build finishes
|
|
||||||
successfully, Nix makes a note of this in its database: it registers
|
|
||||||
that the path denoted by <envar>out</envar> is now
|
|
||||||
<quote>valid</quote>. If you try to build the derivation again, Nix
|
|
||||||
will see that the path is already valid and finish immediately. If a
|
|
||||||
build fails, either because it returns a non-zero exit code, because
|
|
||||||
Nix or the builder are killed, or because the machine crashes, then
|
|
||||||
the output paths will not be registered as valid. If you try to build
|
|
||||||
the derivation again, Nix will remove the output paths if they exist
|
|
||||||
(e.g., because the builder died half-way through <literal>make
|
|
||||||
install</literal>) and try again. Note that there is no
|
|
||||||
<quote>negative caching</quote>: Nix doesn't remember that a build
|
|
||||||
failed, and so a failed build can always be repeated. This is because
|
|
||||||
Nix cannot distinguish between permanent failures (e.g., a compiler
|
|
||||||
error due to a syntax error in the source) and transient failures
|
|
||||||
(e.g., a disk full condition).</para>
|
|
||||||
|
|
||||||
<para>Nix also performs locking. If you run multiple Nix builds
|
|
||||||
simultaneously, and they try to build the same derivation, the first
|
|
||||||
Nix instance that gets there will perform the build, while the others
|
|
||||||
block (or perform other derivations if available) until the build
|
|
||||||
finishes:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-build -A hello
|
|
||||||
waiting for lock on `/nix/store/0h5b7hp8d4hqfrw8igvx97x1xawrjnac-hello-2.1.1x'</screen>
|
|
||||||
|
|
||||||
So it is always safe to run multiple instances of Nix in parallel
|
|
||||||
(which isn’t the case with, say, <command>make</command>).</para>
|
|
||||||
|
|
||||||
<para>If you have a system with multiple CPUs, you may want to have
|
|
||||||
Nix build different derivations in parallel (insofar as possible).
|
|
||||||
Just pass the option <link linkend='opt-max-jobs'><option>-j
|
|
||||||
<replaceable>N</replaceable></option></link>, where
|
|
||||||
<replaceable>N</replaceable> is the maximum number of jobs to be run
|
|
||||||
in parallel, or set. Typically this should be the number of
|
|
||||||
CPUs.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-simple-expression">
|
|
||||||
|
|
||||||
<title>A Simple Nix Expression</title>
|
|
||||||
|
|
||||||
<para>This section shows how to add and test the <link
|
|
||||||
xlink:href='http://www.gnu.org/software/hello/hello.html'>GNU Hello
|
|
||||||
package</link> to the Nix Packages collection. Hello is a program
|
|
||||||
that prints out the text <quote>Hello, world!</quote>.</para>
|
|
||||||
|
|
||||||
<para>To add a package to the Nix Packages collection, you generally
|
|
||||||
need to do three things:
|
|
||||||
|
|
||||||
<orderedlist>
|
|
||||||
|
|
||||||
<listitem><para>Write a Nix expression for the package. This is a
|
|
||||||
file that describes all the inputs involved in building the package,
|
|
||||||
such as dependencies, sources, and so on.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Write a <emphasis>builder</emphasis>. This is a
|
|
||||||
shell script<footnote><para>In fact, it can be written in any
|
|
||||||
language, but typically it's a <command>bash</command> shell
|
|
||||||
script.</para></footnote> that actually builds the package from
|
|
||||||
the inputs.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Add the package to the file
|
|
||||||
<filename>pkgs/top-level/all-packages.nix</filename>. The Nix
|
|
||||||
expression written in the first step is a
|
|
||||||
<emphasis>function</emphasis>; it requires other packages in order
|
|
||||||
to build it. In this step you put it all together, i.e., you call
|
|
||||||
the function with the right arguments to build the actual
|
|
||||||
package.</para></listitem>
|
|
||||||
|
|
||||||
</orderedlist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<xi:include href="expression-syntax.xml" />
|
|
||||||
<xi:include href="build-script.xml" />
|
|
||||||
<xi:include href="arguments-variables.xml" />
|
|
||||||
<xi:include href="simple-building-testing.xml" />
|
|
||||||
<xi:include href="generic-builder.xml" />
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<part xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id='chap-writing-nix-expressions'>
|
|
||||||
|
|
||||||
<title>Writing Nix Expressions</title>
|
|
||||||
|
|
||||||
<partintro>
|
|
||||||
<para>This chapter shows you how to write Nix expressions, which
|
|
||||||
instruct Nix how to build packages. It starts with a
|
|
||||||
simple example (a Nix expression for GNU Hello), and then moves
|
|
||||||
on to a more in-depth look at the Nix expression language.</para>
|
|
||||||
|
|
||||||
<note><para>This chapter is mostly about the Nix expression language.
|
|
||||||
For more extensive information on adding packages to the Nix Packages
|
|
||||||
collection (such as functions in the standard environment and coding
|
|
||||||
conventions), please consult <link
|
|
||||||
xlink:href="http://nixos.org/nixpkgs/manual/">its
|
|
||||||
manual</link>.</para></note>
|
|
||||||
</partintro>
|
|
||||||
|
|
||||||
<xi:include href="simple-expression.xml" />
|
|
||||||
<xi:include href="expression-language.xml" />
|
|
||||||
|
|
||||||
</part>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 83 KiB |
@@ -1,6 +1,5 @@
|
|||||||
<appendix xmlns="http://docbook.org/ns/docbook"
|
<appendix xmlns="http://docbook.org/ns/docbook"
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
xml:id="part-glossary">
|
|
||||||
|
|
||||||
<title>Glossary</title>
|
<title>Glossary</title>
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@
|
|||||||
|
|
||||||
<glossdef><para>A substitute is a command invocation stored in the
|
<glossdef><para>A substitute is a command invocation stored in the
|
||||||
Nix database that describes how to build a store object, bypassing
|
Nix database that describes how to build a store object, bypassing
|
||||||
the normal build mechanism (i.e., derivations). Typically, the
|
normal the build mechanism (i.e., derivations). Typically, the
|
||||||
substitute builds the store object by downloading a pre-built
|
substitute builds the store object by downloading a pre-built
|
||||||
version of the store object from some server.</para></glossdef>
|
version of the store object from some server.</para></glossdef>
|
||||||
|
|
||||||
@@ -86,48 +85,29 @@
|
|||||||
|
|
||||||
<glossentry xml:id="gloss-reference"><glossterm>reference</glossterm>
|
<glossentry xml:id="gloss-reference"><glossterm>reference</glossterm>
|
||||||
|
|
||||||
<glossdef>
|
<glossdef><para>A store path <varname>P</varname> is said to have a
|
||||||
<para>A store path <varname>P</varname> is said to have a
|
reference to a store path <varname>Q</varname> if the store object
|
||||||
reference to a store path <varname>Q</varname> if the store object
|
at <varname>P</varname> contains the path <varname>Q</varname>
|
||||||
at <varname>P</varname> contains the path <varname>Q</varname>
|
somewhere. This implies than an execution involving
|
||||||
somewhere. The <emphasis>references</emphasis> of a store path are
|
<varname>P</varname> potentially needs <varname>Q</varname> to be
|
||||||
the set of store paths to which it has a reference.
|
present. The <emphasis>references</emphasis> of a store path are
|
||||||
</para>
|
the set of store paths to which it has a reference.</para></glossdef>
|
||||||
<para>A derivation can reference other derivations and sources
|
|
||||||
(but not output paths), whereas an output path only references other
|
|
||||||
output paths.
|
|
||||||
</para>
|
|
||||||
</glossdef>
|
|
||||||
|
|
||||||
</glossentry>
|
</glossentry>
|
||||||
|
|
||||||
<glossentry xml:id="gloss-reachable"><glossterm>reachable</glossterm>
|
|
||||||
|
|
||||||
<glossdef><para>A store path <varname>Q</varname> is reachable from
|
|
||||||
another store path <varname>P</varname> if <varname>Q</varname> is in the
|
|
||||||
<link linkend="gloss-closure">closure</link> of the
|
|
||||||
<link linkend="gloss-reference">references</link> relation.
|
|
||||||
</para></glossdef>
|
|
||||||
</glossentry>
|
|
||||||
|
|
||||||
<glossentry xml:id="gloss-closure"><glossterm>closure</glossterm>
|
<glossentry xml:id="gloss-closure"><glossterm>closure</glossterm>
|
||||||
|
|
||||||
<glossdef><para>The closure of a store path is the set of store
|
<glossdef><para>The closure of a store path is the set of store
|
||||||
paths that are directly or indirectly “reachable” from that store
|
paths that are directly or indirectly “reachable” from that store
|
||||||
path; that is, it’s the closure of the path under the <link
|
path; that is, it’s the closure of the path under the <link
|
||||||
linkend="gloss-reference">references</link> relation. For a package, the
|
linkend="gloss-reference">references</link> relation. For instance,
|
||||||
closure of its derivation is equivalent to the build-time
|
if the store object at path <varname>P</varname> contains a
|
||||||
dependencies, while the closure of its output path is equivalent to its
|
reference to path <varname>Q</varname>, then <varname>Q</varname> is
|
||||||
runtime dependencies. For correct deployment it is necessary to deploy whole
|
in the closure of <varname>P</varname>. For correct deployment it
|
||||||
closures, since otherwise at runtime files could be missing. The command
|
is necessary to deploy whole closures, since otherwise at runtime
|
||||||
<command>nix-store -qR</command> prints out closures of store paths.
|
files could be missing. The command <command>nix-store
|
||||||
</para>
|
-qR</command> prints out closures of store paths.</para></glossdef>
|
||||||
<para>As an example, if the store object at path <varname>P</varname> contains
|
|
||||||
a reference to path <varname>Q</varname>, then <varname>Q</varname> is
|
|
||||||
in the closure of <varname>P</varname>. Further, if <varname>Q</varname>
|
|
||||||
references <varname>R</varname> then <varname>R</varname> is also in
|
|
||||||
the closure of <varname>P</varname>.
|
|
||||||
</para></glossdef>
|
|
||||||
|
|
||||||
</glossentry>
|
</glossentry>
|
||||||
|
|
||||||
@@ -167,7 +147,7 @@
|
|||||||
linkend="sec-profiles" />.</para>
|
linkend="sec-profiles" />.</para>
|
||||||
|
|
||||||
</glossdef>
|
</glossdef>
|
||||||
|
|
||||||
</glossentry>
|
</glossentry>
|
||||||
|
|
||||||
|
|
||||||
@@ -180,18 +160,6 @@
|
|||||||
</glossentry>
|
</glossentry>
|
||||||
|
|
||||||
|
|
||||||
<glossentry xml:id="gloss-nar"><glossterm>NAR</glossterm>
|
|
||||||
|
|
||||||
<glossdef><para>A <emphasis>N</emphasis>ix
|
|
||||||
<emphasis>AR</emphasis>chive. This is a serialisation of a path in
|
|
||||||
the Nix store. It can contain regular files, directories and
|
|
||||||
symbolic links. NARs are generated and unpacked using
|
|
||||||
<command>nix-store --dump</command> and <command>nix-store
|
|
||||||
--restore</command>.</para></glossdef>
|
|
||||||
|
|
||||||
</glossentry>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</glosslist>
|
</glosslist>
|
||||||
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<appendix xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xml:id="chap-hacking">
|
|
||||||
|
|
||||||
<title>Hacking</title>
|
|
||||||
|
|
||||||
<para>This section provides some notes on how to hack on Nix. To get
|
|
||||||
the latest version of Nix from GitHub:
|
|
||||||
<screen>
|
|
||||||
$ git clone git://github.com/NixOS/nix.git
|
|
||||||
$ cd nix
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>To build it and its dependencies:
|
|
||||||
<screen>
|
|
||||||
$ nix-build release.nix -A build.x86_64-linux
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>To build all dependencies and start a shell in which all
|
|
||||||
environment variables are set up so that those dependencies can be
|
|
||||||
found:
|
|
||||||
<screen>
|
|
||||||
$ nix-shell
|
|
||||||
</screen>
|
|
||||||
To build Nix itself in this shell:
|
|
||||||
<screen>
|
|
||||||
[nix-shell]$ ./bootstrap.sh
|
|
||||||
[nix-shell]$ configurePhase
|
|
||||||
[nix-shell]$ make
|
|
||||||
</screen>
|
|
||||||
To install it in <literal>$(pwd)/inst</literal> and test it:
|
|
||||||
<screen>
|
|
||||||
[nix-shell]$ make install
|
|
||||||
[nix-shell]$ make installcheck
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</appendix>
|
|
||||||
@@ -0,0 +1,474 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xml:id="chap-installation">
|
||||||
|
|
||||||
|
<title>Installation</title>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Supported platforms</title>
|
||||||
|
|
||||||
|
<para>Nix is currently supported on the following platforms:
|
||||||
|
|
||||||
|
<itemizedlist>
|
||||||
|
|
||||||
|
<listitem><para>Linux (particularly on x86, x86_64, and
|
||||||
|
PowerPC).</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>Mac OS X, both on Intel and
|
||||||
|
PowerPC.</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>FreeBSD (only tested on Intel).</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>Windows through <link
|
||||||
|
xlink:href="http://www.cygwin.com/">Cygwin</link>.</para>
|
||||||
|
|
||||||
|
<warning><para>On Cygwin, Nix <emphasis>must</emphasis> be installed
|
||||||
|
on an NTFS partition. It will not work correctly on a FAT
|
||||||
|
partition.</para></warning>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>Nix is pretty portable, so it should work on most other Unix
|
||||||
|
platforms as well.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Obtaining Nix</title>
|
||||||
|
|
||||||
|
<para>The easiest way to obtain Nix is to download a <link
|
||||||
|
xlink:href="http://nixos.org/">source distribution</link>. RPMs
|
||||||
|
for Red Hat, SuSE, and Fedora Core are also available.</para>
|
||||||
|
|
||||||
|
<para>Alternatively, the most recent sources of Nix can be obtained
|
||||||
|
from its <link
|
||||||
|
xlink:href="https://svn.nixos.org/repos/nix/nix/trunk">Subversion
|
||||||
|
repository</link>. For example, the following command will check out
|
||||||
|
the latest revision into a directory called
|
||||||
|
<filename>nix</filename>:</para>
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ svn checkout https://svn.nixos.org/repos/nix/nix/trunk nix</screen>
|
||||||
|
|
||||||
|
<para>Likewise, specific releases can be obtained from the <link
|
||||||
|
xlink:href="https://svn.nixos.org/repos/nix/nix/tags">tags
|
||||||
|
directory</link> of the repository.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Prerequisites</title>
|
||||||
|
|
||||||
|
<para><emphasis>The following prerequisites only apply when you build
|
||||||
|
from source</emphasis>. Binary releases (e.g., RPMs) have no
|
||||||
|
prerequisites.</para>
|
||||||
|
|
||||||
|
<para>A fairly recent version of GCC/G++ is required. Version 2.95
|
||||||
|
and higher should work.</para>
|
||||||
|
|
||||||
|
<para>To build this manual and the man-pages you need the
|
||||||
|
<command>xmllint</command> and <command>xsltproc</command> programs,
|
||||||
|
which are part of the <literal>libxml2</literal> and
|
||||||
|
<literal>libxslt</literal> packages, respectively. You also need the
|
||||||
|
<link
|
||||||
|
xlink:href="http://docbook.sourceforge.net/projects/xsl/">DocBook XSL
|
||||||
|
stylesheets</link> and optionally the <link
|
||||||
|
xlink:href="http://www.docbook.org/schemas/5x"> DocBook 5.0 RELAX NG
|
||||||
|
schemas</link>. Note that these are only required if you modify the
|
||||||
|
manual sources or when you are building from the Subversion
|
||||||
|
repository.</para>
|
||||||
|
|
||||||
|
<para>To build the parser, very <emphasis>recent</emphasis> versions
|
||||||
|
of Bison and Flex are required. (This is because Nix needs GLR
|
||||||
|
support in Bison and reentrancy support in Flex.) For Bison, you need
|
||||||
|
version 2.3 or higher (1.875 does <emphasis>not</emphasis> work),
|
||||||
|
which can be obtained from
|
||||||
|
the <link xlink:href="ftp://alpha.gnu.org/pub/gnu/bison">GNU FTP
|
||||||
|
server</link>. For Flex, you need version 2.5.33, which is available
|
||||||
|
on <link xlink:href="http://lex.sourceforge.net/">SourceForge</link>.
|
||||||
|
Slightly older versions may also work, but ancient versions like the
|
||||||
|
ubiquitous 2.5.4a won't. Note that these are only required if you
|
||||||
|
modify the parser or when you are building from the Subversion
|
||||||
|
repository.</para>
|
||||||
|
|
||||||
|
<para>Nix uses CWI's ATerm library and the bzip2 compressor (including
|
||||||
|
the bzip2 library). These are included in the Nix source
|
||||||
|
distribution. If you build from the Subversion repository, you must
|
||||||
|
download them yourself and place them in the
|
||||||
|
<filename>externals/</filename> directory. See
|
||||||
|
<filename>externals/Makefile.am</filename> for the precise URLs of
|
||||||
|
these packages. Alternatively, if you already have them installed,
|
||||||
|
you can use <command>configure</command>'s
|
||||||
|
<option>--with-aterm</option> and <option>--with-bzip2</option>
|
||||||
|
options to point to their respective locations.</para>
|
||||||
|
|
||||||
|
<para>If you want to be able to upgrade Nix stores from before version
|
||||||
|
0.12pre12020, you need Sleepycat's Berkeley DB version version 4.5.
|
||||||
|
(Other versions may not have compatible database formats.). Berkeley
|
||||||
|
DB 4.5 is included in the Nix source distribution. If you do not need
|
||||||
|
this ability, you can build Nix with the
|
||||||
|
<option>--disable-old-db-compat</option> configure option.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Building Nix from source</title>
|
||||||
|
|
||||||
|
<para>After unpacking or checking out the Nix sources, issue the
|
||||||
|
following commands:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ ./configure <replaceable>options...</replaceable>
|
||||||
|
$ make
|
||||||
|
$ make install</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>When building from the Subversion repository, these should be
|
||||||
|
preceded by the command:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ ./bootstrap</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>The installation path can be specified by passing the
|
||||||
|
<option>--prefix=<replaceable>prefix</replaceable></option> to
|
||||||
|
<command>configure</command>. The default installation directory is
|
||||||
|
<filename>/nix</filename>. You can change this to any location you
|
||||||
|
like. You must have write permission to the
|
||||||
|
<replaceable>prefix</replaceable> path.</para>
|
||||||
|
|
||||||
|
<warning><para>It is best <emphasis>not</emphasis> to change the
|
||||||
|
installation prefix from its default, since doing so makes it
|
||||||
|
impossible to use pre-built binaries from the standard Nixpkgs
|
||||||
|
channels.</para></warning>
|
||||||
|
|
||||||
|
<para>If you want to rebuilt the documentation, pass the full path to
|
||||||
|
the DocBook RELAX NG schemas and to the DocBook XSL stylesheets using
|
||||||
|
the
|
||||||
|
<option>--with-docbook-rng=<replaceable>path</replaceable></option>
|
||||||
|
and
|
||||||
|
<option>--with-docbook-xsl=<replaceable>path</replaceable></option>
|
||||||
|
options.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Installing from RPMs</title>
|
||||||
|
|
||||||
|
<para>RPM packages of Nix can be downloaded from <link
|
||||||
|
xlink:href="http://nixos.org/" />. These RPMs should work for most
|
||||||
|
fairly recent releases of SuSE and Red Hat Linux. They have been
|
||||||
|
known to work work on SuSE Linux 8.1 and 9.0, and Red Hat 9.0. In
|
||||||
|
fact, it should work on any RPM-based Linux distribution based on
|
||||||
|
<literal>glibc</literal> 2.3 or later.</para>
|
||||||
|
|
||||||
|
<para>Once downloaded, the RPMs can be installed or upgraded using
|
||||||
|
<command>rpm -U</command>. For example,
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ rpm -U nix-0.5pre664-1.i386.rpm</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>The RPMs install into the directory <filename>/nix</filename>.
|
||||||
|
Nix can be uninstalled using <command>rpm -e nix</command>. After
|
||||||
|
this it will be necessary to manually remove the Nix store and other
|
||||||
|
auxiliary data:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ rm -rf /nix/store
|
||||||
|
$ rm -rf /nix/var</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Upgrading Nix through Nix</title>
|
||||||
|
|
||||||
|
<para>You can install the latest stable version of Nix through Nix
|
||||||
|
itself by subscribing to the channel <link
|
||||||
|
xlink:href="http://nixos.org/releases/nix/channels/nix-stable" />,
|
||||||
|
or the latest unstable version by subscribing to the channel <link
|
||||||
|
xlink:href="http://nixos.org/releases/nix/channels/nix-unstable" />.
|
||||||
|
You can also do a <link linkend="sec-one-click">one-click
|
||||||
|
installation</link> by clicking on the package links at <link
|
||||||
|
xlink:href="http://nixos.org/releases/full-index-nix.html" />.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Security</title>
|
||||||
|
|
||||||
|
<para>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 <systemitem
|
||||||
|
class="username">root</systemitem>) who performs all package
|
||||||
|
management operations. All other users can then use the installed
|
||||||
|
packages, but they cannot perform package management operations
|
||||||
|
themselves.</para>
|
||||||
|
|
||||||
|
<para>Alternatively, you can configure Nix in “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.</para>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Single-user mode</title>
|
||||||
|
|
||||||
|
<para>In single-user mode, all Nix operations that access the database
|
||||||
|
in <filename><replaceable>prefix</replaceable>/var/nix/db</filename>
|
||||||
|
or modify the Nix store in
|
||||||
|
<filename><replaceable>prefix</replaceable>/store</filename> must be
|
||||||
|
performed under the user ID that owns those directories. This is
|
||||||
|
typically <systemitem class="username">root</systemitem>. (If you
|
||||||
|
install from RPM packages, that’s in fact the default ownership.)
|
||||||
|
However, on single-user machines, it is often convenient to
|
||||||
|
<command>chown</command> those directories to your normal user account
|
||||||
|
so that you don’t have to <command>su</command> to <systemitem
|
||||||
|
class="username">root</systemitem> all the time.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section xml:id="ssec-multi-user"><title>Multi-user mode</title>
|
||||||
|
|
||||||
|
<para>To allow a Nix store to be shared safely among multiple users,
|
||||||
|
it is important that users are not able to run builders that modify
|
||||||
|
the Nix store or database in arbitrary ways, or that interfere with
|
||||||
|
builds started by other users. If they could do so, they could
|
||||||
|
install a Trojan horse in some package and compromise the accounts of
|
||||||
|
other users.</para>
|
||||||
|
|
||||||
|
<para>To prevent this, the Nix store and database are owned by some
|
||||||
|
privileged user (usually <literal>root</literal>) and builders are
|
||||||
|
executed under special user accounts (usually named
|
||||||
|
<literal>nixbld1</literal>, <literal>nixbld2</literal>, etc.). When a
|
||||||
|
unprivileged user runs a Nix command, actions that operate on the Nix
|
||||||
|
store (such as builds) are forwarded to a <emphasis>Nix
|
||||||
|
daemon</emphasis> running under the owner of the Nix store/database
|
||||||
|
that performs the operation.</para>
|
||||||
|
|
||||||
|
<note><para>Multi-user mode has one important limitation: only
|
||||||
|
<systemitem class="username">root</systemitem> can run <command
|
||||||
|
linkend="sec-nix-pull">nix-pull</command> to register the availability
|
||||||
|
of pre-built binaries. However, those registrations are shared by all
|
||||||
|
users, so they still get the benefit from <command>nix-pull</command>s
|
||||||
|
done by <systemitem class="username">root</systemitem>.</para></note>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Setting up the build users</title>
|
||||||
|
|
||||||
|
<para>The <emphasis>build users</emphasis> are the special UIDs under
|
||||||
|
which builds are performed. They should all be members of the
|
||||||
|
<emphasis>build users group</emphasis> (usually called
|
||||||
|
<literal>nixbld</literal>). This group should have no other members.
|
||||||
|
The build users should not be members of any other group.</para>
|
||||||
|
|
||||||
|
<para>Here is a typical <filename>/etc/group</filename> definition of
|
||||||
|
the build users group with 10 build users:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
nixbld:!:30000:nixbld1,nixbld2,nixbld3,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9,nixbld10
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
In this example the <literal>nixbld</literal> group has UID 30000, but
|
||||||
|
of course it can be anything that doesn’t collide with an existing
|
||||||
|
group.</para>
|
||||||
|
|
||||||
|
<para>Here is the corresponding part of
|
||||||
|
<filename>/etc/passwd</filename>:
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
nixbld1:x:30001:65534:Nix build user 1:/var/empty:/noshell
|
||||||
|
nixbld2:x:30002:65534:Nix build user 2:/var/empty:/noshell
|
||||||
|
nixbld3:x:30003:65534:Nix build user 3:/var/empty:/noshell
|
||||||
|
...
|
||||||
|
nixbld10:x:30010:65534:Nix build user 10:/var/empty:/noshell
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
The home directory of the build users should not exist or should be an
|
||||||
|
empty directory to which they do not have write access.</para>
|
||||||
|
|
||||||
|
<para>The build users should have write access to the Nix store, but
|
||||||
|
they should not have the right to delete files. Thus the Nix store’s
|
||||||
|
group should be the build users group, and it should have the sticky
|
||||||
|
bit turned on (like <filename>/tmp</filename>):
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ chgrp nixbld /nix/store
|
||||||
|
$ chmod 1777 /nix/store
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>Finally, you should tell Nix to use the build users by
|
||||||
|
specifying the build users group in the <link
|
||||||
|
linkend="conf-build-users-group"><literal>build-users-group</literal>
|
||||||
|
option</link> in the <link linkend="sec-conf-file">Nix configuration
|
||||||
|
file</link> (<literal>/nix/etc/nix/nix.conf</literal>):
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
build-users-group = nixbld
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Nix store/database owned by root</title>
|
||||||
|
|
||||||
|
<para>The simplest setup is to let <literal>root</literal> own the Nix
|
||||||
|
store and database. I.e.,
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ chown -R root /nix/store /nix/var/nix</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>The <link linkend="sec-nix-worker">Nix daemon</link> should be
|
||||||
|
started as follows (as <literal>root</literal>):
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-worker --daemon</screen>
|
||||||
|
|
||||||
|
You’ll want to put that line somewhere in your system’s boot
|
||||||
|
scripts.</para>
|
||||||
|
|
||||||
|
<para>To let unprivileged users use the daemon, they should set the
|
||||||
|
<link linkend="envar-remote"><envar>NIX_REMOTE</envar> environment
|
||||||
|
variable</link> to <literal>daemon</literal>. So you should put a
|
||||||
|
line like
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
export NIX_REMOTE=daemon</programlisting>
|
||||||
|
|
||||||
|
into the users’ login scripts.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Nix store/database not owned by root</title>
|
||||||
|
|
||||||
|
<para>It is also possible to let the Nix store and database be owned
|
||||||
|
by a non-root user, which should be more secure<footnote><para>Note
|
||||||
|
however that even when the Nix daemon runs as root, not
|
||||||
|
<emphasis>that</emphasis> much code is executed as root: Nix
|
||||||
|
expression evaluation is performed by the calling (unprivileged) user,
|
||||||
|
and builds are performed under the special build user accounts. So
|
||||||
|
only the code that accesses the database and starts builds is executed
|
||||||
|
as <literal>root</literal>.</para></footnote>. Typically, this user
|
||||||
|
is a special account called <literal>nix</literal>, but it can be
|
||||||
|
named anything. It should own the Nix store and database:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ chown -R root /nix/store /nix/var/nix</screen>
|
||||||
|
|
||||||
|
and of course <command>nix-worker --daemon</command> should be started
|
||||||
|
under that user, e.g.,
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ su - nix -c "exec /nix/bin/nix-worker --daemon"</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>There is a catch, though: non-<literal>root</literal> users
|
||||||
|
cannot start builds under the build user accounts, since the
|
||||||
|
<function>setuid</function> system call is obviously privileged. To
|
||||||
|
allow a non-<literal>root</literal> Nix daemon to use the build user
|
||||||
|
feature, it calls a setuid-root helper program,
|
||||||
|
<command>nix-setuid-helper</command>. This program is installed in
|
||||||
|
<filename><replaceable>prefix</replaceable>/libexec/nix-setuid-helper</filename>.
|
||||||
|
To set the permissions properly (Nix’s <command>make install</command>
|
||||||
|
doesn’t do this, since we don’t want to ship setuid-root programs
|
||||||
|
out-of-the-box):
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ chown root.root /nix/libexec/nix-setuid-helper
|
||||||
|
$ chmod 4755 /nix/libexec/nix-setuid-helper
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
(This example assumes that the Nix binaries are installed in
|
||||||
|
<filename>/nix</filename>.)</para>
|
||||||
|
|
||||||
|
<para>Of course, the <command>nix-setuid-helper</command> command
|
||||||
|
should not be usable by just anybody, since then anybody could run
|
||||||
|
commands under the Nix build user accounts. For that reason there is
|
||||||
|
a configuration file <filename>/etc/nix-setuid.conf</filename> that
|
||||||
|
restricts the use of the helper. This file should be a text file
|
||||||
|
containing precisely two lines, the first being the Nix daemon user
|
||||||
|
and the second being the build users group, e.g.,
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
nix
|
||||||
|
nixbld
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
The setuid-helper barfs if it is called by a user other than the one
|
||||||
|
specified on the first line, or if it is asked to execute a build
|
||||||
|
under a user who is not a member of the group specified on the second
|
||||||
|
line. The file <filename>/etc/nix-setuid.conf</filename> must be
|
||||||
|
owned by root, and must not be group- or world-writable. The
|
||||||
|
setuid-helper barfs if this is not the case.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Restricting access</title>
|
||||||
|
|
||||||
|
<para>To limit which users can perform Nix operations, you can use the
|
||||||
|
permissions on the directory
|
||||||
|
<filename>/nix/var/nix/daemon-socket</filename>. For instance, if you
|
||||||
|
want to restrict the use of Nix to the members of a group called
|
||||||
|
<literal>nix-users</literal>, do
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ chgrp nix-users /nix/var/nix/daemon-socket
|
||||||
|
$ chmod ug=rwx,o= /nix/var/nix/daemon-socket
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
This way, users who are not in the <literal>nix-users</literal> group
|
||||||
|
cannot connect to the Unix domain socket
|
||||||
|
<filename>/nix/var/nix/daemon-socket/socket</filename>, so they cannot
|
||||||
|
perform Nix operations.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
</section> <!-- end of multi-user -->
|
||||||
|
|
||||||
|
|
||||||
|
</section> <!-- end of security -->
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Using Nix</title>
|
||||||
|
|
||||||
|
<para>To use Nix, some environment variables should be set. In
|
||||||
|
particular, <envar>PATH</envar> should contain the directories
|
||||||
|
<filename><replaceable>prefix</replaceable>/bin</filename> and
|
||||||
|
<filename>~/.nix-profile/bin</filename>. The first directory contains
|
||||||
|
the Nix tools themselves, while <filename>~/.nix-profile</filename> is
|
||||||
|
a symbolic link to the current <emphasis>user environment</emphasis>
|
||||||
|
(an automatically generated package consisting of symlinks to
|
||||||
|
installed packages). The simplest way to set the required environment
|
||||||
|
variables is to include the file
|
||||||
|
<filename><replaceable>prefix</replaceable>/etc/profile.d/nix.sh</filename>
|
||||||
|
in your <filename>~/.bashrc</filename> (or similar), like this:</para>
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
source <replaceable>prefix</replaceable>/etc/profile.d/nix.sh</screen>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
</chapter>
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-building-source">
|
|
||||||
|
|
||||||
<title>Building Nix from Source</title>
|
|
||||||
|
|
||||||
<para>After unpacking or checking out the Nix sources, issue the
|
|
||||||
following commands:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ ./configure <replaceable>options...</replaceable>
|
|
||||||
$ make
|
|
||||||
$ make install</screen>
|
|
||||||
|
|
||||||
Nix requires GNU Make so you may need to invoke
|
|
||||||
<command>gmake</command> instead.</para>
|
|
||||||
|
|
||||||
<para>When building from the Git repository, these should be preceded
|
|
||||||
by the command:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ ./bootstrap.sh</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The installation path can be specified by passing the
|
|
||||||
<option>--prefix=<replaceable>prefix</replaceable></option> to
|
|
||||||
<command>configure</command>. The default installation directory is
|
|
||||||
<filename>/usr/local</filename>. You can change this to any location
|
|
||||||
you like. You must have write permission to the
|
|
||||||
<replaceable>prefix</replaceable> path.</para>
|
|
||||||
|
|
||||||
<para>Nix keeps its <emphasis>store</emphasis> (the place where
|
|
||||||
packages are stored) in <filename>/nix/store</filename> by default.
|
|
||||||
This can be changed using
|
|
||||||
<option>--with-store-dir=<replaceable>path</replaceable></option>.</para>
|
|
||||||
|
|
||||||
<warning><para>It is best <emphasis>not</emphasis> to change the Nix
|
|
||||||
store from its default, since doing so makes it impossible to use
|
|
||||||
pre-built binaries from the standard Nixpkgs channels — that is, all
|
|
||||||
packages will need to be built from source.</para></warning>
|
|
||||||
|
|
||||||
<para>Nix keeps state (such as its database and log files) in
|
|
||||||
<filename>/nix/var</filename> by default. This can be changed using
|
|
||||||
<option>--localstatedir=<replaceable>path</replaceable></option>.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-env-variables">
|
|
||||||
|
|
||||||
<title>Environment Variables</title>
|
|
||||||
|
|
||||||
<para>To use Nix, some environment variables should be set. In
|
|
||||||
particular, <envar>PATH</envar> should contain the directories
|
|
||||||
<filename><replaceable>prefix</replaceable>/bin</filename> and
|
|
||||||
<filename>~/.nix-profile/bin</filename>. The first directory contains
|
|
||||||
the Nix tools themselves, while <filename>~/.nix-profile</filename> is
|
|
||||||
a symbolic link to the current <emphasis>user environment</emphasis>
|
|
||||||
(an automatically generated package consisting of symlinks to
|
|
||||||
installed packages). The simplest way to set the required environment
|
|
||||||
variables is to include the file
|
|
||||||
<filename><replaceable>prefix</replaceable>/etc/profile.d/nix.sh</filename>
|
|
||||||
in your <filename>~/.profile</filename> (or similar), like this:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
source <replaceable>prefix</replaceable>/etc/profile.d/nix.sh</screen>
|
|
||||||
|
|
||||||
<section xml:id="sec-nix-ssl-cert-file">
|
|
||||||
|
|
||||||
<title><envar>NIX_SSL_CERT_FILE</envar></title>
|
|
||||||
|
|
||||||
<para>If you need to specify a custom certificate bundle to account
|
|
||||||
for an HTTPS-intercepting man in the middle proxy, you must specify
|
|
||||||
the path to the certificate bundle in the environment variable
|
|
||||||
<envar>NIX_SSL_CERT_FILE</envar>.</para>
|
|
||||||
|
|
||||||
|
|
||||||
<para>If you don't specify a <envar>NIX_SSL_CERT_FILE</envar>
|
|
||||||
manually, Nix will install and use its own certificate
|
|
||||||
bundle.</para>
|
|
||||||
|
|
||||||
<procedure>
|
|
||||||
<step><para>Set the environment variable and install Nix</para>
|
|
||||||
<screen>
|
|
||||||
$ export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt
|
|
||||||
$ sh <(curl https://nixos.org/nix/install)
|
|
||||||
</screen></step>
|
|
||||||
|
|
||||||
<step><para>In the shell profile and rc files (for example,
|
|
||||||
<filename>/etc/bashrc</filename>, <filename>/etc/zshrc</filename>),
|
|
||||||
add the following line:</para>
|
|
||||||
<programlisting>
|
|
||||||
export NIX_SSL_CERT_FILE=/etc/ssl/my-certificate-bundle.crt
|
|
||||||
</programlisting>
|
|
||||||
</step>
|
|
||||||
</procedure>
|
|
||||||
|
|
||||||
<note><para>You must not add the export and then do the install, as
|
|
||||||
the Nix installer will detect the presense of Nix configuration, and
|
|
||||||
abort.</para></note>
|
|
||||||
|
|
||||||
<section xml:id="sec-nix-ssl-cert-file-with-nix-daemon-and-macos">
|
|
||||||
<title><envar>NIX_SSL_CERT_FILE</envar> with macOS and the Nix daemon</title>
|
|
||||||
|
|
||||||
<para>On macOS you must specify the environment variable for the Nix
|
|
||||||
daemon service, then restart it:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ sudo launchctl setenv NIX_SSL_CERT_FILE /etc/ssl/my-certificate-bundle.crt
|
|
||||||
$ sudo launchctl kickstart -k system/org.nixos.nix-daemon
|
|
||||||
</screen>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section xml:id="sec-installer-proxy-settings">
|
|
||||||
|
|
||||||
<title>Proxy Environment Variables</title>
|
|
||||||
|
|
||||||
<para>The Nix installer has special handling for these proxy-related
|
|
||||||
environment variables:
|
|
||||||
<varname>http_proxy</varname>, <varname>https_proxy</varname>,
|
|
||||||
<varname>ftp_proxy</varname>, <varname>no_proxy</varname>,
|
|
||||||
<varname>HTTP_PROXY</varname>, <varname>HTTPS_PROXY</varname>,
|
|
||||||
<varname>FTP_PROXY</varname>, <varname>NO_PROXY</varname>.
|
|
||||||
</para>
|
|
||||||
<para>If any of these variables are set when running the Nix installer,
|
|
||||||
then the installer will create an override file at
|
|
||||||
<filename>/etc/systemd/system/nix-daemon.service.d/override.conf</filename>
|
|
||||||
so <command>nix-daemon</command> will use them.
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
</chapter>
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<part xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="chap-installation">
|
|
||||||
|
|
||||||
<title>Installation</title>
|
|
||||||
|
|
||||||
<partintro>
|
|
||||||
<para>This section describes how to install and configure Nix for first-time use.</para>
|
|
||||||
</partintro>
|
|
||||||
|
|
||||||
<xi:include href="supported-platforms.xml" />
|
|
||||||
<xi:include href="installing-binary.xml" />
|
|
||||||
<xi:include href="installing-source.xml" />
|
|
||||||
<xi:include href="nix-security.xml" />
|
|
||||||
<xi:include href="env-variables.xml" />
|
|
||||||
|
|
||||||
<!-- TODO: should be updated
|
|
||||||
<section><title>Upgrading Nix through Nix</title>
|
|
||||||
|
|
||||||
<para>You can install the latest stable version of Nix through Nix
|
|
||||||
itself by subscribing to the channel <link
|
|
||||||
xlink:href="http://nixos.org/releases/nix/channels/nix-stable" />,
|
|
||||||
or the latest unstable version by subscribing to the channel <link
|
|
||||||
xlink:href="http://nixos.org/releases/nix/channels/nix-unstable" />.
|
|
||||||
You can also do a <link linkend="sec-one-click">one-click
|
|
||||||
installation</link> by clicking on the package links at <link
|
|
||||||
xlink:href="http://nixos.org/releases/full-index-nix.html" />.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
-->
|
|
||||||
|
|
||||||
</part>
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-installing-binary">
|
|
||||||
|
|
||||||
<title>Installing a Binary Distribution</title>
|
|
||||||
|
|
||||||
<para>If you are using Linux or macOS, the easiest way to install Nix
|
|
||||||
is to run the following command:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ sh <(curl https://nixos.org/nix/install)
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
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.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<section xml:id="sect-single-user-installation">
|
|
||||||
<title>Single User Installation</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
To explicitly select a single-user installation on your system:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
sh <(curl https://nixos.org/nix/install) --no-daemon
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
This will perform a single-user installation of Nix, meaning that
|
|
||||||
<filename>/nix</filename> is owned by the invoking user. You should
|
|
||||||
run this under your usual user account, <emphasis>not</emphasis> as
|
|
||||||
root. The script will invoke <command>sudo</command> to create
|
|
||||||
<filename>/nix</filename> if it doesn’t already exist. If you don’t
|
|
||||||
have <command>sudo</command>, you should manually create
|
|
||||||
<command>/nix</command> first as root, e.g.:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ mkdir /nix
|
|
||||||
$ chown alice /nix
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
The install script will modify the first writable file from amongst
|
|
||||||
<filename>.bash_profile</filename>, <filename>.bash_login</filename>
|
|
||||||
and <filename>.profile</filename> to source
|
|
||||||
<filename>~/.nix-profile/etc/profile.d/nix.sh</filename>. You can set
|
|
||||||
the <command>NIX_INSTALLER_NO_MODIFY_PROFILE</command> environment
|
|
||||||
variable before executing the install script to disable this
|
|
||||||
behaviour.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
|
|
||||||
<para>You can uninstall Nix simply by running:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ rm -rf /nix
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section xml:id="sect-multi-user-installation">
|
|
||||||
<title>Multi User Installation</title>
|
|
||||||
<para>
|
|
||||||
The multi-user Nix installation creates system users, and a system
|
|
||||||
service for the Nix daemon.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
<title>Supported Systems</title>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Linux running systemd, with SELinux disabled</para>
|
|
||||||
</listitem>
|
|
||||||
<listitem><para>macOS</para></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
You can instruct the installer to perform a multi-user
|
|
||||||
installation on your system:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
sh <(curl https://nixos.org/nix/install) --daemon
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
The multi-user installation of Nix will create build users between
|
|
||||||
the user IDs 30001 and 30032, and a group with the group ID 30000.
|
|
||||||
|
|
||||||
You should run this under your usual user account,
|
|
||||||
<emphasis>not</emphasis> as root. The script will invoke
|
|
||||||
<command>sudo</command> as needed.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<note><para>
|
|
||||||
If you need Nix to use a different group ID or user ID set, you
|
|
||||||
will have to download the tarball manually and <link
|
|
||||||
linkend="sect-nix-install-binary-tarball">edit the install
|
|
||||||
script</link>.
|
|
||||||
</para></note>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
The installer will modify <filename>/etc/bashrc</filename>, and
|
|
||||||
<filename>/etc/zshrc</filename> if they exist. The installer will
|
|
||||||
first back up these files with a
|
|
||||||
<literal>.backup-before-nix</literal> extension. The installer
|
|
||||||
will also create <filename>/etc/profile.d/nix.sh</filename>.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>You can uninstall Nix with the following commands:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
sudo rm -rf /etc/profile/nix.sh /etc/nix /nix ~root/.nix-profile ~root/.nix-defexpr ~root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
|
|
||||||
|
|
||||||
# If you are on Linux with systemd, you will need to run:
|
|
||||||
sudo systemctl stop nix-daemon.socket
|
|
||||||
sudo systemctl stop nix-daemon.service
|
|
||||||
sudo systemctl disable nix-daemon.socket
|
|
||||||
sudo systemctl disable nix-daemon.service
|
|
||||||
sudo systemctl daemon-reload
|
|
||||||
|
|
||||||
# If you are on macOS, you will need to run:
|
|
||||||
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
||||||
sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
There may also be references to Nix in
|
|
||||||
<filename>/etc/profile</filename>,
|
|
||||||
<filename>/etc/bashrc</filename>, and
|
|
||||||
<filename>/etc/zshrc</filename> which you may remove.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section xml:id="sect-nix-install-pinned-version-url">
|
|
||||||
<title>Installing a pinned Nix version from a URL</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
NixOS.org hosts version-specific installation URLs for all Nix
|
|
||||||
versions since 1.11.16, at
|
|
||||||
<literal>https://releases.nixos.org/nix/nix-<replaceable>version</replaceable>/install</literal>.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
These install scripts can be used the same as the main
|
|
||||||
NixOS.org installation script:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
sh <(curl https://nixos.org/nix/install)
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
In the same directory of the install script are sha256 sums, and
|
|
||||||
gpg signature files.
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section xml:id="sect-nix-install-binary-tarball">
|
|
||||||
<title>Installing from a binary tarball</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
You can also download a binary tarball that contains Nix and all
|
|
||||||
its dependencies. (This is what the install script at
|
|
||||||
<uri>https://nixos.org/nix/install</uri> does automatically.) You
|
|
||||||
should unpack it somewhere (e.g. in <filename>/tmp</filename>),
|
|
||||||
and then run the script named <command>install</command> inside
|
|
||||||
the binary tarball:
|
|
||||||
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
alice$ cd /tmp
|
|
||||||
alice$ tar xfj nix-1.8-x86_64-darwin.tar.bz2
|
|
||||||
alice$ cd nix-1.8-x86_64-darwin
|
|
||||||
alice$ ./install
|
|
||||||
</screen>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
If you need to edit the multi-user installation script to use
|
|
||||||
different group ID or a different user ID range, modify the
|
|
||||||
variables set in the file named
|
|
||||||
<filename>install-multi-user</filename>.
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
</chapter>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-installing-source">
|
|
||||||
|
|
||||||
<title>Installing Nix from Source</title>
|
|
||||||
|
|
||||||
<para>If no binary package is available, you can download and compile
|
|
||||||
a source distribution.</para>
|
|
||||||
|
|
||||||
<xi:include href="prerequisites-source.xml" />
|
|
||||||
<xi:include href="obtaining-source.xml" />
|
|
||||||
<xi:include href="building-source.xml" />
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ssec-multi-user">
|
|
||||||
|
|
||||||
<title>Multi-User Mode</title>
|
|
||||||
|
|
||||||
<para>To allow a Nix store to be shared safely among multiple users,
|
|
||||||
it is important that users are not able to run builders that modify
|
|
||||||
the Nix store or database in arbitrary ways, or that interfere with
|
|
||||||
builds started by other users. If they could do so, they could
|
|
||||||
install a Trojan horse in some package and compromise the accounts of
|
|
||||||
other users.</para>
|
|
||||||
|
|
||||||
<para>To prevent this, the Nix store and database are owned by some
|
|
||||||
privileged user (usually <literal>root</literal>) and builders are
|
|
||||||
executed under special user accounts (usually named
|
|
||||||
<literal>nixbld1</literal>, <literal>nixbld2</literal>, etc.). When a
|
|
||||||
unprivileged user runs a Nix command, actions that operate on the Nix
|
|
||||||
store (such as builds) are forwarded to a <emphasis>Nix
|
|
||||||
daemon</emphasis> running under the owner of the Nix store/database
|
|
||||||
that performs the operation.</para>
|
|
||||||
|
|
||||||
<note><para>Multi-user mode has one important limitation: only
|
|
||||||
<systemitem class="username">root</systemitem> and a set of trusted
|
|
||||||
users specified in <filename>nix.conf</filename> can specify arbitrary
|
|
||||||
binary caches. So while unprivileged users may install packages from
|
|
||||||
arbitrary Nix expressions, they may not get pre-built
|
|
||||||
binaries.</para></note>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect>
|
|
||||||
|
|
||||||
<title>Setting up the build users</title>
|
|
||||||
|
|
||||||
<para>The <emphasis>build users</emphasis> are the special UIDs under
|
|
||||||
which builds are performed. They should all be members of the
|
|
||||||
<emphasis>build users group</emphasis> <literal>nixbld</literal>.
|
|
||||||
This group should have no other members. The build users should not
|
|
||||||
be members of any other group. On Linux, you can create the group and
|
|
||||||
users as follows:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ groupadd -r nixbld
|
|
||||||
$ for n in $(seq 1 10); do useradd -c "Nix build user $n" \
|
|
||||||
-d /var/empty -g nixbld -G nixbld -M -N -r -s "$(which nologin)" \
|
|
||||||
nixbld$n; done
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
This creates 10 build users. There can never be more concurrent builds
|
|
||||||
than the number of build users, so you may want to increase this if
|
|
||||||
you expect to do many builds at the same time.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect>
|
|
||||||
|
|
||||||
<title>Running the daemon</title>
|
|
||||||
|
|
||||||
<para>The <link linkend="sec-nix-daemon">Nix daemon</link> should be
|
|
||||||
started as follows (as <literal>root</literal>):
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-daemon</screen>
|
|
||||||
|
|
||||||
You’ll want to put that line somewhere in your system’s boot
|
|
||||||
scripts.</para>
|
|
||||||
|
|
||||||
<para>To let unprivileged users use the daemon, they should set the
|
|
||||||
<link linkend="envar-remote"><envar>NIX_REMOTE</envar> environment
|
|
||||||
variable</link> to <literal>daemon</literal>. So you should put a
|
|
||||||
line like
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
export NIX_REMOTE=daemon</programlisting>
|
|
||||||
|
|
||||||
into the users’ login scripts.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect>
|
|
||||||
|
|
||||||
<title>Restricting access</title>
|
|
||||||
|
|
||||||
<para>To limit which users can perform Nix operations, you can use the
|
|
||||||
permissions on the directory
|
|
||||||
<filename>/nix/var/nix/daemon-socket</filename>. For instance, if you
|
|
||||||
want to restrict the use of Nix to the members of a group called
|
|
||||||
<literal>nix-users</literal>, do
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ chgrp nix-users /nix/var/nix/daemon-socket
|
|
||||||
$ chmod ug=rwx,o= /nix/var/nix/daemon-socket
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
This way, users who are not in the <literal>nix-users</literal> group
|
|
||||||
cannot connect to the Unix domain socket
|
|
||||||
<filename>/nix/var/nix/daemon-socket/socket</filename>, so they cannot
|
|
||||||
perform Nix operations.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-nix-security">
|
|
||||||
|
|
||||||
<title>Security</title>
|
|
||||||
|
|
||||||
<para>Nix has two basic security models. First, it can be used in
|
|
||||||
“single-user mode”, which is similar to what most other package
|
|
||||||
management tools do: there is a single user (typically <systemitem
|
|
||||||
class="username">root</systemitem>) who performs all package
|
|
||||||
management operations. All other users can then use the installed
|
|
||||||
packages, but they cannot perform package management operations
|
|
||||||
themselves.</para>
|
|
||||||
|
|
||||||
<para>Alternatively, you can configure Nix in “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.</para>
|
|
||||||
|
|
||||||
<xi:include href="single-user.xml" />
|
|
||||||
<xi:include href="multi-user.xml" />
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-obtaining-source">
|
|
||||||
|
|
||||||
<title>Obtaining a Source Distribution</title>
|
|
||||||
|
|
||||||
<para>The source tarball of the most recent stable release can be
|
|
||||||
downloaded from the <link
|
|
||||||
xlink:href="http://nixos.org/nix/download.html">Nix homepage</link>.
|
|
||||||
You can also grab the <link
|
|
||||||
xlink:href="http://hydra.nixos.org/job/nix/master/release/latest-finished#tabs-constituents">most
|
|
||||||
recent development release</link>.</para>
|
|
||||||
|
|
||||||
<para>Alternatively, the most recent sources of Nix can be obtained
|
|
||||||
from its <link
|
|
||||||
xlink:href="https://github.com/NixOS/nix">Git
|
|
||||||
repository</link>. For example, the following command will check out
|
|
||||||
the latest revision into a directory called
|
|
||||||
<filename>nix</filename>:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ git clone https://github.com/NixOS/nix</screen>
|
|
||||||
|
|
||||||
<para>Likewise, specific releases can be obtained from the <link
|
|
||||||
xlink:href="https://github.com/NixOS/nix/tags">tags</link> of the
|
|
||||||
repository.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-prerequisites-source">
|
|
||||||
|
|
||||||
<title>Prerequisites</title>
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para>GNU Autoconf
|
|
||||||
(<link xlink:href="https://www.gnu.org/software/autoconf/"/>)
|
|
||||||
and the autoconf-archive macro collection
|
|
||||||
(<link xlink:href="https://www.gnu.org/software/autoconf-archive/"/>).
|
|
||||||
These are only needed to run the bootstrap script, and are not necessary
|
|
||||||
if your source distribution came with a pre-built
|
|
||||||
<literal>./configure</literal> script.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>GNU Make.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Bash Shell. The <literal>./configure</literal> script
|
|
||||||
relies on bashisms, so Bash is required.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>A version of GCC or Clang that supports C++17.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><command>pkg-config</command> to locate
|
|
||||||
dependencies. If your distribution does not provide it, you can get
|
|
||||||
it from <link
|
|
||||||
xlink:href="http://www.freedesktop.org/wiki/Software/pkg-config"
|
|
||||||
/>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The OpenSSL library to calculate cryptographic hashes.
|
|
||||||
If your distribution does not provide it, you can get it from <link
|
|
||||||
xlink:href="https://www.openssl.org"/>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The <literal>libbrotlienc</literal> and
|
|
||||||
<literal>libbrotlidec</literal> libraries to provide implementation
|
|
||||||
of the Brotli compression algorithm. They are available for download
|
|
||||||
from the official repository <link
|
|
||||||
xlink:href="https://github.com/google/brotli" />.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The bzip2 compressor program and the
|
|
||||||
<literal>libbz2</literal> library. Thus you must have bzip2
|
|
||||||
installed, including development headers and libraries. If your
|
|
||||||
distribution does not provide these, you can obtain bzip2 from <link
|
|
||||||
xlink:href="https://web.archive.org/web/20180624184756/http://www.bzip.org/"
|
|
||||||
/>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><literal>liblzma</literal>, which is provided by
|
|
||||||
XZ Utils. If your distribution does not provide this, you can
|
|
||||||
get it from <link xlink:href="https://tukaani.org/xz/"/>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>cURL and its library. If your distribution does not
|
|
||||||
provide it, you can get it from <link
|
|
||||||
xlink:href="https://curl.haxx.se/"/>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The SQLite embedded database library, version 3.6.19
|
|
||||||
or higher. If your distribution does not provide it, please install
|
|
||||||
it from <link xlink:href="http://www.sqlite.org/" />.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The <link
|
|
||||||
xlink:href="http://www.hboehm.info/gc/">Boehm
|
|
||||||
garbage collector</link> to reduce the evaluator’s memory
|
|
||||||
consumption (optional). To enable it, install
|
|
||||||
<literal>pkgconfig</literal> and the Boehm garbage collector, and
|
|
||||||
pass the flag <option>--enable-gc</option> to
|
|
||||||
<command>configure</command>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The <literal>boost</literal> library of version
|
|
||||||
1.66.0 or higher. It can be obtained from the official web site
|
|
||||||
<link xlink:href="https://www.boost.org/" />.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The <literal>editline</literal> library of version
|
|
||||||
1.14.0 or higher. It can be obtained from the its repository
|
|
||||||
<link xlink:href="https://github.com/troglobit/editline" />.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The <command>xmllint</command> and
|
|
||||||
<command>xsltproc</command> programs to build this manual and the
|
|
||||||
man-pages. These are part of the <literal>libxml2</literal> and
|
|
||||||
<literal>libxslt</literal> packages, respectively. You also need
|
|
||||||
the <link
|
|
||||||
xlink:href="http://docbook.sourceforge.net/projects/xsl/">DocBook
|
|
||||||
XSL stylesheets</link> and optionally the <link
|
|
||||||
xlink:href="http://www.docbook.org/schemas/5x"> DocBook 5.0 RELAX NG
|
|
||||||
schemas</link>. Note that these are only required if you modify the
|
|
||||||
manual sources or when you are building from the Git
|
|
||||||
repository.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Recent versions of Bison and Flex to build the
|
|
||||||
parser. (This is because Nix needs GLR support in Bison and
|
|
||||||
reentrancy support in Flex.) For Bison, you need version 2.6, which
|
|
||||||
can be obtained from the <link
|
|
||||||
xlink:href="ftp://alpha.gnu.org/pub/gnu/bison">GNU FTP
|
|
||||||
server</link>. For Flex, you need version 2.5.35, which is
|
|
||||||
available on <link
|
|
||||||
xlink:href="http://lex.sourceforge.net/">SourceForge</link>.
|
|
||||||
Slightly older versions may also work, but ancient versions like the
|
|
||||||
ubiquitous 2.5.4a won't. Note that these are only required if you
|
|
||||||
modify the parser or when you are building from the Git
|
|
||||||
repository.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The <literal>libseccomp</literal> is used to provide
|
|
||||||
syscall filtering on Linux. This is an optional dependency and can
|
|
||||||
be disabled passing a <option>--disable-seccomp-sandboxing</option>
|
|
||||||
option to the <command>configure</command> script (Not recommended
|
|
||||||
unless your system doesn't support
|
|
||||||
<literal>libseccomp</literal>). To get the library, visit <link
|
|
||||||
xlink:href="https://github.com/seccomp/libseccomp"
|
|
||||||
/>.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<section xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="sec-single-user">
|
|
||||||
|
|
||||||
<title>Single-User Mode</title>
|
|
||||||
|
|
||||||
<para>In single-user mode, all Nix operations that access the database
|
|
||||||
in <filename><replaceable>prefix</replaceable>/var/nix/db</filename>
|
|
||||||
or modify the Nix store in
|
|
||||||
<filename><replaceable>prefix</replaceable>/store</filename> must be
|
|
||||||
performed under the user ID that owns those directories. This is
|
|
||||||
typically <systemitem class="username">root</systemitem>. (If you
|
|
||||||
install from RPM packages, that’s in fact the default ownership.)
|
|
||||||
However, on single-user machines, it is often convenient to
|
|
||||||
<command>chown</command> those directories to your normal user account
|
|
||||||
so that you don’t have to <command>su</command> to <systemitem
|
|
||||||
class="username">root</systemitem> all the time.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-supported-platforms">
|
|
||||||
|
|
||||||
<title>Supported Platforms</title>
|
|
||||||
|
|
||||||
<para>Nix is currently supported on the following platforms:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para>Linux (i686, x86_64, aarch64).</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>macOS (x86_64).</para></listitem>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<listitem><para>FreeBSD (only tested on Intel).</para></listitem>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<listitem><para>Windows through <link
|
|
||||||
xlink:href="http://www.cygwin.com/">Cygwin</link>.</para>
|
|
||||||
|
|
||||||
<warning><para>On Cygwin, Nix <emphasis>must</emphasis> be installed
|
|
||||||
on an NTFS partition. It will not work correctly on a FAT
|
|
||||||
partition.</para></warning>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
-->
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-upgrading-nix">
|
|
||||||
|
|
||||||
<title>Upgrading Nix</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Multi-user Nix users on macOS can upgrade Nix by running:
|
|
||||||
<command>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'</command>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Single-user installations of Nix should run this:
|
|
||||||
<command>nix-channel --update; nix-env -iA nixpkgs.nix</command>
|
|
||||||
</para>
|
|
||||||
</chapter>
|
|
||||||
@@ -0,0 +1,337 @@
|
|||||||
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xml:id="chap-introduction">
|
||||||
|
|
||||||
|
<title>Introduction</title>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>About Nix</title>
|
||||||
|
|
||||||
|
<para>Nix is a <emphasis>purely functional package manager</emphasis>.
|
||||||
|
This means that it treats packages like values in purely functional
|
||||||
|
programming languages such as Haskell — 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 <emphasis>Nix
|
||||||
|
store</emphasis>, usually the directory
|
||||||
|
<filename>/nix/store</filename>, where each package has its own unique
|
||||||
|
subdirectory such as
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
/nix/store/r8vvq9kq18pz08v249h8my6r9vs7s0n3-firefox-2.0.0.1/
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
where <literal>r8vvq9kq…</literal> 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.</para>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Multiple versions</title>
|
||||||
|
|
||||||
|
<para>You can have multiple versions or variants of a package
|
||||||
|
installed at the same time. This is especially important when
|
||||||
|
different applications have dependencies on different versions of the
|
||||||
|
same package — 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.</para>
|
||||||
|
|
||||||
|
<para>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.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Complete dependencies</title>
|
||||||
|
|
||||||
|
<para>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 <emphasis>your</emphasis>
|
||||||
|
machine if you have the dependency installed, but not on the end
|
||||||
|
user's machine if it's not there.</para>
|
||||||
|
|
||||||
|
<para>Since Nix on the other hand doesn’t install packages in “global”
|
||||||
|
locations like <filename>/usr/bin</filename> but in package-specific
|
||||||
|
directories, the risk of incomplete dependencies is greatly reduced.
|
||||||
|
This is because tools such as compilers don’t search in per-packages
|
||||||
|
directories such as
|
||||||
|
<filename>/nix/store/5lbfaxb722zp…-openssl-0.9.8d/include</filename>,
|
||||||
|
so if a package builds correctly on your system, this is because you
|
||||||
|
specified the dependency explicitly.</para>
|
||||||
|
|
||||||
|
<para>Runtime dependencies are found by scanning binaries for the hash
|
||||||
|
parts of Nix store paths (such as <literal>r8vvq9kq…</literal>). This
|
||||||
|
sounds risky, but it works extremely well.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Multi-user support</title>
|
||||||
|
|
||||||
|
<para>Starting at version 0.11, Nix has multi-user support. This
|
||||||
|
means that non-privileged users can securely install software. Each
|
||||||
|
user can have a different <emphasis>profile</emphasis>, a set of
|
||||||
|
packages in the Nix store that appear in the user’s
|
||||||
|
<envar>PATH</envar>. 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.</para>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<para>More details can be found in Section 3 of our <a
|
||||||
|
href="docs/papers.html#securesharing">ASE 2005 paper</a>.</para>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Atomic upgrades and rollbacks</title>
|
||||||
|
|
||||||
|
<para>Since package management operations never overwrite packages in
|
||||||
|
the Nix store but just add new versions in different paths, they are
|
||||||
|
<emphasis>atomic</emphasis>. So during a package upgrade, there is no
|
||||||
|
time window in which the package has some files from the old version
|
||||||
|
and some files from the new version — which would be bad because a
|
||||||
|
program might well crash if it’s started during that period.</para>
|
||||||
|
|
||||||
|
<para>And since package aren’t overwritten, the old versions are still
|
||||||
|
there after an upgrade. This means that you can <emphasis>roll
|
||||||
|
back</emphasis> to the old version:</para>
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-env --upgrade <replaceable>some-packages</replaceable>
|
||||||
|
$ nix-env --rollback
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Garbage collection</title>
|
||||||
|
|
||||||
|
<para>When you install a package like this…
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-env --uninstall firefox
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
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
|
||||||
|
<emphasis>garbage collector</emphasis>:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-collect-garbage
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
This deletes all packages that aren’t in use by any user profile or by
|
||||||
|
a currently running program.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Functional package language</title>
|
||||||
|
|
||||||
|
<para>Packages are built from <emphasis>Nix expressions</emphasis>,
|
||||||
|
which is a simple functional language. A Nix expression describes
|
||||||
|
everything that goes into a package build action (a “derivation”):
|
||||||
|
other packages, sources, the build script, environment variables for
|
||||||
|
the build script, etc. Nix tries very hard to ensure that Nix
|
||||||
|
expressions are <emphasis>deterministic</emphasis>: building a Nix
|
||||||
|
expression twice should yield the same result.</para>
|
||||||
|
|
||||||
|
<para>Because it’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.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Transparent source/binary deployment</title>
|
||||||
|
|
||||||
|
<para>Nix expressions generally describe how to build a package from
|
||||||
|
source, so an installation action like
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-env --install firefox
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
<emphasis>could</emphasis> cause quite a bit of build activity, as not
|
||||||
|
only Firefox but also all its dependencies (all the way up to the C
|
||||||
|
library and the compiler) would have to built, at least if they are
|
||||||
|
not already in the Nix store. This is a <emphasis>source deployment
|
||||||
|
model</emphasis>. For most users, building from source is not very
|
||||||
|
pleasant as it takes far too long. However, Nix can automatically
|
||||||
|
skip building from source and download a pre-built binary instead if
|
||||||
|
it knows about it. <emphasis>Nix channels</emphasis> provide Nix
|
||||||
|
expressions along with pre-built binaries.</para>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<para>source deployment model (like <a
|
||||||
|
href="http://www.gentoo.org/">Gentoo</a>) and a binary model (like
|
||||||
|
RPM)</para>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Binary patching</title>
|
||||||
|
|
||||||
|
<para>In addition to downloading binaries automatically if they’re
|
||||||
|
available, Nix can download binary deltas that patch an existing
|
||||||
|
package in the Nix store into a new version. This speeds up
|
||||||
|
upgrades.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Nix Packages collection</title>
|
||||||
|
|
||||||
|
<para>We provide a large set of Nix expressions containing hundreds of
|
||||||
|
existing Unix packages, the <emphasis>Nix Packages
|
||||||
|
collection</emphasis> (Nixpkgs).</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Service deployment</title>
|
||||||
|
|
||||||
|
<para>Nix can be used not only for rolling out packages, but also
|
||||||
|
complete <emphasis>configurations</emphasis> of services. This is
|
||||||
|
done by treating all the static bits of a service (such as software
|
||||||
|
packages, configuration files, control scripts, static web pages,
|
||||||
|
etc.) as “packages” that can be built by Nix expressions. As a
|
||||||
|
result, all the features above apply to services as well: for
|
||||||
|
instance, you can roll back a web server configuration if a
|
||||||
|
configuration change turns out to be undesirable, you can easily have
|
||||||
|
multiple instances of a service (e.g., a test and production server),
|
||||||
|
and because the whole service is built in a purely functional way from
|
||||||
|
a Nix expression, it is repeatable so you can easily reproduce the
|
||||||
|
service on another machine.</para>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<para>You can read more about this in our <a
|
||||||
|
href="docs/papers.html#servicecm">SCM-12 paper</a>.</para>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>Portability</title>
|
||||||
|
|
||||||
|
<para>Nix should run on most Unix systems, including Linux, FreeBSD and
|
||||||
|
Mac OS X. It is also supported on Windows using Cygwin.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<simplesect><title>NixOS</title>
|
||||||
|
|
||||||
|
<para>NixOS is a Linux distribution based on Nix. It uses Nix not
|
||||||
|
just for package management but also to manage the system
|
||||||
|
configuration (e.g., to build configuration files in
|
||||||
|
<filename>/etc</filename>). This means, among other things, that it’s
|
||||||
|
possible to easily roll back the entire configuration of the system to
|
||||||
|
an earlier state. Also, users can install software without root
|
||||||
|
privileges. For more information and downloads, see the <link
|
||||||
|
xlink:href="http://nixos.org/">NixOS homepage</link>.</para>
|
||||||
|
|
||||||
|
</simplesect>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- other features:
|
||||||
|
|
||||||
|
- build farms
|
||||||
|
- reproducibility (Nix expressions allows whole configuration to be rebuilt)
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>About us</title>
|
||||||
|
|
||||||
|
<para>Nix was originally developed at the <link
|
||||||
|
xlink:href="http://www.cs.uu.nl/">Department of Information and
|
||||||
|
Computing Sciences</link>, Utrecht University by the <link
|
||||||
|
xlink:href="http://www.cs.uu.nl/wiki/Trace/WebHome">TraCE
|
||||||
|
project</link> (2003-2008). The project was funded by the Software
|
||||||
|
Engineering Research Program <link
|
||||||
|
xlink:href="http://www.jacquard.nl/">Jacquard</link> to improve the
|
||||||
|
support for variability in software systems. Further funding is now
|
||||||
|
provided by the NIRICT LaQuSo Build Farm project.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>About this manual</title>
|
||||||
|
|
||||||
|
<para>This manual tells you how to install and use Nix and how to
|
||||||
|
write Nix expressions for software not already in the Nix Packages
|
||||||
|
collection. It also discusses some advanced topics, such as setting
|
||||||
|
up a Nix-based build farm.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>License</title>
|
||||||
|
|
||||||
|
<para>Nix is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the <link
|
||||||
|
xlink:href="http://www.gnu.org/licenses/lgpl.html">GNU Lesser General
|
||||||
|
Public License</link> as published by the <link
|
||||||
|
xlink:href="http://www.fsf.org/">Free Software Foundation</link>;
|
||||||
|
either version 2.1 of the License, or (at your option) any later
|
||||||
|
version. Nix is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>More information</title>
|
||||||
|
|
||||||
|
<para>Some background information on Nix can be found in a number of
|
||||||
|
papers. The ICSE 2004 paper <citetitle
|
||||||
|
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/immdsd-icse2004-final.pdf'>Imposing
|
||||||
|
a Memory Management Discipline on Software Deployment</citetitle>
|
||||||
|
discusses the hashing mechanism used to ensure reliable dependency
|
||||||
|
identification and non-interference between different versions and
|
||||||
|
variants of packages. The LISA 2004 paper <citetitle
|
||||||
|
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/nspfssd-lisa2004-final.pdf'>Nix:
|
||||||
|
A Safe and Policy-Free System for Software Deployment</citetitle>
|
||||||
|
gives a more general discussion of Nix from a system-administration
|
||||||
|
perspective. The CBSE 2005 paper <citetitle
|
||||||
|
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/eupfcdm-cbse2005-final.pdf'>Efficient
|
||||||
|
Upgrading in a Purely Functional Component Deployment Model
|
||||||
|
</citetitle> is about transparent patch deployment in Nix. The SCM-12
|
||||||
|
paper <citetitle
|
||||||
|
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/servicecm-scm12-final.pdf'>
|
||||||
|
Service Configuration Management</citetitle> shows how services (e.g.,
|
||||||
|
web servers) can be deployed and managed through Nix. A short
|
||||||
|
overview of NixOS is given in the HotOS XI paper <citetitle
|
||||||
|
xlink:href="http://www.st.ewi.tudelft.nl/~dolstra/pubs/hotos-final.pdf">Purely
|
||||||
|
Functional System Configuration Management</citetitle>. The Nix
|
||||||
|
homepage has <link
|
||||||
|
xlink:href="http://nix.cs.uu.nl/docs/papers.html">an up-to-date list
|
||||||
|
of Nix-related papers</link>.</para>
|
||||||
|
|
||||||
|
<para>Nix is the subject of Eelco Dolstra’s PhD thesis <citetitle
|
||||||
|
xlink:href="http://igitur-archive.library.uu.nl/dissertations/2006-0118-200031/index.htm">The
|
||||||
|
Purely Functional Software Deployment Model</citetitle>, which
|
||||||
|
contains most of the papers listed above.</para>
|
||||||
|
|
||||||
|
<para>Nix has a homepage at <link
|
||||||
|
xlink:href="http://nixos.org/"/>.</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
</chapter>
|
||||||
@@ -1,268 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="ch-about-nix">
|
|
||||||
|
|
||||||
<title>About Nix</title>
|
|
||||||
|
|
||||||
<para>Nix is a <emphasis>purely functional package manager</emphasis>.
|
|
||||||
This means that it treats packages like values in purely functional
|
|
||||||
programming languages such as Haskell — 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 <emphasis>Nix
|
|
||||||
store</emphasis>, usually the directory
|
|
||||||
<filename>/nix/store</filename>, where each package has its own unique
|
|
||||||
subdirectory such as
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
/nix/store/b6gvzjyb2pg0kjfwrjmg1vfhh54ad73z-firefox-33.1/
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
where <literal>b6gvzjyb2pg0…</literal> 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.</para>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Multiple versions</title>
|
|
||||||
|
|
||||||
<para>You can have multiple versions or variants of a package
|
|
||||||
installed at the same time. This is especially important when
|
|
||||||
different applications have dependencies on different versions of the
|
|
||||||
same package — 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.</para>
|
|
||||||
|
|
||||||
<para>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.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Complete dependencies</title>
|
|
||||||
|
|
||||||
<para>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 <emphasis>your</emphasis>
|
|
||||||
machine if you have the dependency installed, but not on the end
|
|
||||||
user's machine if it's not there.</para>
|
|
||||||
|
|
||||||
<para>Since Nix on the other hand doesn’t install packages in “global”
|
|
||||||
locations like <filename>/usr/bin</filename> but in package-specific
|
|
||||||
directories, the risk of incomplete dependencies is greatly reduced.
|
|
||||||
This is because tools such as compilers don’t search in per-packages
|
|
||||||
directories such as
|
|
||||||
<filename>/nix/store/5lbfaxb722zp…-openssl-0.9.8d/include</filename>,
|
|
||||||
so if a package builds correctly on your system, this is because you
|
|
||||||
specified the dependency explicitly. This takes care of the build-time
|
|
||||||
dependencies.</para>
|
|
||||||
|
|
||||||
<para>Once a package is built, runtime dependencies are found by
|
|
||||||
scanning binaries for the hash parts of Nix store paths (such as
|
|
||||||
<literal>r8vvq9kq…</literal>). This sounds risky, but it works
|
|
||||||
extremely well.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Multi-user support</title>
|
|
||||||
|
|
||||||
<para>Nix has multi-user support. This means that non-privileged
|
|
||||||
users can securely install software. Each user can have a different
|
|
||||||
<emphasis>profile</emphasis>, a set of packages in the Nix store that
|
|
||||||
appear in the user’s <envar>PATH</envar>. 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.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Atomic upgrades and rollbacks</title>
|
|
||||||
|
|
||||||
<para>Since package management operations never overwrite packages in
|
|
||||||
the Nix store but just add new versions in different paths, they are
|
|
||||||
<emphasis>atomic</emphasis>. So during a package upgrade, there is no
|
|
||||||
time window in which the package has some files from the old version
|
|
||||||
and some files from the new version — which would be bad because a
|
|
||||||
program might well crash if it’s started during that period.</para>
|
|
||||||
|
|
||||||
<para>And since packages aren’t overwritten, the old versions are still
|
|
||||||
there after an upgrade. This means that you can <emphasis>roll
|
|
||||||
back</emphasis> to the old version:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env --upgrade <replaceable>some-packages</replaceable>
|
|
||||||
$ nix-env --rollback
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Garbage collection</title>
|
|
||||||
|
|
||||||
<para>When you uninstall a package like this…
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env --uninstall firefox
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
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
|
|
||||||
<emphasis>garbage collector</emphasis>:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-collect-garbage
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
This deletes all packages that aren’t in use by any user profile or by
|
|
||||||
a currently running program.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Functional package language</title>
|
|
||||||
|
|
||||||
<para>Packages are built from <emphasis>Nix expressions</emphasis>,
|
|
||||||
which is a simple functional language. A Nix expression describes
|
|
||||||
everything that goes into a package build action (a “derivation”):
|
|
||||||
other packages, sources, the build script, environment variables for
|
|
||||||
the build script, etc. Nix tries very hard to ensure that Nix
|
|
||||||
expressions are <emphasis>deterministic</emphasis>: building a Nix
|
|
||||||
expression twice should yield the same result.</para>
|
|
||||||
|
|
||||||
<para>Because it’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.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Transparent source/binary deployment</title>
|
|
||||||
|
|
||||||
<para>Nix expressions generally describe how to build a package from
|
|
||||||
source, so an installation action like
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env --install firefox
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<emphasis>could</emphasis> cause quite a bit of build activity, as not
|
|
||||||
only Firefox but also all its dependencies (all the way up to the C
|
|
||||||
library and the compiler) would have to built, at least if they are
|
|
||||||
not already in the Nix store. This is a <emphasis>source deployment
|
|
||||||
model</emphasis>. For most users, building from source is not very
|
|
||||||
pleasant as it takes far too long. However, Nix can automatically
|
|
||||||
skip building from source and instead use a <emphasis>binary
|
|
||||||
cache</emphasis>, a web server that provides pre-built binaries. For
|
|
||||||
instance, when asked to build
|
|
||||||
<literal>/nix/store/b6gvzjyb2pg0…-firefox-33.1</literal> from source,
|
|
||||||
Nix would first check if the file
|
|
||||||
<uri>https://cache.nixos.org/b6gvzjyb2pg0….narinfo</uri> exists, and
|
|
||||||
if so, fetch the pre-built binary referenced from there; otherwise, it
|
|
||||||
would fall back to building from source.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<simplesect><title>Binary patching</title>
|
|
||||||
|
|
||||||
<para>In addition to downloading binaries automatically if they’re
|
|
||||||
available, Nix can download binary deltas that patch an existing
|
|
||||||
package in the Nix store into a new version. This speeds up
|
|
||||||
upgrades.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Nix Packages collection</title>
|
|
||||||
|
|
||||||
<para>We provide a large set of Nix expressions containing hundreds of
|
|
||||||
existing Unix packages, the <emphasis>Nix Packages
|
|
||||||
collection</emphasis> (Nixpkgs).</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Managing build environments</title>
|
|
||||||
|
|
||||||
<para>Nix is extremely useful for developers as it makes it easy to
|
|
||||||
automatically set up the build environment for a package. Given a
|
|
||||||
Nix expression that describes the dependencies of your package, the
|
|
||||||
command <command>nix-shell</command> will build or download those
|
|
||||||
dependencies if they’re not already in your Nix store, and then start
|
|
||||||
a Bash shell in which all necessary environment variables (such as
|
|
||||||
compiler search paths) are set.</para>
|
|
||||||
|
|
||||||
<para>For example, the following command gets all dependencies of the
|
|
||||||
Pan newsreader, as described by <link
|
|
||||||
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix">its
|
|
||||||
Nix expression</link>:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell '<nixpkgs>' -A pan
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<para>You’re then dropped into a shell where you can edit, build and test
|
|
||||||
the package:</para>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
[nix-shell]$ tar xf $src
|
|
||||||
[nix-shell]$ cd pan-*
|
|
||||||
[nix-shell]$ ./configure
|
|
||||||
[nix-shell]$ make
|
|
||||||
[nix-shell]$ ./pan/gui/pan
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<para>Since Nix packages are reproducible and have complete dependency
|
|
||||||
specifications, Nix makes an excellent basis for <a
|
|
||||||
href="[%root%]hydra">a continuous build system</a>.</para>
|
|
||||||
-->
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>Portability</title>
|
|
||||||
|
|
||||||
<para>Nix runs on Linux and macOS.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>NixOS</title>
|
|
||||||
|
|
||||||
<para>NixOS is a Linux distribution based on Nix. It uses Nix not
|
|
||||||
just for package management but also to manage the system
|
|
||||||
configuration (e.g., to build configuration files in
|
|
||||||
<filename>/etc</filename>). This means, among other things, that it
|
|
||||||
is easy to roll back the entire configuration of the system to an
|
|
||||||
earlier state. Also, users can install software without root
|
|
||||||
privileges. For more information and downloads, see the <link
|
|
||||||
xlink:href="http://nixos.org/">NixOS homepage</link>.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
<simplesect><title>License</title>
|
|
||||||
|
|
||||||
<para>Nix is released under the terms of the <link
|
|
||||||
xlink:href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">GNU
|
|
||||||
LGPLv2.1 or (at your option) any later version</link>.</para>
|
|
||||||
|
|
||||||
</simplesect>
|
|
||||||
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<part xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="chap-introduction">
|
|
||||||
|
|
||||||
<title>Introduction</title>
|
|
||||||
|
|
||||||
<xi:include href="about-nix.xml" />
|
|
||||||
<xi:include href="quick-start.xml" />
|
|
||||||
|
|
||||||
</part>
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0"
|
|
||||||
xml:id="chap-quick-start">
|
|
||||||
|
|
||||||
<title>Quick Start</title>
|
|
||||||
|
|
||||||
<para>This chapter is for impatient people who don't like reading
|
|
||||||
documentation. For more in-depth information you are kindly referred
|
|
||||||
to subsequent chapters.</para>
|
|
||||||
|
|
||||||
<procedure>
|
|
||||||
|
|
||||||
<step><para>Install single-user Nix by running the following:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ bash <(curl https://nixos.org/nix/install)
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
This will install Nix in <filename>/nix</filename>. The install script
|
|
||||||
will create <filename>/nix</filename> using <command>sudo</command>,
|
|
||||||
so make sure you have sufficient rights. (For other installation
|
|
||||||
methods, see <xref linkend="chap-installation"/>.)</para></step>
|
|
||||||
|
|
||||||
<step><para>See what installable packages are currently available
|
|
||||||
in the channel:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env -qa
|
|
||||||
docbook-xml-4.3
|
|
||||||
docbook-xml-4.5
|
|
||||||
firefox-33.0.2
|
|
||||||
hello-2.9
|
|
||||||
libxslt-1.1.28
|
|
||||||
<replaceable>...</replaceable></screen>
|
|
||||||
|
|
||||||
</para></step>
|
|
||||||
|
|
||||||
<step><para>Install some packages from the channel:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env -i hello</screen>
|
|
||||||
|
|
||||||
This should download pre-built packages; it should not build them
|
|
||||||
locally (if it does, something went wrong).</para></step>
|
|
||||||
|
|
||||||
<step><para>Test that they work:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ which hello
|
|
||||||
/home/eelco/.nix-profile/bin/hello
|
|
||||||
$ hello
|
|
||||||
Hello, world!
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</para></step>
|
|
||||||
|
|
||||||
<step><para>Uninstall a package:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env -e hello</screen>
|
|
||||||
|
|
||||||
</para></step>
|
|
||||||
|
|
||||||
<step><para>You can also test a package without installing it:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-shell -p hello
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
This builds or downloads GNU Hello and its dependencies, then drops
|
|
||||||
you into a Bash shell where the <command>hello</command> command is
|
|
||||||
present, all without affecting your normal environment:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
[nix-shell:~]$ hello
|
|
||||||
Hello, world!
|
|
||||||
|
|
||||||
[nix-shell:~]$ exit
|
|
||||||
|
|
||||||
$ hello
|
|
||||||
hello: command not found
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</para></step>
|
|
||||||
|
|
||||||
<step><para>To keep up-to-date with the channel, do:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-channel --update nixpkgs
|
|
||||||
$ nix-env -u '*'</screen>
|
|
||||||
|
|
||||||
The latter command will upgrade each installed package for which there
|
|
||||||
is a “newer” version (as determined by comparing the version
|
|
||||||
numbers).</para></step>
|
|
||||||
|
|
||||||
<step><para>If you're unhappy with the result of a
|
|
||||||
<command>nix-env</command> action (e.g., an upgraded package turned
|
|
||||||
out not to work properly), you can go back:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env --rollback</screen>
|
|
||||||
|
|
||||||
</para></step>
|
|
||||||
|
|
||||||
<step><para>You should periodically run the Nix garbage collector
|
|
||||||
to get rid of unused packages, since uninstalls or upgrades don't
|
|
||||||
actually delete them:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-collect-garbage -d</screen>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The first command deletes old “generations” of your profile (making
|
|
||||||
rollbacks impossible, but also making the packages in those old
|
|
||||||
generations available for garbage collection), while the second
|
|
||||||
command actually deletes them.-->
|
|
||||||
|
|
||||||
</para></step>
|
|
||||||
|
|
||||||
</procedure>
|
|
||||||
|
|
||||||
</chapter>
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
|
|
||||||
ifeq ($(doc_generate),yes)
|
|
||||||
|
|
||||||
XSLTPROC = $(xsltproc) --nonet $(xmlflags) \
|
|
||||||
--param section.autolabel 1 \
|
|
||||||
--param section.label.includes.component.label 1 \
|
|
||||||
--param xref.with.number.and.title 1 \
|
|
||||||
--param toc.section.depth 3 \
|
|
||||||
--param admon.style \'\' \
|
|
||||||
--param callout.graphics 0 \
|
|
||||||
--param contrib.inline.enabled 0 \
|
|
||||||
--stringparam generate.toc "book toc" \
|
|
||||||
--param keep.relative.image.uris 0
|
|
||||||
|
|
||||||
docbookxsl = http://docbook.sourceforge.net/release/xsl-ns/current
|
|
||||||
docbookrng = http://docbook.org/xml/5.0/rng/docbook.rng
|
|
||||||
|
|
||||||
MANUAL_SRCS := $(call rwildcard, $(d), *.xml)
|
|
||||||
|
|
||||||
|
|
||||||
# Do XInclude processing / RelaxNG validation
|
|
||||||
$(d)/manual.xmli: $(d)/manual.xml $(MANUAL_SRCS) $(d)/version.txt
|
|
||||||
$(trace-gen) $(xmllint) --nonet --xinclude $< -o $@.tmp
|
|
||||||
@mv $@.tmp $@
|
|
||||||
|
|
||||||
$(d)/version.txt:
|
|
||||||
$(trace-gen) echo -n $(PACKAGE_VERSION) > $@
|
|
||||||
|
|
||||||
# Note: RelaxNG validation requires xmllint >= 2.7.4.
|
|
||||||
$(d)/manual.is-valid: $(d)/manual.xmli
|
|
||||||
$(trace-gen) $(XSLTPROC) --novalid --stringparam profile.condition manual \
|
|
||||||
$(docbookxsl)/profiling/profile.xsl $< 2> /dev/null | \
|
|
||||||
$(xmllint) --nonet --noout --relaxng $(docbookrng) -
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
clean-files += $(d)/manual.xmli $(d)/version.txt $(d)/manual.is-valid
|
|
||||||
|
|
||||||
dist-files += $(d)/manual.xmli $(d)/version.txt $(d)/manual.is-valid
|
|
||||||
|
|
||||||
|
|
||||||
# Generate man pages.
|
|
||||||
man-pages := $(foreach n, \
|
|
||||||
nix-env.1 nix-build.1 nix-shell.1 nix-store.1 nix-instantiate.1 \
|
|
||||||
nix-collect-garbage.1 \
|
|
||||||
nix-prefetch-url.1 nix-channel.1 \
|
|
||||||
nix-hash.1 nix-copy-closure.1 \
|
|
||||||
nix.conf.5 nix-daemon.8, \
|
|
||||||
$(d)/$(n))
|
|
||||||
|
|
||||||
$(firstword $(man-pages)): $(d)/manual.xmli $(d)/manual.is-valid
|
|
||||||
$(trace-gen) $(XSLTPROC) --novalid --stringparam profile.condition manpage \
|
|
||||||
$(docbookxsl)/profiling/profile.xsl $< 2> /dev/null | \
|
|
||||||
(cd doc/manual && $(XSLTPROC) $(docbookxsl)/manpages/docbook.xsl -)
|
|
||||||
|
|
||||||
$(wordlist 2, $(words $(man-pages)), $(man-pages)): $(firstword $(man-pages))
|
|
||||||
|
|
||||||
clean-files += $(d)/*.1 $(d)/*.5 $(d)/*.8
|
|
||||||
|
|
||||||
dist-files += $(man-pages)
|
|
||||||
|
|
||||||
|
|
||||||
# Generate the HTML manual.
|
|
||||||
$(d)/manual.html: $(d)/manual.xml $(MANUAL_SRCS) $(d)/manual.is-valid
|
|
||||||
$(trace-gen) $(XSLTPROC) --xinclude --stringparam profile.condition manual \
|
|
||||||
$(docbookxsl)/profiling/profile.xsl $< | \
|
|
||||||
$(XSLTPROC) --output $@ $(docbookxsl)/xhtml/docbook.xsl -
|
|
||||||
|
|
||||||
$(foreach file, $(d)/manual.html, $(eval $(call install-data-in, $(file), $(docdir)/manual)))
|
|
||||||
|
|
||||||
$(foreach file, $(wildcard $(d)/figures/*.png), $(eval $(call install-data-in, $(file), $(docdir)/manual/figures)))
|
|
||||||
|
|
||||||
$(eval $(call install-symlink, manual.html, $(docdir)/manual/index.html))
|
|
||||||
|
|
||||||
|
|
||||||
all: $(d)/manual.html
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
clean-files += $(d)/manual.html
|
|
||||||
|
|
||||||
dist-files += $(d)/manual.html
|
|
||||||
|
|
||||||
|
|
||||||
endif
|
|
||||||
+99
-29
@@ -1,52 +1,122 @@
|
|||||||
<book xmlns="http://docbook.org/ns/docbook"
|
<book xmlns="http://docbook.org/ns/docbook"
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
||||||
version="5.0">
|
|
||||||
|
|
||||||
<info>
|
<info>
|
||||||
<title>Nix Package Manager Guide</title>
|
|
||||||
<subtitle>Version <xi:include href="version.txt" parse="text" /></subtitle>
|
<title>Nix User's Guide</title>
|
||||||
|
|
||||||
|
<subtitle>Draft (Version <xi:include href="version.txt"
|
||||||
|
parse="text" />)</subtitle>
|
||||||
|
|
||||||
<author>
|
<author>
|
||||||
<personname>
|
<personname>
|
||||||
<firstname>Eelco</firstname>
|
<firstname>Eelco</firstname>
|
||||||
<surname>Dolstra</surname>
|
<surname>Dolstra</surname>
|
||||||
</personname>
|
</personname>
|
||||||
<contrib>Author</contrib>
|
<affiliation>
|
||||||
|
<orgname>Delft University of Technology</orgname>
|
||||||
|
<orgdiv>Department of Software Technology</orgdiv>
|
||||||
|
</affiliation>
|
||||||
</author>
|
</author>
|
||||||
|
|
||||||
<copyright>
|
<copyright>
|
||||||
<year>2004-2018</year>
|
<year>2004</year>
|
||||||
|
<year>2005</year>
|
||||||
|
<year>2006</year>
|
||||||
|
<year>2007</year>
|
||||||
|
<year>2008</year>
|
||||||
<holder>Eelco Dolstra</holder>
|
<holder>Eelco Dolstra</holder>
|
||||||
</copyright>
|
</copyright>
|
||||||
|
|
||||||
|
<date>November 2008</date>
|
||||||
|
|
||||||
</info>
|
</info>
|
||||||
|
|
||||||
<!--
|
|
||||||
<preface>
|
<xi:include href="introduction.xml" />
|
||||||
<title>Preface</title>
|
<xi:include href="quick-start.xml" />
|
||||||
<para>This manual describes how to set up and use the Nix package
|
<xi:include href="installation.xml" />
|
||||||
manager.</para>
|
<xi:include href="package-management.xml" />
|
||||||
</preface>
|
<xi:include href="writing-nix-expressions.xml" />
|
||||||
-->
|
<xi:include href="build-farm.xml" />
|
||||||
|
|
||||||
<xi:include href="introduction/introduction.xml" />
|
|
||||||
<xi:include href="installation/installation.xml" />
|
|
||||||
<xi:include href="installation/upgrading.xml" />
|
|
||||||
<xi:include href="packages/package-management.xml" />
|
|
||||||
<xi:include href="expressions/writing-nix-expressions.xml" />
|
|
||||||
<xi:include href="advanced-topics/advanced-topics.xml" />
|
|
||||||
<xi:include href="command-ref/command-ref.xml" />
|
|
||||||
<xi:include href="glossary/glossary.xml" />
|
|
||||||
<xi:include href="hacking.xml" />
|
|
||||||
<xi:include href="release-notes/release-notes.xml" />
|
|
||||||
|
|
||||||
<!--
|
<appendix>
|
||||||
<appendix>
|
<title>Command Reference</title>
|
||||||
|
<xi:include href="opt-common.xml" />
|
||||||
|
<xi:include href="env-common.xml" />
|
||||||
|
<xi:include href="conf-file.xml" />
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>Main commands</title>
|
||||||
|
<section xml:id="sec-nix-env">
|
||||||
|
<title>nix-env</title>
|
||||||
|
<xi:include href="nix-env.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-instantiate">
|
||||||
|
<title>nix-instantiate</title>
|
||||||
|
<xi:include href="nix-instantiate.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-store">
|
||||||
|
<title>nix-store</title>
|
||||||
|
<xi:include href="nix-store.xml" />
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>Utilities</title>
|
||||||
|
<section xml:id="sec-nix-build">
|
||||||
|
<title>nix-build</title>
|
||||||
|
<xi:include href="nix-build.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-channel">
|
||||||
|
<title>nix-channel</title>
|
||||||
|
<xi:include href="nix-channel.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-collect-garbage">
|
||||||
|
<title>nix-collect-garbage</title>
|
||||||
|
<xi:include href="nix-collect-garbage.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-copy-closure">
|
||||||
|
<title>nix-copy-closure</title>
|
||||||
|
<xi:include href="nix-copy-closure.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-hash">
|
||||||
|
<title>nix-hash</title>
|
||||||
|
<xi:include href="nix-hash.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-install-package">
|
||||||
|
<title>nix-install-package</title>
|
||||||
|
<xi:include href="nix-install-package.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-prefetch-url">
|
||||||
|
<title>nix-prefetch-url</title>
|
||||||
|
<xi:include href="nix-prefetch-url.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-pull">
|
||||||
|
<title>nix-pull</title>
|
||||||
|
<xi:include href="nix-pull.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-push">
|
||||||
|
<title>nix-push</title>
|
||||||
|
<xi:include href="nix-push.xml" />
|
||||||
|
</section>
|
||||||
|
<section xml:id="sec-nix-worker">
|
||||||
|
<title>nix-worker</title>
|
||||||
|
<xi:include href="nix-worker.xml" />
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</appendix>
|
||||||
|
|
||||||
|
<xi:include href="troubleshooting.xml" />
|
||||||
|
<!-- <xi:include href="bugs.xml" /> -->
|
||||||
|
<xi:include href="glossary.xml" />
|
||||||
|
|
||||||
|
<appendix>
|
||||||
<title>Nix Release Notes</title>
|
<title>Nix Release Notes</title>
|
||||||
<xi:include href="release-notes/release-notes.xml"
|
<xi:include href="release-notes.xml"
|
||||||
xpointer="xmlns(x=http://docbook.org/ns/docbook)xpointer(x:article/x:section)" />
|
xpointer="xmlns(x=http://docbook.org/ns/docbook)xpointer(x:article/x:section)" />
|
||||||
</appendix>
|
</appendix>
|
||||||
-->
|
|
||||||
|
|
||||||
</book>
|
</book>
|
||||||
Loaded 100 of 935 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user