Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a10da8466f | ||
|
|
e23d134b85 | ||
|
|
c3a79daaf3 | ||
|
|
74ce938e18 | ||
|
|
981afe821c | ||
|
|
cd9d10d4e3 | ||
|
|
c1179badd5 | ||
|
|
3d14ed9270 | ||
|
|
8e0488370d | ||
|
|
b57f8bd38d |
No files matched your search
+15
-8
@@ -1,19 +1,23 @@
|
|||||||
SUBDIRS = externals src scripts corepkgs doc misc tests
|
SUBDIRS = externals src scripts corepkgs doc misc tests
|
||||||
EXTRA_DIST = substitute.mk nix.spec nix.spec.in bootstrap.sh \
|
EXTRA_DIST = substitute.mk nix.spec nix.spec.in bootstrap.sh \
|
||||||
nix.conf.example NEWS version
|
svn-revision nix.conf.example NEWS
|
||||||
|
|
||||||
include ./substitute.mk
|
include ./substitute.mk
|
||||||
|
|
||||||
nix.spec: nix.spec.in
|
nix.spec: nix.spec.in
|
||||||
|
|
||||||
|
rpm: nix.spec dist
|
||||||
|
rpm $(EXTRA_RPM_FLAGS) -ta $(distdir).tar.gz
|
||||||
|
|
||||||
|
relname:
|
||||||
|
echo -n $(distdir) > relname
|
||||||
|
|
||||||
install-data-local: init-state
|
install-data-local: init-state
|
||||||
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix
|
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix
|
||||||
$(INSTALL_DATA) $(srcdir)/nix.conf.example $(DESTDIR)$(sysconfdir)/nix
|
$(INSTALL_DATA) $(srcdir)/nix.conf.example $(DESTDIR)$(sysconfdir)/nix
|
||||||
if ! test -e $(DESTDIR)$(sysconfdir)/nix/nix.conf; then \
|
if ! test -e $(DESTDIR)$(sysconfdir)/nix/nix.conf; then \
|
||||||
$(INSTALL_DATA) $(srcdir)/nix.conf.example $(DESTDIR)$(sysconfdir)/nix/nix.conf; \
|
$(INSTALL_DATA) $(srcdir)/nix.conf.example $(DESTDIR)$(sysconfdir)/nix/nix.conf; \
|
||||||
fi
|
fi
|
||||||
$(INSTALL) -d $(DESTDIR)$(docdir)
|
|
||||||
$(INSTALL_DATA) README $(DESTDIR)$(docdir)/
|
|
||||||
|
|
||||||
if INIT_STATE
|
if INIT_STATE
|
||||||
|
|
||||||
@@ -33,16 +37,19 @@ init-state:
|
|||||||
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/channels
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/channels
|
||||||
ln -sfn $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
ln -sfn $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/userpool
|
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/userpool
|
||||||
$(INSTALL) $(INIT_FLAGS) -m 1777 -d $(DESTDIR)$(storedir)
|
$(INSTALL) $(INIT_FLAGS) -m 1777 -d $(DESTDIR)$(prefix)/store
|
||||||
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/manifests
|
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/manifests
|
||||||
ln -sfn $(localstatedir)/nix/manifests $(DESTDIR)$(localstatedir)/nix/gcroots/manifests
|
ln -sfn $(localstatedir)/nix/manifests $(DESTDIR)$(localstatedir)/nix/gcroots/manifests
|
||||||
|
# $(bindir)/nix-store --init
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
init-state:
|
init-state:
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
NEWS:
|
svn-revision:
|
||||||
$(MAKE) -C doc/manual NEWS.txt
|
svnversion . > svn-revision
|
||||||
|
|
||||||
|
all-local: NEWS
|
||||||
|
|
||||||
|
NEWS: doc/manual/NEWS.txt
|
||||||
cp $(srcdir)/doc/manual/NEWS.txt NEWS
|
cp $(srcdir)/doc/manual/NEWS.txt NEWS
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
Nix is a purely functional package manager. For installation and
|
For installation and usage instructions, please read the manual, which
|
||||||
usage instructions, please read the manual, which can be found in
|
can be found in `docs/manual/manual.html', and additionally at the Nix
|
||||||
`docs/manual/manual.html', and additionally at the Nix website at
|
website at <http://www.cs.uu.nl/groups/ST/Trace/Nix>.
|
||||||
<http://nixos.org/>.
|
|
||||||
|
|
||||||
|
|
||||||
Acknowledgments
|
Acknowledgments
|
||||||
|
|
||||||
This product includes software developed by the OpenSSL Project for
|
This product includes software developed by the OpenSSL Project for
|
||||||
use in the OpenSSL Toolkit (http://www.OpenSSL.org/).
|
use in the OpenSSL Toolkit (http://www.OpenSSL.org/)
|
||||||
+152
-85
@@ -1,117 +1,184 @@
|
|||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
ATerm library conservatively scans for GC roots
|
||||||
Memcheck:Cond
|
Memcheck:Cond
|
||||||
fun:*
|
fun:mark_memory_young
|
||||||
fun:AT_collect_minor
|
fun:mark_phase_young
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
ATerm library conservatively scans for GC roots
|
||||||
Memcheck:Cond
|
Memcheck:Cond
|
||||||
fun:*
|
fun:AT_isValidSymbol
|
||||||
fun:*
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_isValidSymbol
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_isInsideValidTerm
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:AT_isInsideValidTerm
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_markTerm_young
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:AT_markTerm_young
|
||||||
|
fun:mark_memory_young
|
||||||
|
fun:mark_phase_young
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:AT_isValidSymbol
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_isValidSymbol
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_isInsideValidTerm
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:AT_isInsideValidTerm
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:AT_markTerm
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_markTerm
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Value4
|
||||||
|
fun:AT_markTerm
|
||||||
|
fun:mark_memory
|
||||||
|
fun:mark_phase
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ATerm library conservatively scans for GC roots
|
||||||
|
Memcheck:Cond
|
||||||
|
fun:mark_phase_young
|
||||||
fun:AT_collect_minor
|
fun:AT_collect_minor
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
ATerm library conservatively scans for GC roots
|
||||||
Memcheck:Value4
|
Memcheck:Value4
|
||||||
fun:*
|
fun:mark_phase_young
|
||||||
fun:AT_collect_minor
|
fun:AT_collect_minor
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
<insert a suppression name here>
|
||||||
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
|
Memcheck:Cond
|
||||||
fun:*
|
fun:AT_isValidSymbol
|
||||||
fun:AT_collect
|
fun:mark_phase_young
|
||||||
|
fun:AT_collect_minor
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
<insert a suppression name here>
|
||||||
Memcheck:Value4
|
Memcheck:Value4
|
||||||
fun:*
|
fun:AT_isValidSymbol
|
||||||
fun:AT_collect
|
fun:mark_phase_young
|
||||||
|
fun:AT_collect_minor
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
<insert a suppression name here>
|
||||||
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
|
Memcheck:Value4
|
||||||
fun:*
|
fun:AT_isInsideValidTerm
|
||||||
fun:*
|
fun:mark_phase_young
|
||||||
fun:AT_collect
|
fun:AT_collect_minor
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ATerm library conservatively scans for GC roots
|
<insert a suppression name here>
|
||||||
Memcheck:Value8
|
|
||||||
fun:*
|
|
||||||
fun:*
|
|
||||||
fun:AT_collect
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
ATerm library conservatively scans for GC roots
|
|
||||||
Memcheck:Cond
|
Memcheck:Cond
|
||||||
fun:*
|
fun:AT_isInsideValidTerm
|
||||||
fun:*
|
fun:mark_phase_young
|
||||||
fun:AT_collect
|
fun:AT_collect_minor
|
||||||
}
|
}
|
||||||
+30
-78
@@ -1,9 +1,24 @@
|
|||||||
AC_INIT(nix, m4_esyscmd([echo -n $(cat ./version)$VERSION_SUFFIX]))
|
AC_INIT(nix, 0.11)
|
||||||
AC_CONFIG_SRCDIR(README)
|
AC_CONFIG_SRCDIR(README)
|
||||||
AC_CONFIG_AUX_DIR(config)
|
AC_CONFIG_AUX_DIR(config)
|
||||||
AM_INIT_AUTOMAKE([dist-bzip2 foreign])
|
AM_INIT_AUTOMAKE([dist-bzip2 foreign])
|
||||||
|
|
||||||
|
# Change to `1' to produce a `stable' release (i.e., the `preREVISION'
|
||||||
|
# suffix is not added).
|
||||||
|
STABLE=0
|
||||||
|
|
||||||
AC_DEFINE_UNQUOTED(NIX_VERSION, ["$VERSION"], [Nix version.])
|
# Put the revision number in the version.
|
||||||
|
if test "$STABLE" != "1"; then
|
||||||
|
if REVISION=`test -d $srcdir/.svn && svnversion -n $srcdir 2> /dev/null`; then
|
||||||
|
VERSION=${VERSION}pre${REVISION}
|
||||||
|
elif REVISION=`cat $srcdir/svn-revision 2> /dev/null`; then
|
||||||
|
VERSION=${VERSION}pre${REVISION}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_DEFINE_UNQUOTED(NIX_VERSION, ["$VERSION"], [version])
|
||||||
|
|
||||||
|
AC_PREFIX_DEFAULT(/nix)
|
||||||
|
|
||||||
AC_CANONICAL_HOST
|
AC_CANONICAL_HOST
|
||||||
|
|
||||||
@@ -39,41 +54,21 @@ case $sys_name in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
|
AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
|
||||||
[Platform identifier (e.g., `i686-linux').]),
|
[platform identifier (e.g., `i686-linux')]),
|
||||||
system=$withval, system="${machine_name}-${sys_name}")
|
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.
|
|
||||||
test "$localstatedir" = '${prefix}/var' && localstatedir=/nix/var
|
|
||||||
|
|
||||||
|
|
||||||
# Whether to produce a statically linked binary. On Cygwin, this is
|
|
||||||
# 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.
|
# Windows-specific stuff.
|
||||||
if test "$sys_name" = "cygwin"; then
|
if test "$sys_name" = "cygwin"; then
|
||||||
# We cannot delete open files.
|
# We cannot delete open files.
|
||||||
AC_DEFINE(CANNOT_DELETE_OPEN_FILES, 1, [Whether it is impossible to delete open files.])
|
AC_DEFINE(CANNOT_DELETE_OPEN_FILES, 1, [Whether it is impossible to delete open files.])
|
||||||
|
|
||||||
|
# Shared libraries don't work, currently.
|
||||||
|
AC_DISABLE_SHARED
|
||||||
|
AC_ENABLE_STATIC
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -99,34 +94,17 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <iostream>
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
static char buf[1024];]],
|
static char buf[1024];]],
|
||||||
[[cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));]])],
|
[[cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));]])],
|
||||||
[AC_MSG_RESULT(yes) AC_DEFINE(HAVE_PUBSETBUF, 1, [Whether pubsetbuf is available.])],
|
[AC_MSG_RESULT(yes) AC_DEFINE(HAVE_PUBSETBUF, 1, [whether pubsetbuf is available])],
|
||||||
AC_MSG_RESULT(no))
|
AC_MSG_RESULT(no))
|
||||||
AC_LANG_POP(C++)
|
AC_LANG_POP(C++)
|
||||||
|
|
||||||
|
|
||||||
# Check for chroot support (requires chroot() and bind mounts).
|
# Check for <locale>
|
||||||
AC_CHECK_FUNCS([chroot])
|
|
||||||
AC_CHECK_FUNCS([unshare])
|
|
||||||
AC_CHECK_HEADERS([sched.h], [], [], [])
|
|
||||||
AC_CHECK_HEADERS([sys/param.h], [], [], [])
|
|
||||||
AC_CHECK_HEADERS([sys/mount.h], [], [],
|
|
||||||
[#ifdef HAVE_SYS_PARAM_H
|
|
||||||
# include <sys/param.h>
|
|
||||||
# endif
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
# 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)
|
||||||
@@ -136,7 +114,7 @@ fi
|
|||||||
])
|
])
|
||||||
|
|
||||||
NEED_PROG(curl, curl)
|
NEED_PROG(curl, curl)
|
||||||
NEED_PROG(bash, bash)
|
NEED_PROG(shell, sh)
|
||||||
NEED_PROG(patch, patch)
|
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)
|
||||||
@@ -147,8 +125,6 @@ AC_PATH_PROG(bison, bison, false)
|
|||||||
NEED_PROG(perl, perl)
|
NEED_PROG(perl, perl)
|
||||||
NEED_PROG(tar, tar)
|
NEED_PROG(tar, tar)
|
||||||
AC_PATH_PROG(dot, dot)
|
AC_PATH_PROG(dot, dot)
|
||||||
AC_PATH_PROG(dblatex, dblatex)
|
|
||||||
AC_PATH_PROG(gzip, gzip)
|
|
||||||
|
|
||||||
AC_PATH_PROG(openssl_prog, openssl, openssl) # if not found, call openssl in $PATH
|
AC_PATH_PROG(openssl_prog, openssl, openssl) # if not found, call openssl in $PATH
|
||||||
AC_SUBST(openssl_prog)
|
AC_SUBST(openssl_prog)
|
||||||
@@ -186,16 +162,11 @@ 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]),
|
[path of the Nix store]),
|
||||||
storedir=$withval, storedir='/nix/store')
|
storedir=$withval, storedir='${prefix}/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")
|
|
||||||
|
|
||||||
AC_ARG_WITH(bdb, AC_HELP_STRING([--with-bdb=PATH],
|
AC_ARG_WITH(bdb, AC_HELP_STRING([--with-bdb=PATH],
|
||||||
[prefix of Berkeley DB (for Nix <= 0.11 compatibility)]),
|
[prefix of Berkeley DB]),
|
||||||
bdb=$withval, bdb=)
|
bdb=$withval, bdb=)
|
||||||
AM_CONDITIONAL(HAVE_BDB, test -n "$bdb")
|
AM_CONDITIONAL(HAVE_BDB, test -n "$bdb")
|
||||||
if test -z "$bdb"; then
|
if test -z "$bdb"; then
|
||||||
@@ -205,12 +176,6 @@ else
|
|||||||
bdb_lib="-L$bdb/lib -ldb_cxx"
|
bdb_lib="-L$bdb/lib -ldb_cxx"
|
||||||
bdb_include="-I$bdb/include"
|
bdb_include="-I$bdb/include"
|
||||||
fi
|
fi
|
||||||
if test "$old_db_compat" = "no"; then
|
|
||||||
bdb_lib=
|
|
||||||
bdb_include=
|
|
||||||
else
|
|
||||||
AC_DEFINE(OLD_DB_COMPAT, 1, [Whether to support converting from old Berkeley DB-based Nix stores.])
|
|
||||||
fi
|
|
||||||
AC_SUBST(bdb_lib)
|
AC_SUBST(bdb_lib)
|
||||||
AC_SUBST(bdb_include)
|
AC_SUBST(bdb_include)
|
||||||
|
|
||||||
@@ -239,7 +204,7 @@ if test -n "$openssl"; then
|
|||||||
LDFLAGS="-L$openssl/lib -lcrypto $LDFLAGS"
|
LDFLAGS="-L$openssl/lib -lcrypto $LDFLAGS"
|
||||||
CFLAGS="-I$openssl/include $CFLAGS"
|
CFLAGS="-I$openssl/include $CFLAGS"
|
||||||
CXXFLAGS="-I$openssl/include $CXXFLAGS"
|
CXXFLAGS="-I$openssl/include $CXXFLAGS"
|
||||||
AC_DEFINE(HAVE_OPENSSL, 1, [Whether to use OpenSSL.])
|
AC_DEFINE(HAVE_OPENSSL, 1, [whether to use OpenSSL])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_ARG_WITH(bzip2, AC_HELP_STRING([--with-bzip2=PATH],
|
AC_ARG_WITH(bzip2, AC_HELP_STRING([--with-bzip2=PATH],
|
||||||
@@ -252,7 +217,7 @@ if test -z "$bzip2"; then
|
|||||||
bzip2_lib='-L${top_builddir}/externals/inst-bzip2/lib -lbz2'
|
bzip2_lib='-L${top_builddir}/externals/inst-bzip2/lib -lbz2'
|
||||||
bzip2_include='-I${top_builddir}/externals/inst-bzip2/include'
|
bzip2_include='-I${top_builddir}/externals/inst-bzip2/include'
|
||||||
# The binary will be copied to $libexecdir.
|
# The binary will be copied to $libexecdir.
|
||||||
bzip2_bin='${libexecdir}/nix'
|
bzip2_bin='${libexecdir}'
|
||||||
# But for testing, we have to use the temporary copy :-(
|
# But for testing, we have to use the temporary copy :-(
|
||||||
bzip2_bin_test='${top_builddir}/externals/inst-bzip2/bin'
|
bzip2_bin_test='${top_builddir}/externals/inst-bzip2/bin'
|
||||||
else
|
else
|
||||||
@@ -280,11 +245,6 @@ AM_CONDITIONAL(INIT_STATE, test "$init_state" = "yes")
|
|||||||
AC_CHECK_FUNCS([setresuid setreuid lchown])
|
AC_CHECK_FUNCS([setresuid setreuid lchown])
|
||||||
|
|
||||||
|
|
||||||
# Nice to have, but not essential.
|
|
||||||
AC_CHECK_FUNCS([strsignal])
|
|
||||||
AC_CHECK_FUNCS([posix_fallocate])
|
|
||||||
|
|
||||||
|
|
||||||
# This is needed if ATerm, Berkeley DB or bzip2 are static libraries,
|
# This is needed if ATerm, Berkeley DB or bzip2 are static libraries,
|
||||||
# and the Nix libraries are dynamic.
|
# and the Nix libraries are dynamic.
|
||||||
if test "$(uname)" = "Darwin"; then
|
if test "$(uname)" = "Darwin"; then
|
||||||
@@ -292,14 +252,6 @@ if test "$(uname)" = "Darwin"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if test "$static_nix" = yes; then
|
|
||||||
# `-all-static' has to be added at the end of configure, because
|
|
||||||
# the C compiler doesn't know about -all-static (it's filtered out
|
|
||||||
# by libtool, but configure doesn't use libtool).
|
|
||||||
LDFLAGS="-all-static $LDFLAGS"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
AM_CONFIG_HEADER([config.h])
|
AM_CONFIG_HEADER([config.h])
|
||||||
AC_CONFIG_FILES([Makefile
|
AC_CONFIG_FILES([Makefile
|
||||||
externals/Makefile
|
externals/Makefile
|
||||||
|
|||||||
@@ -8,15 +8,9 @@ inputs=($inputs)
|
|||||||
for ((n = 0; n < ${#inputs[*]}; n += 2)); do
|
for ((n = 0; n < ${#inputs[*]}; n += 2)); do
|
||||||
channelName=${inputs[n]}
|
channelName=${inputs[n]}
|
||||||
channelTarball=${inputs[n+1]}
|
channelTarball=${inputs[n+1]}
|
||||||
|
|
||||||
echo "unpacking channel $channelName"
|
echo "unpacking channel $channelName"
|
||||||
|
|
||||||
@bunzip2@ < $channelTarball | @tar@ xf -
|
@bunzip2@ < $channelTarball | @tar@ xf -
|
||||||
|
|
||||||
if test -e */channel-name; then
|
|
||||||
channelName="$(@coreutils@/cat */channel-name)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
nr=1
|
nr=1
|
||||||
attrName=$(echo $channelName | @tr@ -- '- ' '__')
|
attrName=$(echo $channelName | @tr@ -- '- ' '__')
|
||||||
dirName=$attrName
|
dirName=$attrName
|
||||||
|
|||||||
+9
-22
@@ -14,16 +14,15 @@ XSLTPROC = $(xsltproc) $(xmlflags) \
|
|||||||
man1_MANS = nix-env.1 nix-build.1 nix-store.1 nix-instantiate.1 \
|
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-collect-garbage.1 nix-push.1 nix-pull.1 \
|
||||||
nix-prefetch-url.1 nix-channel.1 \
|
nix-prefetch-url.1 nix-channel.1 \
|
||||||
|
nix-pack-closure.1 nix-unpack-closure.1 \
|
||||||
nix-install-package.1 nix-hash.1 nix-copy-closure.1
|
nix-install-package.1 nix-hash.1 nix-copy-closure.1
|
||||||
|
|
||||||
man8_MANS = nix-worker.8
|
|
||||||
|
|
||||||
FIGURES = figures/user-environments.png
|
FIGURES = figures/user-environments.png
|
||||||
|
|
||||||
MANUAL_SRCS = manual.xml introduction.xml installation.xml \
|
MANUAL_SRCS = manual.xml introduction.xml installation.xml \
|
||||||
package-management.xml writing-nix-expressions.xml builtins.xml \
|
package-management.xml writing-nix-expressions.xml \
|
||||||
build-farm.xml \
|
build-farm.xml \
|
||||||
$(man1_MANS:.1=.xml) $(man8_MANS:.8=.xml) \
|
$(man1_MANS:.1=.xml) \
|
||||||
troubleshooting.xml bugs.xml opt-common.xml opt-common-syn.xml \
|
troubleshooting.xml bugs.xml opt-common.xml opt-common-syn.xml \
|
||||||
env-common.xml quick-start.xml nix-lang-ref.xml glossary.xml \
|
env-common.xml quick-start.xml nix-lang-ref.xml glossary.xml \
|
||||||
conf-file.xml release-notes.xml \
|
conf-file.xml release-notes.xml \
|
||||||
@@ -48,14 +47,6 @@ manual.html: $(MANUAL_SRCS) manual.is-valid images
|
|||||||
$(XSLTPROC) --nonet --xinclude --output manual.html \
|
$(XSLTPROC) --nonet --xinclude --output manual.html \
|
||||||
$(docbookxsl)/html/docbook.xsl manual.xml
|
$(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 = \
|
NEWS_OPTS = \
|
||||||
--stringparam generate.toc "article nop" \
|
--stringparam generate.toc "article nop" \
|
||||||
@@ -77,16 +68,12 @@ NEWS.txt: release-notes.xml
|
|||||||
all-local: manual.html NEWS.html NEWS.txt
|
all-local: manual.html NEWS.html NEWS.txt
|
||||||
|
|
||||||
install-data-local: manual.html
|
install-data-local: manual.html
|
||||||
$(INSTALL) -d $(DESTDIR)$(docdir)/manual
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/manual
|
||||||
$(INSTALL_DATA) manual.html $(DESTDIR)$(docdir)/manual
|
$(INSTALL_DATA) manual.html $(DESTDIR)$(datadir)/nix/manual
|
||||||
ln -sf manual.html $(DESTDIR)$(docdir)/manual/index.html
|
$(INSTALL_DATA) style.css $(DESTDIR)$(datadir)/nix/manual
|
||||||
$(INSTALL_DATA) style.css $(DESTDIR)$(docdir)/manual
|
cp -r images $(DESTDIR)$(datadir)/nix/manual/images
|
||||||
cp -r images $(DESTDIR)$(docdir)/manual/images
|
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/manual/figures
|
||||||
$(INSTALL) -d $(DESTDIR)$(docdir)/manual/figures
|
$(INSTALL_DATA) $(FIGURES) $(DESTDIR)$(datadir)/nix/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:
|
images:
|
||||||
mkdir images
|
mkdir images
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ build farm, since:
|
|||||||
builds, and Nix expressions are self-contained.</para></listitem>
|
builds, and Nix expressions are self-contained.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>Nix will only rebuild things that have actually
|
<listitem><para>Nix will only rebuild things that have actually
|
||||||
changed. For instance, if the sources of a package haven't changed
|
changed. For instance, if the sources of a component haven't
|
||||||
between runs of the build farm, the package won't be rebuilt (unless
|
changed between runs of the build farm, the component won't be
|
||||||
it was garbage-collected). Also, dependencies typically don't
|
rebuild (unless it was garbage-collected). Also, dependencies
|
||||||
change very often, so they only need to be built
|
typically don't change very often, so they only need to be built
|
||||||
once.</para></listitem>
|
once.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>The results of a Nix build farm can be made
|
<listitem><para>The results of a Nix build farm can be made
|
||||||
@@ -56,7 +56,7 @@ build farm, since:
|
|||||||
<para>TODO</para>
|
<para>TODO</para>
|
||||||
|
|
||||||
<para>The sources of the Nix build farm are at <link
|
<para>The sources of the Nix build farm are at <link
|
||||||
xlink:href='https://svn.nixos.org/repos/nix/release/trunk'/>.</para>
|
xlink:href='https://svn.cs.uu.nl:12443/repos/trace/release/trunk'/>.</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ nix@scratchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy_auto
|
|||||||
|
|
||||||
<para>An example build hook can be found in the Nix build farm
|
<para>An example build hook can be found in the Nix build farm
|
||||||
sources: <link
|
sources: <link
|
||||||
xlink:href='https://svn.nixos.org/repos/nix/release/trunk/common/distributed/build-remote.pl'
|
xlink:href='https://svn.cs.uu.nl:12443/repos/trace/release/trunk/common/distributed/build-remote.pl'
|
||||||
/>. It should be suitable for most purposes, with maybe some minor
|
/>. It should be suitable for most purposes, with maybe some minor
|
||||||
adjustments. It uses <command>ssh</command> and
|
adjustments. It uses <command>ssh</command> and
|
||||||
<command>rsync</command> to copy the build inputs and outputs and
|
<command>rsync</command> to copy the build inputs and outputs and
|
||||||
|
|||||||
@@ -1,841 +0,0 @@
|
|||||||
<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>
|
|
||||||
+21
-117
@@ -60,6 +60,27 @@ env-keep-derivations = false
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-gc-reserved-space"><term><literal>gc-reserved-space</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>This option specifies how much space should be
|
||||||
|
reserved in normal use so that the garbage collector can run
|
||||||
|
succesfully. Since the garbage collector must perform Berkeley DB
|
||||||
|
transactions, it needs some disk space for itself. However, when
|
||||||
|
the disk is full, this space is not available, so the collector
|
||||||
|
would not be able to run precisely when it is most needed.</para>
|
||||||
|
|
||||||
|
<para>For this reason, when Nix is run, it allocates a file
|
||||||
|
<filename>/nix/var/nix/db/reserved</filename> of the size
|
||||||
|
specified by this option. When the garbage collector is run, this
|
||||||
|
file is deleted before the Berkeley DB environment is opened.
|
||||||
|
This should give it enough room to proceed.</para>
|
||||||
|
|
||||||
|
<para>The default is <literal>1048576</literal> (1
|
||||||
|
MiB).</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><literal>env-keep-derivations</literal></term>
|
<varlistentry><term><literal>env-keep-derivations</literal></term>
|
||||||
|
|
||||||
<listitem><para>If <literal>false</literal> (default), derivations
|
<listitem><para>If <literal>false</literal> (default), derivations
|
||||||
@@ -97,123 +118,6 @@ env-keep-derivations = false
|
|||||||
</varlistentry>
|
</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>
|
<varlistentry><term><literal>system</literal></term>
|
||||||
|
|
||||||
<listitem><para>This option specifies the canonical Nix system
|
<listitem><para>This option specifies the canonical Nix system
|
||||||
|
|||||||
+37
-46
@@ -151,12 +151,12 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|||||||
<para>On the basis of this information, and whatever persistent
|
<para>On the basis of this information, and whatever persistent
|
||||||
state the build hook keeps about other machines and their current
|
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
|
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
|
out on file descriptor 3 one of the following responses (terminated
|
||||||
a newline, <literal>"\n"</literal>):
|
by a newline, <literal>"\n"</literal>):
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
|
||||||
<varlistentry><term><literal># decline</literal></term>
|
<varlistentry><term><literal>decline</literal></term>
|
||||||
|
|
||||||
<listitem><para>The build hook is not willing or able to perform
|
<listitem><para>The build hook is not willing or able to perform
|
||||||
the build; the calling Nix process should do the build itself,
|
the build; the calling Nix process should do the build itself,
|
||||||
@@ -164,7 +164,7 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><literal># postpone</literal></term>
|
<varlistentry><term><literal>postpone</literal></term>
|
||||||
|
|
||||||
<listitem><para>The build hook cannot perform the build now, but
|
<listitem><para>The build hook cannot perform the build now, but
|
||||||
can do so in the future (e.g., because all available build slots
|
can do so in the future (e.g., because all available build slots
|
||||||
@@ -174,7 +174,7 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><literal># accept</literal></term>
|
<varlistentry><term><literal>accept</literal></term>
|
||||||
|
|
||||||
<listitem><para>The build hook has accepted the
|
<listitem><para>The build hook has accepted the
|
||||||
build.</para></listitem>
|
build.</para></listitem>
|
||||||
@@ -185,12 +185,37 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>After sending <literal># accept</literal>, the hook should
|
<para>If the build hook accepts the build, it is possible that it is
|
||||||
read one line from standard input, which will be the string
|
no longer necessary to do the build because some other process has
|
||||||
<literal>okay</literal>. It can then proceed with the build.
|
performed the build in the meantime. To prevent races, the hook
|
||||||
Before sending <literal>okay</literal>, Nix will store in the hook’s
|
must read from file descriptor 4 a single line that tells it whether
|
||||||
current directory a number of text files that contain information
|
to continue:
|
||||||
about the derivation:
|
|
||||||
|
<variablelist>
|
||||||
|
|
||||||
|
<varlistentry><term><literal>cancel</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>The build has already been done, so the hook
|
||||||
|
should exit.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><literal>okay</literal></term>
|
||||||
|
|
||||||
|
<listitem><para>The hook should proceed with the build. At this
|
||||||
|
point, the calling Nix process has acquired locks on the output
|
||||||
|
path, so no other Nix process will perform the
|
||||||
|
build.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>If the hook has been told to proceed, Nix will store in the
|
||||||
|
hook’s current directory a number of text files that contain
|
||||||
|
information about the derivation:
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
|
||||||
@@ -230,9 +255,7 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|||||||
<para>The hook should copy the inputs to the remote machine,
|
<para>The hook should copy the inputs to the remote machine,
|
||||||
register the validity of the inputs, perform the remote build, and
|
register the validity of the inputs, perform the remote build, and
|
||||||
copy the outputs back to the local machine. An exit code other than
|
copy the outputs back to the local machine. An exit code other than
|
||||||
<literal>0</literal> indicates that the hook has failed. An exit
|
<literal>0</literal> indicates that the hook has failed.</para>
|
||||||
code equal to 100 means that the remote build failed (as opposed to,
|
|
||||||
e.g., a network error).</para>
|
|
||||||
|
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
@@ -240,38 +263,6 @@ $ mount -o bind /mnt/otherdisk/nix /nix</screen>
|
|||||||
</varlistentry>
|
</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>
|
</variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,9 @@
|
|||||||
|
|
||||||
<glossentry><glossterm>Nix expression</glossterm>
|
<glossentry><glossterm>Nix expression</glossterm>
|
||||||
|
|
||||||
<glossdef><para>A high-level description of software packages and
|
<glossdef><para>A high-level description of software components and
|
||||||
compositions thereof. Deploying software using Nix entails writing
|
compositions thereof. Deploying software using Nix entails writing
|
||||||
Nix expressions for your packages. Nix expressions are translated
|
Nix expressions for your components. Nix expressions are translated
|
||||||
to derivations that are stored in the Nix store. These derivations
|
to derivations that are stored in the Nix store. These derivations
|
||||||
can then be built.</para></glossdef>
|
can then be built.</para></glossdef>
|
||||||
|
|
||||||
|
|||||||
+50
-241
@@ -42,22 +42,26 @@ platforms as well.</para>
|
|||||||
<section><title>Obtaining Nix</title>
|
<section><title>Obtaining Nix</title>
|
||||||
|
|
||||||
<para>The easiest way to obtain Nix is to download a <link
|
<para>The easiest way to obtain Nix is to download a <link
|
||||||
xlink:href="http://nixos.org/">source distribution</link>. RPMs
|
xlink:href="http://www.cs.uu.nl/groups/ST/Trace/Nix">source
|
||||||
for Red Hat, SuSE, and Fedora Core are also available.</para>
|
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
|
<para>Alternatively, the most recent sources of Nix can be obtained
|
||||||
from its <link
|
from its <link
|
||||||
xlink:href="https://svn.nixos.org/repos/nix/nix/trunk">Subversion
|
xlink:href="https://svn.cs.uu.nl:12443/repos/trace/nix/trunk">Subversion
|
||||||
repository</link>. For example, the following command will check out
|
repository</link>. For example, the following command will check out
|
||||||
the latest revision into a directory called
|
the latest revision into a directory called
|
||||||
<filename>nix</filename>:</para>
|
<filename>nix</filename>:</para>
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ svn checkout https://svn.nixos.org/repos/nix/nix/trunk nix</screen>
|
$ svn checkout https://svn.cs.uu.nl:12443/repos/trace/nix/trunk nix</screen>
|
||||||
|
|
||||||
<para>Likewise, specific releases can be obtained from the <link
|
<para>Likewise, specific releases can be obtained from the <link
|
||||||
xlink:href="https://svn.nixos.org/repos/nix/nix/tags">tags
|
xlink:href="https://svn.cs.uu.nl:12443/repos/trace/nix/tags">tags
|
||||||
directory</link> of the repository.</para>
|
directory</link> of the repository. If you don't have Subversion, you
|
||||||
|
can also download an automatically generated <link
|
||||||
|
xlink:href="https://svn.cs.uu.nl:12443/dist/trace/">compressed
|
||||||
|
tar-file</link> of the head revision of the trunk.</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -96,23 +100,16 @@ 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
|
modify the parser or when you are building from the Subversion
|
||||||
repository.</para>
|
repository.</para>
|
||||||
|
|
||||||
<para>Nix uses CWI's ATerm library and the bzip2 compressor (including
|
<para>Nix uses Sleepycat's Berkeley DB and CWI's ATerm library. These
|
||||||
the bzip2 library). These are included in the Nix source
|
are included in the Nix source distribution. If you build from the
|
||||||
distribution. If you build from the Subversion repository, you must
|
Subversion repository, you must download them yourself and place them
|
||||||
download them yourself and place them in the
|
in the <filename>externals/</filename> directory. See
|
||||||
<filename>externals/</filename> directory. See
|
|
||||||
<filename>externals/Makefile.am</filename> for the precise URLs of
|
<filename>externals/Makefile.am</filename> for the precise URLs of
|
||||||
these packages. Alternatively, if you already have them installed,
|
these packages. Alternatively, if you already have them installed,
|
||||||
you can use <command>configure</command>'s
|
you can use <command>configure</command>'s <option>--with-bdb</option>
|
||||||
<option>--with-aterm</option> and <option>--with-bzip2</option>
|
and <option>--with-aterm</option> options to point to their respective
|
||||||
options to point to their respective locations.</para>
|
locations. Note that Berkeley DB <emphasis>must</emphasis> be version
|
||||||
|
4.5; other versions may not have compatible database formats.</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>
|
||||||
|
|
||||||
@@ -121,21 +118,19 @@ this ability, you can build Nix with the
|
|||||||
|
|
||||||
<para>After unpacking or checking out the Nix sources, issue the
|
<para>After unpacking or checking out the Nix sources, issue the
|
||||||
following commands:
|
following commands:
|
||||||
|
</para>
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ ./configure <replaceable>options...</replaceable>
|
$ ./configure <replaceable>options...</replaceable>
|
||||||
$ make
|
$ make
|
||||||
$ make install</screen>
|
$ make install</screen>
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>When building from the Subversion repository, these should be
|
<para>When building from the Subversion repository, these should be
|
||||||
preceded by the command:
|
preceded by the command:
|
||||||
|
</para>
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ ./bootstrap</screen>
|
$ ./boostrap</screen>
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The installation path can be specified by passing the
|
<para>The installation path can be specified by passing the
|
||||||
<option>--prefix=<replaceable>prefix</replaceable></option> to
|
<option>--prefix=<replaceable>prefix</replaceable></option> to
|
||||||
@@ -162,32 +157,28 @@ options.</para>
|
|||||||
|
|
||||||
<section><title>Installing from RPMs</title>
|
<section><title>Installing from RPMs</title>
|
||||||
|
|
||||||
<para>RPM packages of Nix can be downloaded from <link
|
<para>RPM packages of Nix can be downloaded from <uri
|
||||||
xlink:href="http://nixos.org/" />. These RPMs should work for most
|
xlink:href="http://www.cs.uu.nl/groups/ST/Trace/Nix">http://www.cs.uu.nl/groups/ST/Trace/Nix</uri>.
|
||||||
fairly recent releases of SuSE and Red Hat Linux. They have been
|
These RPMs should work for most fairly recent releases of SuSE and Red
|
||||||
known to work work on SuSE Linux 8.1 and 9.0, and Red Hat 9.0. In
|
Hat Linux. They have been known to work work on SuSE Linux 8.1 and
|
||||||
fact, it should work on any RPM-based Linux distribution based on
|
9.0, and Red Hat 9.0. In fact, it should work on any RPM-based Linux
|
||||||
<literal>glibc</literal> 2.3 or later.</para>
|
distribution based on <literal>glibc</literal> 2.3 or later.</para>
|
||||||
|
|
||||||
<para>Once downloaded, the RPMs can be installed or upgraded using
|
<para>Once downloaded, the RPMs can be installed or upgraded using
|
||||||
<command>rpm -U</command>. For example,
|
<command>rpm -U</command>. For example,</para>
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ rpm -U nix-0.5pre664-1.i386.rpm</screen>
|
$ rpm -U nix-0.5pre664-1.i386.rpm</screen>
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The RPMs install into the directory <filename>/nix</filename>.
|
<para>The RPMs install into the directory <filename>/nix</filename>.
|
||||||
Nix can be uninstalled using <command>rpm -e nix</command>. After
|
Nix can be uninstalled using <command>rpm -e nix</command>. After
|
||||||
this it will be necessary to manually remove the Nix store and other
|
this it will be necessary to manually remove the Nix store and other
|
||||||
auxiliary data:
|
auxiliary data:</para>
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ rm -rf /nix/store
|
$ rm -rf /nix/store
|
||||||
$ rm -rf /nix/var</screen>
|
$ rm -rf /nix/var</screen>
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
@@ -195,12 +186,12 @@ $ rm -rf /nix/var</screen>
|
|||||||
|
|
||||||
<para>You can install the latest stable version of Nix through Nix
|
<para>You can install the latest stable version of Nix through Nix
|
||||||
itself by subscribing to the channel <link
|
itself by subscribing to the channel <link
|
||||||
xlink:href="http://nixos.org/releases/nix/channels/nix-stable" />,
|
xlink:href="http://nix.cs.uu.nl/dist/nix/channels-v3/nix-stable" />,
|
||||||
or the latest unstable version by subscribing to the channel <link
|
or the latest unstable version by subscribing to the channel<link
|
||||||
xlink:href="http://nixos.org/releases/nix/channels/nix-unstable" />.
|
xlink:href="http://nix.cs.uu.nl/dist/nix/channels-v3/nix-unstable" />.
|
||||||
You can also do a <link linkend="sec-one-click">one-click
|
You can also do a <link linkend="sec-one-click">one-click
|
||||||
installation</link> by clicking on the package links at <link
|
installation</link> by clicking on the package links at <link
|
||||||
xlink:href="http://nixos.org/releases/full-index-nix.html" />.</para>
|
xlink:href="http://nix.cs.uu.nl/dist/nix/" />.</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -240,215 +231,33 @@ class="username">root</systemitem> all the time.</para>
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
<section xml:id="ssec-multi-user"><title>Multi-user mode</title>
|
<section><title>Multi-user mode</title>
|
||||||
|
|
||||||
<para>To allow a Nix store to be shared safely among multiple users,
|
<para></para>
|
||||||
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
|
warning: the nix-builders group should contain *only* the Nix
|
||||||
unprivileged user runs a Nix command, actions that operate on the Nix
|
builders, and nothing else. If the Nix account is compromised, you
|
||||||
store (such as builds) are forwarded to a <emphasis>Nix
|
can execute programs under the accounts in the nix-builders group, so
|
||||||
daemon</emphasis> running under the owner of the Nix store/database
|
it obviously shouldn’t contain any “real” user accounts. So don’t use
|
||||||
that performs the operation.</para>
|
an existing group like <literal>users</literal> — just create a new
|
||||||
|
one.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
<note><para>Multi-user mode has one important limitation: only
|
<note><para>Multi-user mode has one important limitation: only
|
||||||
<systemitem class="username">root</systemitem> can run <command
|
<systemitem class="username">root</systemitem> can run <command
|
||||||
linkend="sec-nix-pull">nix-pull</command> to register the availability
|
linkend="sec-nix-pull">nix-pull</command> to register the availability
|
||||||
of pre-built binaries. However, those registrations are shared by all
|
of pre-built binaries. However, those registrations
|
||||||
users, so they still get the benefit from <command>nix-pull</command>s
|
<emphasis>are</emphasis> used by all users to speed up
|
||||||
done by <systemitem class="username">root</systemitem>.</para></note>
|
builds.</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>
|
||||||
|
|
||||||
|
|
||||||
<section><title>Nix store/database owned by root</title>
|
</section> <!-- end of permissions section -->
|
||||||
|
|
||||||
<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>
|
<section><title>Using Nix</title>
|
||||||
|
|||||||
+130
-317
@@ -1,337 +1,150 @@
|
|||||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
xml:id="chap-introduction">
|
|
||||||
|
|
||||||
<title>Introduction</title>
|
<title>Introduction</title>
|
||||||
|
|
||||||
|
<para>Nix is a system for the deployment of software. Software
|
||||||
<section><title>About Nix</title>
|
deployment is concerned with the creation, distribution, and
|
||||||
|
management of software components (<quote>packages</quote>). Its main
|
||||||
<para>Nix is a <emphasis>purely functional package manager</emphasis>.
|
features are:
|
||||||
This means that it treats packages like values in purely functional
|
|
||||||
programming languages such as Haskell — they are built by functions
|
<itemizedlist>
|
||||||
that don’t have side-effects, and they never change after they have
|
|
||||||
been built. Nix stores packages in the <emphasis>Nix
|
<listitem><para>It helps you make sure that dependency specifications
|
||||||
store</emphasis>, usually the directory
|
are complete. In general in a deployment system you have to specify
|
||||||
<filename>/nix/store</filename>, where each package has its own unique
|
for each component what its dependencies are, but there are no
|
||||||
subdirectory such as
|
guarantees that this specification is complete. If you forget a
|
||||||
|
dependency, then the component will build and work correctly on
|
||||||
<programlisting>
|
<emphasis>your</emphasis> machine if you have the dependency
|
||||||
/nix/store/r8vvq9kq18pz08v249h8my6r9vs7s0n3-firefox-2.0.0.1/
|
installed, but not on the end user's machine if it's not
|
||||||
</programlisting>
|
there.</para></listitem>
|
||||||
|
|
||||||
where <literal>r8vvq9kq…</literal> is a unique identifier for the
|
<listitem><para>It is possible to have <emphasis>multiple versions or
|
||||||
package that captures all its dependencies (it’s a cryptographic hash
|
variants</emphasis> of a component installed at the same time. In
|
||||||
of the package’s build dependency graph). This enables many powerful
|
contrast, in systems such as RPM different versions of the same
|
||||||
features.</para>
|
package tend to install to the same location in the file system, so
|
||||||
|
installing one version will remove the other. This is especially
|
||||||
|
important if you want to use applications that have conflicting
|
||||||
<simplesect><title>Multiple versions</title>
|
requirements on different versions of a component (e.g., application A
|
||||||
|
requires version 1.0 of library X, while application B requires a
|
||||||
<para>You can have multiple versions or variants of a package
|
non-backwards compatible version 1.1).</para></listitem>
|
||||||
installed at the same time. This is especially important when
|
|
||||||
different applications have dependencies on different versions of the
|
<listitem><para>Users can have different <quote>views</quote>
|
||||||
same package — it prevents the “DLL hell”. Because of the hashing
|
(<quote>profiles</quote> in Nix parlance) on the set of installed
|
||||||
scheme, different versions of a package end up in different paths in
|
applications in a system. For instance, one user can have version 1.0
|
||||||
the Nix store, so they don’t interfere with each other.</para>
|
of some package visible, while another is using version 1.1, and a
|
||||||
|
third doesn't use it at all.</para></listitem>
|
||||||
<para>An important consequence is that operations like upgrading or
|
|
||||||
uninstalling an application cannot break other applications, since
|
<listitem><para>It is possible to atomically
|
||||||
these operations never “destructively” update or delete files that are
|
<emphasis>upgrade</emphasis> software. I.e., there is no time window
|
||||||
used by other packages.</para>
|
during an upgrade in which part of the old version and part of the new
|
||||||
|
version are simultaneously visible (which might well cause the
|
||||||
</simplesect>
|
component to fail).</para></listitem>
|
||||||
|
|
||||||
|
<listitem><para>Likewise, it is possible to atomically roll back after
|
||||||
<simplesect><title>Complete dependencies</title>
|
an install, upgrade, or uninstall action. That is, in a fast (O(1))
|
||||||
|
operation the previous configuration of the system can be restored.
|
||||||
<para>Nix helps you make sure that package dependency specifications
|
This is because upgrade or uninstall actions don't actually remove
|
||||||
are complete. In general, when you’re making a package for a package
|
components from the system.</para></listitem>
|
||||||
management system like RPM, you have to specify for each package what
|
|
||||||
its dependencies are, but there are no guarantees that this
|
<listitem><para>Unused components can be
|
||||||
specification is complete. If you forget a dependency, then the
|
<emphasis>garbage-collected</emphasis> automatically and safely: when
|
||||||
package will build and work correctly on <emphasis>your</emphasis>
|
you remove an application from a profile, its dependencies will be
|
||||||
machine if you have the dependency installed, but not on the end
|
deleted by the garbage collector only if there are no other active
|
||||||
user's machine if it's not there.</para>
|
applications using them.</para></listitem>
|
||||||
|
|
||||||
<para>Since Nix on the other hand doesn’t install packages in “global”
|
<listitem><para>Nix supports both source-based deployment models
|
||||||
locations like <filename>/usr/bin</filename> but in package-specific
|
(where you distribute <emphasis>Nix expressions</emphasis> that tell
|
||||||
directories, the risk of incomplete dependencies is greatly reduced.
|
Nix how to build software from source) and binary-based deployment
|
||||||
This is because tools such as compilers don’t search in per-packages
|
models. The latter is more-or-less transparent: installation of
|
||||||
directories such as
|
components is always based on Nix expressions, but if the expressions
|
||||||
<filename>/nix/store/5lbfaxb722zp…-openssl-0.9.8d/include</filename>,
|
have been built before and Nix knows that the resulting binaries are
|
||||||
so if a package builds correctly on your system, this is because you
|
available somewhere, it will use those instead.</para></listitem>
|
||||||
specified the dependency explicitly.</para>
|
|
||||||
|
<listitem><para>Nix is flexible in the deployment policies that it
|
||||||
<para>Runtime dependencies are found by scanning binaries for the hash
|
supports. There is a clear separation between the tools that
|
||||||
parts of Nix store paths (such as <literal>r8vvq9kq…</literal>). This
|
implement basic Nix <emphasis>mechanisms</emphasis> (e.g., building
|
||||||
sounds risky, but it works extremely well.</para>
|
Nix expressions), and the tools that implement various deployment
|
||||||
|
<emphasis>policies</emphasis>. For instance, there is a concept of
|
||||||
</simplesect>
|
<quote>Nix channels</quote> that can be used to keep software
|
||||||
|
installations up-to-date automatically from a network source. This is
|
||||||
|
a policy that is implemented by a fairly short Perl script, which can
|
||||||
<simplesect><title>Multi-user support</title>
|
be adapted easily to achieve similar policies.</para></listitem>
|
||||||
|
|
||||||
<para>Starting at version 0.11, Nix has multi-user support. This
|
<listitem><para>Nix component builds aim to be <quote>pure</quote>;
|
||||||
means that non-privileged users can securely install software. Each
|
that is, unaffected by anything other than the declared dependencies.
|
||||||
user can have a different <emphasis>profile</emphasis>, a set of
|
This means that if a component was built successfully once, it can be
|
||||||
packages in the Nix store that appear in the user’s
|
rebuilt again on another machine and the result will be the same. We
|
||||||
<envar>PATH</envar>. If a user installs a package that another user
|
cannot <emphasis>guarantee</emphasis> this (e.g., if the build depends
|
||||||
has already installed previously, the package won’t be built or
|
on the time-of-day), but Nix (and the tools in the Nix Packages
|
||||||
downloaded a second time. At the same time, it is not possible for
|
collection) takes special care to help achieve this.</para></listitem>
|
||||||
one user to inject a Trojan horse into a package that might be used by
|
|
||||||
another user.</para>
|
<listitem><para>Nix expressions (the things that tell Nix how to build
|
||||||
|
components) are self-contained: they describe not just components but
|
||||||
<!--
|
complete compositions. In other words, Nix expressions also describe
|
||||||
<para>More details can be found in Section 3 of our <a
|
how to build all the dependencies. This is in contrast to component
|
||||||
href="docs/papers.html#securesharing">ASE 2005 paper</a>.</para>
|
specification languages like RPM spec files, which might say that a
|
||||||
-->
|
component X depends on some other component Y, but since it does not
|
||||||
|
describe <emphasis>exactly</emphasis> what Y is, the result of
|
||||||
</simplesect>
|
building or running X might be different on different machines.
|
||||||
|
Combined with purity, self-containedness ensures that a component that
|
||||||
|
<quote>works</quote> on one machine also works on another, when
|
||||||
<simplesect><title>Atomic upgrades and rollbacks</title>
|
deployed using Nix.</para></listitem>
|
||||||
|
|
||||||
<para>Since package management operations never overwrite packages in
|
<listitem><para>The Nix expression language makes it easy to describe
|
||||||
the Nix store but just add new versions in different paths, they are
|
variability in components (e.g., optional features or
|
||||||
<emphasis>atomic</emphasis>. So during a package upgrade, there is no
|
dependencies).</para></listitem>
|
||||||
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
|
<listitem><para>Nix is ideal for building build farms that do
|
||||||
program might well crash if it’s started during that period.</para>
|
continuous builds of software from a version management system, since
|
||||||
|
it can take care of building all the dependencies as well. Also, Nix
|
||||||
<para>And since package aren’t overwritten, the old versions are still
|
only rebuilds components that have changed, so there are no
|
||||||
there after an upgrade. This means that you can <emphasis>roll
|
unnecessary builds. In addition, Nix can transparently distribute
|
||||||
back</emphasis> to the old version:</para>
|
build jobs over different machines, including different
|
||||||
|
platforms.</para></listitem>
|
||||||
<screen>
|
|
||||||
$ nix-env --upgrade <replaceable>some-packages</replaceable>
|
<listitem><para>Nix can be used not only for software deployment, but
|
||||||
$ nix-env --rollback
|
also for <emphasis>service deployment</emphasis>, such as the
|
||||||
</screen>
|
deployment of a complete web server with all its configuration files,
|
||||||
|
static pages, software dependencies, and so on. Nix's advantages for
|
||||||
</simplesect>
|
software deployment also apply here: for instance, the ability
|
||||||
|
trivially to have multiple configurations at the same time, or the
|
||||||
|
ability to do rollbacks.</para></listitem>
|
||||||
<simplesect><title>Garbage collection</title>
|
|
||||||
|
<listitem><para>Nix can efficiently upgrade between different versions
|
||||||
<para>When you install a package like this…
|
of a component through <emphasis>binary patching</emphasis>. If
|
||||||
|
patches are available on a server, and you try to install a new
|
||||||
<screen>
|
version of some component, Nix will automatically apply a patch (or
|
||||||
$ nix-env --uninstall firefox
|
sequence of patches), if available, to transform the installed
|
||||||
</screen>
|
component into the new version.</para></listitem>
|
||||||
|
|
||||||
the package isn’t deleted from the system right away (after all, you
|
</itemizedlist>
|
||||||
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
|
</para>
|
||||||
<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
|
<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
|
write Nix expressions for software not already in the Nix Packages
|
||||||
collection. It also discusses some advanced topics, such as setting
|
collection. It also discusses some advanced topics, such as setting
|
||||||
up a Nix-based build farm.</para>
|
up a Nix-based build farm, and doing service deployment using
|
||||||
|
Nix.</para>
|
||||||
|
|
||||||
</section>
|
<note><para>Some background information on Nix can be found in a
|
||||||
|
number of papers. The ICSE 2004 paper <citetitle
|
||||||
|
xlink:href='http://www.cs.uu.nl/~eelco/pubs/immdsd-icse2004-final.pdf'>Imposing
|
||||||
<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>
|
a Memory Management Discipline on Software Deployment</citetitle>
|
||||||
discusses the hashing mechanism used to ensure reliable dependency
|
discusses the hashing mechanism used to ensure reliable dependency
|
||||||
identification and non-interference between different versions and
|
identification and non-interference between different versions and
|
||||||
variants of packages. The LISA 2004 paper <citetitle
|
variants of packages. The LISA 2004 paper <citetitle
|
||||||
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/nspfssd-lisa2004-final.pdf'>Nix:
|
xlink:href='http://www.cs.uu.nl/~eelco/pubs/nspfssd-lisa2004-final.pdf'>Nix:
|
||||||
A Safe and Policy-Free System for Software Deployment</citetitle>
|
A Safe and Policy-Free System for Software Deployment</citetitle>
|
||||||
gives a more general discussion of Nix from a system-administration
|
gives a more general discussion of Nix from a system-administration
|
||||||
perspective. The CBSE 2005 paper <citetitle
|
perspective. The CBSE 2005 paper <citetitle
|
||||||
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/eupfcdm-cbse2005-final.pdf'>Efficient
|
xlink:href='http://www.cs.uu.nl/~eelco/pubs/eupfcdm-cbse2005-final.pdf'>Efficient
|
||||||
Upgrading in a Purely Functional Component Deployment Model
|
Upgrading in a Purely Functional Component Deployment Model
|
||||||
</citetitle> is about transparent patch deployment in Nix. The SCM-12
|
</citetitle> is about transparent patch deployment in Nix. Finally,
|
||||||
paper <citetitle
|
the SCM-12 paper <citetitle
|
||||||
xlink:href='http://www.st.ewi.tudelft.nl/~dolstra/pubs/servicecm-scm12-final.pdf'>
|
xlink:href='http://www.cs.uu.nl/~eelco/pubs/servicecm-scm12-final.pdf'>
|
||||||
Service Configuration Management</citetitle> shows how services (e.g.,
|
Service Configuration Management</citetitle> shows how services (e.g.,
|
||||||
web servers) can be deployed and managed through Nix. A short
|
web servers) can be deployed and managed through Nix.</para></note>
|
||||||
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>
|
</chapter>
|
||||||
+11
-8
@@ -14,8 +14,8 @@
|
|||||||
<surname>Dolstra</surname>
|
<surname>Dolstra</surname>
|
||||||
</personname>
|
</personname>
|
||||||
<affiliation>
|
<affiliation>
|
||||||
<orgname>Delft University of Technology</orgname>
|
<orgname>Utrecht University</orgname>
|
||||||
<orgdiv>Department of Software Technology</orgdiv>
|
<orgdiv>Faculty of Science, Department of Information and Computing Sciences</orgdiv>
|
||||||
</affiliation>
|
</affiliation>
|
||||||
</author>
|
</author>
|
||||||
|
|
||||||
@@ -24,11 +24,10 @@
|
|||||||
<year>2005</year>
|
<year>2005</year>
|
||||||
<year>2006</year>
|
<year>2006</year>
|
||||||
<year>2007</year>
|
<year>2007</year>
|
||||||
<year>2008</year>
|
|
||||||
<holder>Eelco Dolstra</holder>
|
<holder>Eelco Dolstra</holder>
|
||||||
</copyright>
|
</copyright>
|
||||||
|
|
||||||
<date>November 2008</date>
|
<date>September 2007</date>
|
||||||
|
|
||||||
</info>
|
</info>
|
||||||
|
|
||||||
@@ -89,6 +88,10 @@
|
|||||||
<title>nix-install-package</title>
|
<title>nix-install-package</title>
|
||||||
<xi:include href="nix-install-package.xml" />
|
<xi:include href="nix-install-package.xml" />
|
||||||
</section>
|
</section>
|
||||||
|
<section xml:id="sec-nix-pack-closure">
|
||||||
|
<title>nix-pack-closure</title>
|
||||||
|
<xi:include href="nix-pack-closure.xml" />
|
||||||
|
</section>
|
||||||
<section xml:id="sec-nix-prefetch-url">
|
<section xml:id="sec-nix-prefetch-url">
|
||||||
<title>nix-prefetch-url</title>
|
<title>nix-prefetch-url</title>
|
||||||
<xi:include href="nix-prefetch-url.xml" />
|
<xi:include href="nix-prefetch-url.xml" />
|
||||||
@@ -101,16 +104,16 @@
|
|||||||
<title>nix-push</title>
|
<title>nix-push</title>
|
||||||
<xi:include href="nix-push.xml" />
|
<xi:include href="nix-push.xml" />
|
||||||
</section>
|
</section>
|
||||||
<section xml:id="sec-nix-worker">
|
<section xml:id="sec-nix-unpack-closure">
|
||||||
<title>nix-worker</title>
|
<title>nix-unpack-closure</title>
|
||||||
<xi:include href="nix-worker.xml" />
|
<xi:include href="nix-unpack-closure.xml" />
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</appendix>
|
</appendix>
|
||||||
|
|
||||||
<xi:include href="troubleshooting.xml" />
|
<xi:include href="troubleshooting.xml" />
|
||||||
<!-- <xi:include href="bugs.xml" /> -->
|
<xi:include href="bugs.xml" />
|
||||||
<xi:include href="glossary.xml" />
|
<xi:include href="glossary.xml" />
|
||||||
|
|
||||||
<appendix>
|
<appendix>
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
<command>nix-build</command>
|
<command>nix-build</command>
|
||||||
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="opt-common-syn.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(/db:nop/*)" />
|
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="opt-common-syn.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(/db:nop/*)" />
|
||||||
<arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
<arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
||||||
<arg><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
|
||||||
<arg>
|
<arg>
|
||||||
<group choice='req'>
|
<group choice='req'>
|
||||||
<arg choice='plain'><option>--attr</option></arg>
|
<arg choice='plain'><option>--attr</option></arg>
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ also <xref linkend="sec-channels" />.</para>
|
|||||||
<varlistentry><term><option>--update</option></term>
|
<varlistentry><term><option>--update</option></term>
|
||||||
|
|
||||||
<listitem><para>Downloads the Nix expressions of all subscribed
|
<listitem><para>Downloads the Nix expressions of all subscribed
|
||||||
channels, makes them the default for <command>nix-env</command>
|
channels, makes the conjunction of these the default for
|
||||||
operations (by symlinking them in the directory
|
<command>nix-env</command> operations (by calling <command>nix-env
|
||||||
<filename>~/.nix-defexpr</filename>), and performs a
|
-I</command>), and performs a <command>nix-pull</command> on the
|
||||||
<command>nix-pull</command> on the manifests of all channels to
|
manifests of all channels to make pre-built binaries
|
||||||
make pre-built binaries available.</para></listitem>
|
available.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ those paths. If this bothers you, use
|
|||||||
<para>Copy Firefox with all its dependencies to a remote machine:
|
<para>Copy Firefox with all its dependencies to a remote machine:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-copy-closure --to alice@itchy.labs $(type -tP firefox)</screen>
|
$ nix-copy-closure alice@itchy.labs $(type -tP firefox)</screen>
|
||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|||||||
+35
-216
@@ -19,7 +19,13 @@
|
|||||||
<command>nix-env</command>
|
<command>nix-env</command>
|
||||||
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="opt-common-syn.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(/db:nop/*)" />
|
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="opt-common-syn.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(/db:nop/*)" />
|
||||||
<arg><option>--arg</option> <replaceable>name</replaceable> <replaceable>value</replaceable></arg>
|
<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>
|
<arg>
|
||||||
<group choice='req'>
|
<group choice='req'>
|
||||||
<arg choice='plain'><option>--file</option></arg>
|
<arg choice='plain'><option>--file</option></arg>
|
||||||
@@ -39,6 +45,9 @@
|
|||||||
<replaceable>system</replaceable>
|
<replaceable>system</replaceable>
|
||||||
</arg>
|
</arg>
|
||||||
<arg><option>--dry-run</option></arg>
|
<arg><option>--dry-run</option></arg>
|
||||||
|
<arg><option>--from-expression</option></arg>
|
||||||
|
<arg><option>-E</option></arg>
|
||||||
|
<arg><option>--from-profile</option> <replaceable>path</replaceable></arg>
|
||||||
<arg choice='plain'><replaceable>operation</replaceable></arg>
|
<arg choice='plain'><replaceable>operation</replaceable></arg>
|
||||||
<arg rep='repeat'><replaceable>options</replaceable></arg>
|
<arg rep='repeat'><replaceable>options</replaceable></arg>
|
||||||
<arg rep='repeat'><replaceable>arguments</replaceable></arg>
|
<arg rep='repeat'><replaceable>arguments</replaceable></arg>
|
||||||
@@ -49,7 +58,7 @@
|
|||||||
<refsection><title>Description</title>
|
<refsection><title>Description</title>
|
||||||
|
|
||||||
<para>The command <command>nix-env</command> is used to manipulate Nix
|
<para>The command <command>nix-env</command> is used to manipulate Nix
|
||||||
user environments. User environments are sets of software packages
|
user environments. User environments are sets of software components
|
||||||
available to a user at some point in time. In other words, they are a
|
available to a user at some point in time. In other words, they are a
|
||||||
synthesised view of the programs available in the Nix store. There
|
synthesised view of the programs available in the Nix store. There
|
||||||
may be many user environments: different users can have different
|
may be many user environments: different users can have different
|
||||||
@@ -142,33 +151,13 @@ linkend="sec-common-options" />.</para>
|
|||||||
|
|
||||||
<varlistentry><term><filename>~/.nix-defexpr</filename></term>
|
<varlistentry><term><filename>~/.nix-defexpr</filename></term>
|
||||||
|
|
||||||
<listitem><para>A directory that contains the default Nix
|
<!-- !!! .nix-defexpr can be a directory now -->
|
||||||
expressions used by the <option>--install</option>,
|
|
||||||
<option>--upgrade</option>, and <option>--query
|
<listitem><para>The default Nix expression used by the
|
||||||
--available</option> operations to obtain derivations. The
|
<option>--install</option>, <option>--upgrade</option>, and
|
||||||
<option>--file</option> option may be used to override this
|
<option>--query --available</option> operations to obtain
|
||||||
default.</para>
|
derivations. The <option>--file</option> option may be used to
|
||||||
|
override this default.</para></listitem>
|
||||||
<para>The Nix expressions in this directory are combined into a
|
|
||||||
single attribute set, with each file as an attribute that has the
|
|
||||||
name of the file. Thus, if <filename>~/.nix-defexpr</filename>
|
|
||||||
contains two files, <filename>foo</filename> and
|
|
||||||
<filename>bar</filename>, then the default Nix expression will
|
|
||||||
essentially be
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{
|
|
||||||
foo = import ~/.nix-defexpr/foo;
|
|
||||||
bar = import ~/.nix-defexpr/bar;
|
|
||||||
}</programlisting>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The command <command>nix-channel</command> places symlinks
|
|
||||||
to the downloaded Nix expressions from each subscribed channel in
|
|
||||||
this directory.</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
@@ -201,7 +190,6 @@ linkend="sec-common-options" />.</para>
|
|||||||
<arg choice='plain'><option>--install</option></arg>
|
<arg choice='plain'><option>--install</option></arg>
|
||||||
<arg choice='plain'><option>-i</option></arg>
|
<arg choice='plain'><option>-i</option></arg>
|
||||||
</group>
|
</group>
|
||||||
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="opt-inst-syn.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(/db:nop/*)" />
|
|
||||||
<group choice='opt'>
|
<group choice='opt'>
|
||||||
<arg choice='plain'><option>--preserve-installed</option></arg>
|
<arg choice='plain'><option>--preserve-installed</option></arg>
|
||||||
<arg choice='plain'><option>-P</option></arg>
|
<arg choice='plain'><option>-P</option></arg>
|
||||||
@@ -233,21 +221,11 @@ number of possible ways:
|
|||||||
<para>If there are multiple derivations matching a name in
|
<para>If there are multiple derivations matching a name in
|
||||||
<replaceable>args</replaceable> that have the same name (e.g.,
|
<replaceable>args</replaceable> that have the same name (e.g.,
|
||||||
<literal>gcc-3.3.6</literal> and <literal>gcc-4.1.1</literal>), then
|
<literal>gcc-3.3.6</literal> and <literal>gcc-4.1.1</literal>), then
|
||||||
the derivation with the highest <emphasis>priority</emphasis> is
|
only the highest version will be installed. You can force the
|
||||||
used. A derivation can define a priority by declaring the
|
installation of multiple derivations with the same name by being
|
||||||
<varname>meta.priority</varname> attribute. This attribute should
|
specific about the versions. For instance, <literal>nix-env -i
|
||||||
be a number, with a higher value denoting a lower priority. The
|
gcc-3.3.6 gcc-4.1.1</literal> will install both version of GCC (and
|
||||||
default priority is <literal>0</literal>.</para>
|
will probably cause a user environment conflict!).</para></listitem>
|
||||||
|
|
||||||
<para>If there are multiple matching derivations with the same
|
|
||||||
priority, then the derivation with the highest version will be
|
|
||||||
installed.</para>
|
|
||||||
|
|
||||||
<para>You can force the installation of multiple derivations with
|
|
||||||
the same name by being specific about the versions. For instance,
|
|
||||||
<literal>nix-env -i gcc-3.3.6 gcc-4.1.1</literal> will install both
|
|
||||||
version of GCC (and will probably cause a user environment
|
|
||||||
conflict!).</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>If <link
|
<listitem><para>If <link
|
||||||
linkend='opt-attr'><option>--attr</option></link>
|
linkend='opt-attr'><option>--attr</option></link>
|
||||||
@@ -294,15 +272,6 @@ number of possible ways:
|
|||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
|
||||||
<varlistentry><term><option>--prebuild-only</option> / <option>-b</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Use only derivations for which a substitute is
|
|
||||||
registered, i.e., there is a pre-built binary available that can
|
|
||||||
be downloaded in lieu of building the derivation. Thus, no
|
|
||||||
packages will be built from source.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--preserve-installed</option></term>
|
<varlistentry><term><option>--preserve-installed</option></term>
|
||||||
<term><option>-P</option></term>
|
<term><option>-P</option></term>
|
||||||
|
|
||||||
@@ -418,7 +387,7 @@ the following paths will be substituted:
|
|||||||
|
|
||||||
<!--######################################################################-->
|
<!--######################################################################-->
|
||||||
|
|
||||||
<refsection xml:id="rsec-nix-env-upgrade"><title>Operation <option>--upgrade</option></title>
|
<refsection><title>Operation <option>--upgrade</option></title>
|
||||||
|
|
||||||
<refsection><title>Synopsis</title>
|
<refsection><title>Synopsis</title>
|
||||||
|
|
||||||
@@ -428,7 +397,6 @@ the following paths will be substituted:
|
|||||||
<arg choice='plain'><option>--upgrade</option></arg>
|
<arg choice='plain'><option>--upgrade</option></arg>
|
||||||
<arg choice='plain'><option>-u</option></arg>
|
<arg choice='plain'><option>-u</option></arg>
|
||||||
</group>
|
</group>
|
||||||
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="opt-inst-syn.xml#xmlns(db=http://docbook.org/ns/docbook)xpointer(/db:nop/*)" />
|
|
||||||
<group choice='opt'>
|
<group choice='opt'>
|
||||||
<arg choice='plain'><option>--lt</option></arg>
|
<arg choice='plain'><option>--lt</option></arg>
|
||||||
<arg choice='plain'><option>--leq</option></arg>
|
<arg choice='plain'><option>--leq</option></arg>
|
||||||
@@ -503,9 +471,6 @@ installed.</para>
|
|||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
<para>For the other flags, see <option
|
|
||||||
linkend="rsec-nix-env-install">--install</option>.</para>
|
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
<refsection><title>Examples</title>
|
<refsection><title>Examples</title>
|
||||||
@@ -526,7 +491,7 @@ upgrading `mozilla-1.2' to `mozilla-1.4'</screen>
|
|||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
<refsection xml:id="ssec-version-comparisons"><title>Versions</title>
|
<refsection><title>Versions</title>
|
||||||
|
|
||||||
<para>The upgrade operation determines whether a derivation
|
<para>The upgrade operation determines whether a derivation
|
||||||
<varname>y</varname> is an upgrade of a derivation
|
<varname>y</varname> is an upgrade of a derivation
|
||||||
@@ -615,111 +580,6 @@ $ nix-env -e '*' <lineannotation>(remove everything)</lineannotation></screen>
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection xml:id="rsec-nix-env-set-flag"><title>Operation <option>--set-flag</option></title>
|
|
||||||
|
|
||||||
<refsection><title>Synopsis</title>
|
|
||||||
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-env</command>
|
|
||||||
<arg choice='plain'><option>--set-flag</option></arg>
|
|
||||||
<arg choice='plain'><replaceable>name</replaceable></arg>
|
|
||||||
<arg choice='plain'><replaceable>value</replaceable></arg>
|
|
||||||
<arg choice='plain' rep='repeat'><replaceable>drvnames</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The <option>--set-flag</option> operation allows meta attributes
|
|
||||||
of installed packages to be modified. There are several attributes
|
|
||||||
that can be usefully modified, because they affect the behaviour of
|
|
||||||
<command>nix-env</command> or the user environment build
|
|
||||||
script:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para><varname>priority</varname> can be changed to
|
|
||||||
resolve filename clashes. The user environment build script uses
|
|
||||||
the <varname>meta.priority</varname> attribute of derivations to
|
|
||||||
resolve filename collisions between packages. Lower priority values
|
|
||||||
denote a higher priority. For instance, the GCC wrapper package and
|
|
||||||
the Binutils package in Nixpkgs both have a file
|
|
||||||
<filename>bin/ld</filename>, so previously if you tried to install
|
|
||||||
both you would get a collision. Now, on the other hand, the GCC
|
|
||||||
wrapper declares a higher priority than Binutils, so the former’s
|
|
||||||
<filename>bin/ld</filename> is symlinked in the user
|
|
||||||
environment.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><varname>keep</varname> can be set to
|
|
||||||
<literal>true</literal> to prevent the package from being upgraded
|
|
||||||
or replaced. This is useful if you want to hang on to an older
|
|
||||||
version of a package.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><varname>active</varname> can be set to
|
|
||||||
<literal>false</literal> to “disable” the package. That is, no
|
|
||||||
symlinks will be generated to the files of the package, but it
|
|
||||||
remains part of the profile (so it won’t be garbage-collected). It
|
|
||||||
can be set back to <literal>true</literal> to re-enable the
|
|
||||||
package.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Examples</title>
|
|
||||||
|
|
||||||
<para>To prevent the currently installed Firefox from being upgraded:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env --set-flag keep true firefox</screen>
|
|
||||||
|
|
||||||
After this, <command>nix-env -u</command> will ignore Firefox.</para>
|
|
||||||
|
|
||||||
<para>To disable the currently installed Firefox, then install a new
|
|
||||||
Firefox while the old remains part of the profile:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env -q \*
|
|
||||||
firefox-2.0.0.9 <lineannotation>(the current one)</lineannotation>
|
|
||||||
|
|
||||||
$ nix-env --preserve-installed -i firefox-2.0.0.11
|
|
||||||
installing `firefox-2.0.0.11'
|
|
||||||
building path(s) `/nix/store/myy0y59q3ig70dgq37jqwg1j0rsapzsl-user-environment'
|
|
||||||
Collission between `/nix/store/<replaceable>...</replaceable>-firefox-2.0.0.11/bin/firefox'
|
|
||||||
and `/nix/store/<replaceable>...</replaceable>-firefox-2.0.0.9/bin/firefox'.
|
|
||||||
<lineannotation>(i.e., can’t have two active at the same time)</lineannotation>
|
|
||||||
|
|
||||||
$ nix-env --set-flag active false firefox
|
|
||||||
setting flag on `firefox-2.0.0.9'
|
|
||||||
|
|
||||||
$ nix-env --preserve-installed -i firefox-2.0.0.11
|
|
||||||
installing `firefox-2.0.0.11'
|
|
||||||
|
|
||||||
$ nix-env -q \*
|
|
||||||
firefox-2.0.0.11 <lineannotation>(the enabled one)</lineannotation>
|
|
||||||
firefox-2.0.0.9 <lineannotation>(the disabled one)</lineannotation></screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>To make files from <literal>binutils</literal> take precedence
|
|
||||||
over files from <literal>gcc</literal>:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env --set-flag priority 5 binutils
|
|
||||||
$ nix-env --set-flag priority 10 gcc</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
<!--######################################################################-->
|
||||||
|
|
||||||
<refsection><title>Operation <option>--query</option></title>
|
<refsection><title>Operation <option>--query</option></title>
|
||||||
@@ -732,14 +592,13 @@ $ nix-env --set-flag priority 10 gcc</screen>
|
|||||||
<arg choice='plain'><option>--query</option></arg>
|
<arg choice='plain'><option>--query</option></arg>
|
||||||
<arg choice='plain'><option>-q</option></arg>
|
<arg choice='plain'><option>-q</option></arg>
|
||||||
</group>
|
</group>
|
||||||
|
<arg><option>--xml</option></arg>
|
||||||
<group choice='opt'>
|
<group choice='opt'>
|
||||||
<arg choice='plain'><option>--installed</option></arg>
|
<arg choice='plain'><option>--installed</option></arg>
|
||||||
<arg choice='plain'><option>--available</option></arg>
|
<arg choice='plain'><option>--available</option></arg>
|
||||||
<arg choice='plain'><option>-a</option></arg>
|
<arg choice='plain'><option>-a</option></arg>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<sbr />
|
<sbr />
|
||||||
|
|
||||||
<arg>
|
<arg>
|
||||||
<group choice='req'>
|
<group choice='req'>
|
||||||
<arg choice='plain'><option>--status</option></arg>
|
<arg choice='plain'><option>--status</option></arg>
|
||||||
@@ -748,8 +607,8 @@ $ nix-env --set-flag priority 10 gcc</screen>
|
|||||||
</arg>
|
</arg>
|
||||||
<arg>
|
<arg>
|
||||||
<group choice='req'>
|
<group choice='req'>
|
||||||
<arg choice='plain'><option>--attr-path</option></arg>
|
<arg choice='plain'><option>--attr</option></arg>
|
||||||
<arg choice='plain'><option>-P</option></arg>
|
<arg choice='plain'><option>-A</option></arg>
|
||||||
</group>
|
</group>
|
||||||
</arg>
|
</arg>
|
||||||
<arg><option>--no-name</option></arg>
|
<arg><option>--no-name</option></arg>
|
||||||
@@ -763,28 +622,6 @@ $ nix-env --set-flag priority 10 gcc</screen>
|
|||||||
<arg><option>--drv-path</option></arg>
|
<arg><option>--drv-path</option></arg>
|
||||||
<arg><option>--out-path</option></arg>
|
<arg><option>--out-path</option></arg>
|
||||||
<arg><option>--description</option></arg>
|
<arg><option>--description</option></arg>
|
||||||
<arg><option>--meta</option></arg>
|
|
||||||
|
|
||||||
<sbr />
|
|
||||||
|
|
||||||
<arg><option>--xml</option></arg>
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--prebuilt-only</option></arg>
|
|
||||||
<arg choice='plain'><option>-b</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--attr</option></arg>
|
|
||||||
<arg choice='plain'><option>-A</option></arg>
|
|
||||||
</group>
|
|
||||||
<replaceable>attribute-path</replaceable>
|
|
||||||
</arg>
|
|
||||||
|
|
||||||
<sbr />
|
|
||||||
|
|
||||||
<arg choice='plain' rep='repeat'><replaceable>names</replaceable></arg>
|
<arg choice='plain' rep='repeat'><replaceable>names</replaceable></arg>
|
||||||
</cmdsynopsis>
|
</cmdsynopsis>
|
||||||
|
|
||||||
@@ -861,16 +698,6 @@ user environment elements, etc. -->
|
|||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><option>--prebuild-only</option> / <option>-b</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Show only derivations for which a substitute is
|
|
||||||
registered, i.e., there is a pre-built binary available that can
|
|
||||||
be downloaded in lieu of building the derivation. Thus, this
|
|
||||||
shows all packages that probably can be installed
|
|
||||||
quickly.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--status</option></term>
|
<varlistentry><term><option>--status</option></term>
|
||||||
<term><option>-s</option></term>
|
<term><option>-s</option></term>
|
||||||
|
|
||||||
@@ -890,8 +717,8 @@ user environment elements, etc. -->
|
|||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><option>--attr-path</option></term>
|
<varlistentry><term><option>--attr</option></term>
|
||||||
<term><option>-P</option></term>
|
<term><option>-a</option></term>
|
||||||
|
|
||||||
<listitem><para>Print the <emphasis>attribute path</emphasis> of
|
<listitem><para>Print the <emphasis>attribute path</emphasis> of
|
||||||
the derivation, which can be used to unambiguously select it using
|
the derivation, which can be used to unambiguously select it using
|
||||||
@@ -914,35 +741,35 @@ user environment elements, etc. -->
|
|||||||
<listitem><para>Compare installed versions to available versions,
|
<listitem><para>Compare installed versions to available versions,
|
||||||
or vice versa (if <option>--available</option> is given). This is
|
or vice versa (if <option>--available</option> is given). This is
|
||||||
useful for quickly seeing whether upgrades for installed
|
useful for quickly seeing whether upgrades for installed
|
||||||
packages are available in a Nix expression. A column is added
|
components are available in a Nix expression. A column is added
|
||||||
with the following meaning:
|
with the following meaning:
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
|
|
||||||
<varlistentry><term><literal><</literal> <replaceable>version</replaceable></term>
|
<varlistentry><term><literal><</literal> <replaceable>version</replaceable></term>
|
||||||
|
|
||||||
<listitem><para>A newer version of the package is available
|
<listitem><para>A newer version of the component is available
|
||||||
or installed.</para></listitem>
|
or installed.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><literal>=</literal> <replaceable>version</replaceable></term>
|
<varlistentry><term><literal>=</literal> <replaceable>version</replaceable></term>
|
||||||
|
|
||||||
<listitem><para>At most the same version of the package is
|
<listitem><para>At most the same version of the component is
|
||||||
available or installed.</para></listitem>
|
available or installed.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><literal>></literal> <replaceable>version</replaceable></term>
|
<varlistentry><term><literal>></literal> <replaceable>version</replaceable></term>
|
||||||
|
|
||||||
<listitem><para>Only older versions of the package are
|
<listitem><para>Only older versions of the component are
|
||||||
available or installed.</para></listitem>
|
available or installed.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><literal>- ?</literal></term>
|
<varlistentry><term><literal>- ?</literal></term>
|
||||||
|
|
||||||
<listitem><para>No version of the package is available or
|
<listitem><para>No version of the component is available or
|
||||||
installed.</para></listitem>
|
installed.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@@ -983,14 +810,6 @@ user environment elements, etc. -->
|
|||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry><term><option>--meta</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Print all of the meta-attributes of the
|
|
||||||
derivation. This option is only available with
|
|
||||||
<option>--xml</option>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<refentry xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||||
|
|
||||||
|
<refmeta>
|
||||||
|
<refentrytitle>nix-pack-closure</refentrytitle>
|
||||||
|
<manvolnum>1</manvolnum>
|
||||||
|
<refmiscinfo class="source">Nix</refmiscinfo>
|
||||||
|
<refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo>
|
||||||
|
</refmeta>
|
||||||
|
|
||||||
|
<refnamediv>
|
||||||
|
<refname>nix-pack-closure</refname>
|
||||||
|
<refpurpose>pack the closure of a store path into a single file that
|
||||||
|
can be unpacked with
|
||||||
|
<command>nix-unpack-closure</command></refpurpose>
|
||||||
|
</refnamediv>
|
||||||
|
|
||||||
|
<refsynopsisdiv>
|
||||||
|
<cmdsynopsis>
|
||||||
|
<command>nix-pack-closure</command>
|
||||||
|
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
||||||
|
</cmdsynopsis>
|
||||||
|
</refsynopsisdiv>
|
||||||
|
|
||||||
|
|
||||||
|
<refsection><title>Description</title>
|
||||||
|
|
||||||
|
<para>The command <command>nix-pack-closure</command> packs the
|
||||||
|
contents of the store paths <replaceable>paths</replaceable> and
|
||||||
|
<emphasis>all their dependencies</emphasis> into a single file, which
|
||||||
|
is written to standard output. (That is, it
|
||||||
|
<emphasis>serialises</emphasis> <replaceable>paths</replaceable>.)
|
||||||
|
The output can then be unpacked into the Nix store of another machine
|
||||||
|
using <command>nix-unpack-closure</command>.</para>
|
||||||
|
|
||||||
|
<para>Together, <command>nix-pack-closure</command> and
|
||||||
|
<command>nix-unpack-closure</command> provide a quick and easy way to
|
||||||
|
deploy a package to a different machine. However, as the output of
|
||||||
|
<command>nix-pack-closure</command> tends to be rather large (since it
|
||||||
|
contains all dependencies), it’s not very efficient.
|
||||||
|
<command>nix-push</command> and <command>nix-pull</command> are more
|
||||||
|
efficient, but are also a bit more cumbersome to use.</para>
|
||||||
|
|
||||||
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
|
<refsection><title>Examples</title>
|
||||||
|
|
||||||
|
<para>To copy some instance of Subversion with all its dependencies to
|
||||||
|
another machine:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-pack-closure /nix/store/hj232g1r...-subversion-1.3.0 > svn.closure
|
||||||
|
|
||||||
|
<lineannotation>Copy <!-- !!! <filename> -->svn.closure to the remote machine, then on the remote machine do:</lineannotation>
|
||||||
|
$ nix-unpack-closure < svn.closure</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>Copy the program <command>azureus</command> with all its
|
||||||
|
dependencies to the machine <literal>scratchy</literal>:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-pack-closure $(which azureus) | ssh scratchy nix-unpack-closure</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>As a variation on the previous example, copy
|
||||||
|
<command>azureus</command>, and also install it in the user’s profile
|
||||||
|
on the target machine:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-pack-closure $(which azureus) | ssh scratchy 'nix-env -i $(nix-unpack-closure)'</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
|
||||||
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
|
</refentry>
|
||||||
+1
-306
@@ -128,7 +128,6 @@ lrwxrwxrwx 1 ... 2005-03-13 21:10 /home/eelco/bla/result -> /nix/store/1r1134
|
|||||||
<arg choice='plain'><option>-r</option></arg>
|
<arg choice='plain'><option>-r</option></arg>
|
||||||
</group>
|
</group>
|
||||||
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
||||||
<arg><option>--dry-run</option></arg>
|
|
||||||
</cmdsynopsis>
|
</cmdsynopsis>
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
@@ -167,11 +166,6 @@ the specified store paths. Realisation is a somewhat overloaded term:
|
|||||||
output. (For non-derivations argument, the argument itself is
|
output. (For non-derivations argument, the argument itself is
|
||||||
printed.)</para>
|
printed.)</para>
|
||||||
|
|
||||||
<para>If the <option>--dry-run</option> option is used, then
|
|
||||||
<command>nix-store</command> will print on standard error a
|
|
||||||
description of what packages would be built or downloaded, and then
|
|
||||||
quit.</para>
|
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
@@ -210,10 +204,6 @@ linkend="sec-nix-build"><command>nix-build</command></link> does.</para>
|
|||||||
<arg choice='plain'><option>--print-dead</option></arg>
|
<arg choice='plain'><option>--print-dead</option></arg>
|
||||||
<arg choice='plain'><option>--delete</option></arg>
|
<arg choice='plain'><option>--delete</option></arg>
|
||||||
</group>
|
</group>
|
||||||
<arg><option>--max-freed</option> <replaceable>bytes</replaceable></arg>
|
|
||||||
<arg><option>--max-links</option> <replaceable>nrlinks</replaceable></arg>
|
|
||||||
<arg><option>--max-atime</option> <replaceable>atime</replaceable></arg>
|
|
||||||
<arg><option>--use-atime</option></arg>
|
|
||||||
</cmdsynopsis>
|
</cmdsynopsis>
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
@@ -268,70 +258,7 @@ the Nix store not reachable via file system references from a set of
|
|||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
<para>By default, all unreachable paths are deleted. The following
|
<para>The behaviour of the collector is influenced by the <link
|
||||||
options control what gets deleted and in what order:
|
|
||||||
|
|
||||||
<variablelist>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--max-freed</option> <replaceable>bytes</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Keep deleting paths until at least
|
|
||||||
<replaceable>bytes</replaceable> bytes have been
|
|
||||||
deleted, then stop.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--max-links</option> <replaceable>nrlinks</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Keep deleting paths until the hard link count on
|
|
||||||
<filename>/nix/store</filename> is less than
|
|
||||||
<replaceable>nrlinks</replaceable>, then stop. This is useful for
|
|
||||||
very large Nix stores on filesystems with a 32000 subdirectories
|
|
||||||
limit (like <literal>ext3</literal>).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--max-atime</option> <replaceable>atime</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>Only delete a store path if its last-accessed time
|
|
||||||
is less than <replaceable>atime</replaceable>. This allows you to
|
|
||||||
garbage-collect only packages that haven’t been used recently.
|
|
||||||
The time is expressed as the number of seconds in the Unix epoch,
|
|
||||||
i.e., since 1970-01-01 00:00:00 UTC. An easy way to convert to
|
|
||||||
this format is <literal>date +%s -d "<replaceable>date
|
|
||||||
specification</replaceable>"</literal>.</para>
|
|
||||||
|
|
||||||
<para>For directories, the last-accessed time is the highest
|
|
||||||
last-accessed time of any regular file in the directory (or in any
|
|
||||||
of its subdirectories). That is, the <literal>atime</literal>
|
|
||||||
field maintained by the filesystem is ignored for directories.
|
|
||||||
This is because operations such as rebuilding the
|
|
||||||
<command>locate</command> database tend to update the
|
|
||||||
<literal>atime</literal> values of all directories, so they’re not
|
|
||||||
a useful indicator of whether a package was recently used.</para>
|
|
||||||
|
|
||||||
<para>Note that <command>nix-store --optimise</command> reads all
|
|
||||||
regular files in the Nix store, and so causes all last-accessed
|
|
||||||
times to be set to the present time. This makes
|
|
||||||
<option>--max-atime</option> ineffective (for a while at
|
|
||||||
least).</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--use-atime</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Delete store paths in order of ascending
|
|
||||||
last-accessed time. This is useful in conjunction with the other
|
|
||||||
options to delete only the least recently used
|
|
||||||
packages.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
</variablelist>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>The behaviour of the collector is also influenced by the <link
|
|
||||||
linkend="conf-gc-keep-outputs"><literal>gc-keep-outputs</literal></link>
|
linkend="conf-gc-keep-outputs"><literal>gc-keep-outputs</literal></link>
|
||||||
and <link
|
and <link
|
||||||
linkend="conf-gc-keep-derivations"><literal>gc-keep-derivations</literal></link>
|
linkend="conf-gc-keep-derivations"><literal>gc-keep-derivations</literal></link>
|
||||||
@@ -357,20 +284,6 @@ deleting `/nix/store/kq82idx6g0nyzsp2s14gfsc38npai7lf-cairo-1.0.4.tar.gz.drv'
|
|||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>To delete unreachable paths not accessed in the last two months:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --gc -v --max-atime $(date +%s -d "2 months ago")</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>To delete at least 100 MiBs of unreachable paths:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --gc --max-freed $((100 * 1024 * 1024))</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
@@ -866,222 +779,4 @@ archive is read from standard input.</para>
|
|||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection xml:id='refsec-nix-store-export'><title>Operation <option>--export</option></title>
|
|
||||||
|
|
||||||
<refsection>
|
|
||||||
<title>Synopsis</title>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-store</command>
|
|
||||||
<arg choice='plain'><option>--export</option></arg>
|
|
||||||
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The operation <option>--export</option> writes a serialisation
|
|
||||||
of the specified store paths to standard output in a format that can
|
|
||||||
be imported into another Nix store with <command
|
|
||||||
linkend="refsec-nix-store-import">nix-store --import</command>. This
|
|
||||||
is like <command linkend="refsec-nix-store-dump">nix-store
|
|
||||||
--dump</command>, except that the NAR archive produced by that command
|
|
||||||
doesn’t contain the necessary meta-information to allow it to be
|
|
||||||
imported into another Nix store (namely, the set of references of the
|
|
||||||
path).</para>
|
|
||||||
|
|
||||||
<para>This command does not produce a <emphasis>closure</emphasis> of
|
|
||||||
the specified paths, so if a store path references other store paths
|
|
||||||
that are missing in the target Nix store, the import will fail. To
|
|
||||||
copy a whole closure, do something like
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --export $(nix-store -qR <replaceable>paths</replaceable>) > out</screen>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>For an example of how <option>--export</option> and
|
|
||||||
<option>--import</option> can be used, see the source of the <command
|
|
||||||
linkend="sec-nix-copy-closure">nix-copy-closure</command>
|
|
||||||
command.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection xml:id='refsec-nix-store-import'><title>Operation <option>--import</option></title>
|
|
||||||
|
|
||||||
<refsection>
|
|
||||||
<title>Synopsis</title>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-store</command>
|
|
||||||
<arg choice='plain'><option>--import</option></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The operation <option>--export</option> reads a serialisation of
|
|
||||||
a set of store paths produced by <command
|
|
||||||
linkend="refsec-nix-store-export">nix-store --import</command> from
|
|
||||||
standard input and adds those store paths to the Nix store. Paths
|
|
||||||
that already exist in the Nix store are ignored. If a path refers to
|
|
||||||
another path that doesn’t exist in the Nix store, the import
|
|
||||||
fails.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection><title>Operation <option>--optimise</option></title>
|
|
||||||
|
|
||||||
<refsection>
|
|
||||||
<title>Synopsis</title>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-store</command>
|
|
||||||
<arg choice='plain'><option>--optimise</option></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The operation <option>--optimise</option> reduces Nix store disk
|
|
||||||
space usage by finding identical files in the store and hard-linking
|
|
||||||
them to each other. It typically reduces the size of the store by
|
|
||||||
something like 25-35%. Only regular files and symlinks are
|
|
||||||
hard-linked in this manner. Files are considered identical when they
|
|
||||||
have the same NAR archive serialisation: that is, regular files must
|
|
||||||
have the same contents and permission (executable or non-executable),
|
|
||||||
and symlinks must have the same contents.</para>
|
|
||||||
|
|
||||||
<para>After completion, or when the command is interrupted, a report
|
|
||||||
on the achieved savings is printed on standard error.</para>
|
|
||||||
|
|
||||||
<para>Use <option>-vv</option> or <option>-vvv</option> to get some
|
|
||||||
progress indication.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Example</title>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --optimise
|
|
||||||
hashing files in `/nix/store/qhqx7l2f1kmwihc9bnxs7rc159hsxnf3-gcc-4.1.1'
|
|
||||||
<replaceable>...</replaceable>
|
|
||||||
541838819 bytes (516.74 MiB) freed by hard-linking 54143 files;
|
|
||||||
there are 114486 files with equal contents out of 215894 files in total
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection><title>Operation <option>--read-log</option></title>
|
|
||||||
|
|
||||||
<refsection>
|
|
||||||
<title>Synopsis</title>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-store</command>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--read-log</option></arg>
|
|
||||||
<arg choice='plain'><option>-l</option></arg>
|
|
||||||
</group>
|
|
||||||
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The operation <option>--read-log</option> prints the build log
|
|
||||||
of the specified store paths on standard output. The build log is
|
|
||||||
whatever the builder of a derivation wrote to standard output and
|
|
||||||
standard error. If a store path is not a derivation, the deriver of
|
|
||||||
the store path is used.</para>
|
|
||||||
|
|
||||||
<para>Build logs are kept in
|
|
||||||
<filename>/nix/var/log/nix/drvs</filename>. However, there is no
|
|
||||||
guarantee that a build log is available for any particular store
|
|
||||||
path. For instance, if the path was downloaded as a pre-built binary
|
|
||||||
through a substitute, then the log is unavailable.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Example</title>
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store -l $(which ktorrent)
|
|
||||||
building /nix/store/dhc73pvzpnzxhdgpimsd9sw39di66ph1-ktorrent-2.2.1
|
|
||||||
unpacking sources
|
|
||||||
unpacking source archive /nix/store/p8n1jpqs27mgkjw07pb5269717nzf5f8-ktorrent-2.2.1.tar.gz
|
|
||||||
ktorrent-2.2.1/
|
|
||||||
ktorrent-2.2.1/NEWS
|
|
||||||
<replaceable>...</replaceable>
|
|
||||||
</screen>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection><title>Operation <option>--dump-db</option></title>
|
|
||||||
|
|
||||||
<refsection>
|
|
||||||
<title>Synopsis</title>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-store</command>
|
|
||||||
<arg choice='plain'><option>--dump-db</option></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The operation <option>--dump-db</option> writes a dump of the
|
|
||||||
Nix database to standard output. It can be loaded into an empty Nix
|
|
||||||
store using <option>--load-db</option>. This is useful for making
|
|
||||||
backups and when migrating to different database schemas.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
<!--######################################################################-->
|
|
||||||
|
|
||||||
<refsection><title>Operation <option>--dump-db</option></title>
|
|
||||||
|
|
||||||
<refsection>
|
|
||||||
<title>Synopsis</title>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-store</command>
|
|
||||||
<arg choice='plain'><option>--load-db</option></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The operation <option>--load-db</option> reads a dump of the Nix
|
|
||||||
database created by <option>--dump-db</option> from standard input and
|
|
||||||
loads it into the Nix database.</para>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
|
|
||||||
</refentry>
|
</refentry>
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<refentry xmlns="http://docbook.org/ns/docbook"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||||
|
|
||||||
|
<refmeta>
|
||||||
|
<refentrytitle>nix-unpack-closure</refentrytitle>
|
||||||
|
<manvolnum>1</manvolnum>
|
||||||
|
<refmiscinfo class="source">Nix</refmiscinfo>
|
||||||
|
<refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo>
|
||||||
|
</refmeta>
|
||||||
|
|
||||||
|
<refnamediv>
|
||||||
|
<refname>nix-unpack-closure</refname>
|
||||||
|
<refpurpose>unpack the closure of a store path created by <command>nix-pack-closure</command> into the Nix store</refpurpose>
|
||||||
|
</refnamediv>
|
||||||
|
|
||||||
|
<refsynopsisdiv>
|
||||||
|
<cmdsynopsis>
|
||||||
|
<command>nix-unpack-closure</command>
|
||||||
|
</cmdsynopsis>
|
||||||
|
</refsynopsisdiv>
|
||||||
|
|
||||||
|
|
||||||
|
<refsection><title>Description</title>
|
||||||
|
|
||||||
|
<para>The command <command>nix-unpack-closure</command> unpacks the
|
||||||
|
closure of a set of store paths created by
|
||||||
|
<command>nix-pack-closure</command> into the local Nix store. The
|
||||||
|
closure is a single file read from standard input. See the
|
||||||
|
description of <command>nix-pack-closure</command> for details and
|
||||||
|
examples.</para>
|
||||||
|
|
||||||
|
<para>The top-level paths in the closure (i.e., the paths passed to
|
||||||
|
the original <command>nix-pack-closure</command> call that created the
|
||||||
|
closure) are printed on standard output. These paths can be passed,
|
||||||
|
for instance, to <literal>nix-env -i</literal> to install them into a
|
||||||
|
user environment on the target machine.</para>
|
||||||
|
|
||||||
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
|
</refentry>
|
||||||
@@ -1,34 +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">
|
|
||||||
|
|
||||||
<refmeta>
|
|
||||||
<refentrytitle>nix-worker</refentrytitle>
|
|
||||||
<manvolnum>8</manvolnum>
|
|
||||||
<refmiscinfo class="source">Nix</refmiscinfo>
|
|
||||||
<refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo>
|
|
||||||
</refmeta>
|
|
||||||
|
|
||||||
<refnamediv>
|
|
||||||
<refname>nix-worker</refname>
|
|
||||||
<refpurpose>Nix multi-user support daemon</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<cmdsynopsis>
|
|
||||||
<command>nix-worker</command>
|
|
||||||
<arg choice="plain"><option>--daemon</option></arg>
|
|
||||||
</cmdsynopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
|
|
||||||
<refsection><title>Description</title>
|
|
||||||
|
|
||||||
<para>The Nix daemon is necessary in multi-user Nix installations. It
|
|
||||||
performs build actions and other operations on the Nix store on behalf
|
|
||||||
of unprivileged users.</para>
|
|
||||||
|
|
||||||
|
|
||||||
</refsection>
|
|
||||||
|
|
||||||
</refentry>
|
|
||||||
@@ -13,10 +13,6 @@
|
|||||||
</group>
|
</group>
|
||||||
<replaceable>number</replaceable>
|
<replaceable>number</replaceable>
|
||||||
</arg>
|
</arg>
|
||||||
<arg>
|
|
||||||
<arg><option>--max-silent-time</option></arg>
|
|
||||||
<replaceable>number</replaceable>
|
|
||||||
</arg>
|
|
||||||
<arg><option>--keep-going</option></arg>
|
<arg><option>--keep-going</option></arg>
|
||||||
<arg><option>-k</option></arg>
|
<arg><option>-k</option></arg>
|
||||||
<arg><option>--keep-failed</option></arg>
|
<arg><option>--keep-failed</option></arg>
|
||||||
@@ -24,7 +20,6 @@
|
|||||||
<arg><option>--fallback</option></arg>
|
<arg><option>--fallback</option></arg>
|
||||||
<arg><option>--readonly-mode</option></arg>
|
<arg><option>--readonly-mode</option></arg>
|
||||||
<arg><option>--log-type</option> <replaceable>type</replaceable></arg>
|
<arg><option>--log-type</option> <replaceable>type</replaceable></arg>
|
||||||
<arg><option>--show-trace</option></arg>
|
|
||||||
<sbr />
|
<sbr />
|
||||||
|
|
||||||
</nop>
|
</nop>
|
||||||
@@ -103,17 +103,6 @@
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="opt-max-silent-time"><term><option>--max-silent-time</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Sets the maximum number of seconds that a builder
|
|
||||||
can go without producing any data on standard output or standard
|
|
||||||
error. The default is specified by the <link
|
|
||||||
linkend='conf-build-max-silent-time'><literal>build-max-silent-time</literal></link>
|
|
||||||
configuration setting. <literal>0</literal> means no
|
|
||||||
time-out.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
<varlistentry><term><option>--keep-going</option></term>
|
<varlistentry><term><option>--keep-going</option></term>
|
||||||
<term><option>-k</option></term>
|
<term><option>-k</option></term>
|
||||||
|
|
||||||
@@ -251,14 +240,14 @@
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{ # The system (e.g., `i686-linux') for which to build the packages.
|
{ # The system (e.g., `i686-linux') for which to build the packages.
|
||||||
system ? builtins.currentSystem
|
system ? __currentSystem
|
||||||
<replaceable>...</replaceable>
|
<replaceable>...</replaceable>
|
||||||
}: <replaceable>...</replaceable></programlisting>
|
}: <replaceable>...</replaceable></programlisting>
|
||||||
|
|
||||||
So if you call this Nix expression (e.g., when you do
|
So if you call this Nix expression (e.g., when you do
|
||||||
<literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
|
<literal>nix-env -i <replaceable>pkgname</replaceable></literal>),
|
||||||
the function will be called automatically using the value <link
|
the function will be called automatically using the value <link
|
||||||
linkend='builtin-currentSystem'><literal>builtins.currentSystem</literal></link>
|
linkend='builtin-currentSystem'><literal>__currentSystem</literal></link>
|
||||||
for the <literal>system</literal> argument. You can override this
|
for the <literal>system</literal> argument. You can override this
|
||||||
using <option>--arg</option>, e.g., <literal>nix-env -i
|
using <option>--arg</option>, e.g., <literal>nix-env -i
|
||||||
<replaceable>pkgname</replaceable> --arg system
|
<replaceable>pkgname</replaceable> --arg system
|
||||||
@@ -268,17 +257,6 @@
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><option>--argstr</option> <replaceable>name</replaceable> <replaceable>value</replaceable></term>
|
|
||||||
|
|
||||||
<listitem><para>This option is like <option>--arg</option>, only the
|
|
||||||
value is not a Nix expression but a string. So instead of
|
|
||||||
<literal>--arg system \"i686-linux\"</literal> (the outer quotes are
|
|
||||||
to keep the shell happy) you can say <literal>--argstr system
|
|
||||||
i686-linux</literal>.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
|
<varlistentry xml:id="opt-attr"><term><option>--attr</option> / <option>-A</option>
|
||||||
<replaceable>attrPath</replaceable></term>
|
<replaceable>attrPath</replaceable></term>
|
||||||
|
|
||||||
@@ -305,14 +283,6 @@
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><option>--show-trace</option></term>
|
|
||||||
|
|
||||||
<listitem><para>Causes Nix to print out a stack trace in case of Nix
|
|
||||||
expression evaluation errors.</para></listitem>
|
|
||||||
|
|
||||||
</varlistentry>
|
|
||||||
|
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
<nop xmlns="http://docbook.org/ns/docbook">
|
|
||||||
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--prebuilt-only</option></arg>
|
|
||||||
<arg choice='plain'><option>-b</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
|
|
||||||
<arg>
|
|
||||||
<group choice='req'>
|
|
||||||
<arg choice='plain'><option>--attr</option></arg>
|
|
||||||
<arg choice='plain'><option>-A</option></arg>
|
|
||||||
</group>
|
|
||||||
</arg>
|
|
||||||
|
|
||||||
<arg><option>--from-expression</option></arg>
|
|
||||||
<arg><option>-E</option></arg>
|
|
||||||
|
|
||||||
<arg><option>--from-profile</option> <replaceable>path</replaceable></arg>
|
|
||||||
|
|
||||||
</nop>
|
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
|
|
||||||
<para>This chapter discusses how to do package management with Nix,
|
<para>This chapter discusses how to do package management with Nix,
|
||||||
i.e., how to obtain, install, upgrade, and erase packages. This is
|
i.e., how to obtain, install, upgrade, and erase components. This is
|
||||||
the “user’s” perspective of the Nix system — people
|
the “user’s” perspective of the Nix system — people
|
||||||
who want to <emphasis>create</emphasis> packages should consult
|
who want to <emphasis>create</emphasis> components should consult
|
||||||
<xref linkend='chap-writing-nix-expressions' />.</para>
|
<xref linkend='chap-writing-nix-expressions' />.</para>
|
||||||
|
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ who want to <emphasis>create</emphasis> packages should consult
|
|||||||
|
|
||||||
<para>The main command for package management is <link
|
<para>The main command for package management is <link
|
||||||
linkend="sec-nix-env"><command>nix-env</command></link>. You can use
|
linkend="sec-nix-env"><command>nix-env</command></link>. You can use
|
||||||
it to install, upgrade, and erase packages, and to query what
|
it to install, upgrade, and erase components, and to query what
|
||||||
packages are installed or are available for installation.</para>
|
components are installed or are available for installation.</para>
|
||||||
|
|
||||||
<para>In Nix, different users can have different “views”
|
<para>In Nix, different users can have different “views”
|
||||||
on the set of installed applications. That is, there might be lots of
|
on the set of installed applications. That is, there might be lots of
|
||||||
@@ -30,18 +30,18 @@ environment</emphasis>, which is just a directory tree consisting of
|
|||||||
symlinks to the files of the active applications. </para>
|
symlinks to the files of the active applications. </para>
|
||||||
|
|
||||||
<para>Components are installed from a set of <emphasis>Nix
|
<para>Components are installed from a set of <emphasis>Nix
|
||||||
expressions</emphasis> that tell Nix how to build those packages,
|
expressions</emphasis> that tell Nix how to build those components,
|
||||||
including, if necessary, their dependencies. There is a collection of
|
including, if necessary, their dependencies. There is a collection of
|
||||||
Nix expressions called the Nix Package collection that contains
|
Nix expressions called the Nix Package collection that contains
|
||||||
packages ranging from basic development stuff such as GCC and Glibc,
|
components ranging from basic development stuff such as GCC and Glibc,
|
||||||
to end-user applications like Mozilla Firefox. (Nix is however not
|
to end-user applications like Mozilla Firefox. (Nix is however not
|
||||||
tied to the Nix Package collection; you could write your own Nix
|
tied to the Nix Package collection; you could write your own Nix
|
||||||
expressions based on it, or completely new ones.) You can download
|
expressions based on it, or completely new ones.) You can download
|
||||||
the latest version from <link
|
the latest version from <link
|
||||||
xlink:href='http://nixos.org/releases/full-index-nixpkgs.html' />.</para>
|
xlink:href='http://nix.cs.uu.nl/dist/nix' />.</para>
|
||||||
|
|
||||||
<para>Assuming that you have downloaded and unpacked a release of Nix
|
<para>Assuming that you have downloaded and unpacked a release of Nix
|
||||||
Packages, you can view the set of available packages in the release:
|
Packages, you can view the set of available components in the release:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-env -qaf nixpkgs-<replaceable>version</replaceable> '*'
|
$ nix-env -qaf nixpkgs-<replaceable>version</replaceable> '*'
|
||||||
@@ -74,7 +74,7 @@ gcc-4.1.1</screen>
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>It is also possible to see the <emphasis>status</emphasis> of
|
<para>It is also possible to see the <emphasis>status</emphasis> of
|
||||||
available packages, i.e., whether they are installed into the user
|
available components, i.e., whether they are installed into the user
|
||||||
environment and/or present in the system:
|
environment and/or present in the system:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
@@ -86,24 +86,24 @@ IPS bison-1.875d
|
|||||||
...</screen>
|
...</screen>
|
||||||
|
|
||||||
The first character (<literal>I</literal>) indicates whether the
|
The first character (<literal>I</literal>) indicates whether the
|
||||||
package is installed in your current user environment. The second
|
component is installed in your current user environment. The second
|
||||||
(<literal>P</literal>) indicates whether it is present on your system
|
(<literal>P</literal>) indicates whether it is present on your system
|
||||||
(in which case installing it into your user environment would be a
|
(in which case installing it into your user environment would be a
|
||||||
very quick operation). The last one (<literal>S</literal>) indicates
|
very quick operation). The last one (<literal>S</literal>) indicates
|
||||||
whether there is a so-called <emphasis>substitute</emphasis> for the
|
whether there is a so-called <emphasis>substitute</emphasis> for the
|
||||||
package, which is Nix’s mechanism for doing binary deployment. It
|
component, which is Nix’s mechanism for doing binary deployment. It
|
||||||
just means that Nix knows that it can fetch a pre-built package from
|
just means that Nix knows that it can fetch a pre-built component from
|
||||||
somewhere (typically a network server) instead of building it
|
somewhere (typically a network server) instead of building it
|
||||||
locally.</para>
|
locally.</para>
|
||||||
|
|
||||||
<para>So now that we have a set of Nix expressions we can build the
|
<para>So now that we have a set of Nix expressions we can build the
|
||||||
packages contained in them. This is done using <literal>nix-env
|
components contained in them. This is done using <literal>nix-env
|
||||||
-i</literal>. For instance,
|
-i</literal>. For instance,
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -i subversion</screen>
|
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -i subversion</screen>
|
||||||
|
|
||||||
will install the package called <literal>subversion</literal> (which
|
will install the component called <literal>subversion</literal> (which
|
||||||
is, of course, the <link
|
is, of course, the <link
|
||||||
xlink:href='http://subversion.tigris.org/'>Subversion version
|
xlink:href='http://subversion.tigris.org/'>Subversion version
|
||||||
management system</link>).</para>
|
management system</link>).</para>
|
||||||
@@ -112,21 +112,21 @@ management system</link>).</para>
|
|||||||
Subversion and all its dependencies. This will take quite a while —
|
Subversion and all its dependencies. This will take quite a while —
|
||||||
typically an hour or two on modern machines. Fortunately, there is a
|
typically an hour or two on modern machines. Fortunately, there is a
|
||||||
faster way (so do a Ctrl-C on that install operation!): you just need
|
faster way (so do a Ctrl-C on that install operation!): you just need
|
||||||
to tell Nix that pre-built binaries of all those packages are
|
to tell Nix that pre-built binaries of all those components are
|
||||||
available somewhere. This is done using the
|
available somewhere. This is done using the
|
||||||
<command>nix-pull</command> command, which must be supplied with a URL
|
<command>nix-pull</command> command, which must be supplied with a URL
|
||||||
containing a <emphasis>manifest</emphasis> describing what binaries
|
containing a <emphasis>manifest</emphasis> describing what binaries
|
||||||
are available. This URL should correspond to the Nix Packages release
|
are available. This URL should correspond to the Nix Packages release
|
||||||
that you’re using. For instance, if you obtained a release from <link
|
that you’re using. For instance, if you obtained a release from <link
|
||||||
xlink:href='http://nixos.org/releases/nixpkgs/nixpkgs-0.12pre11712-4lrp7j8x'
|
xlink:href='http://nix.cs.uu.nl/dist/nix/nixpkgs-0.6pre1554/' />, then
|
||||||
/>, then you should do:
|
you should do:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-pull http://nixos.org/releases/nixpkgs/nixpkgs-0.12pre11712-4lrp7j8x/MANIFEST</screen>
|
$ nix-pull http://nix.cs.uu.nl/dist/nix/nixpkgs-0.6pre1554/MANIFEST</screen>
|
||||||
|
|
||||||
If you then issue the installation command, it should start
|
If you then issue the installation command, it should start
|
||||||
downloading binaries from <systemitem
|
downloading binaries from <systemitem
|
||||||
class='fqdomainname'>nixos.org</systemitem>, instead of building
|
class='fqdomainname'>nix.cs.uu.nl</systemitem>, instead of building
|
||||||
them from source. This might still take a while since all
|
them from source. This might still take a while since all
|
||||||
dependencies must be downloaded, but on a reasonably fast connection
|
dependencies must be downloaded, but on a reasonably fast connection
|
||||||
such as an DSL line it’s on the order of a few minutes.</para>
|
such as an DSL line it’s on the order of a few minutes.</para>
|
||||||
@@ -153,7 +153,7 @@ expressions, use <parameter>-i</parameter> instead of
|
|||||||
<parameter>-u</parameter>; <parameter>-i</parameter> will remove
|
<parameter>-u</parameter>; <parameter>-i</parameter> will remove
|
||||||
whatever version is already installed.</para>
|
whatever version is already installed.</para>
|
||||||
|
|
||||||
<para>You can also upgrade all packages for which there are newer
|
<para>You can also upgrade all components for which there are newer
|
||||||
versions:
|
versions:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
@@ -199,19 +199,19 @@ set.</para></footnote></para>
|
|||||||
implementing the ability to allow different users to have different
|
implementing the ability to allow different users to have different
|
||||||
configurations, and to do atomic upgrades and rollbacks. To
|
configurations, and to do atomic upgrades and rollbacks. To
|
||||||
understand how they work, it’s useful to know a bit about how Nix
|
understand how they work, it’s useful to know a bit about how Nix
|
||||||
works. In Nix, packages are stored in unique locations in the
|
works. In Nix, components are stored in unique locations in the
|
||||||
<emphasis>Nix store</emphasis> (typically,
|
<emphasis>Nix store</emphasis> (typically,
|
||||||
<filename>/nix/store</filename>). For instance, a particular version
|
<filename>/nix/store</filename>). For instance, a particular version
|
||||||
of the Subversion package might be stored in a directory
|
of the Subversion component might be stored in a directory
|
||||||
<filename>/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3/</filename>,
|
<filename>/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3/</filename>,
|
||||||
while another version might be stored in
|
while another version might be stored in
|
||||||
<filename>/nix/store/5mq2jcn36ldlmh93yj1n8s9c95pj7c5s-subversion-1.1.2</filename>.
|
<filename>/nix/store/5mq2jcn36ldlmh93yj1n8s9c95pj7c5s-subversion-1.1.2</filename>.
|
||||||
The long strings prefixed to the directory names are cryptographic
|
The long strings prefixed to the directory names are cryptographic
|
||||||
hashes<footnote><para>160-bit truncations of SHA-256 hashes encoded in
|
hashes<footnote><para>160-bit truncations of SHA-256 hashes encoded in
|
||||||
a base-32 notation, to be precise.</para></footnote> of
|
a base-32 notation, to be precise.</para></footnote> of
|
||||||
<emphasis>all</emphasis> inputs involved in building the package —
|
<emphasis>all</emphasis> inputs involved in building the component —
|
||||||
sources, dependencies, compiler flags, and so on. So if two
|
sources, dependencies, compiler flags, and so on. So if two
|
||||||
packages differ in any way, they end up in different locations in
|
components differ in any way, they end up in different locations in
|
||||||
the file system, so they don’t interfere with each other. <xref
|
the file system, so they don’t interfere with each other. <xref
|
||||||
linkend='fig-user-environments' /> shows a part of a typical Nix
|
linkend='fig-user-environments' /> shows a part of a typical Nix
|
||||||
store.</para>
|
store.</para>
|
||||||
@@ -231,12 +231,12 @@ $ /nix/store/dpmvp969yhdq...-subversion-1.1.3/bin/svn</screen>
|
|||||||
|
|
||||||
every time you want to run Subversion. Of course we could set up the
|
every time you want to run Subversion. Of course we could set up the
|
||||||
<envar>PATH</envar> environment variable to include the
|
<envar>PATH</envar> environment variable to include the
|
||||||
<filename>bin</filename> directory of every package we want to use,
|
<filename>bin</filename> directory of every component we want to use,
|
||||||
but this is not very convenient since changing <envar>PATH</envar>
|
but this is not very convenient since changing <envar>PATH</envar>
|
||||||
doesn’t take effect for already existing processes. The solution Nix
|
doesn’t take effect for already existing processes. The solution Nix
|
||||||
uses is to create directory trees of symlinks to
|
uses is to create directory trees of symlinks to
|
||||||
<emphasis>activated</emphasis> packages. These are called
|
<emphasis>activated</emphasis> components. These are called
|
||||||
<emphasis>user environments</emphasis> and they are packages
|
<emphasis>user environments</emphasis> and they are components
|
||||||
themselves (though automatically generated by
|
themselves (though automatically generated by
|
||||||
<command>nix-env</command>), so they too reside in the Nix store. For
|
<command>nix-env</command>), so they too reside in the Nix store. For
|
||||||
instance, in <xref linkend='fig-user-environments' /> the user
|
instance, in <xref linkend='fig-user-environments' /> the user
|
||||||
@@ -285,8 +285,8 @@ operation, a new user environment and generation link are created
|
|||||||
based on the current one, and finally the <filename>default</filename>
|
based on the current one, and finally the <filename>default</filename>
|
||||||
symlink is made to point at the new generation. This last step is
|
symlink is made to point at the new generation. This last step is
|
||||||
atomic on Unix, which explains how we can do atomic upgrades. (Note
|
atomic on Unix, which explains how we can do atomic upgrades. (Note
|
||||||
that the building/installing of new packages doesn’t interfere in
|
that the building/installing of new components doesn’t interfere in
|
||||||
any way with old packages, since they are stored in different
|
any way with old components, since they are stored in different
|
||||||
locations in the Nix store.)</para>
|
locations in the Nix store.)</para>
|
||||||
|
|
||||||
<para>If you find that you want to undo a <command>nix-env</command>
|
<para>If you find that you want to undo a <command>nix-env</command>
|
||||||
@@ -352,18 +352,18 @@ This will <emphasis>not</emphasis> change the
|
|||||||
|
|
||||||
<para><command>nix-env</command> operations such as upgrades
|
<para><command>nix-env</command> operations such as upgrades
|
||||||
(<option>-u</option>) and uninstall (<option>-e</option>) never
|
(<option>-u</option>) and uninstall (<option>-e</option>) never
|
||||||
actually delete packages from the system. All they do (as shown
|
actually delete components from the system. All they do (as shown
|
||||||
above) is to create a new user environment that no longer contains
|
above) is to create a new user environment that no longer contains
|
||||||
symlinks to the “deleted” packages.</para>
|
symlinks to the “deleted” components.</para>
|
||||||
|
|
||||||
<para>Of course, since disk space is not infinite, unused packages
|
<para>Of course, since disk space is not infinite, unused components
|
||||||
should be removed at some point. You can do this by running the Nix
|
should be removed at some point. You can do this by running the Nix
|
||||||
garbage collector. It will remove from the Nix store any package
|
garbage collector. It will remove from the Nix store any component
|
||||||
not used (directly or indirectly) by any generation of any
|
not used (directly or indirectly) by any generation of any
|
||||||
profile.</para>
|
profile.</para>
|
||||||
|
|
||||||
<para>Note however that as long as old generations reference a
|
<para>Note however that as long as old generations reference a
|
||||||
package, it will not be deleted. After all, we wouldn’t be able to
|
component, it will not be deleted. After all, we wouldn’t be able to
|
||||||
do a rollback otherwise. So in order for garbage collection to be
|
do a rollback otherwise. So in order for garbage collection to be
|
||||||
effective, you should also delete (some) old generations. Of course,
|
effective, you should also delete (some) old generations. Of course,
|
||||||
this should only be done if you are certain that you will not need to
|
this should only be done if you are certain that you will not need to
|
||||||
@@ -458,7 +458,7 @@ URL.</para>
|
|||||||
<command>nix-channel --add</command>, e.g.,
|
<command>nix-channel --add</command>, e.g.,
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-channel --add http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable</screen>
|
$ nix-channel --add http://nix.cs.uu.nl/dist/nix/channels-v3/nixpkgs-unstable</screen>
|
||||||
|
|
||||||
subscribes you to a channel that always contains that latest version
|
subscribes you to a channel that always contains that latest version
|
||||||
of the Nix Packages collection. (Instead of
|
of the Nix Packages collection. (Instead of
|
||||||
@@ -486,7 +486,7 @@ makes the union of each channel’s Nix expressions the default for
|
|||||||
<screen>
|
<screen>
|
||||||
$ nix-env -u '*'</screen>
|
$ nix-env -u '*'</screen>
|
||||||
|
|
||||||
to upgrade all packages in your profile to the latest versions
|
to upgrade all components in your profile to the latest versions
|
||||||
available in the subscribed channels.</para>
|
available in the subscribed channels.</para>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
@@ -496,19 +496,20 @@ available in the subscribed channels.</para>
|
|||||||
|
|
||||||
<para>Often, when you want to install a specific package (e.g., from
|
<para>Often, when you want to install a specific package (e.g., from
|
||||||
the <link
|
the <link
|
||||||
xlink:href="http://nixos.org/releases/nixpkgs/nixpkgs-unstable/">Nix
|
xlink:href="http://nix.cs.uu.nl/dist/nix/nixpkgs-unstable-latest/">Nix
|
||||||
Packages collection</link>), subscribing to a channel is a bit
|
Packages collection</link> or from our <link
|
||||||
cumbersome. And channels don’t help you at all if you want to install
|
xlink:href='http://nix.cs.uu.nl/dist/'>release server</link>),
|
||||||
an older version of a package than the one provided by the current
|
subscribing to a channel is a bit cumbersome. And channels don’t help
|
||||||
contents of the channel, or a package that has been removed from the
|
you at all if you want to install an older version of a package than
|
||||||
channel. That’s when <emphasis>one-click installs</emphasis> come in
|
the one provided by the current contents of the channel, or a package
|
||||||
handy: you can just go to the web page that contains the package,
|
that has been removed from the channel. That’s when
|
||||||
click on it, and it will be installed with all the necessary
|
<emphasis>one-click installs</emphasis> come in handy: you can just go
|
||||||
dependencies.</para>
|
to the web page that contains the package, click on it, and it will be
|
||||||
|
installed with all the necessary dependencies.</para>
|
||||||
|
|
||||||
<para>For instance, you can go to <link
|
<para>For instance, you can go to <link
|
||||||
xlink:href="http://nixos.org/releases/nixpkgs/nixpkgs-unstable/" /> —
|
xlink:href="http://nix.cs.uu.nl/dist/nix/nixpkgs-unstable-latest/" />
|
||||||
or to any older release of Nix Packages — and click on any link for
|
— or to any older release of Nix Packages — and click on any link for
|
||||||
the individual packages for your platform (say, <link
|
the individual packages for your platform (say, <link
|
||||||
xlink:href='http://nix.cs.uu.nl/dist/nix/nixpkgs-0.10pre6622/pkgs/subversion-1.4.0-i686-linux.nixpkg'><literal>subversion-1.4.0</literal>
|
xlink:href='http://nix.cs.uu.nl/dist/nix/nixpkgs-0.10pre6622/pkgs/subversion-1.4.0-i686-linux.nixpkg'><literal>subversion-1.4.0</literal>
|
||||||
for <literal>i686-linux</literal></link>). The first time you do
|
for <literal>i686-linux</literal></link>). The first time you do
|
||||||
@@ -528,82 +529,4 @@ linkend='sec-nix-install-package' /> for details.</para>
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
<section xml:id="sec-sharing-packages"><title>Sharing packages between machines</title>
|
|
||||||
|
|
||||||
<para>Sometimes you want to copy a package from one machine to
|
|
||||||
another. Or, you want to install some packages and you know that
|
|
||||||
another machine already has some or all of those packages or their
|
|
||||||
dependencies. In that case there are mechanisms to quickly copy
|
|
||||||
packages between machines.</para>
|
|
||||||
|
|
||||||
<para>The command <command
|
|
||||||
linkend="sec-nix-copy-closure">nix-copy-closure</command> copies a Nix
|
|
||||||
store path along with all its dependencies to or from another machine
|
|
||||||
via the SSH protocol. It doesn’t copy store paths that are already
|
|
||||||
present on the target machine. For example, the following command
|
|
||||||
copies Firefox with all its dependencies:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-copy-closure --to alice@itchy.example.org $(type -p firefox)</screen>
|
|
||||||
|
|
||||||
See <xref linkend='sec-nix-copy-closure' /> for details.</para>
|
|
||||||
|
|
||||||
<para>With <command linkend='refsec-nix-store-export'>nix-store
|
|
||||||
--export</command> and <command
|
|
||||||
linkend='refsec-nix-store-import'>nix-store --import</command> you can
|
|
||||||
write the closure of a store path (that is, the path and all its
|
|
||||||
dependencies) to a file, and then unpack that file into another Nix
|
|
||||||
store. For example,
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --export $(type -p firefox) > firefox.closure</screen>
|
|
||||||
|
|
||||||
writes the closure of Firefox to a file. You can then copy this file
|
|
||||||
to another machine and install the closure:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --import < firefox.closure</screen>
|
|
||||||
|
|
||||||
Any store paths in the closure that are already present in the target
|
|
||||||
store are ignored. It is also possible to pipe the export into
|
|
||||||
another command, e.g. to copy and install a closure directly to/on
|
|
||||||
another machine:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --export $(type -p firefox) | bzip2 | \
|
|
||||||
ssh alice@itchy.example.org "bunzip2 | nix-store --import"</screen>
|
|
||||||
|
|
||||||
But note that <command>nix-copy-closure</command> is generally more
|
|
||||||
efficient in this example because it only copies paths that are not
|
|
||||||
already present in the target Nix store.</para>
|
|
||||||
|
|
||||||
<para>Finally, if you can mount the Nix store of a remote machine in
|
|
||||||
your local filesystem, Nix can copy paths from the remote Nix store to
|
|
||||||
the local Nix store <emphasis>on demand</emphasis>. For instance,
|
|
||||||
suppose that you mount a remote machine containing a Nix store via
|
|
||||||
<command
|
|
||||||
xlink:href="http://fuse.sourceforge.net/sshfs.html">sshfs</command>:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ sshfs alice@itchy.example.org:/ /mnt</screen>
|
|
||||||
|
|
||||||
You should then set the <envar>NIX_OTHER_STORES</envar> environment
|
|
||||||
variable to tell Nix about this remote Nix store:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ export NIX_OTHER_STORES=/mnt/nix</screen>
|
|
||||||
|
|
||||||
Then if you do any Nix operation, e.g.
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-env -i firefox</screen>
|
|
||||||
|
|
||||||
and Nix has to build a path that it sees is already present in
|
|
||||||
<filename>/mnt/nix</filename>, then it will just copy from there
|
|
||||||
instead of building it from source.</para>
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
|
||||||
</chapter>
|
</chapter>
|
||||||
+14
-15
@@ -11,7 +11,7 @@ to the following chapters.</para>
|
|||||||
<orderedlist>
|
<orderedlist>
|
||||||
|
|
||||||
<listitem><para>Download a source tarball or RPM from <link
|
<listitem><para>Download a source tarball or RPM from <link
|
||||||
xlink:href='http://nixos.org/'/>. Build source
|
xlink:href='http://www.cs.uu.nl/groups/ST/Trace/Nix'/>. Build source
|
||||||
distributions using the regular sequence:
|
distributions using the regular sequence:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
@@ -22,9 +22,8 @@ $ make install <lineannotation>(as root)</lineannotation></screen>
|
|||||||
|
|
||||||
This will install Nix in <filename>/nix</filename>. You shouldn't
|
This will install Nix in <filename>/nix</filename>. You shouldn't
|
||||||
change the prefix if at all possible since that will make it
|
change the prefix if at all possible since that will make it
|
||||||
impossible to use pre-built binaries from the Nixpkgs channel and
|
impossible to use our pre-built components. Alternatively, you could
|
||||||
other channels. Alternatively, you could grab an RPM if you're on an
|
grab an RPM if you're on an RPM-based system. You should also add
|
||||||
RPM-based system. You should also add
|
|
||||||
<filename>/nix/etc/profile.d/nix.sh</filename> to your
|
<filename>/nix/etc/profile.d/nix.sh</filename> to your
|
||||||
<filename>~/.bashrc</filename> (or some other login
|
<filename>~/.bashrc</filename> (or some other login
|
||||||
file).</para></listitem>
|
file).</para></listitem>
|
||||||
@@ -33,7 +32,7 @@ file).</para></listitem>
|
|||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-channel --add \
|
$ nix-channel --add \
|
||||||
http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable</screen>
|
http://nix.cs.uu.nl/dist/nix/channels-v3/nixpkgs-unstable</screen>
|
||||||
|
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
|
|
||||||
@@ -41,14 +40,14 @@ $ nix-channel --add \
|
|||||||
<screen>
|
<screen>
|
||||||
$ nix-channel --update</screen>
|
$ nix-channel --update</screen>
|
||||||
|
|
||||||
Note that this in itself doesn't download any packages, it just
|
Note that this in itself doesn't download any components, it just
|
||||||
downloads the Nix expressions that build them and stores them
|
downloads the Nix expressions that build them and stores them
|
||||||
somewhere (under <filename>~/.nix-defexpr</filename>, in case you're
|
somewhere (under <filename>~/.nix-defexpr</filename>, in case you're
|
||||||
curious). Also, it registers the fact that pre-built binaries are
|
curious). Also, it registers the fact that pre-built binaries are
|
||||||
available remotely.</para></listitem>
|
available remotely.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>See what installable packages are currently available
|
<listitem><para>See what installable components are currently
|
||||||
in the channel:
|
available in the channel:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-env -qa ’*’ <lineannotation>(mind the quotes!)</lineannotation>
|
$ nix-env -qa ’*’ <lineannotation>(mind the quotes!)</lineannotation>
|
||||||
@@ -60,13 +59,13 @@ libxslt-1.1.0
|
|||||||
|
|
||||||
</para></listitem>
|
</para></listitem>
|
||||||
|
|
||||||
<listitem><para>Install some packages from the channel:
|
<listitem><para>Install some components from the channel:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
$ nix-env -i hello firefox <replaceable>...</replaceable> </screen>
|
$ nix-env -i hello firefox <replaceable>...</replaceable> </screen>
|
||||||
|
|
||||||
This should download pre-built packages; it should not build them
|
This should download the pre-built components; it should not build
|
||||||
locally (if it does, something went wrong).</para></listitem>
|
them locally (if it does, something went wrong).</para></listitem>
|
||||||
|
|
||||||
<listitem><para>Test that they work:
|
<listitem><para>Test that they work:
|
||||||
|
|
||||||
@@ -93,8 +92,8 @@ $ nix-env -e hello</screen>
|
|||||||
$ nix-channel --update
|
$ nix-channel --update
|
||||||
$ nix-env -u '*'</screen>
|
$ nix-env -u '*'</screen>
|
||||||
|
|
||||||
The latter command will upgrade each installed package for which there
|
The latter command will upgrade each installed component for which
|
||||||
is a “newer” version (as determined by comparing the version
|
there is a “newer” version (as determined by comparing the version
|
||||||
numbers).</para></listitem>
|
numbers).</para></listitem>
|
||||||
|
|
||||||
<listitem><para>You can also install specific packages directly from
|
<listitem><para>You can also install specific packages directly from
|
||||||
@@ -108,7 +107,7 @@ appear asking you whether it’s okay to install the package. Say
|
|||||||
installed.</para></listitem>
|
installed.</para></listitem>
|
||||||
|
|
||||||
<listitem><para>If you're unhappy with the result of a
|
<listitem><para>If you're unhappy with the result of a
|
||||||
<command>nix-env</command> action (e.g., an upgraded package turned
|
<command>nix-env</command> action (e.g., an upgraded component turned
|
||||||
out not to work properly), you can go back:
|
out not to work properly), you can go back:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
@@ -125,7 +124,7 @@ $ nix-collect-garbage -d</screen>
|
|||||||
|
|
||||||
<!--
|
<!--
|
||||||
The first command deletes old “generations” of your profile (making
|
The first command deletes old “generations” of your profile (making
|
||||||
rollbacks impossible, but also making the packages in those old
|
rollbacks impossible, but also making the components in those old
|
||||||
generations available for garbage collection), while the second
|
generations available for garbage collection), while the second
|
||||||
command actually deletes them.-->
|
command actually deletes them.-->
|
||||||
|
|
||||||
|
|||||||
+69
-473
@@ -8,519 +8,115 @@
|
|||||||
|
|
||||||
<!--==================================================================-->
|
<!--==================================================================-->
|
||||||
|
|
||||||
<section xml:id="ssec-relnotes-0.13"><title>Release 0.13 (April NN,
|
<section xml:id="ssec-relnotes-0.11"><title>Release 0.11 (TBA)</title>
|
||||||
2009)</title>
|
|
||||||
|
|
||||||
<para>This is primarily a bug fix release. It has some new
|
|
||||||
features:</para>
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Syntactic sugar for writing nested attribute sets. Instead of
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{
|
|
||||||
foo = {
|
|
||||||
bar = 123;
|
|
||||||
xyzzy = true;
|
|
||||||
};
|
|
||||||
a = { b = { c = "d"; }; };
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
you can write
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
{
|
|
||||||
foo.bar = 123;
|
|
||||||
foo.xyzzy = true;
|
|
||||||
a.b.c = "d";
|
|
||||||
}
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
This is useful, for instance, in NixOS configuration files.</para>
|
|
||||||
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Support for Nix channels generated by Hydra, the Nix-based
|
|
||||||
continuous build system. (Hydra generates NAR archives on the
|
|
||||||
fly, so the size and hash of these archives isn’t known in
|
|
||||||
advance.)</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Support <literal>i686-linux</literal> builds directly on
|
|
||||||
<literal>x86_64-linux</literal> Nix installations. This is
|
|
||||||
implemented using the <function>personality()</function> syscall,
|
|
||||||
which causes <command>uname</command> to return
|
|
||||||
<literal>i686</literal> in child processes.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Various improvements to the <literal>chroot</literal>
|
|
||||||
support. Building in a <literal>chroot</literal> works quite well
|
|
||||||
now.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Nix no longer blocks if it tries to build a path and another
|
|
||||||
process is already building the same path. Instead it tries to
|
|
||||||
build another buildable path first. This improves
|
|
||||||
parallelism.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Support for large (> 4 GiB) files in NAR archives.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Various (performance) improvements to the remote build
|
|
||||||
mechanism.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>New primops: <varname>builtins.addErrorContext</varname> (to
|
|
||||||
add a string to stack traces — useful for debugging),
|
|
||||||
<varname>builtins.isBool</varname>,
|
|
||||||
<varname>builtins.isString</varname>,
|
|
||||||
<varname>builtins.isInt</varname>.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
|
||||||
<!--==================================================================-->
|
|
||||||
|
|
||||||
<section xml:id="ssec-relnotes-0.12"><title>Release 0.12 (November 20,
|
|
||||||
2008)</title>
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem>
|
|
||||||
<para>Nix no longer uses Berkeley DB to store Nix store metadata.
|
|
||||||
The principal advantages of the new storage scheme are: it works
|
|
||||||
properly over decent implementations of NFS (allowing Nix stores
|
|
||||||
to be shared between multiple machines); no recovery is needed
|
|
||||||
when a Nix process crashes; no write access is needed for
|
|
||||||
read-only operations; no more running out of Berkeley DB locks on
|
|
||||||
certain operations.</para>
|
|
||||||
|
|
||||||
<para>You still need to compile Nix with Berkeley DB support if
|
|
||||||
you want Nix to automatically convert your old Nix store to the
|
|
||||||
new schema. If you don’t need this, you can build Nix with the
|
|
||||||
<filename>configure</filename> option
|
|
||||||
<option>--disable-old-db-compat</option>.</para>
|
|
||||||
|
|
||||||
<para>After the automatic conversion to the new schema, you can
|
|
||||||
delete the old Berkeley DB files:
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ cd /nix/var/nix/db
|
|
||||||
$ rm __db* log.* derivers references referrers reserved validpaths DB_CONFIG</screen>
|
|
||||||
|
|
||||||
The new metadata is stored in the directories
|
|
||||||
<filename>/nix/var/nix/db/info</filename> and
|
|
||||||
<filename>/nix/var/nix/db/referrer</filename>. Though the
|
|
||||||
metadata is stored in human-readable plain-text files, they are
|
|
||||||
not intended to be human-editable, as Nix is rather strict about
|
|
||||||
the format.</para>
|
|
||||||
|
|
||||||
<para>The new storage schema may or may not require less disk
|
|
||||||
space than the Berkeley DB environment, mostly depending on the
|
|
||||||
cluster size of your file system. With 1 KiB clusters (which
|
|
||||||
seems to be the <literal>ext3</literal> default nowadays) it
|
|
||||||
usually takes up much less space.</para>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem><para>There is a new substituter that copies paths
|
|
||||||
directly from other (remote) Nix stores mounted somewhere in the
|
|
||||||
filesystem. For instance, you can speed up an installation by
|
|
||||||
mounting some remote Nix store that already has the packages in
|
|
||||||
question via NFS or <literal>sshfs</literal>. The environment
|
|
||||||
variable <envar>NIX_OTHER_STORES</envar> specifies the locations of
|
|
||||||
the remote Nix directories,
|
|
||||||
e.g. <literal>/mnt/remote-fs/nix</literal>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>New <command>nix-store</command> operations
|
|
||||||
<option>--dump-db</option> and <option>--load-db</option> to dump
|
|
||||||
and reload the Nix database.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The garbage collector has a number of new options to
|
|
||||||
allow only some of the garbage to be deleted. The option
|
|
||||||
<option>--max-freed <replaceable>N</replaceable></option> tells the
|
|
||||||
collector to stop after at least <replaceable>N</replaceable> bytes
|
|
||||||
have been deleted. The option <option>--max-links
|
|
||||||
<replaceable>N</replaceable></option> tells it to stop after the
|
|
||||||
link count on <filename>/nix/store</filename> has dropped below
|
|
||||||
<replaceable>N</replaceable>. This is useful for very large Nix
|
|
||||||
stores on filesystems with a 32000 subdirectories limit (like
|
|
||||||
<literal>ext3</literal>). The option <option>--use-atime</option>
|
|
||||||
causes store paths to be deleted in order of ascending last access
|
|
||||||
time. This allows non-recently used stuff to be deleted. The
|
|
||||||
option <option>--max-atime <replaceable>time</replaceable></option>
|
|
||||||
specifies an upper limit to the last accessed time of paths that may
|
|
||||||
be deleted. For instance,
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
$ nix-store --gc -v --max-atime $(date +%s -d "2 months ago")</screen>
|
|
||||||
|
|
||||||
deletes everything that hasn’t been accessed in two months.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env</command> now uses optimistic
|
|
||||||
profile locking when performing an operation like installing or
|
|
||||||
upgrading, instead of setting an exclusive lock on the profile.
|
|
||||||
This allows multiple <command>nix-env -i / -u / -e</command>
|
|
||||||
operations on the same profile in parallel. If a
|
|
||||||
<command>nix-env</command> operation sees at the end that the profile
|
|
||||||
was changed in the meantime by another process, it will just
|
|
||||||
restart. This is generally cheap because the build results are
|
|
||||||
still in the Nix store.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The option <option>--dry-run</option> is now
|
|
||||||
supported by <command>nix-store -r</command> and
|
|
||||||
<command>nix-build</command>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>The information previously shown by
|
|
||||||
<option>--dry-run</option> (i.e., which derivations will be built
|
|
||||||
and which paths will be substituted) is now always shown by
|
|
||||||
<command>nix-env</command>, <command>nix-store -r</command> and
|
|
||||||
<command>nix-build</command>. The total download size of
|
|
||||||
substitutable paths is now also shown. For instance, a build will
|
|
||||||
show something like
|
|
||||||
|
|
||||||
<screen>
|
|
||||||
the following derivations will be built:
|
|
||||||
/nix/store/129sbxnk5n466zg6r1qmq1xjv9zymyy7-activate-configuration.sh.drv
|
|
||||||
/nix/store/7mzy971rdm8l566ch8hgxaf89x7lr7ik-upstart-jobs.drv
|
|
||||||
...
|
|
||||||
the following paths will be downloaded/copied (30.02 MiB):
|
|
||||||
/nix/store/4m8pvgy2dcjgppf5b4cj5l6wyshjhalj-samba-3.2.4
|
|
||||||
/nix/store/7h1kwcj29ip8vk26rhmx6bfjraxp0g4l-libunwind-0.98.6
|
|
||||||
...</screen>
|
|
||||||
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Language features:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para>@-patterns as in Haskell. For instance, in a
|
|
||||||
function definition
|
|
||||||
|
|
||||||
<programlisting>f = args @ {x, y, z}: <replaceable>...</replaceable>;</programlisting>
|
|
||||||
|
|
||||||
<varname>args</varname> refers to the argument as a whole, which
|
|
||||||
is further pattern-matched against the attribute set pattern
|
|
||||||
<literal>{x, y, z}</literal>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>“<literal>...</literal>” (ellipsis) patterns.
|
|
||||||
An attribute set pattern can now say <literal>...</literal> at
|
|
||||||
the end of the attribute name list to specify that the function
|
|
||||||
takes <emphasis>at least</emphasis> the listed attributes, while
|
|
||||||
ignoring additional attributes. For instance,
|
|
||||||
|
|
||||||
<programlisting>{stdenv, fetchurl, fuse, ...}: <replaceable>...</replaceable></programlisting>
|
|
||||||
|
|
||||||
defines a function that accepts any attribute set that includes
|
|
||||||
at least the three listed attributes.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>New primops:
|
|
||||||
<varname>builtins.parseDrvName</varname> (split a package name
|
|
||||||
string like <literal>"nix-0.12pre12876"</literal> into its name
|
|
||||||
and version components, e.g. <literal>"nix"</literal> and
|
|
||||||
<literal>"0.12pre12876"</literal>),
|
|
||||||
<varname>builtins.compareVersions</varname> (compare two version
|
|
||||||
strings using the same algorithm that <command>nix-env</command>
|
|
||||||
uses), <varname>builtins.length</varname> (efficiently compute
|
|
||||||
the length of a list), <varname>builtins.mul</varname> (integer
|
|
||||||
multiplication), <varname>builtins.div</varname> (integer
|
|
||||||
division).
|
|
||||||
<!-- <varname>builtins.genericClosure</varname> -->
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><command>nix-prefetch-url</command> now supports
|
|
||||||
<literal>mirror://</literal> URLs, provided that the environment
|
|
||||||
variable <envar>NIXPKGS_ALL</envar> points at a Nixpkgs
|
|
||||||
tree.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Removed the commands
|
|
||||||
<command>nix-pack-closure</command> and
|
|
||||||
<command>nix-unpack-closure</command>. You can do almost the same
|
|
||||||
thing but much more efficiently by doing <literal>nix-store --export
|
|
||||||
$(nix-store -qR <replaceable>paths</replaceable>) > closure</literal> and
|
|
||||||
<literal>nix-store --import <
|
|
||||||
closure</literal>.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para>Lots of bug fixes, including a big performance bug in
|
|
||||||
the handling of <literal>with</literal>-expressions.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
|
||||||
<!--==================================================================-->
|
|
||||||
|
|
||||||
<section xml:id="ssec-relnotes-0.11"><title>Release 0.11 (December 31,
|
|
||||||
2007)</title>
|
|
||||||
|
|
||||||
<para>Nix 0.11 has many improvements over the previous stable release.
|
|
||||||
The most important improvement is secure multi-user support. It also
|
|
||||||
features many usability enhancements and language extensions, many of
|
|
||||||
them prompted by NixOS, the purely functional Linux distribution based
|
|
||||||
on Nix. Here is an (incomplete) list:</para>
|
|
||||||
|
|
||||||
|
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>Secure multi-user support. A single Nix store can
|
<listitem><para>TODO: multi-user support. The old setuid method for
|
||||||
now be shared between multiple (possible untrusted) users. This is
|
sharing a store between multiple users has been
|
||||||
an important feature for NixOS, where it allows non-root users to
|
removed.</para></listitem>
|
||||||
install software. The old setuid method for sharing a store between
|
|
||||||
multiple users has been removed. Details for setting up a
|
|
||||||
multi-user store can be found in the manual.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>The new command <command>nix-copy-closure</command>
|
<listitem><para>The new command <command>nix-copy-closure</command>
|
||||||
gives you an easy and efficient way to exchange software between
|
gives you an easy and efficient way to exchange software between
|
||||||
machines. It copies the missing parts of the closure of a set of
|
machines. It copies the missing parts of the closure of a set of
|
||||||
store path to or from a remote machine via
|
store path to or from a remote machine.</para></listitem>
|
||||||
<command>ssh</command>.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>A new kind of string literal: strings between double
|
<listitem><para><command>nix-prefetch-url</command> now by default
|
||||||
single-quotes (<literal>''</literal>) have indentation
|
computes the SHA-256 hash of the file instead of the MD5 hash. In
|
||||||
“intelligently” removed. This allows large strings (such as shell
|
calls to <function>fetchurl</function> you should pass an
|
||||||
scripts or configuration file fragments in NixOS) to cleanly follow
|
<literal>sha256</literal> attribute instead of
|
||||||
the indentation of the surrounding expression. It also requires
|
<literal>md5</literal>. You can pass either a hexadecimal or a
|
||||||
much less escaping, since <literal>''</literal> is less common in
|
base-32 encoding of the hash.</para></listitem>
|
||||||
most languages than <literal>"</literal>.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env</command> <option>--set</option>
|
|
||||||
modifies the current generation of a profile so that it contains
|
|
||||||
exactly the specified derivation, and nothing else. For example,
|
|
||||||
<literal>nix-env -p /nix/var/nix/profiles/browser --set
|
|
||||||
firefox</literal> lets the profile named
|
|
||||||
<filename>browser</filename> contain just Firefox.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env</command> now maintains
|
|
||||||
meta-information about installed packages in profiles. The
|
|
||||||
meta-information is the contents of the <varname>meta</varname>
|
|
||||||
attribute of derivations, such as <varname>description</varname> or
|
|
||||||
<varname>homepage</varname>. The command <literal>nix-env -q --xml
|
|
||||||
--meta</literal> shows all meta-information.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env</command> now uses the
|
|
||||||
<varname>meta.priority</varname> attribute of derivations to resolve
|
|
||||||
filename collisions between packages. Lower priority values denote
|
|
||||||
a higher priority. For instance, the GCC wrapper package and the
|
|
||||||
Binutils package in Nixpkgs both have a file
|
|
||||||
<filename>bin/ld</filename>, so previously if you tried to install
|
|
||||||
both you would get a collision. Now, on the other hand, the GCC
|
|
||||||
wrapper declares a higher priority than Binutils, so the former’s
|
|
||||||
<filename>bin/ld</filename> is symlinked in the user
|
|
||||||
environment.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env -i / -u</command>: instead of
|
|
||||||
breaking package ties by version, break them by priority and version
|
|
||||||
number. That is, if there are multiple packages with the same name,
|
|
||||||
then pick the package with the highest priority, and only use the
|
|
||||||
version if there are multiple packages with the same
|
|
||||||
priority.</para>
|
|
||||||
|
|
||||||
<para>This makes it possible to mark specific versions/variant in
|
|
||||||
Nixpkgs more or less desirable than others. A typical example would
|
|
||||||
be a beta version of some package (e.g.,
|
|
||||||
<literal>gcc-4.2.0rc1</literal>) which should not be installed even
|
|
||||||
though it is the highest version, except when it is explicitly
|
|
||||||
selected (e.g., <literal>nix-env -i
|
|
||||||
gcc-4.2.0rc1</literal>).</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env --set-flag</command> allows meta
|
|
||||||
attributes of installed packages to be modified. There are several
|
|
||||||
attributes that can be usefully modified, because they affect the
|
|
||||||
behaviour of <command>nix-env</command> or the user environment
|
|
||||||
build script:
|
|
||||||
|
|
||||||
<itemizedlist>
|
|
||||||
|
|
||||||
<listitem><para><varname>meta.priority</varname> can be changed
|
|
||||||
to resolve filename clashes (see above).</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><varname>meta.keep</varname> can be set to
|
|
||||||
<literal>true</literal> to prevent the package from being
|
|
||||||
upgraded or replaced. Useful if you want to hang on to an older
|
|
||||||
version of a package.</para></listitem>
|
|
||||||
|
|
||||||
<listitem><para><varname>meta.active</varname> can be set to
|
|
||||||
<literal>false</literal> to “disable” the package. That is, no
|
|
||||||
symlinks will be generated to the files of the package, but it
|
|
||||||
remains part of the profile (so it won’t be garbage-collected).
|
|
||||||
Set it back to <literal>true</literal> to re-enable the
|
|
||||||
package.</para></listitem>
|
|
||||||
|
|
||||||
</itemizedlist>
|
|
||||||
|
|
||||||
</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-env -q</command> now has a flag
|
|
||||||
<option>--prebuilt-only</option> (<option>-b</option>) that causes
|
|
||||||
<command>nix-env</command> to show only those derivations whose
|
|
||||||
output is already in the Nix store or that can be substituted (i.e.,
|
|
||||||
downloaded from somewhere). In other words, it shows the packages
|
|
||||||
that can be installed “quickly”, i.e., don’t need to be built from
|
|
||||||
source. The <option>-b</option> flag is also available in
|
|
||||||
<command>nix-env -i</command> and <command>nix-env -u</command> to
|
|
||||||
filter out derivations for which no pre-built binary is
|
|
||||||
available.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>The new option <option>--argstr</option> (in
|
|
||||||
<command>nix-env</command>, <command>nix-instantiate</command> and
|
|
||||||
<command>nix-build</command>) is like <option>--arg</option>, except
|
|
||||||
that the value is a string. For example, <literal>--argstr system
|
|
||||||
i686-linux</literal> is equivalent to <literal>--arg system
|
|
||||||
\"i686-linux\"</literal> (note that <option>--argstr</option>
|
|
||||||
prevents annoying quoting around shell arguments).</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-store</command> has a new operation
|
<listitem><para><command>nix-store</command> has a new operation
|
||||||
<option>--read-log</option> (<option>-l</option>)
|
<option>--read-log</option> (<option>-l</option>)
|
||||||
<parameter>paths</parameter> that shows the build log of the given
|
<parameter>paths</parameter> that shows the build log of the given
|
||||||
paths.</para></listitem>
|
paths.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<listitem><para>TODO: <varname>allowedReferences</varname> for
|
||||||
|
checking the set of references in the output of a
|
||||||
|
derivation.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>TODO: semantic cleanups of string concatenation
|
<listitem><para>TODO: semantic cleanups of string concatenation
|
||||||
etc. (mostly in r6740).</para></listitem>
|
etc. (mostly in r6740).</para></listitem>
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>Nix now uses Berkeley DB 4.5. The database is
|
<listitem><para>TODO: now using Berkeley DB 4.5.</para></listitem>
|
||||||
upgraded automatically, but you should be careful not to use old
|
|
||||||
versions of Nix that still use Berkeley DB 4.4.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- foo
|
<listitem><para>TODO: option <option>--reregister</option> in
|
||||||
<listitem><para>TODO: option <option>- -reregister</option> in
|
<command>nix-store --register-validity</command>.</para></listitem>
|
||||||
<command>nix-store - -register-validity</command>.</para></listitem>
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>The option <option>--max-silent-time</option>
|
<listitem><para>TODO: magic <varname>exportReferencesGraph</varname>
|
||||||
(corresponding to the configuration setting
|
attribute.</para></listitem>
|
||||||
<literal>build-max-silent-time</literal>) allows you to set a
|
|
||||||
timeout on builds — if a build produces no output on
|
|
||||||
<literal>stdout</literal> or <literal>stderr</literal> for the given
|
|
||||||
number of seconds, it is terminated. This is useful for recovering
|
|
||||||
automatically from builds that are stuck in an infinite
|
|
||||||
loop.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-channel</command>: each subscribed
|
<listitem><para>TODO: option <option>--max-silent-time</option>,
|
||||||
channel is its own attribute in the top-level expression generated
|
configuration setting
|
||||||
for the channel. This allows disambiguation (e.g. <literal>nix-env
|
<literal>build-max-silent-time</literal>.</para></listitem>
|
||||||
-i -A nixpkgs_unstable.firefox</literal>).</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>The substitutes table has been removed from the
|
<listitem><para>TODO: <command>nix-env</command>
|
||||||
database. This makes operations such as <command>nix-pull</command>
|
<option>--set</option>.</para></listitem>
|
||||||
and <command>nix-channel --update</command> much, much
|
|
||||||
faster.</para></listitem>
|
|
||||||
|
<listitem><para>TODO: <option>--argstr</option>.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-pull</command> now supports
|
<listitem><para>TODO: <command>nix-env</command> now maintains meta
|
||||||
bzip2-compressed manifests. This speeds up
|
info about installed packages in user environments. <option>-q
|
||||||
channels.</para></listitem>
|
--xml --meta</option> to show all meta info.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
|
<listitem><para>TODO: <command>nix-env</command>
|
||||||
|
<option>--set-flag</option>. Specific flags:
|
||||||
|
<literal>active</literal>, <literal>priority</literal>,
|
||||||
|
<literal>keep</literal>.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
|
<listitem><para>TODO: <command>nix-env</command> <option>-i</option>
|
||||||
|
/ <option>-u</option> take package priorities into
|
||||||
|
account.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
|
<listitem><para><command>nix-env -q</command> now has a flag
|
||||||
|
<option>--prebuilt-only</option> (<option>-b</option>) that causes
|
||||||
|
<command>nix-env</command> to show only those derivations whose
|
||||||
|
output is already in the Nix store or that can be substituted (i.e.,
|
||||||
|
downloaded from somewhere). In other words, it shows the packages
|
||||||
|
that can be installed “quickly”, i.e., don’t need to be built from
|
||||||
|
source.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
|
<listitem><para>TODO: new built-ins
|
||||||
|
<function>builtins.attrNames</function>,
|
||||||
|
<function>builtins.filterSource</function>,
|
||||||
|
<function>builtins.sub</function>,
|
||||||
|
<function>builtins.stringLength</function>,
|
||||||
|
<function>builtins.substring</function>.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
|
<listitem><para>TODO: each subscribed channel is its own attribute
|
||||||
|
in the top-level expression generated for the channel, this allows
|
||||||
|
disambiguation (<command>nix-env -qaA</command>).</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
|
<listitem><para>TODO: substitutes table is gone, registering
|
||||||
|
substitutes is now much faster.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-prefetch-url</command> now has a
|
<listitem><para><command>nix-prefetch-url</command> now has a
|
||||||
limited form of caching. This is used by
|
limited form of caching. This is used by
|
||||||
<command>nix-channel</command> to prevent unnecessary downloads when
|
<command>nix-channel</command> to prevent unnecessary downloads when
|
||||||
the channel hasn’t changed.</para></listitem>
|
the channel hasn’t changed.</para></listitem>
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><command>nix-prefetch-url</command> now by default
|
|
||||||
computes the SHA-256 hash of the file instead of the MD5 hash. In
|
|
||||||
calls to <function>fetchurl</function> you should pass the
|
|
||||||
<literal>sha256</literal> attribute instead of
|
|
||||||
<literal>md5</literal>. You can pass either a hexadecimal or a
|
|
||||||
base-32 encoding of the hash.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>Nix can now perform builds in an automatically
|
|
||||||
generated “chroot”. This prevents a builder from accessing stuff
|
|
||||||
outside of the Nix store, and thus helps ensure purity. This is an
|
|
||||||
experimental feature.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>The new command <command>nix-store
|
|
||||||
--optimise</command> reduces Nix store disk space usage by finding
|
|
||||||
identical files in the store and hard-linking them to each other.
|
|
||||||
It typically reduces the size of the store by something like
|
|
||||||
25-35%.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para><filename>~/.nix-defexpr</filename> can now be a
|
|
||||||
directory, in which case the Nix expressions in that directory are
|
|
||||||
combined into an attribute set, with the file names used as the
|
|
||||||
names of the attributes. The command <command>nix-env
|
|
||||||
--import</command> (which set the
|
|
||||||
<filename>~/.nix-defexpr</filename> symlink) is
|
|
||||||
removed.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>Derivations can specify the new special attribute
|
|
||||||
<varname>allowedReferences</varname> to enforce that the references
|
|
||||||
in the output of a derivation are a subset of a declared set of
|
|
||||||
paths. For example, if <varname>allowedReferences</varname> is an
|
|
||||||
empty list, then the output must not have any references. This is
|
|
||||||
used in NixOS to check that generated files such as initial ramdisks
|
|
||||||
for booting Linux don’t have any dependencies.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>The new attribute
|
|
||||||
<varname>exportReferencesGraph</varname> allows builders access to
|
|
||||||
the references graph of their inputs. This is used in NixOS for
|
|
||||||
tasks such as generating ISO-9660 images that contain a Nix store
|
|
||||||
populated with the closure of certain paths.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>Fixed-output derivations (like
|
|
||||||
<function>fetchurl</function>) can define the attribute
|
|
||||||
<varname>impureEnvVars</varname> to allow external environment
|
|
||||||
variables to be passed to builders. This is used in Nixpkgs to
|
|
||||||
support proxy configuration, among other things.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
<listitem><para>Several new built-in functions:
|
|
||||||
<function>builtins.attrNames</function>,
|
|
||||||
<function>builtins.filterSource</function>,
|
|
||||||
<function>builtins.isAttrs</function>,
|
|
||||||
<function>builtins.isFunction</function>,
|
|
||||||
<function>builtins.listToAttrs</function>,
|
|
||||||
<function>builtins.stringLength</function>,
|
|
||||||
<function>builtins.sub</function>,
|
|
||||||
<function>builtins.substring</function>,
|
|
||||||
<function>throw</function>,
|
|
||||||
<function>builtins.trace</function>,
|
|
||||||
<function>builtins.readFile</function>.</para></listitem>
|
|
||||||
|
|
||||||
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ h3 /* subsections */
|
|||||||
font-size: 125%;
|
font-size: 125%;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.simplesect h2
|
|
||||||
{
|
|
||||||
font-size: 110%;
|
|
||||||
}
|
|
||||||
|
|
||||||
div.appendix h3
|
div.appendix h3
|
||||||
{
|
{
|
||||||
font-size: 150%;
|
font-size: 150%;
|
||||||
|
|||||||
@@ -4,9 +4,78 @@
|
|||||||
<title>Troubleshooting</title>
|
<title>Troubleshooting</title>
|
||||||
|
|
||||||
|
|
||||||
<para>This section provides solutions for some common problems. See
|
<para>This section provides solutions for some common problems.</para>
|
||||||
the <link xlink:href="http://bugs.strategoxt.org/browse/NIX">Nix
|
|
||||||
bug tracker</link> for a list of currently known issues.</para>
|
|
||||||
|
<section><title>Berkeley DB: <quote>Cannot allocate memory</quote></title>
|
||||||
|
|
||||||
|
<para>Symptom: Nix operations (in particular the
|
||||||
|
<command>nix-store</command> operations <option>--gc</option>,
|
||||||
|
<option>--verify</option>, and <option>--clear-substitutes</option> —
|
||||||
|
the latter being called by <command>nix-channel --update</command>)
|
||||||
|
failing:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ nix-store --verify
|
||||||
|
error: Db::del: Cannot allocate memory</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>Possible solution: make sure that no Nix processes are running,
|
||||||
|
then do:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ cd /nix/var/nix/db
|
||||||
|
$ rm __db.00*</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<section><title>Berkeley DB gives weird error messages</title>
|
||||||
|
|
||||||
|
<para>Symptom: you get error messages such as
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
Berkeley DB message: Finding last valid log LSN: file: 1 offset 28
|
||||||
|
Berkeley DB error: file validpaths (meta pgno = 0) has LSN [483][34721].
|
||||||
|
Berkeley DB error: end of log is [1][28]
|
||||||
|
Berkeley DB error: /nix/var/nix/db/validpaths: unexpected file type or format</screen>
|
||||||
|
|
||||||
|
or other weird Berkeley DB errors, and they don’t go away (i.e.,
|
||||||
|
automatic recovery doesn’t work). This may be the case after a system
|
||||||
|
crash.</para>
|
||||||
|
|
||||||
|
<para>Solution: first try to run <command>db_recover</command> and
|
||||||
|
then <link linkend='refsec-nix-store-verify'><command>nix-store
|
||||||
|
--verify</command></link>:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ db_recover -h /nix/var/nix/db
|
||||||
|
$ nix-store --verify</screen>
|
||||||
|
|
||||||
|
(Make sure that you have the right version of
|
||||||
|
<command>db_recover</command>, namely, Berkeley DB 4.4 for Nix 0.10,
|
||||||
|
and 4.5 for Nix 0.11.)</para>
|
||||||
|
|
||||||
|
<para>If that doesn’t work, it’s time to bring out the big guns:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
$ cd /nix/var/nix
|
||||||
|
$ cp -pr db db-backup <lineannotation>(making a backup just in case)</lineannotation>
|
||||||
|
$ cd db
|
||||||
|
$ rm __db.* log* <lineannotation>(removing the Berkeley DB environment)</lineannotation>
|
||||||
|
$ mkdir tmp
|
||||||
|
$ for i in *; do db_dump $i | (cd tmp && db_load $i); done
|
||||||
|
<lineannotation>(ignore error messages about non-database files like “reserved”)</lineannotation>
|
||||||
|
$ mv tmp/* .
|
||||||
|
$ nix-store --verify</screen>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<section><title>Collisions in <command>nix-env</command></title>
|
<section><title>Collisions in <command>nix-env</command></title>
|
||||||
@@ -76,8 +145,7 @@ Furthermore, the <literal>st_nlink</literal> field of the
|
|||||||
<para>This only happens on very large Nix installations (such as build
|
<para>This only happens on very large Nix installations (such as build
|
||||||
machines).</para>
|
machines).</para>
|
||||||
|
|
||||||
<para>Quick solution: run the garbage collector. You may want to use
|
<para>Quick solution: run the garbage collector.</para>
|
||||||
the <option>--max-links</option> option.</para>
|
|
||||||
|
|
||||||
<para>Real solution: put the Nix store on a file system that supports
|
<para>Real solution: put the Nix store on a file system that supports
|
||||||
more than 32,000 subdirectories per directory, such as ReiserFS.
|
more than 32,000 subdirectories per directory, such as ReiserFS.
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
Vendored
+5
-13
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
DB = db-4.5.20
|
DB = db-4.5.20
|
||||||
|
|
||||||
if OLD_DB_COMPAT
|
|
||||||
|
|
||||||
$(DB).tar.gz:
|
$(DB).tar.gz:
|
||||||
@echo "Nix requires Berkeley DB to build."
|
@echo "Nix requires Berkeley DB to build."
|
||||||
@echo "Please download version 4.5.20 from"
|
@echo "Please download version 4.5.20 from"
|
||||||
@@ -34,12 +32,6 @@ build-db: have-db
|
|||||||
touch build-db
|
touch build-db
|
||||||
endif
|
endif
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
build-db:
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
# CWI ATerm
|
# CWI ATerm
|
||||||
|
|
||||||
@@ -48,7 +40,7 @@ ATERM = aterm-2.4.2-fixes-r2
|
|||||||
$(ATERM).tar.bz2:
|
$(ATERM).tar.bz2:
|
||||||
@echo "Nix requires the CWI ATerm library to build."
|
@echo "Nix requires the CWI ATerm library to build."
|
||||||
@echo "Please download version 2.4.2-fixes-r2 from"
|
@echo "Please download version 2.4.2-fixes-r2 from"
|
||||||
@echo " http://nixos.org/tarballs/aterm-2.4.2-fixes-r2.tar.bz2"
|
@echo " http://losser.st-lab.cs.uu.nl/~eelco/dist/aterm-2.4.2-fixes-r2.tar.bz2"
|
||||||
@echo "and place it in the externals/ directory."
|
@echo "and place it in the externals/ directory."
|
||||||
false
|
false
|
||||||
|
|
||||||
@@ -75,12 +67,12 @@ endif
|
|||||||
|
|
||||||
# bzip2
|
# bzip2
|
||||||
|
|
||||||
BZIP2 = bzip2-1.0.5
|
BZIP2 = bzip2-1.0.4
|
||||||
|
|
||||||
$(BZIP2).tar.gz:
|
$(BZIP2).tar.gz:
|
||||||
@echo "Nix requires bzip2 to build."
|
@echo "Nix requires bzip2 to build."
|
||||||
@echo "Please download version 1.0.5 from"
|
@echo "Please download version 1.0.4 from"
|
||||||
@echo " http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz"
|
@echo " http://www.bzip.org/1.0.4/bzip2-1.0.4.tar.gz"
|
||||||
@echo "and place it in the externals/ directory."
|
@echo "and place it in the externals/ directory."
|
||||||
false
|
false
|
||||||
|
|
||||||
@@ -113,5 +105,5 @@ EXTRA_DIST = $(DB).tar.gz $(ATERM).tar.bz2 $(BZIP2).tar.gz \
|
|||||||
bdb-cygwin.patch
|
bdb-cygwin.patch
|
||||||
|
|
||||||
ext-clean:
|
ext-clean:
|
||||||
$(RM) -f have-db build-db have-aterm build-aterm have-bzip2 build-bzip2
|
$(RM) -f have-db build-db have-aterm build-aterm
|
||||||
$(RM) -rf $(DB) $(ATERM) $(BZIP2)
|
$(RM) -rf $(DB) $(ATERM) $(BZIP2)
|
||||||
@@ -76,10 +76,10 @@ The hook `nix-mode-hook' is run when Nix mode is started.
|
|||||||
("\\<baseNameOf\\>" . font-lock-builtin-face)
|
("\\<baseNameOf\\>" . font-lock-builtin-face)
|
||||||
("\\<toString\\>" . font-lock-builtin-face)
|
("\\<toString\\>" . font-lock-builtin-face)
|
||||||
("\\<isNull\\>" . font-lock-builtin-face)
|
("\\<isNull\\>" . font-lock-builtin-face)
|
||||||
|
("\\<\\([a-zA-Z_][a-zA-Z0-9_']*\\)[ \t]*="
|
||||||
|
(1 font-lock-variable-name-face nil nil))
|
||||||
("[a-zA-Z][a-zA-Z0-9\\+-\\.]*:[a-zA-Z0-9%/\\?:@&=\\+\\$,_\\.!~\\*'-]+"
|
("[a-zA-Z][a-zA-Z0-9\\+-\\.]*:[a-zA-Z0-9%/\\?:@&=\\+\\$,_\\.!~\\*'-]+"
|
||||||
. font-lock-constant-face)
|
. font-lock-constant-face)
|
||||||
("\\<\\([a-zA-Z_][a-zA-Z0-9_'\.]*\\)[ \t]*="
|
|
||||||
(1 font-lock-variable-name-face nil nil))
|
|
||||||
("[a-zA-Z0-9._\\+-]*\\(/[a-zA-Z0-9._\\+-]+\\)+"
|
("[a-zA-Z0-9._\\+-]*\\(/[a-zA-Z0-9._\\+-]+\\)+"
|
||||||
. font-lock-constant-face)
|
. font-lock-constant-face)
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
" Vim syntax file
|
|
||||||
" Language: nix
|
|
||||||
" Maintainer: Marc Weber <marco-oweber@gmx.de>
|
|
||||||
" Modify and commit if you feel that way
|
|
||||||
" Last Change: 2007 Dec
|
|
||||||
|
|
||||||
" Quit when a (custom) syntax file was already loaded
|
|
||||||
if exists("b:current_syntax")
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
syn keyword nixKeyword let throw inherit import true false null with
|
|
||||||
syn keyword nixConditional if else then
|
|
||||||
syn keyword nixBrace ( ) { } =
|
|
||||||
syn keyword nixBuiltin __currentSystem __currentTime __isFunction __getEnv __trace __toPath __pathExists
|
|
||||||
\ __readFile __toXML __toFile __filterSource __attrNames __getAttr __hasAttr __isAttrs __listToAttrs __isList
|
|
||||||
\ __head __tail __add __sub __lessThan __substring __stringLength
|
|
||||||
|
|
||||||
syn match nixAttr "\w\+\ze\s*="
|
|
||||||
syn match nixFuncArg "\zs\w\+\ze\s*:"
|
|
||||||
syn region nixStringParam start=+\${+ end=+}+
|
|
||||||
syn region nixMultiLineComment start=+/\*+ skip=+\\"+ end=+\*/+
|
|
||||||
syn match nixEndOfLineComment "#.*$"
|
|
||||||
syn region nixStringIndented start=+''+ skip=+'''\|''${\|"+ end=+''+ contains=nixStringParam
|
|
||||||
syn region nixString start=+"+ skip=+\\"+ end=+"+ contains=nixStringParam
|
|
||||||
|
|
||||||
hi def link nixKeyword Keyword
|
|
||||||
hi def link nixConditional Conditional
|
|
||||||
hi def link nixBrace Special
|
|
||||||
hi def link nixString String
|
|
||||||
hi def link nixStringIndented String
|
|
||||||
hi def link nixBuiltin Special
|
|
||||||
hi def link nixStringParam Macro
|
|
||||||
hi def link nixMultiLineComment Comment
|
|
||||||
hi def link nixEndOfLineComment Comment
|
|
||||||
hi def link nixAttr Identifier
|
|
||||||
hi def link nixFuncArg Identifier
|
|
||||||
+34
-49
@@ -29,6 +29,25 @@
|
|||||||
#gc-keep-derivations = true
|
#gc-keep-derivations = true
|
||||||
|
|
||||||
|
|
||||||
|
### Option `gc-reserved-space'
|
||||||
|
#
|
||||||
|
# This option specifies how much space should be reserved in normal
|
||||||
|
# use so that the garbage collector can run succesfully. Since the
|
||||||
|
# garbage collector must perform Berkeley DB transactions, it needs
|
||||||
|
# some disk space for itself. However, when the disk is full, this
|
||||||
|
# space is not available, so the collector would not be able to run
|
||||||
|
# precisely when it is most needed.
|
||||||
|
#
|
||||||
|
# For this reason, when Nix is run, it allocates a file
|
||||||
|
# /nix/var/nix/db/reserved of the size specified by this option. When
|
||||||
|
# the garbage collector is run, this file is deleted before the
|
||||||
|
# Berkeley DB environment is opened. This should give it enough room
|
||||||
|
# to proceed.
|
||||||
|
#
|
||||||
|
# The default is "1048576" (1 MiB).
|
||||||
|
#gc-reserved-space = 1048576
|
||||||
|
|
||||||
|
|
||||||
### Option `env-keep-derivations'
|
### Option `env-keep-derivations'
|
||||||
#
|
#
|
||||||
# If `false' (default), derivations are not stored in Nix user
|
# If `false' (default), derivations are not stored in Nix user
|
||||||
@@ -61,7 +80,7 @@
|
|||||||
|
|
||||||
### Option `build-max-silent-time'
|
### Option `build-max-silent-time'
|
||||||
#
|
#
|
||||||
# This option defines the maximum number of seconds that a builder can
|
# This option defines the maximum number of seconds that builder can
|
||||||
# go without producing any data on standard output or standard error.
|
# go without producing any data on standard output or standard error.
|
||||||
# This is useful (for instance in a automated build system) to catch
|
# 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
|
# builds that are stuck in an infinite loop, or to catch remote builds
|
||||||
@@ -116,55 +135,21 @@
|
|||||||
#build-users-group =
|
#build-users-group =
|
||||||
|
|
||||||
|
|
||||||
### Option `build-use-chroot'
|
### Option `system'
|
||||||
#
|
#
|
||||||
# If set to `true', builds will be performed in a chroot environment,
|
# This option specifies the canonical Nix system name of the current
|
||||||
# i.e., the build will be isolated from the normal file system
|
# installation, such as `i686-linux' or `powerpc-darwin'. Nix can
|
||||||
# hierarchy and will only see the Nix store, the temporary build
|
# only build derivations whose `system' attribute equals the value
|
||||||
# directory, and the directories configured with the
|
# specified here. In general, it never makes sense to modify this
|
||||||
# `build-chroot-dirs' option (such as /proc and /dev). This is useful
|
# value from its default, since you can use it to `lie' about the
|
||||||
# to prevent undeclared dependencies on files in directories such as
|
# platform you are building on (e.g., perform a Mac OS build on a
|
||||||
# /usr/bin.
|
# 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 `powerpc-darwin' and `i686-darwin'.
|
||||||
#
|
#
|
||||||
# The use of a chroot requires that Nix is run as root (but you can
|
# It defaults to the canonical Nix system name detected by `configure'
|
||||||
# still use the "build users" feature to perform builds under
|
# at build time.
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
# The default is `false'.
|
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# build-use-chroot = true
|
# system = i686-darwin
|
||||||
#build-use-chroot = false
|
#system =
|
||||||
|
|
||||||
|
|
||||||
### Option `build-chroot-dirs'
|
|
||||||
#
|
|
||||||
# When builds are performed in a chroot environment, Nix will mount
|
|
||||||
# (using `mount --bind' on Linux) some directories from the normal
|
|
||||||
# file system hierarchy inside the chroot. These are the Nix store,
|
|
||||||
# the temporary build directory (usually /tmp/nix-<pid>-<number>) and
|
|
||||||
# the directories listed here. The default is "/dev /dev/pts /proc".
|
|
||||||
# Files in /dev (such as /dev/null) are needed by many builds, and
|
|
||||||
# some files in /proc may also be needed occasionally.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# build-use-chroot = /dev /proc /bin
|
|
||||||
#build-chroot-dirs = /dev /dev/pts /proc
|
|
||||||
|
|
||||||
|
|
||||||
### Option `build-cache-failure'
|
|
||||||
#
|
|
||||||
# If this option is enabled, Nix will do negative caching; that is, it
|
|
||||||
# will remember failed builds, and won't attempt to try to build them
|
|
||||||
# again if you ask for it. Negative caching is disabled by default
|
|
||||||
# because Nix cannot distinguish between permanent build errors (e.g.,
|
|
||||||
# a syntax error in a source file) and transient build errors (e.g., a
|
|
||||||
# full disk), as they both cause the builder to return a non-zero exit
|
|
||||||
# code. You can clear the cache by doing `rm -f
|
|
||||||
# /nix/var/nix/db/failed/*'.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# build-cache-failure = true
|
|
||||||
#build-cache-failure = false
|
|
||||||
+10
-8
@@ -13,10 +13,11 @@ Version: @version@
|
|||||||
Release: 1
|
Release: 1
|
||||||
License: GPL
|
License: GPL
|
||||||
Group: Software Deployment
|
Group: Software Deployment
|
||||||
URL: http://nixos.org/
|
URL: http://nix.cs.uu.nl/
|
||||||
Source0: %{name}-@version@.tar.bz2
|
Source0: %{name}-@version@.tar.bz2
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
|
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
|
||||||
Prefix: /usr
|
%define _prefix /nix
|
||||||
|
Prefix: %{_prefix}
|
||||||
Requires: /usr/bin/perl
|
Requires: /usr/bin/perl
|
||||||
Requires: curl
|
Requires: curl
|
||||||
|
|
||||||
@@ -46,14 +47,14 @@ if test -n "%{enable_setuid}"; then
|
|||||||
extraFlags="$extraFlags --with-nix-group=%{nix_group}"
|
extraFlags="$extraFlags --with-nix-group=%{nix_group}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
./configure --prefix=%{_prefix} --sysconfdir=/etc $extraFlags
|
./configure --prefix=%{_prefix} $extraFlags
|
||||||
make
|
make
|
||||||
make check
|
make check
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
make DESTDIR=$RPM_BUILD_ROOT install
|
make DESTDIR=$RPM_BUILD_ROOT install
|
||||||
rm $RPM_BUILD_ROOT/etc/nix/nix.conf
|
rm $RPM_BUILD_ROOT/%{_prefix}/etc/nix/nix.conf
|
||||||
strip $RPM_BUILD_ROOT/%{_prefix}/bin/* || true
|
strip $RPM_BUILD_ROOT/%{_prefix}/bin/* || true
|
||||||
|
|
||||||
%clean
|
%clean
|
||||||
@@ -75,9 +76,10 @@ fi
|
|||||||
%{_prefix}/lib
|
%{_prefix}/lib
|
||||||
%{_prefix}/libexec
|
%{_prefix}/libexec
|
||||||
%{_prefix}/include
|
%{_prefix}/include
|
||||||
|
%{_prefix}/var
|
||||||
%{_prefix}/share
|
%{_prefix}/share
|
||||||
/etc/profile.d/nix.sh
|
%{_prefix}/store
|
||||||
/nix/var
|
|
||||||
/nix/store
|
|
||||||
%config
|
%config
|
||||||
/etc/nix
|
%{_prefix}/etc
|
||||||
|
#%doc
|
||||||
|
#%{_prefix}/share/nix/manual
|
||||||
-196
@@ -1,196 +0,0 @@
|
|||||||
{ nixpkgs ? ../nixpkgs }:
|
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
jobs = rec {
|
|
||||||
|
|
||||||
|
|
||||||
tarball =
|
|
||||||
{ nix ? {outPath = ./.; rev = 1234;}
|
|
||||||
, officialRelease ? false
|
|
||||||
}:
|
|
||||||
|
|
||||||
with import nixpkgs {};
|
|
||||||
|
|
||||||
releaseTools.sourceTarball {
|
|
||||||
name = "nix-tarball";
|
|
||||||
version = builtins.readFile ./version;
|
|
||||||
src = nix;
|
|
||||||
inherit officialRelease;
|
|
||||||
|
|
||||||
buildInputs = [curl bison flex2533 perl libxml2 libxslt w3m bzip2 jing_tools tetex dblatex];
|
|
||||||
|
|
||||||
configureFlags = ''
|
|
||||||
--with-docbook-rng=${docbook5}/xml/rng/docbook
|
|
||||||
--with-docbook-xsl=${docbook5_xsl}/xml/xsl/docbook
|
|
||||||
--with-xml-flags=--nonet
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Include the BDB, ATerm and Bzip2 tarballs in the distribution.
|
|
||||||
preConfigure = ''
|
|
||||||
stripHash ${db45.src}
|
|
||||||
# Remove unnecessary stuff from the Berkeley DB tarball.
|
|
||||||
( mkdir bdb-temp
|
|
||||||
cd bdb-temp
|
|
||||||
tar xfz ${db45.src}
|
|
||||||
cd *
|
|
||||||
rm -rf docs test tcl perl libdb_java java rpc_server build_vxworks \
|
|
||||||
examples_java examples_c examples_cxx dist/tags
|
|
||||||
mkdir test
|
|
||||||
touch test/include.tcl
|
|
||||||
cd ..
|
|
||||||
tar cvfz ../externals/$strippedName *
|
|
||||||
)
|
|
||||||
|
|
||||||
stripHash ${aterm242fixes.src}
|
|
||||||
cp -pv ${aterm242fixes.src} externals/$strippedName
|
|
||||||
|
|
||||||
stripHash ${bzip2.src}
|
|
||||||
cp -pv ${bzip2.src} externals/$strippedName
|
|
||||||
'';
|
|
||||||
|
|
||||||
preDist = ''
|
|
||||||
make -C doc/manual install prefix=$out
|
|
||||||
|
|
||||||
make -C doc/manual manual.pdf prefix=$out
|
|
||||||
cp doc/manual/manual.pdf $out/manual.pdf
|
|
||||||
|
|
||||||
echo "doc manual $out/share/doc/nix/manual" >> $out/nix-support/hydra-build-products
|
|
||||||
echo "doc-pdf manual $out/manual.pdf" >> $out/nix-support/hydra-build-products
|
|
||||||
echo "doc release-notes $out/share/doc/nix/release-notes" >> $out/nix-support/hydra-build-products
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
build =
|
|
||||||
{ tarball ? jobs.tarball {}
|
|
||||||
, system ? "i686-linux"
|
|
||||||
}:
|
|
||||||
|
|
||||||
with import nixpkgs {inherit system;};
|
|
||||||
|
|
||||||
releaseTools.nixBuild {
|
|
||||||
name = "nix";
|
|
||||||
src = tarball;
|
|
||||||
|
|
||||||
buildInputs = [curl perl bzip2 openssl];
|
|
||||||
|
|
||||||
configureFlags = ''
|
|
||||||
--disable-init-state
|
|
||||||
--with-bdb=${db45} --with-aterm=${aterm242fixes} --with-bzip2=${bzip2}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static =
|
|
||||||
{ tarball ? jobs.tarball {}
|
|
||||||
, system ? "i686-linux"
|
|
||||||
}:
|
|
||||||
|
|
||||||
with import nixpkgs {inherit system;};
|
|
||||||
|
|
||||||
releaseTools.binaryTarball {
|
|
||||||
name = "nix-static-tarball";
|
|
||||||
src = tarball;
|
|
||||||
|
|
||||||
buildInputs = [curl perl bzip2];
|
|
||||||
|
|
||||||
configureFlags = ''
|
|
||||||
--disable-init-state
|
|
||||||
--disable-old-db-compat --with-aterm=${aterm242fixes} --with-bzip2=${bzip2}
|
|
||||||
--enable-static-nix
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
coverage =
|
|
||||||
{ tarball ? jobs.tarball {}
|
|
||||||
}:
|
|
||||||
|
|
||||||
with import nixpkgs {};
|
|
||||||
|
|
||||||
releaseTools.coverageAnalysis {
|
|
||||||
name = "nix-build";
|
|
||||||
src = tarball;
|
|
||||||
|
|
||||||
buildInputs = [
|
|
||||||
curl perl bzip2 openssl
|
|
||||||
# These are for "make check" only:
|
|
||||||
graphviz libxml2 libxslt
|
|
||||||
];
|
|
||||||
|
|
||||||
configureFlags = ''
|
|
||||||
--disable-init-state --disable-shared
|
|
||||||
--with-bdb=${db45} --with-aterm=${aterm242fixes} --with-bzip2=${bzip2}
|
|
||||||
'';
|
|
||||||
|
|
||||||
lcovFilter = ["*/boost/*" "*-tab.*"];
|
|
||||||
|
|
||||||
# We call `dot', and even though we just use it to
|
|
||||||
# syntax-check generated dot files, it still requires some
|
|
||||||
# fonts. So provide those.
|
|
||||||
FONTCONFIG_FILE = texFunctions.fontsConf;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
rpm_fedora5i386 = makeRPM_i686 (diskImages: diskImages.fedora5i386) 20;
|
|
||||||
rpm_fedora9i386 = makeRPM_i686 (diskImages: diskImages.fedora9i386) 50;
|
|
||||||
rpm_fedora9x86_64 = makeRPM_x86_64 (diskImages: diskImages.fedora9x86_64) 50;
|
|
||||||
rpm_fedora10i386 = makeRPM_i686 (diskImages: diskImages.fedora10i386) 40;
|
|
||||||
rpm_fedora10x86_64 = makeRPM_x86_64 (diskImages: diskImages.fedora10x86_64) 40;
|
|
||||||
rpm_opensuse103i386 = makeRPM_i686 (diskImages: diskImages.opensuse103i386) 40;
|
|
||||||
|
|
||||||
|
|
||||||
deb_debian40i386 = makeDeb_i686 (diskImages: diskImages.debian40i386) 40;
|
|
||||||
deb_debian40x86_64 = makeDeb_x86_64 (diskImages: diskImages.debian40x86_64) 40;
|
|
||||||
deb_debian50i386 = makeDeb_i686 (diskImages: diskImages.debian50i386) 30;
|
|
||||||
deb_debian50x86_64 = makeDeb_x86_64 (diskImages: diskImages.debian50x86_64) 30;
|
|
||||||
deb_ubuntu804i386 = makeDeb_i686 (diskImages: diskImages.ubuntu804i386) 50;
|
|
||||||
deb_ubuntu804x86_64 = makeDeb_x86_64 (diskImages: diskImages.ubuntu804x86_64) 50;
|
|
||||||
deb_ubuntu810i386 = makeDeb_i686 (diskImages: diskImages.ubuntu810i386) 40;
|
|
||||||
deb_ubuntu810x86_64 = makeDeb_x86_64 (diskImages: diskImages.ubuntu810x86_64) 40;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
makeRPM_i686 = makeRPM "i686-linux";
|
|
||||||
makeRPM_x86_64 = makeRPM "x86_64-linux";
|
|
||||||
|
|
||||||
makeRPM =
|
|
||||||
system: diskImageFun: prio:
|
|
||||||
{ tarball ? jobs.tarball {}
|
|
||||||
}:
|
|
||||||
|
|
||||||
with import nixpkgs {inherit system;};
|
|
||||||
|
|
||||||
releaseTools.rpmBuild rec {
|
|
||||||
name = "nix-rpm-${diskImage.name}";
|
|
||||||
src = tarball;
|
|
||||||
diskImage = diskImageFun vmTools.diskImages;
|
|
||||||
memSize = 1024;
|
|
||||||
meta = { schedulingPriority = toString prio; };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
makeDeb_i686 = makeDeb "i686-linux";
|
|
||||||
makeDeb_x86_64 = makeDeb "x86_64-linux";
|
|
||||||
|
|
||||||
makeDeb =
|
|
||||||
system: diskImageFun: prio:
|
|
||||||
{ tarball ? jobs.tarball {}
|
|
||||||
}:
|
|
||||||
|
|
||||||
with import nixpkgs {inherit system;};
|
|
||||||
|
|
||||||
releaseTools.debBuild {
|
|
||||||
name = "nix-deb";
|
|
||||||
src = tarball;
|
|
||||||
diskImage = diskImageFun vmTools.diskImages;
|
|
||||||
memSize = 1024;
|
|
||||||
meta = { schedulingPriority = toString prio; };
|
|
||||||
configureFlags = "--sysconfdir=/etc";
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
in jobs
|
|
||||||
+7
-14
@@ -1,26 +1,22 @@
|
|||||||
bin_SCRIPTS = nix-collect-garbage \
|
bin_SCRIPTS = nix-collect-garbage \
|
||||||
nix-pull nix-push nix-prefetch-url \
|
nix-pull nix-push nix-prefetch-url \
|
||||||
nix-install-package nix-channel nix-build \
|
nix-install-package nix-channel nix-build \
|
||||||
nix-copy-closure
|
nix-pack-closure nix-unpack-closure \
|
||||||
|
nix-copy-closure
|
||||||
|
|
||||||
noinst_SCRIPTS = nix-profile.sh generate-patches.pl \
|
noinst_SCRIPTS = nix-profile.sh generate-patches.pl find-runtime-roots.pl
|
||||||
find-runtime-roots.pl build-remote.pl nix-reduce-build \
|
|
||||||
copy-from-other-stores.pl nix-http-export.cgi
|
|
||||||
|
|
||||||
nix-pull nix-push: readmanifest.pm readconfig.pm download-using-manifests.pl
|
nix-pull nix-push: readmanifest.pm readconfig.pm download-using-manifests.pl
|
||||||
|
|
||||||
install-exec-local: readmanifest.pm download-using-manifests.pl copy-from-other-stores.pl find-runtime-roots.pl
|
install-exec-local: readmanifest.pm download-using-manifests.pl find-runtime-roots.pl
|
||||||
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/profile.d
|
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/profile.d
|
||||||
$(INSTALL_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh
|
$(INSTALL_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh
|
||||||
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix
|
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix
|
||||||
$(INSTALL_DATA) readmanifest.pm $(DESTDIR)$(libexecdir)/nix
|
$(INSTALL_DATA) readmanifest.pm $(DESTDIR)$(libexecdir)/nix
|
||||||
$(INSTALL_DATA) readconfig.pm $(DESTDIR)$(libexecdir)/nix
|
$(INSTALL_DATA) readconfig.pm $(DESTDIR)$(libexecdir)/nix
|
||||||
|
$(INSTALL_PROGRAM) download-using-manifests.pl $(DESTDIR)$(libexecdir)/nix
|
||||||
$(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix
|
$(INSTALL_PROGRAM) find-runtime-roots.pl $(DESTDIR)$(libexecdir)/nix
|
||||||
$(INSTALL_PROGRAM) generate-patches.pl $(DESTDIR)$(libexecdir)/nix
|
$(INSTALL_PROGRAM) generate-patches.pl $(DESTDIR)$(libexecdir)/nix
|
||||||
$(INSTALL_PROGRAM) build-remote.pl $(DESTDIR)$(libexecdir)/nix
|
|
||||||
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix/substituters
|
|
||||||
$(INSTALL_PROGRAM) download-using-manifests.pl $(DESTDIR)$(libexecdir)/nix/substituters
|
|
||||||
$(INSTALL_PROGRAM) copy-from-other-stores.pl $(DESTDIR)$(libexecdir)/nix/substituters
|
|
||||||
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix
|
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix
|
||||||
|
|
||||||
include ../substitute.mk
|
include ../substitute.mk
|
||||||
@@ -33,10 +29,7 @@ EXTRA_DIST = nix-collect-garbage.in \
|
|||||||
readconfig.pm.in \
|
readconfig.pm.in \
|
||||||
nix-build.in \
|
nix-build.in \
|
||||||
download-using-manifests.pl.in \
|
download-using-manifests.pl.in \
|
||||||
copy-from-other-stores.pl.in \
|
|
||||||
generate-patches.pl.in \
|
generate-patches.pl.in \
|
||||||
|
nix-pack-closure.in nix-unpack-closure.in \
|
||||||
nix-copy-closure.in \
|
nix-copy-closure.in \
|
||||||
find-runtime-roots.pl.in \
|
find-runtime-roots.pl.in
|
||||||
build-remote.pl.in \
|
|
||||||
nix-reduce-build.in \
|
|
||||||
nix-http-export.cgi.in
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
#! @perl@ -w
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Fcntl ':flock';
|
|
||||||
use English '-no_match_vars';
|
|
||||||
use IO::Handle;
|
|
||||||
|
|
||||||
# General operation:
|
|
||||||
#
|
|
||||||
# Try to find a free machine of type $neededSystem. We do this as
|
|
||||||
# follows:
|
|
||||||
# - We acquire an exclusive lock on $currentLoad/main-lock.
|
|
||||||
# - For each machine $machine of type $neededSystem and for each $slot
|
|
||||||
# less than the maximum load for that machine, we try to get an
|
|
||||||
# exclusive lock on $currentLoad/$machine-$slot (without blocking).
|
|
||||||
# If we get such a lock, we send "accept" to the caller. Otherwise,
|
|
||||||
# we send "postpone" and exit.
|
|
||||||
# - We release the exclusive lock on $currentLoad/main-lock.
|
|
||||||
# - We perform the build on $neededSystem.
|
|
||||||
# - We release the exclusive lock on $currentLoad/$machine-$slot.
|
|
||||||
#
|
|
||||||
# The nice thing about this scheme is that if we die prematurely, the
|
|
||||||
# locks are released automatically.
|
|
||||||
|
|
||||||
my $loadIncreased = 0;
|
|
||||||
|
|
||||||
my ($amWilling, $localSystem, $neededSystem, $drvPath, $maxSilentTime) = @ARGV;
|
|
||||||
$maxSilentTime = 0 unless defined $maxSilentTime;
|
|
||||||
|
|
||||||
sub sendReply {
|
|
||||||
my $reply = shift;
|
|
||||||
print STDERR "# $reply\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
sub decline {
|
|
||||||
sendReply "decline";
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $currentLoad = $ENV{"NIX_CURRENT_LOAD"};
|
|
||||||
decline unless defined $currentLoad;
|
|
||||||
mkdir $currentLoad, 0777 or die unless -d $currentLoad;
|
|
||||||
|
|
||||||
my $conf = $ENV{"NIX_REMOTE_SYSTEMS"};
|
|
||||||
decline if !defined $conf || ! -e $conf;
|
|
||||||
|
|
||||||
my $canBuildLocally = $amWilling && ($localSystem eq $neededSystem);
|
|
||||||
|
|
||||||
|
|
||||||
# Otherwise find a willing remote machine.
|
|
||||||
my @machines;
|
|
||||||
my %curJobs;
|
|
||||||
|
|
||||||
|
|
||||||
# Read the list of machines.
|
|
||||||
open CONF, "< $conf" or die;
|
|
||||||
|
|
||||||
while (<CONF>) {
|
|
||||||
chomp;
|
|
||||||
s/\#.*$//g;
|
|
||||||
next if /^\s*$/;
|
|
||||||
/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s*$/ or die;
|
|
||||||
push @machines,
|
|
||||||
{ hostName => $1
|
|
||||||
, systemType => $2
|
|
||||||
, sshKeys => $3
|
|
||||||
, maxJobs => $4
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
close CONF;
|
|
||||||
|
|
||||||
|
|
||||||
# Acquire the exclusive lock on $currentLoad/main-lock.
|
|
||||||
my $mainLock = "$currentLoad/main-lock";
|
|
||||||
open MAINLOCK, ">>$mainLock" or die;
|
|
||||||
flock(MAINLOCK, LOCK_EX) or die;
|
|
||||||
|
|
||||||
|
|
||||||
# Find a suitable system.
|
|
||||||
my $rightType = 0;
|
|
||||||
my $machine;
|
|
||||||
my $slotLock;
|
|
||||||
LOOP: foreach my $cur (@machines) {
|
|
||||||
if ($neededSystem eq $cur->{systemType}
|
|
||||||
|| ($neededSystem eq "i686-linux" && $cur->{systemType} eq "x86_64-linux"))
|
|
||||||
{
|
|
||||||
$rightType = 1;
|
|
||||||
|
|
||||||
# We have a machine of the right type. Try to get a lock on
|
|
||||||
# one of the machine's lock files.
|
|
||||||
my $slot = 0;
|
|
||||||
while ($slot < $cur->{maxJobs}) {
|
|
||||||
my $slotLockFn = "$currentLoad/" . $cur->{systemType} . "-" . $cur->{hostName} . "-$slot";
|
|
||||||
$slotLock = new IO::Handle;
|
|
||||||
open $slotLock, ">>$slotLockFn" or die;
|
|
||||||
if (flock($slotLock, LOCK_EX | LOCK_NB)) {
|
|
||||||
utime undef, undef, $slotLock;
|
|
||||||
$machine = $cur;
|
|
||||||
last LOOP;
|
|
||||||
}
|
|
||||||
close $slotLock;
|
|
||||||
$slot++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close MAINLOCK;
|
|
||||||
|
|
||||||
|
|
||||||
# Didn't find one? Then decline or postpone.
|
|
||||||
if (!defined $machine) {
|
|
||||||
# Postpone if we have a machine of the right type, except if the
|
|
||||||
# local system can and wants to do the build.
|
|
||||||
if ($rightType && !$canBuildLocally) {
|
|
||||||
sendReply "postpone";
|
|
||||||
exit 0;
|
|
||||||
} else {
|
|
||||||
decline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Yes we did, accept.
|
|
||||||
sendReply "accept";
|
|
||||||
my $x = <STDIN>;
|
|
||||||
chomp $x;
|
|
||||||
|
|
||||||
if ($x ne "okay") {
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Do the actual job.
|
|
||||||
my $hostName = $machine->{hostName};
|
|
||||||
print STDERR "building `$drvPath' on `$hostName'\n";
|
|
||||||
|
|
||||||
# Make sure that we don't get any SSH passphrase or host key popups -
|
|
||||||
# if there is any problem it should fail, not do something
|
|
||||||
# interactive.
|
|
||||||
$ENV{"DISPLAY"} = "";
|
|
||||||
$ENV{"SSH_PASSWORD_FILE="} = "";
|
|
||||||
$ENV{"SSH_ASKPASS="} = "";
|
|
||||||
|
|
||||||
my $sshOpts = "-i " . $machine->{sshKeys} . " -x";
|
|
||||||
|
|
||||||
# Hack to support Cygwin: if we login without a password, we don't
|
|
||||||
# have exactly the same rights as when we do. This causes the
|
|
||||||
# Microsoft C compiler to fail with certain flags:
|
|
||||||
#
|
|
||||||
# http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99676
|
|
||||||
#
|
|
||||||
# So as a workaround, we pass a verbatim password. ssh tries to makes
|
|
||||||
# this very hard; the trick is to make it call SSH_ASKPASS to get the
|
|
||||||
# password. (It only calls this command when there is no controlling
|
|
||||||
# terminal, but Nix ensures that is is the case. When doing this
|
|
||||||
# manually, use setsid(1).)
|
|
||||||
if ($machine->{sshKeys} =~ /^password:/) {
|
|
||||||
my $passwordFile = $machine->{sshKeys};
|
|
||||||
$passwordFile =~ s/^password://;
|
|
||||||
$sshOpts = "ssh -x";
|
|
||||||
$ENV{"SSH_PASSWORD_FILE"} = $passwordFile;
|
|
||||||
$ENV{"SSH_ASKPASS"} = "/tmp/writepass";
|
|
||||||
|
|
||||||
open WRITEPASS, ">/tmp/writepass" or die;
|
|
||||||
print WRITEPASS "#! /bin/sh\ncat \"\$SSH_PASSWORD_FILE\"";
|
|
||||||
close WRITEPASS;
|
|
||||||
chmod 0755, "/tmp/writepass" or die;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $inputs = `cat inputs`; die if ($? != 0);
|
|
||||||
$inputs =~ s/\n/ /g;
|
|
||||||
|
|
||||||
my $outputs = `cat outputs`; die if ($? != 0);
|
|
||||||
$outputs =~ s/\n/ /g;
|
|
||||||
|
|
||||||
print "copying inputs...\n";
|
|
||||||
|
|
||||||
my $maybeSign = "";
|
|
||||||
$maybeSign = "--sign" if -e "/nix/etc/nix/signing-key.sec";
|
|
||||||
|
|
||||||
system("NIX_SSHOPTS=\"$sshOpts\" @bindir@/nix-copy-closure --gzip $hostName $maybeSign $drvPath $inputs") == 0
|
|
||||||
or die "cannot copy inputs to $hostName: $?";
|
|
||||||
|
|
||||||
print "building...\n";
|
|
||||||
|
|
||||||
my $buildFlags = "--max-silent-time $maxSilentTime";
|
|
||||||
|
|
||||||
# `-tt' forces allocation of a pseudo-terminal. This is required to
|
|
||||||
# make the remote nix-store process receive a signal when the
|
|
||||||
# connection dies. Without it, the remote process might continue to
|
|
||||||
# run indefinitely (that is, until it next tries to write to
|
|
||||||
# stdout/stderr).
|
|
||||||
if (system("ssh -tt $sshOpts $hostName 'nix-store --realise -K $buildFlags $drvPath > /dev/null'") != 0) {
|
|
||||||
# If we couldn't run ssh or there was an ssh problem (indicated by
|
|
||||||
# exit code 255), then we return exit code 1; otherwise we assume
|
|
||||||
# that the builder failed, which we indicated to Nix using exit
|
|
||||||
# code 100. It's important to distinguish between the two because
|
|
||||||
# the first is a transient failure and the latter is permanent.
|
|
||||||
my $res = $? == -1 || ($? >> 8) == 255 ? 1 : 100;
|
|
||||||
print STDERR "build of `$drvPath' on `$hostName' failed with exit code $?\n";
|
|
||||||
exit $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
print "build of `$drvPath' on `$hostName' succeeded\n";
|
|
||||||
|
|
||||||
foreach my $output (split '\n', $outputs) {
|
|
||||||
my $maybeSignRemote = "";
|
|
||||||
$maybeSignRemote = "--sign" if $UID != 0;
|
|
||||||
|
|
||||||
system("ssh $sshOpts $hostName 'nix-store --export $maybeSignRemote $output | gzip' | gunzip | @bindir@/nix-store --import > /dev/null") == 0
|
|
||||||
or die "cannot copy $output from $hostName: $?";
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
#! @perl@ -w
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use File::Basename;
|
|
||||||
use IO::Handle;
|
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
||||||
|
|
||||||
|
|
||||||
STDOUT->autoflush(1);
|
|
||||||
|
|
||||||
my @remoteStoresAll = split ':', ($ENV{"NIX_OTHER_STORES"} or "");
|
|
||||||
|
|
||||||
my @remoteStores;
|
|
||||||
foreach my $dir (@remoteStoresAll) {
|
|
||||||
push @remoteStores, glob($dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub findStorePath {
|
|
||||||
my $storePath = shift;
|
|
||||||
|
|
||||||
my $storePathName = basename $storePath;
|
|
||||||
|
|
||||||
foreach my $store (@remoteStores) {
|
|
||||||
# Determine whether $storePath exists by looking for the
|
|
||||||
# existence of the info file, and if so, get store path info
|
|
||||||
# from that file. This rather breaks abstraction: we should
|
|
||||||
# be using `nix-store' for that. But right now there is no
|
|
||||||
# good way to tell nix-store to access a store mounted under a
|
|
||||||
# different location (there's $NIX_STORE, but that only works
|
|
||||||
# if the remote store is mounted under its "real" location).
|
|
||||||
my $infoFile = "$store/var/nix/db/info/$storePathName";
|
|
||||||
my $storePath2 = "$store/store/$storePathName";
|
|
||||||
if (-f $infoFile && -e $storePath2) {
|
|
||||||
return ($infoFile, $storePath2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($ARGV[0] eq "--query") {
|
|
||||||
|
|
||||||
while (<STDIN>) {
|
|
||||||
my $cmd = $_; chomp $cmd;
|
|
||||||
|
|
||||||
if ($cmd eq "have") {
|
|
||||||
my $storePath = <STDIN>; chomp $storePath;
|
|
||||||
(my $infoFile) = findStorePath $storePath;
|
|
||||||
print STDOUT ($infoFile ? "1\n" : "0\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif ($cmd eq "info") {
|
|
||||||
my $storePath = <STDIN>; chomp $storePath;
|
|
||||||
(my $infoFile) = findStorePath $storePath;
|
|
||||||
if (!$infoFile) {
|
|
||||||
print "0\n";
|
|
||||||
next; # not an error
|
|
||||||
}
|
|
||||||
print "1\n";
|
|
||||||
|
|
||||||
my $deriver = "";
|
|
||||||
my @references = ();
|
|
||||||
|
|
||||||
open INFO, "<$infoFile" or die "cannot read info file $infoFile\n";
|
|
||||||
while (<INFO>) {
|
|
||||||
chomp;
|
|
||||||
/^([\w-]+): (.*)$/ or die "bad info file";
|
|
||||||
my $key = $1;
|
|
||||||
my $value = $2;
|
|
||||||
if ($key eq "Deriver") { $deriver = $value; }
|
|
||||||
elsif ($key eq "References") { @references = split ' ', $value; }
|
|
||||||
}
|
|
||||||
close INFO;
|
|
||||||
|
|
||||||
print "$deriver\n";
|
|
||||||
print scalar @references, "\n";
|
|
||||||
print "$_\n" foreach @references;
|
|
||||||
print "0\n"; # !!! showing size not supported (yet)
|
|
||||||
}
|
|
||||||
|
|
||||||
else { die "unknown command `$cmd'"; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
elsif ($ARGV[0] eq "--substitute") {
|
|
||||||
die unless scalar @ARGV == 2;
|
|
||||||
my $storePath = $ARGV[1];
|
|
||||||
(my $infoFile, my $sourcePath) = findStorePath $storePath;
|
|
||||||
die unless $infoFile;
|
|
||||||
print "\n*** Copying `$storePath' from `$sourcePath'\n\n";
|
|
||||||
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $storePath") == 0
|
|
||||||
or die "cannot copy `$sourcePath' to `$storePath'";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
else { die; }
|
|
||||||
@@ -5,13 +5,22 @@ use readmanifest;
|
|||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
use File::Temp qw(tempdir);
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
my $manifestDir = "@localstatedir@/nix/manifests";
|
||||||
|
|
||||||
STDOUT->autoflush(1);
|
|
||||||
|
|
||||||
my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "@localstatedir@/nix/manifests");
|
|
||||||
my $logFile = "@localstatedir@/log/nix/downloads";
|
my $logFile = "@localstatedir@/log/nix/downloads";
|
||||||
|
|
||||||
|
open LOGFILE, ">>$logFile" or die "cannot open log file $logFile";
|
||||||
|
|
||||||
|
# Create a temporary directory.
|
||||||
|
my $tmpDir = tempdir("nix-download.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
|
or die "cannot create a temporary directory";
|
||||||
|
|
||||||
|
chdir $tmpDir or die "cannot change to `$tmpDir': $!";
|
||||||
|
|
||||||
|
my $tmpNar = "$tmpDir/nar";
|
||||||
|
my $tmpNar2 = "$tmpDir/nar2";
|
||||||
|
|
||||||
|
END { unlink $tmpNar; unlink $tmpNar2; rmdir $tmpDir; }
|
||||||
|
|
||||||
|
|
||||||
# Load all manifests.
|
# Load all manifests.
|
||||||
my %narFiles;
|
my %narFiles;
|
||||||
@@ -19,56 +28,44 @@ my %localPaths;
|
|||||||
my %patches;
|
my %patches;
|
||||||
|
|
||||||
for my $manifest (glob "$manifestDir/*.nixmanifest") {
|
for my $manifest (glob "$manifestDir/*.nixmanifest") {
|
||||||
my $version = readManifest($manifest, \%narFiles, \%localPaths, \%patches);
|
# print STDERR "reading $manifest\n";
|
||||||
if ($version < 3) {
|
if (readManifest($manifest, \%narFiles, \%localPaths, \%patches) < 3) {
|
||||||
print STDERR "you have an old-style manifest `$manifest'; please delete it\n";
|
print STDERR "you have an old-style manifest `$manifest'; please delete it\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
if ($version >= 10) {
|
|
||||||
print STDERR "manifest `$manifest' is too new; please delete it or upgrade Nix\n";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Parse the arguments.
|
# Parse the arguments.
|
||||||
|
|
||||||
if ($ARGV[0] eq "--query") {
|
if ($ARGV[0] eq "--query-paths") {
|
||||||
|
foreach my $storePath (keys %narFiles) { print "$storePath\n"; }
|
||||||
|
foreach my $storePath (keys %localPaths) { print "$storePath\n"; }
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (<STDIN>) {
|
elsif ($ARGV[0] eq "--query-info") {
|
||||||
my $cmd = $_; chomp $cmd;
|
shift @ARGV;
|
||||||
|
foreach my $storePath (@ARGV) {
|
||||||
if ($cmd eq "have") {
|
my $info;
|
||||||
my $storePath = <STDIN>; chomp $storePath;
|
if (defined $narFiles{$storePath}) {
|
||||||
print STDOUT ((defined $narFiles{$storePath} or defined $localPaths{$storePath})
|
$info = @{$narFiles{$storePath}}[0];
|
||||||
? "1\n" : "0\n");
|
|
||||||
}
|
}
|
||||||
|
elsif (defined $localPaths{$storePath}) {
|
||||||
elsif ($cmd eq "info") {
|
$info = @{$localPaths{$storePath}}[0];
|
||||||
my $storePath = <STDIN>; chomp $storePath;
|
}
|
||||||
my $info;
|
else {
|
||||||
if (defined $narFiles{$storePath}) {
|
next; # not an error
|
||||||
$info = @{$narFiles{$storePath}}[0];
|
}
|
||||||
}
|
print "$storePath\n";
|
||||||
elsif (defined $localPaths{$storePath}) {
|
print "$info->{deriver}\n";
|
||||||
$info = @{$localPaths{$storePath}}[0];
|
my @references = split " ", $info->{references};
|
||||||
}
|
my $count = scalar @references;
|
||||||
else {
|
print "$count\n";
|
||||||
print "0\n";
|
foreach my $reference (@references) {
|
||||||
next; # not an error
|
print "$reference\n";
|
||||||
}
|
|
||||||
print "1\n";
|
|
||||||
print "$info->{deriver}\n";
|
|
||||||
my @references = split " ", $info->{references};
|
|
||||||
print scalar @references, "\n";
|
|
||||||
print "$_\n" foreach @references;
|
|
||||||
my $size = $info->{size} || 0;
|
|
||||||
print "$size\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else { die "unknown command `$cmd'"; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,18 +78,6 @@ die unless scalar @ARGV == 2;
|
|||||||
my $targetPath = $ARGV[1];
|
my $targetPath = $ARGV[1];
|
||||||
|
|
||||||
|
|
||||||
# Create a temporary directory.
|
|
||||||
my $tmpDir = tempdir("nix-download.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
|
||||||
or die "cannot create a temporary directory";
|
|
||||||
|
|
||||||
chdir $tmpDir or die "cannot change to `$tmpDir': $!";
|
|
||||||
|
|
||||||
my $tmpNar = "$tmpDir/nar";
|
|
||||||
my $tmpNar2 = "$tmpDir/nar2";
|
|
||||||
|
|
||||||
|
|
||||||
open LOGFILE, ">>$logFile" or die "cannot open log file $logFile";
|
|
||||||
|
|
||||||
my $date = strftime ("%F %H:%M:%S UTC", gmtime (time));
|
my $date = strftime ("%F %H:%M:%S UTC", gmtime (time));
|
||||||
print LOGFILE "$$ get $targetPath $date\n";
|
print LOGFILE "$$ get $targetPath $date\n";
|
||||||
|
|
||||||
@@ -105,7 +90,7 @@ foreach my $localPath (@{$localPathList}) {
|
|||||||
my $sourcePath = $localPath->{copyFrom};
|
my $sourcePath = $localPath->{copyFrom};
|
||||||
if (-e $sourcePath) {
|
if (-e $sourcePath) {
|
||||||
print "\n*** Step 1/1: copying from $sourcePath\n";
|
print "\n*** Step 1/1: copying from $sourcePath\n";
|
||||||
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $targetPath") == 0
|
system("@bindir@/nix-store --dump $sourcePath | @bindir@/nix-store --restore $targetPath") == 0
|
||||||
or die "cannot copy `$sourcePath' to `$targetPath'";
|
or die "cannot copy `$sourcePath' to `$targetPath'";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
@@ -154,7 +139,7 @@ addToQueue $targetPath;
|
|||||||
|
|
||||||
sub isValidPath {
|
sub isValidPath {
|
||||||
my $p = shift;
|
my $p = shift;
|
||||||
return system("$binDir/nix-store --check-validity '$p' 2> /dev/null") == 0;
|
return system("@bindir@/nix-store --check-validity '$p' 2> /dev/null") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parseHash {
|
sub parseHash {
|
||||||
@@ -188,13 +173,15 @@ while ($queueFront < scalar @queue) {
|
|||||||
my ($baseHashAlgo, $baseHash) = parseHash $patch->{baseHash};
|
my ($baseHashAlgo, $baseHash) = parseHash $patch->{baseHash};
|
||||||
my $format = "--base32";
|
my $format = "--base32";
|
||||||
$format = "" if $baseHashAlgo eq "md5";
|
$format = "" if $baseHashAlgo eq "md5";
|
||||||
my $hash = `$binDir/nix-hash --type '$baseHashAlgo' $format "$patch->{basePath}"`;
|
my $hash = `@bindir@/nix-hash --type '$baseHashAlgo' $format "$patch->{basePath}"`;
|
||||||
chomp $hash;
|
chomp $hash;
|
||||||
|
# print " MY HASH is $hash\n";
|
||||||
if ($hash ne $baseHash) {
|
if ($hash ne $baseHash) {
|
||||||
print LOGFILE "$$ rejecting $patch->{basePath}\n";
|
print LOGFILE "$$ rejecting $patch->{basePath}\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# print " PATCH from $patch->{basePath}\n";
|
||||||
addToQueue $patch->{basePath};
|
addToQueue $patch->{basePath};
|
||||||
addEdge $patch->{basePath}, $u, $patch->{size}, "patch", $patch;
|
addEdge $patch->{basePath}, $u, $patch->{size}, "patch", $patch;
|
||||||
}
|
}
|
||||||
@@ -202,12 +189,10 @@ while ($queueFront < scalar @queue) {
|
|||||||
# Add NAR file edges to the start node.
|
# Add NAR file edges to the start node.
|
||||||
my $narFileList = $narFiles{$u};
|
my $narFileList = $narFiles{$u};
|
||||||
foreach my $narFile (@{$narFileList}) {
|
foreach my $narFile (@{$narFileList}) {
|
||||||
# !!! how to handle files whose size is not known in advance?
|
# print " NAR from $narFile->{url}\n";
|
||||||
# For now, assume some arbitrary size (1 MB).
|
addEdge "start", $u, $narFile->{size}, "narfile", $narFile;
|
||||||
addEdge "start", $u, ($narFile->{size} || 1000000), "narfile", $narFile;
|
|
||||||
if ($u eq $targetPath) {
|
if ($u eq $targetPath) {
|
||||||
my $size = $narFile->{size} || -1;
|
print LOGFILE "$$ full-download-would-be $narFile->{size}\n";
|
||||||
print LOGFILE "$$ full-download-would-be $size\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +218,8 @@ while (scalar @todo > 0) {
|
|||||||
|
|
||||||
my $u_ = $graph{$u};
|
my $u_ = $graph{$u};
|
||||||
|
|
||||||
|
# print "IN $u $u_->{d}\n";
|
||||||
|
|
||||||
foreach my $edge (@{$u_->{edges}}) {
|
foreach my $edge (@{$u_->{edges}}) {
|
||||||
my $v_ = $graph{$edge->{end}};
|
my $v_ = $graph{$edge->{end}};
|
||||||
if ($v_->{d} > $u_->{d} + $edge->{weight}) {
|
if ($v_->{d} > $u_->{d} + $edge->{weight}) {
|
||||||
@@ -240,6 +227,7 @@ while (scalar @todo > 0) {
|
|||||||
# Store the edge; to edge->start is actually the
|
# Store the edge; to edge->start is actually the
|
||||||
# predecessor.
|
# predecessor.
|
||||||
$v_->{pred} = $edge;
|
$v_->{pred} = $edge;
|
||||||
|
# print " RELAX $edge->{end} $v_->{d}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,18 +249,20 @@ while ($cur ne "start") {
|
|||||||
my $curStep = 1;
|
my $curStep = 1;
|
||||||
my $maxStep = scalar @path;
|
my $maxStep = scalar @path;
|
||||||
|
|
||||||
sub downloadFile {
|
sub downloadFile {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
|
my ($hashAlgo, $hash) = parseHash(shift);
|
||||||
$ENV{"PRINT_PATH"} = 1;
|
$ENV{"PRINT_PATH"} = 1;
|
||||||
$ENV{"QUIET"} = 1;
|
$ENV{"QUIET"} = 1;
|
||||||
my ($hash, $path) = `$binDir/nix-prefetch-url '$url'`;
|
$ENV{"NIX_HASH_ALGO"} = $hashAlgo;
|
||||||
|
my ($hash2, $path) = `@bindir@/nix-prefetch-url '$url' '$hash'`;
|
||||||
die "download of `$url' failed" unless $? == 0;
|
die "download of `$url' failed" unless $? == 0;
|
||||||
|
chomp $hash2;
|
||||||
chomp $path;
|
chomp $path;
|
||||||
|
die "hash mismatch, expected $hash, got $hash2" if $hash ne $hash2;
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $finalNarHash;
|
|
||||||
|
|
||||||
while (scalar @path > 0) {
|
while (scalar @path > 0) {
|
||||||
my $edge = pop @path;
|
my $edge = pop @path;
|
||||||
my $u = $edge->{start};
|
my $u = $edge->{start};
|
||||||
@@ -289,7 +279,7 @@ while (scalar @path > 0) {
|
|||||||
# as a base to one or more patches. So turn the base path
|
# as a base to one or more patches. So turn the base path
|
||||||
# into a NAR archive, to which we can apply the patch.
|
# into a NAR archive, to which we can apply the patch.
|
||||||
print " packing base path...\n";
|
print " packing base path...\n";
|
||||||
system("$binDir/nix-store --dump $v > $tmpNar") == 0
|
system("@bindir@/nix-store --dump $v > $tmpNar") == 0
|
||||||
or die "cannot dump `$v'";
|
or die "cannot dump `$v'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +292,7 @@ while (scalar @path > 0) {
|
|||||||
|
|
||||||
# Download the patch.
|
# Download the patch.
|
||||||
print " downloading patch...\n";
|
print " downloading patch...\n";
|
||||||
my $patchPath = downloadFile "$patch->{url}";
|
my $patchPath = downloadFile "$patch->{url}", "$patch->{hash}";
|
||||||
|
|
||||||
# Apply the patch to the NAR archive produced in step 1 (for
|
# Apply the patch to the NAR archive produced in step 1 (for
|
||||||
# the already present path) or a later step (for patch sequences).
|
# the already present path) or a later step (for patch sequences).
|
||||||
@@ -317,23 +307,20 @@ while (scalar @path > 0) {
|
|||||||
# This was the last patch. Unpack the final NAR archive
|
# This was the last patch. Unpack the final NAR archive
|
||||||
# into the target path.
|
# into the target path.
|
||||||
print " unpacking patched archive...\n";
|
print " unpacking patched archive...\n";
|
||||||
system("$binDir/nix-store --restore $v < $tmpNar2") == 0
|
system("@bindir@/nix-store --restore $v < $tmpNar2") == 0
|
||||||
or die "cannot unpack $tmpNar2 into `$v'";
|
or die "cannot unpack $tmpNar2 into `$v'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$finalNarHash = $patch->{narHash};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($edge->{type} eq "narfile") {
|
elsif ($edge->{type} eq "narfile") {
|
||||||
my $narFile = $edge->{info};
|
my $narFile = $edge->{info};
|
||||||
print "downloading `$narFile->{url}' into `$v'\n";
|
print "downloading `$narFile->{url}' into `$v'\n";
|
||||||
|
|
||||||
my $size = $narFile->{size} || -1;
|
print LOGFILE "$$ narfile $narFile->{url} $narFile->{size} $v\n";
|
||||||
print LOGFILE "$$ narfile $narFile->{url} $size $v\n";
|
|
||||||
|
|
||||||
# Download the archive.
|
# Download the archive.
|
||||||
print " downloading archive...\n";
|
print " downloading archive...\n";
|
||||||
my $narFilePath = downloadFile "$narFile->{url}";
|
my $narFilePath = downloadFile "$narFile->{url}", "$narFile->{hash}";
|
||||||
|
|
||||||
if ($curStep < $maxStep) {
|
if ($curStep < $maxStep) {
|
||||||
# The archive will be used a base to a patch.
|
# The archive will be used a base to a patch.
|
||||||
@@ -342,39 +329,14 @@ while (scalar @path > 0) {
|
|||||||
} else {
|
} else {
|
||||||
# Unpack the archive into the target path.
|
# Unpack the archive into the target path.
|
||||||
print " unpacking archive...\n";
|
print " unpacking archive...\n";
|
||||||
system("@bunzip2@ < '$narFilePath' | $binDir/nix-store --restore '$v'") == 0
|
system("@bunzip2@ < '$narFilePath' | @bindir@/nix-store --restore '$v'") == 0
|
||||||
or die "cannot unpack `$narFilePath' into `$v'";
|
or die "cannot unpack `$narFilePath' into `$v'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$finalNarHash = $narFile->{narHash};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$curStep++;
|
$curStep++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Make sure that the hash declared in the manifest matches what we
|
|
||||||
# downloaded and unpacked.
|
|
||||||
|
|
||||||
if (defined $finalNarHash) {
|
|
||||||
my ($hashAlgo, $hash) = parseHash $finalNarHash;
|
|
||||||
|
|
||||||
# The hash in the manifest can be either in base-16 or base-32.
|
|
||||||
# Handle both.
|
|
||||||
my $extraFlag =
|
|
||||||
($hashAlgo eq "sha256" && length($hash) != 64)
|
|
||||||
? "--base32" : "";
|
|
||||||
|
|
||||||
my $hash2 = `@bindir@/nix-hash --type $hashAlgo $extraFlag $targetPath`
|
|
||||||
or die "cannot compute hash of path `$targetPath'";
|
|
||||||
chomp $hash2;
|
|
||||||
|
|
||||||
die "hash mismatch in downloaded path $targetPath; expected $hash, got $hash2"
|
|
||||||
if $hash ne $hash2;
|
|
||||||
} else {
|
|
||||||
die "cannot check integrity of the downloaded path since its hash is not known";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
print LOGFILE "$$ success\n";
|
print LOGFILE "$$ success\n";
|
||||||
close LOGFILE;
|
close LOGFILE;
|
||||||
+9
-40
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
||||||
|
|
||||||
|
|
||||||
my $addDrvLink = 0;
|
my $addDrvLink = 0;
|
||||||
my $addOutLink = 1;
|
my $addOutLink = 1;
|
||||||
@@ -11,8 +9,6 @@ my $addOutLink = 1;
|
|||||||
my $outLink;
|
my $outLink;
|
||||||
my $drvLink;
|
my $drvLink;
|
||||||
|
|
||||||
my $dryRun = 0;
|
|
||||||
|
|
||||||
my @instArgs = ();
|
my @instArgs = ();
|
||||||
my @buildArgs = ();
|
my @buildArgs = ();
|
||||||
my @exprs = ();
|
my @exprs = ();
|
||||||
@@ -77,41 +73,22 @@ EOF
|
|||||||
|
|
||||||
elsif ($arg eq "--attr" or $arg eq "-A") {
|
elsif ($arg eq "--attr" or $arg eq "-A") {
|
||||||
$n++;
|
$n++;
|
||||||
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
die "$0: `--attr' requires an argument\n" unless $n < scalar @ARGV;
|
||||||
push @instArgs, ("--attr", $ARGV[$n]);
|
push @instArgs, ("--attr", $ARGV[$n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($arg eq "--arg" || $arg eq "--argstr") {
|
elsif ($arg eq "--arg") {
|
||||||
die "$0: `$arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
die "$0: `--arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
||||||
push @instArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
push @instArgs, ("--arg", $ARGV[$n + 1], $ARGV[$n + 2]);
|
||||||
$n += 2;
|
$n += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($arg eq "--log-type") {
|
elsif ($arg eq "--max-jobs" or $arg eq "-j" or $arg eq "--max-silent-time") {
|
||||||
$n++;
|
|
||||||
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
|
||||||
push @instArgs, ($arg, $ARGV[$n]);
|
|
||||||
push @buildArgs, ($arg, $ARGV[$n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif ($arg eq "--option") {
|
|
||||||
die "$0: `$arg' requires two arguments\n" unless $n + 2 < scalar @ARGV;
|
|
||||||
push @instArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
|
||||||
push @buildArgs, ($arg, $ARGV[$n + 1], $ARGV[$n + 2]);
|
|
||||||
$n += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif ($arg eq "--max-jobs" or $arg eq "-j" or $arg eq "--max-silent-time" or $arg eq "--log-type") {
|
|
||||||
$n++;
|
$n++;
|
||||||
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
|
||||||
push @buildArgs, ($arg, $ARGV[$n]);
|
push @buildArgs, ($arg, $ARGV[$n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($arg eq "--dry-run") {
|
|
||||||
push @buildArgs, "--dry-run";
|
|
||||||
$dryRun = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
elsif (substr($arg, 0, 1) eq "-") {
|
elsif (substr($arg, 0, 1) eq "-") {
|
||||||
push @buildArgs, $arg;
|
push @buildArgs, $arg;
|
||||||
}
|
}
|
||||||
@@ -140,12 +117,9 @@ foreach my $expr (@exprs) {
|
|||||||
# Instantiate.
|
# Instantiate.
|
||||||
my @drvPaths;
|
my @drvPaths;
|
||||||
# !!! would prefer the perl 5.8.0 pipe open feature here.
|
# !!! would prefer the perl 5.8.0 pipe open feature here.
|
||||||
my $pid = open(DRVPATHS, "-|") || exec "$binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
|
my $pid = open(DRVPATHS, "-|") || exec "@bindir@/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
|
||||||
while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
|
while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
|
||||||
if (!close DRVPATHS) {
|
close DRVPATHS or exit 1;
|
||||||
die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127);
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $drvPath (@drvPaths) {
|
foreach my $drvPath (@drvPaths) {
|
||||||
my $target = readlink $drvPath or die "cannot read symlink `$drvPath'";
|
my $target = readlink $drvPath or die "cannot read symlink `$drvPath'";
|
||||||
@@ -154,15 +128,10 @@ foreach my $expr (@exprs) {
|
|||||||
|
|
||||||
# Build.
|
# Build.
|
||||||
my @outPaths;
|
my @outPaths;
|
||||||
$pid = open(OUTPATHS, "-|") || exec "$binDir/nix-store", "--add-root", $outLink, "--indirect", "-rv",
|
$pid = open(OUTPATHS, "-|") || exec "@bindir@/nix-store", "--add-root", $outLink, "--indirect", "-rv",
|
||||||
@buildArgs, @drvPaths;
|
@buildArgs, @drvPaths;
|
||||||
while (<OUTPATHS>) {chomp; push @outPaths, $_;}
|
while (<OUTPATHS>) {chomp; push @outPaths, $_;}
|
||||||
if (!close OUTPATHS) {
|
close OUTPATHS or exit 1;
|
||||||
die "nix-store killed by signal " . ($? & 127) . "\n" if ($? & 127);
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
next if $dryRun;
|
|
||||||
|
|
||||||
foreach my $outPath (@outPaths) {
|
foreach my $outPath (@outPaths) {
|
||||||
my $target = readlink $outPath or die "cannot read symlink `$outPath'";
|
my $target = readlink $outPath or die "cannot read symlink `$outPath'";
|
||||||
|
|||||||
@@ -125,13 +125,15 @@ sub update {
|
|||||||
|
|
||||||
my $rootFile = "$rootsDir/per-user/$userName/channels";
|
my $rootFile = "$rootsDir/per-user/$userName/channels";
|
||||||
|
|
||||||
# Build the Nix expression.
|
# Instantiate the Nix expression.
|
||||||
print "unpacking channel Nix expressions...\n";
|
print "unpacking channel Nix expressions...\n";
|
||||||
my $outPath = `\\
|
my $storeExpr = `@bindir@/nix-instantiate --add-root '$rootFile'.tmp @datadir@/nix/corepkgs/channels/unpack.nix --argstr system @system@ --arg inputs '$inputs'`
|
||||||
@bindir@/nix-build --out-link '$rootFile' --drv-link '$rootFile'.tmp \\
|
or die "cannot instantiate Nix expression";
|
||||||
@datadir@/nix/corepkgs/channels/unpack.nix \\
|
chomp $storeExpr;
|
||||||
--argstr system @system@ --arg inputs '$inputs'`
|
|
||||||
or die "cannot unpack the channels";
|
# Build the resulting derivation.
|
||||||
|
my $outPath = `@bindir@/nix-store --add-root '$rootFile' -r '$storeExpr'`
|
||||||
|
or die "cannot realise store expression";
|
||||||
chomp $outPath;
|
chomp $outPath;
|
||||||
|
|
||||||
unlink "$rootFile.tmp";
|
unlink "$rootFile.tmp";
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ use strict;
|
|||||||
|
|
||||||
my $profilesDir = "@localstatedir@/nix/profiles";
|
my $profilesDir = "@localstatedir@/nix/profiles";
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
||||||
|
|
||||||
|
|
||||||
# Process the command line arguments.
|
# Process the command line arguments.
|
||||||
my @args = ();
|
my @args = ();
|
||||||
@@ -36,7 +34,7 @@ sub removeOldGenerations {
|
|||||||
$name = $dir . "/" . $name;
|
$name = $dir . "/" . $name;
|
||||||
if (-l $name && (readlink($name) =~ /link/)) {
|
if (-l $name && (readlink($name) =~ /link/)) {
|
||||||
print STDERR "removing old generations of profile $name\n";
|
print STDERR "removing old generations of profile $name\n";
|
||||||
system("$binDir/nix-env", "-p", $name, "--delete-generations", "old");
|
system("@bindir@/nix-env", "-p", $name, "--delete-generations", "old");
|
||||||
}
|
}
|
||||||
elsif (! -l $name && -d $name) {
|
elsif (! -l $name && -d $name) {
|
||||||
removeOldGenerations $name;
|
removeOldGenerations $name;
|
||||||
@@ -50,4 +48,4 @@ removeOldGenerations $profilesDir if $removeOld;
|
|||||||
|
|
||||||
|
|
||||||
# Run the actual garbage collector.
|
# Run the actual garbage collector.
|
||||||
exec "$binDir/nix-store", "--gc", @args;
|
exec "@bindir@/nix-store", "--gc", @args;
|
||||||
+28
-11
@@ -1,11 +1,12 @@
|
|||||||
#! @perl@ -w
|
#! @perl@ -w
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
||||||
|
|
||||||
if (scalar @ARGV < 1) {
|
if (scalar @ARGV < 1) {
|
||||||
print STDERR <<EOF
|
print STDERR <<EOF
|
||||||
Usage: nix-copy-closure [--from | --to] HOSTNAME [--sign] [--gzip] PATHS...
|
Usage: nix-copy-closure [--from | --to] HOSTNAME [--sign] PATHS...
|
||||||
EOF
|
EOF
|
||||||
;
|
;
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -55,17 +56,29 @@ while (@ARGV) {
|
|||||||
if ($toMode) { # Copy TO the remote machine.
|
if ($toMode) { # Copy TO the remote machine.
|
||||||
|
|
||||||
my @allStorePaths;
|
my @allStorePaths;
|
||||||
|
my %storePathsSeen;
|
||||||
|
|
||||||
# Get the closure of this path.
|
foreach my $storePath (@storePaths) {
|
||||||
my $pid = open(READ, "$binDir/nix-store --query --requisites @storePaths|") or die;
|
# $arg might be a symlink to the store, so resolve it.
|
||||||
|
my $storePath2 = (`$binDir/nix-store --query --resolve '$storePath'`
|
||||||
|
or die "cannot resolve `$storePath'");
|
||||||
|
chomp $storePath2;
|
||||||
|
|
||||||
|
# Get the closure of this path.
|
||||||
|
my $pid = open(READ,
|
||||||
|
"$binDir/nix-store --query --requisites '$storePath2'|") or die;
|
||||||
|
|
||||||
while (<READ>) {
|
while (<READ>) {
|
||||||
chomp;
|
chomp;
|
||||||
die "bad: $_" unless /^\//;
|
die "bad: $_" unless /^\//;
|
||||||
push @allStorePaths, $_;
|
if (!defined $storePathsSeen{$_}) {
|
||||||
}
|
push @allStorePaths, $_;
|
||||||
|
$storePathsSeen{$_} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
close READ or die "nix-store failed: $?";
|
close READ or die "nix-store failed: $?";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Ask the remote host which paths are invalid.
|
# Ask the remote host which paths are invalid.
|
||||||
@@ -99,11 +112,15 @@ else { # Copy FROM the remote machine.
|
|||||||
"ssh @sshOpts $sshHost nix-store --query --requisites @storePaths|") or die;
|
"ssh @sshOpts $sshHost nix-store --query --requisites @storePaths|") or die;
|
||||||
|
|
||||||
my @allStorePaths;
|
my @allStorePaths;
|
||||||
|
my %storePathsSeen;
|
||||||
|
|
||||||
while (<READ>) {
|
while (<READ>) {
|
||||||
chomp;
|
chomp;
|
||||||
die "bad: $_" unless /^\//;
|
die "bad: $_" unless /^\//;
|
||||||
push @allStorePaths, $_;
|
if (!defined $storePathsSeen{$_}) {
|
||||||
|
push @allStorePaths, $_;
|
||||||
|
$storePathsSeen{$_} = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close READ or die "nix-store on remote machine `$sshHost' failed: $?";
|
close READ or die "nix-store on remote machine `$sshHost' failed: $?";
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
#! /bin/sh
|
|
||||||
|
|
||||||
export HOME=/tmp
|
|
||||||
export NIX_REMOTE=daemon
|
|
||||||
|
|
||||||
TMP_DIR="${TMP_DIR:-/tmp/nix-export}"
|
|
||||||
|
|
||||||
@coreutils@/mkdir -p "$TMP_DIR" || true
|
|
||||||
@coreutils@/chmod a+r "$TMP_DIR"
|
|
||||||
|
|
||||||
needed_path="?$QUERY_STRING"
|
|
||||||
needed_path="${needed_path#*[?&]needed_path=}"
|
|
||||||
needed_path="${needed_path%%&*}"
|
|
||||||
#needed_path="$(echo $needed_path | ./unhttp)"
|
|
||||||
needed_path="${needed_path//%2B/+}"
|
|
||||||
needed_path="${needed_path//%3D/=}"
|
|
||||||
|
|
||||||
echo needed_path: "$needed_path" >&2
|
|
||||||
|
|
||||||
NIX_STORE="${NIX_STORE_DIR:-/nix/store}"
|
|
||||||
|
|
||||||
echo NIX_STORE: "${NIX_STORE}" >&2
|
|
||||||
|
|
||||||
full_path="${NIX_STORE}"/"$needed_path"
|
|
||||||
|
|
||||||
if [ "$needed_path" != "${needed_path%.drv}" ]; then
|
|
||||||
echo "Status: 403 You should create the derivation file yourself"
|
|
||||||
echo "Content-Type: text/plain"
|
|
||||||
echo
|
|
||||||
echo "Refusing to disclose derivation contents"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if @bindir@/nix-store --check-validity "$full_path"; then
|
|
||||||
if ! [ -e nix-export/"$needed_path".nar.gz ]; then
|
|
||||||
@bindir@/nix-store --export "$full_path" | @gzip@ > "$TMP_DIR"/"$needed_path".nar.gz
|
|
||||||
@coreutils@/ln -fs "$TMP_DIR"/"$needed_path".nar.gz nix-export/"$needed_path".nar.gz
|
|
||||||
fi;
|
|
||||||
echo "Status: 301 Moved"
|
|
||||||
echo "Location: nix-export/"$needed_path".nar.gz"
|
|
||||||
echo
|
|
||||||
else
|
|
||||||
echo "Status: 404 No such path found"
|
|
||||||
echo "Content-Type: text/plain"
|
|
||||||
echo
|
|
||||||
echo "Path not found:"
|
|
||||||
echo "$needed_path"
|
|
||||||
echo "checked:"
|
|
||||||
echo "$full_path"
|
|
||||||
fi
|
|
||||||
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use File::Temp qw(tempdir);
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
||||||
|
|
||||||
|
|
||||||
sub usageError {
|
sub usageError {
|
||||||
print STDERR <<EOF;
|
print STDERR <<EOF;
|
||||||
@@ -61,7 +59,7 @@ if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
|
|||||||
$ENV{"NIX_HAVE_TERMINAL"} = "1";
|
$ENV{"NIX_HAVE_TERMINAL"} = "1";
|
||||||
$ENV{"LD_LIBRARY_PATH"} = "";
|
$ENV{"LD_LIBRARY_PATH"} = "";
|
||||||
foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") {
|
foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") {
|
||||||
exec($term, "-e", "$binDir/nix-install-package", @ARGV);
|
exec($term, "-e", "@bindir@/nix-install-package", @ARGV);
|
||||||
}
|
}
|
||||||
die "cannot execute `xterm'";
|
die "cannot execute `xterm'";
|
||||||
}
|
}
|
||||||
@@ -123,18 +121,13 @@ if ($interactive) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Store the manifest in the temporary directory so that we don't
|
|
||||||
# pollute /nix/var/nix/manifests.
|
|
||||||
$ENV{NIX_MANIFESTS_DIR} = $tmpDir;
|
|
||||||
|
|
||||||
|
|
||||||
print "\nPulling manifests...\n";
|
print "\nPulling manifests...\n";
|
||||||
system("$binDir/nix-pull", $manifestURL) == 0
|
system("@bindir@/nix-pull", $manifestURL) == 0
|
||||||
or barf "nix-pull failed: $?";
|
or barf "nix-pull failed: $?";
|
||||||
|
|
||||||
|
|
||||||
print "\nInstalling package...\n";
|
print "\nInstalling package...\n";
|
||||||
system("$binDir/nix-env", "--install", $outPath, "--force-name", $drvName, @extraNixEnvArgs) == 0
|
system("@bindir@/nix-env", "--install", $outPath, "--force-name", $drvName, @extraNixEnvArgs) == 0
|
||||||
or barf "nix-env failed: $?";
|
or barf "nix-env failed: $?";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#! @perl@ -w
|
||||||
|
|
||||||
|
# This tool computes the closure of a path (using "nix-store --query
|
||||||
|
# --requisites") and puts the contents of each path in the closure in
|
||||||
|
# a big NAR archive that can be installed on another Nix installation
|
||||||
|
# using "nix-unpack-closure".
|
||||||
|
|
||||||
|
# TODO: make this program "streamy", i.e., don't use a temporary
|
||||||
|
# directory.
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
||||||
|
my $tmpDir = tempdir("nix-pack-closure.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
|
or die "cannot create a temporary directory";
|
||||||
|
|
||||||
|
mkdir "$tmpDir/contents", 0755 or die;
|
||||||
|
mkdir "$tmpDir/references", 0755 or die;
|
||||||
|
mkdir "$tmpDir/derivers", 0755 or die;
|
||||||
|
|
||||||
|
open TOPLEVEL, ">$tmpDir/top-level" or die;
|
||||||
|
|
||||||
|
|
||||||
|
my %storePaths;
|
||||||
|
|
||||||
|
|
||||||
|
while (@ARGV) {
|
||||||
|
my $storePath = shift @ARGV;
|
||||||
|
|
||||||
|
# $storePath might be a symlink to the store, so resolve it.
|
||||||
|
$storePath = (`$binDir/nix-store --query --resolve '$storePath'`
|
||||||
|
or die "cannot resolve `$storePath'");
|
||||||
|
chomp $storePath;
|
||||||
|
print TOPLEVEL $storePath, "\n";
|
||||||
|
|
||||||
|
# Get the closure of this path.
|
||||||
|
my $pid = open(READ,
|
||||||
|
"$binDir/nix-store --query --requisites '$storePath'|") or die;
|
||||||
|
|
||||||
|
while (<READ>) {
|
||||||
|
chomp;
|
||||||
|
die "bad: $_" unless /^\//;
|
||||||
|
$storePaths{$_} = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
close READ or die "nix-store failed: $?";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
close TOPLEVEL or die;
|
||||||
|
|
||||||
|
|
||||||
|
foreach my $storePath (sort(keys %storePaths)) {
|
||||||
|
print STDERR "packing `$storePath'...\n";
|
||||||
|
|
||||||
|
$storePath =~ /\/([^\/]+)$/;
|
||||||
|
my $name = $1;
|
||||||
|
|
||||||
|
system("$binDir/nix-store --dump '$storePath' > $tmpDir/contents/$name") == 0
|
||||||
|
or die "nix-store --dump failed on `$storePath': $?";
|
||||||
|
|
||||||
|
system("$binDir/nix-store --query --references '$storePath' > $tmpDir/references/$name") == 0
|
||||||
|
or die "nix-store --query --references failed on `$storePath': $?";
|
||||||
|
|
||||||
|
system("$binDir/nix-store --query --deriver '$storePath' > $tmpDir/derivers/$name") == 0
|
||||||
|
or die "nix-store --query --deriver failed on `$storePath': $?";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Write a NAR archive of everything to standard output.
|
||||||
|
system("nix-store --dump '$tmpDir'") == 0
|
||||||
|
or die "nix-store --dump failed";
|
||||||
@@ -36,62 +36,19 @@ if test -n "$expHash"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
mkTempDir() {
|
|
||||||
if test -n "$tmpPath"; then return; fi
|
|
||||||
local i=0
|
|
||||||
while true; do
|
|
||||||
if test -z "$TMPDIR"; then TMPDIR=/tmp; fi
|
|
||||||
tmpPath=$TMPDIR/nix-prefetch-url-$$-$i
|
|
||||||
if mkdir "$tmpPath"; then break; fi
|
|
||||||
# !!! to bad we can't check for ENOENT in mkdir, so this check
|
|
||||||
# is slightly racy (it bombs out if somebody just removed
|
|
||||||
# $tmpPath...).
|
|
||||||
if ! test -e "$tmpPath"; then exit 1; fi
|
|
||||||
i=$((i + 1))
|
|
||||||
done
|
|
||||||
trap removeTempDir EXIT SIGINT SIGQUIT
|
|
||||||
}
|
|
||||||
|
|
||||||
removeTempDir() {
|
|
||||||
if test -n "$tmpPath"; then
|
|
||||||
rm -rf "$tmpPath" || true
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
doDownload() {
|
doDownload() {
|
||||||
@curl@ $cacheFlags --fail --location --max-redirs 20 --disable-epsv \
|
@curl@ $cacheFlags --fail -# --location --max-redirs 20 --disable-epsv \
|
||||||
--cookie-jar $tmpPath/cookies "$url" -o $tmpFile
|
--cookie-jar $tmpPath/cookies "$url" -o $tmpFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Hack to support the mirror:// scheme from Nixpkgs.
|
|
||||||
if test "${url:0:9}" = "mirror://"; then
|
|
||||||
if test -z "$NIXPKGS_ALL"; then
|
|
||||||
echo "Resolving mirror:// URLs requires Nixpkgs. Please point \$NIXPKGS_ALL at a Nixpkgs tree." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkTempDir
|
|
||||||
nix-build "$NIXPKGS_ALL" -A resolveMirrorURLs --argstr url "$url" -o $tmpPath/urls > /dev/null
|
|
||||||
|
|
||||||
expanded=($(cat $tmpPath/urls))
|
|
||||||
if test "${#expanded[*]}" = 0; then
|
|
||||||
echo "$0: cannot resolve $url." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$url expands to ${expanded[*]} (using ${expanded[0]})" >&2
|
|
||||||
url="${expanded[0]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# If we don't know the hash or a file with that hash doesn't exist,
|
# If we don't know the hash or a file with that hash doesn't exist,
|
||||||
# download the file and add it to the store.
|
# download the file and add it to the store.
|
||||||
if test -z "$finalPath"; then
|
if test -z "$finalPath"; then
|
||||||
|
|
||||||
mkTempDir
|
tmpPath=/tmp/nix-prefetch-url-$$ # !!! security?
|
||||||
tmpFile=$tmpPath/$name
|
tmpFile=$tmpPath/$name
|
||||||
|
mkdir $tmpPath # !!! retry if tmpPath already exists
|
||||||
|
|
||||||
# Optionally do timestamp-based caching of the download.
|
# Optionally do timestamp-based caching of the download.
|
||||||
# Actually, the only thing that we cache in $NIX_DOWNLOAD_CACHE is
|
# Actually, the only thing that we cache in $NIX_DOWNLOAD_CACHE is
|
||||||
@@ -100,7 +57,7 @@ if test -z "$finalPath"; then
|
|||||||
# garbage-collected independently.
|
# garbage-collected independently.
|
||||||
if test -n "$NIX_DOWNLOAD_CACHE"; then
|
if test -n "$NIX_DOWNLOAD_CACHE"; then
|
||||||
echo -n "$url" > $tmpPath/url
|
echo -n "$url" > $tmpPath/url
|
||||||
urlHash=$(@bindir@/nix-hash --type sha256 --base32 --flat $tmpPath/url)
|
urlHash=$(nix-hash --type sha256 --base32 --flat $tmpPath/url)
|
||||||
echo "$url" > "$NIX_DOWNLOAD_CACHE/$urlHash.url"
|
echo "$url" > "$NIX_DOWNLOAD_CACHE/$urlHash.url"
|
||||||
cachedHashFN="$NIX_DOWNLOAD_CACHE/$urlHash.$hashType"
|
cachedHashFN="$NIX_DOWNLOAD_CACHE/$urlHash.$hashType"
|
||||||
cachedTimestampFN="$NIX_DOWNLOAD_CACHE/$urlHash.stamp"
|
cachedTimestampFN="$NIX_DOWNLOAD_CACHE/$urlHash.stamp"
|
||||||
@@ -141,6 +98,8 @@ if test -z "$finalPath"; then
|
|||||||
# Add the downloaded file to the Nix store.
|
# Add the downloaded file to the Nix store.
|
||||||
finalPath=$(@bindir@/nix-store --add-fixed "$hashType" $tmpFile)
|
finalPath=$(@bindir@/nix-store --add-fixed "$hashType" $tmpFile)
|
||||||
|
|
||||||
|
if test -n "$tmpPath"; then rm -rf $tmpPath || true; fi
|
||||||
|
|
||||||
if test -n "$expHash" -a "$expHash" != "$hash"; then
|
if test -n "$expHash" -a "$expHash" != "$hash"; then
|
||||||
echo "hash mismatch for URL \`$url'" >&2
|
echo "hash mismatch for URL \`$url'" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -7,12 +7,5 @@ if test -n "$HOME"; then
|
|||||||
@coreutils@/ln -s "$_NIX_DEF_LINK" "$NIX_LINK"
|
@coreutils@/ln -s "$_NIX_DEF_LINK" "$NIX_LINK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export PATH=$NIX_LINK/bin:$PATH
|
export PATH=$NIX_LINK/bin:@prefix@/bin:$PATH
|
||||||
fi
|
|
||||||
|
|
||||||
# This is a quick hack to make fontconfig-based packages in Nixpkgs
|
|
||||||
# work out of the box on non-NixOS systems. Of course, we should
|
|
||||||
# really fix fontconfig...
|
|
||||||
if test -z "$FONTCONFIG_FILE" -a -e /etc/fonts/fonts.conf; then
|
|
||||||
export FONTCONFIG_FILE=/etc/fonts/fonts.conf
|
|
||||||
fi
|
fi
|
||||||
+15
-10
@@ -7,11 +7,17 @@ use readmanifest;
|
|||||||
my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
my $tmpDir = tempdir("nix-pull.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
or die "cannot create a temporary directory";
|
or die "cannot create a temporary directory";
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
my $libexecDir = ($ENV{"NIX_LIBEXEC_DIR"} or "@libexecdir@");
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
my $storeDir = ($ENV{"NIX_STORE_DIR"} or "@storedir@");
|
|
||||||
my $stateDir = ($ENV{"NIX_STATE_DIR"} or "@localstatedir@/nix");
|
my $libexecDir = $ENV{"NIX_LIBEXEC_DIR"};
|
||||||
my $manifestDir = ($ENV{"NIX_MANIFESTS_DIR"} or "$stateDir/manifests");
|
$libexecDir = "@libexecdir@" unless defined $libexecDir;
|
||||||
|
|
||||||
|
my $stateDir = $ENV{"NIX_STATE_DIR"};
|
||||||
|
$stateDir = "@localstatedir@/nix" unless defined $stateDir;
|
||||||
|
|
||||||
|
my $storeDir = $ENV{"NIX_STORE_DIR"};
|
||||||
|
$storeDir = "@storedir@" unless defined $storeDir;
|
||||||
|
|
||||||
|
|
||||||
# Prevent access problems in shared-stored installations.
|
# Prevent access problems in shared-stored installations.
|
||||||
@@ -63,11 +69,10 @@ sub processURL {
|
|||||||
print "obtaining list of Nix archives at `$url'...\n";
|
print "obtaining list of Nix archives at `$url'...\n";
|
||||||
$manifest = downloadFile $url;
|
$manifest = downloadFile $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $version = readManifest($manifest, \%narFiles, \%localPaths, \%patches);
|
|
||||||
|
|
||||||
die "`$url' is not a manifest or it is too old (i.e., for Nix <= 0.7)\n" if $version < 3;
|
if (readManifest($manifest, \%narFiles, \%localPaths, \%patches) < 3) {
|
||||||
die "manifest `$url' is too new\n" if $version >= 5;
|
die "`$url' is not manifest or it is too old (i.e., for Nix <= 0.7)\n";
|
||||||
|
}
|
||||||
|
|
||||||
if ($skipWrongStore) {
|
if ($skipWrongStore) {
|
||||||
foreach my $path (keys %narFiles) {
|
foreach my $path (keys %narFiles) {
|
||||||
@@ -87,7 +92,7 @@ sub processURL {
|
|||||||
or die "cannot hash `$manifest'";
|
or die "cannot hash `$manifest'";
|
||||||
chomp $hash;
|
chomp $hash;
|
||||||
|
|
||||||
my $finalPath = "$manifestDir/$baseName-$hash.nixmanifest";
|
my $finalPath = "$stateDir/manifests/$baseName-$hash.nixmanifest";
|
||||||
|
|
||||||
system("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0
|
system("@coreutils@/ln", "-sfn", "$manifest", "$finalPath") == 0
|
||||||
or die "cannot link `$finalPath to `$manifest'";
|
or die "cannot link `$finalPath to `$manifest'";
|
||||||
|
|||||||
+16
-14
@@ -16,7 +16,8 @@ my $curl = "@curl@ --fail --silent";
|
|||||||
my $extraCurlFlags = ${ENV{'CURL_FLAGS'}};
|
my $extraCurlFlags = ${ENV{'CURL_FLAGS'}};
|
||||||
$curl = "$curl $extraCurlFlags" if defined $extraCurlFlags;
|
$curl = "$curl $extraCurlFlags" if defined $extraCurlFlags;
|
||||||
|
|
||||||
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
||||||
my $dataDir = $ENV{"NIX_DATA_DIR"};
|
my $dataDir = $ENV{"NIX_DATA_DIR"};
|
||||||
$dataDir = "@datadir@" unless defined $dataDir;
|
$dataDir = "@datadir@" unless defined $dataDir;
|
||||||
@@ -106,7 +107,7 @@ foreach my $storePath (@storePaths) {
|
|||||||
# Construct a Nix expression that creates a Nix archive.
|
# Construct a Nix expression that creates a Nix archive.
|
||||||
my $nixexpr =
|
my $nixexpr =
|
||||||
"((import $dataDir/nix/corepkgs/nar/nar.nix) " .
|
"((import $dataDir/nix/corepkgs/nar/nar.nix) " .
|
||||||
"{storePath = builtins.storePath \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\";}) ";
|
"{storePath = builtins.toPath \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\";}) ";
|
||||||
|
|
||||||
print NIX $nixexpr;
|
print NIX $nixexpr;
|
||||||
}
|
}
|
||||||
@@ -115,9 +116,9 @@ print NIX "]";
|
|||||||
close NIX;
|
close NIX;
|
||||||
|
|
||||||
|
|
||||||
# Instantiate store derivations from the Nix expression.
|
# Instantiate store expressions from the Nix expression.
|
||||||
my @storeExprs;
|
my @storeExprs;
|
||||||
print STDERR "instantiating store derivations...\n";
|
print STDERR "instantiating store expressions...\n";
|
||||||
my $pid = open(READ, "$binDir/nix-instantiate $nixExpr|")
|
my $pid = open(READ, "$binDir/nix-instantiate $nixExpr|")
|
||||||
or die "cannot run nix-instantiate";
|
or die "cannot run nix-instantiate";
|
||||||
while (<READ>) {
|
while (<READ>) {
|
||||||
@@ -128,7 +129,7 @@ while (<READ>) {
|
|||||||
close READ or die "nix-instantiate failed: $?";
|
close READ or die "nix-instantiate failed: $?";
|
||||||
|
|
||||||
|
|
||||||
# Build the derivations.
|
# Realise the store expressions.
|
||||||
print STDERR "creating archives...\n";
|
print STDERR "creating archives...\n";
|
||||||
|
|
||||||
my @narPaths;
|
my @narPaths;
|
||||||
@@ -140,6 +141,11 @@ while (scalar @tmp > 0) {
|
|||||||
my @tmp2 = @tmp[0..$n - 1];
|
my @tmp2 = @tmp[0..$n - 1];
|
||||||
@tmp = @tmp[$n..scalar @tmp - 1];
|
@tmp = @tmp[$n..scalar @tmp - 1];
|
||||||
|
|
||||||
|
# Note: we disable build hooks because of the impure path
|
||||||
|
# reference (see above). Even if that is fixed, using a hook
|
||||||
|
# probably wouldn't make that much sense; pumping lots of data
|
||||||
|
# around just to compress them won't gain that much.
|
||||||
|
$ENV{"NIX_BUILD_HOOK"} = "";
|
||||||
my $pid = open(READ, "$binDir/nix-store --realise @tmp2|")
|
my $pid = open(READ, "$binDir/nix-store --realise @tmp2|")
|
||||||
or die "cannot run nix-store";
|
or die "cannot run nix-store";
|
||||||
while (<READ>) {
|
while (<READ>) {
|
||||||
@@ -218,14 +224,13 @@ writeManifest $manifest, \%narFiles, \%patches;
|
|||||||
sub copyFile {
|
sub copyFile {
|
||||||
my $src = shift;
|
my $src = shift;
|
||||||
my $dst = shift;
|
my $dst = shift;
|
||||||
my $tmp = "$dst.tmp.$$";
|
system("@coreutils@/cp", $src, "$dst.tmp") == 0 or die "cannot copy file";
|
||||||
system("@coreutils@/cp", $src, $tmp) == 0 or die "cannot copy file";
|
rename("$dst.tmp", "$dst") or die "cannot rename file";
|
||||||
rename($tmp, $dst) or die "cannot rename file: $!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Upload/copy the archives.
|
# Upload the archives.
|
||||||
print STDERR "uploading/copying archives...\n";
|
print STDERR "uploading archives...\n";
|
||||||
|
|
||||||
sub archiveExists {
|
sub archiveExists {
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
@@ -239,12 +244,9 @@ foreach my $narArchive (@narArchives) {
|
|||||||
my $basename = $1;
|
my $basename = $1;
|
||||||
|
|
||||||
if ($localCopy) {
|
if ($localCopy) {
|
||||||
# Since nix-push creates $dst atomically, if it exists we
|
|
||||||
# don't have to copy again.
|
|
||||||
my $dst = "$localArchivesDir/$basename";
|
|
||||||
if (! -f "$localArchivesDir/$basename") {
|
if (! -f "$localArchivesDir/$basename") {
|
||||||
print STDERR " $narArchive\n";
|
print STDERR " $narArchive\n";
|
||||||
copyFile $narArchive, $dst;
|
copyFile $narArchive, "$localArchivesDir/$basename";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,171 +0,0 @@
|
|||||||
#! @shell@
|
|
||||||
|
|
||||||
WORKING_DIRECTORY=$(mktemp -d "${TMPDIR:-/tmp}"/nix-reduce-build-XXXXXX);
|
|
||||||
cd "$WORKING_DIRECTORY";
|
|
||||||
|
|
||||||
if test -z "$1" || test "a--help" = "a$1" ; then
|
|
||||||
echo 'nix-reduce-build (paths or Nix expressions) -- (package sources)' >&2
|
|
||||||
echo As in: >&2
|
|
||||||
echo nix-reduce-build /etc/nixos/nixos -- ssh://user@somewhere.nowhere.example.org >&2
|
|
||||||
echo nix-reduce-build /etc/nixos/nixos -- \\
|
|
||||||
echo " " \''http://somewhere.nowhere.example.org/nix/nix-http-export.cgi?needed_path='\' >&2
|
|
||||||
echo " store path name will be added into the end of the URL" >&2
|
|
||||||
echo nix-reduce-build /etc/nixos/nixos -- file://home/user/nar/ >&2
|
|
||||||
echo " that should be a directory where gzipped 'nix-store --export' ">&2
|
|
||||||
echo " files are located (they should have .nar.gz extension)" >&2
|
|
||||||
echo " Or all together: " >&2
|
|
||||||
echo -e nix-reduce-build /expr.nix /e2.nix -- \\\\\\\n\
|
|
||||||
" ssh://a@b.example.com http://n.example.com/get-nar?q= file://nar/" >&2
|
|
||||||
echo " Also supports best-effort local builds of failing expression set:" >&2
|
|
||||||
echo "nix-reduce-build /e.nix -- nix-daemon:// nix-self://" >&2
|
|
||||||
echo " nix-daemon:// builds using daemon"
|
|
||||||
echo " nix-self:// builds directly using nix-store from current installation" >&2
|
|
||||||
echo " nix-daemon-fixed:// and nix-self-fixed:// do the same, but only for" >&2;
|
|
||||||
echo "derivations with specified output hash (sha256, sha1 or md5)." >&2
|
|
||||||
echo " nix-daemon-substitute:// and nix-self-substitute:// try to substitute" >&2;
|
|
||||||
echo "maximum amount of paths" >&2;
|
|
||||||
echo " nix-daemon-build:// and nix-self-build:// try to build (not substitute)" >&2;
|
|
||||||
echo "maximum amount of paths" >&2;
|
|
||||||
echo " If no package sources are specified, required paths are listed." >&2;
|
|
||||||
exit;
|
|
||||||
fi;
|
|
||||||
|
|
||||||
while ! test "$1" = "--" || test "$1" = "" ; do
|
|
||||||
echo "$1" >> initial; >&2
|
|
||||||
shift;
|
|
||||||
done
|
|
||||||
shift;
|
|
||||||
echo Will work on $(cat initial | wc -l) targets. >&2
|
|
||||||
|
|
||||||
while read ; do
|
|
||||||
case "$REPLY" in
|
|
||||||
${NIX_STORE_DIR:-/nix/store}/*)
|
|
||||||
echo "$REPLY" >> paths; >&2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
(
|
|
||||||
IFS=: ;
|
|
||||||
nix-instantiate $REPLY >> paths;
|
|
||||||
);
|
|
||||||
;;
|
|
||||||
esac;
|
|
||||||
done < initial;
|
|
||||||
echo Proceeding $(cat paths | wc -l) paths. >&2
|
|
||||||
|
|
||||||
while read; do
|
|
||||||
case "$REPLY" in
|
|
||||||
*.drv)
|
|
||||||
echo "$REPLY" >> derivers; >&2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
nix-store --query --deriver "$REPLY" >>derivers;
|
|
||||||
;;
|
|
||||||
esac;
|
|
||||||
done < paths;
|
|
||||||
echo Found $(cat derivers | wc -l) derivers. >&2
|
|
||||||
|
|
||||||
cat derivers | xargs nix-store --query -R > derivers-closure;
|
|
||||||
echo Proceeding at most $(cat derivers-closure | wc -l) derivers. >&2
|
|
||||||
|
|
||||||
cat derivers-closure | egrep '[.]drv$' | xargs nix-store --query --outputs > wanted-paths;
|
|
||||||
cat derivers-closure | egrep -v '[.]drv$' >> wanted-paths;
|
|
||||||
echo Prepared $(cat wanted-paths | wc -l) paths to get. >&2
|
|
||||||
|
|
||||||
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
|
||||||
echo We need $(cat needed-paths | wc -l) paths. >&2
|
|
||||||
|
|
||||||
egrep '[.]drv$' derivers-closure > critical-derivers;
|
|
||||||
|
|
||||||
if test -z "$1" ; then
|
|
||||||
cat needed-paths;
|
|
||||||
fi;
|
|
||||||
|
|
||||||
refresh_critical_derivers() {
|
|
||||||
echo "Finding needed derivers..." >&2;
|
|
||||||
cat critical-derivers | while read; do
|
|
||||||
if ! (nix-store --query --outputs "$REPLY" | xargs nix-store --check-validity &> /dev/null;); then
|
|
||||||
echo "$REPLY";
|
|
||||||
fi;
|
|
||||||
done > new-critical-derivers;
|
|
||||||
mv new-critical-derivers critical-derivers;
|
|
||||||
echo The needed paths are realized by $(cat critical-derivers | wc -l) derivers. >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
build_here() {
|
|
||||||
cat critical-derivers | while read; do
|
|
||||||
echo "Realising $REPLY using nix-daemon" >&2
|
|
||||||
@bindir@/nix-store -r "${REPLY}"
|
|
||||||
done;
|
|
||||||
}
|
|
||||||
|
|
||||||
try_to_substitute(){
|
|
||||||
cat needed-paths | while read ; do
|
|
||||||
echo "Building $REPLY using nix-daemon" >&2
|
|
||||||
@bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
|
||||||
done;
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in "$@"; do
|
|
||||||
sshHost="${i#ssh://}";
|
|
||||||
httpHost="${i#http://}";
|
|
||||||
httpsHost="${i#https://}";
|
|
||||||
filePath="${i#file:/}";
|
|
||||||
if [ "$i" != "$sshHost" ]; then
|
|
||||||
cat needed-paths | while read; do
|
|
||||||
echo "Getting $REPLY and its closure over ssh" >&2
|
|
||||||
nix-copy-closure --from "$sshHost" --gzip "$REPLY" </dev/null || true;
|
|
||||||
done;
|
|
||||||
elif [ "$i" != "$httpHost" ] || [ "$i" != "$httpsHost" ]; then
|
|
||||||
cat needed-paths | while read; do
|
|
||||||
echo "Getting $REPLY over http/https" >&2
|
|
||||||
curl ${BAD_CERTIFICATE:+-k} -L "$i${REPLY##*/}" | gunzip | nix-store --import;
|
|
||||||
done;
|
|
||||||
elif [ "$i" != "$filePath" ] ; then
|
|
||||||
cat needed-paths | while read; do
|
|
||||||
echo "Installing $REPLY from file" >&2
|
|
||||||
gunzip < "$filePath/${REPLY##*/}".nar.gz | nix-store --import;
|
|
||||||
done;
|
|
||||||
elif [ "$i" = "nix-daemon://" ] ; then
|
|
||||||
NIX_REMOTE=daemon try_to_substitute;
|
|
||||||
refresh_critical_derivers;
|
|
||||||
NIX_REMOTE=daemon build_here;
|
|
||||||
elif [ "$i" = "nix-self://" ] ; then
|
|
||||||
NIX_REMOTE= try_to_substitute;
|
|
||||||
refresh_critical_derivers;
|
|
||||||
NIX_REMOTE= build_here;
|
|
||||||
elif [ "$i" = "nix-daemon-fixed://" ] ; then
|
|
||||||
refresh_critical_derivers;
|
|
||||||
|
|
||||||
cat critical-derivers | while read; do
|
|
||||||
if egrep '"(md5|sha1|sha256)"' "$REPLY" &>/dev/null; then
|
|
||||||
echo "Realising $REPLY using nix-daemon" >&2
|
|
||||||
NIX_REMOTE=daemon @bindir@/nix-store -r "${REPLY}"
|
|
||||||
fi;
|
|
||||||
done;
|
|
||||||
elif [ "$i" = "nix-self-fixed://" ] ; then
|
|
||||||
refresh_critical_derivers;
|
|
||||||
|
|
||||||
cat critical-derivers | while read; do
|
|
||||||
if egrep '"(md5|sha1|sha256)"' "$REPLY" &>/dev/null; then
|
|
||||||
echo "Realising $REPLY using direct Nix build" >&2
|
|
||||||
NIX_REMOTE= @bindir@/nix-store -r "${REPLY}"
|
|
||||||
fi;
|
|
||||||
done;
|
|
||||||
elif [ "$i" = "nix-daemon-substitute://" ] ; then
|
|
||||||
NIX_REMOTE=daemon try_to_substitute;
|
|
||||||
elif [ "$i" = "nix-self-substitute://" ] ; then
|
|
||||||
NIX_REMOTE= try_to_substitute;
|
|
||||||
elif [ "$i" = "nix-daemon-build://" ] ; then
|
|
||||||
refresh_critical_derivers;
|
|
||||||
NIX_REMOTE=daemon build_here;
|
|
||||||
elif [ "$i" = "nix-self-build://" ] ; then
|
|
||||||
refresh_critical_derivers;
|
|
||||||
NIX_REMOTE= build_here;
|
|
||||||
fi;
|
|
||||||
mv needed-paths wanted-paths;
|
|
||||||
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
|
||||||
echo We still need $(cat needed-paths | wc -l) paths. >&2
|
|
||||||
done;
|
|
||||||
|
|
||||||
cd /
|
|
||||||
rm -r "$WORKING_DIRECTORY"
|
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
#! @perl@ -w
|
||||||
|
|
||||||
|
# This tool unpacks the closures created by "nix-pack-closure" and
|
||||||
|
# adds them to the Nix store.
|
||||||
|
|
||||||
|
# TODO: make this program "streamy", i.e., don't use a temporary
|
||||||
|
# directory.
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use File::Temp qw(tempdir);
|
||||||
|
|
||||||
|
my $binDir = $ENV{"NIX_BIN_DIR"};
|
||||||
|
$binDir = "@bindir@" unless defined $binDir;
|
||||||
|
|
||||||
|
my $tmpDir = tempdir("nix-unpack-closure.XXXXXX", CLEANUP => 1, TMPDIR => 1)
|
||||||
|
or die "cannot create a temporary directory";
|
||||||
|
|
||||||
|
|
||||||
|
# Unpack the NAR archive on standard input.
|
||||||
|
system("nix-store --restore '$tmpDir/unpacked'") == 0
|
||||||
|
or die "nix-store --restore failed";
|
||||||
|
|
||||||
|
|
||||||
|
open VALID, ">$tmpDir/validity" or die;
|
||||||
|
|
||||||
|
|
||||||
|
# For each path in the closure that is not yet valid, add it to the
|
||||||
|
# store. TODO: use proper locking. Or even better, let nix-store do
|
||||||
|
# this.
|
||||||
|
opendir(DIR, "$tmpDir/unpacked/contents") or die "cannot open directory: $!";
|
||||||
|
|
||||||
|
foreach my $name (sort(readdir DIR)) {
|
||||||
|
next if $name eq "." or $name eq "..";
|
||||||
|
|
||||||
|
my $storePath = "@storedir@/$name"; # !!!
|
||||||
|
|
||||||
|
# !!! this really isn't a good validity check!
|
||||||
|
system "$binDir/nix-store --check-validity '$storePath' 2> /dev/null";
|
||||||
|
if ($? != 0) {
|
||||||
|
print STDERR "unpacking `$storePath'...\n";
|
||||||
|
|
||||||
|
# !!! race
|
||||||
|
system("@coreutils@/rm -rf '$storePath'") == 0
|
||||||
|
or die "cannot remove `$storePath': $?";
|
||||||
|
|
||||||
|
system("$binDir/nix-store --restore '$storePath' < '$tmpDir/unpacked/contents/$name'") == 0
|
||||||
|
or die "nix-store --dump failed on `$storePath': $?";
|
||||||
|
|
||||||
|
print VALID "$storePath\n";
|
||||||
|
|
||||||
|
open DRV, "<$tmpDir/unpacked/derivers/$name" or die;
|
||||||
|
my $deriver = <DRV>;
|
||||||
|
chomp $deriver;
|
||||||
|
$deriver = "" if $deriver eq "unknown-deriver";
|
||||||
|
close DRV;
|
||||||
|
|
||||||
|
my @refs;
|
||||||
|
open REFS, "<$tmpDir/unpacked/references/$name" or die;
|
||||||
|
while (<REFS>) {
|
||||||
|
chomp;
|
||||||
|
push @refs, $_;
|
||||||
|
}
|
||||||
|
close REFS;
|
||||||
|
|
||||||
|
print VALID "$deriver\n";
|
||||||
|
|
||||||
|
print VALID (scalar @refs), "\n";
|
||||||
|
foreach my $ref (@refs) {
|
||||||
|
print VALID "$ref\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(DIR) or die;
|
||||||
|
|
||||||
|
|
||||||
|
# Register the invalid paths as valid.
|
||||||
|
system("nix-store --register-validity <'$tmpDir/validity'") == 0
|
||||||
|
or die "nix-store --register-validity failed";
|
||||||
|
|
||||||
|
|
||||||
|
# Show the top-level paths so that something useful can be done with
|
||||||
|
# them, e.g., passing them to `nix-env -i'.
|
||||||
|
if (-e "$tmpDir/unpacked/top-level") {
|
||||||
|
open TOPLEVEL, "<$tmpDir/unpacked/top-level" or die;
|
||||||
|
while (<TOPLEVEL>) { print "$_"; }
|
||||||
|
close TOPLEVEL;
|
||||||
|
}
|
||||||
+37
-11
@@ -2,7 +2,10 @@ use strict;
|
|||||||
|
|
||||||
|
|
||||||
sub addPatch {
|
sub addPatch {
|
||||||
my ($patches, $storePath, $patch) = @_;
|
my $patches = shift;
|
||||||
|
my $storePath = shift;
|
||||||
|
my $patch = shift;
|
||||||
|
my $allowConflicts = shift;
|
||||||
|
|
||||||
$$patches{$storePath} = []
|
$$patches{$storePath} = []
|
||||||
unless defined $$patches{$storePath};
|
unless defined $$patches{$storePath};
|
||||||
@@ -11,9 +14,15 @@ sub addPatch {
|
|||||||
|
|
||||||
my $found = 0;
|
my $found = 0;
|
||||||
foreach my $patch2 (@{$patchList}) {
|
foreach my $patch2 (@{$patchList}) {
|
||||||
$found = 1 if
|
if ($patch2->{url} eq $patch->{url}) {
|
||||||
$patch2->{url} eq $patch->{url} &&
|
if ($patch2->{hash} eq $patch->{hash}) {
|
||||||
$patch2->{basePath} eq $patch->{basePath};
|
$found = 1 if ($patch2->{basePath} eq $patch->{basePath});
|
||||||
|
} else {
|
||||||
|
die "conflicting hashes for URL $patch->{url}, " .
|
||||||
|
"namely $patch2->{hash} and $patch->{hash}"
|
||||||
|
unless $allowConflicts;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push @{$patchList}, $patch if !$found;
|
push @{$patchList}, $patch if !$found;
|
||||||
@@ -23,7 +32,12 @@ sub addPatch {
|
|||||||
|
|
||||||
|
|
||||||
sub readManifest {
|
sub readManifest {
|
||||||
my ($manifest, $narFiles, $localPaths, $patches) = @_;
|
my $manifest = shift;
|
||||||
|
my $narFiles = shift;
|
||||||
|
my $localPaths = shift;
|
||||||
|
my $patches = shift;
|
||||||
|
my $allowConflicts = shift;
|
||||||
|
$allowConflicts = 0 unless defined $allowConflicts;
|
||||||
|
|
||||||
open MANIFEST, "<$manifest"
|
open MANIFEST, "<$manifest"
|
||||||
or die "cannot open `$manifest': $!";
|
or die "cannot open `$manifest': $!";
|
||||||
@@ -84,7 +98,15 @@ sub readManifest {
|
|||||||
|
|
||||||
my $found = 0;
|
my $found = 0;
|
||||||
foreach my $narFile (@{$narFileList}) {
|
foreach my $narFile (@{$narFileList}) {
|
||||||
$found = 1 if $narFile->{url} eq $url;
|
if ($narFile->{url} eq $url) {
|
||||||
|
if ($narFile->{hash} eq $hash) {
|
||||||
|
$found = 1;
|
||||||
|
} else {
|
||||||
|
die "conflicting hashes for URL $url, " .
|
||||||
|
"namely $narFile->{hash} and $hash"
|
||||||
|
unless $allowConflicts;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
push @{$narFileList},
|
push @{$narFileList},
|
||||||
@@ -102,7 +124,7 @@ sub readManifest {
|
|||||||
, basePath => $basePath, baseHash => $baseHash
|
, basePath => $basePath, baseHash => $baseHash
|
||||||
, narHash => $narHash, patchType => $patchType
|
, narHash => $narHash, patchType => $patchType
|
||||||
, hashAlgo => $hashAlgo
|
, hashAlgo => $hashAlgo
|
||||||
};
|
}, $allowConflicts;
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ($type eq "localPath") {
|
elsif ($type eq "localPath") {
|
||||||
@@ -149,8 +171,12 @@ sub readManifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub writeManifest {
|
sub writeManifest
|
||||||
my ($manifest, $narFiles, $patches) = @_;
|
{
|
||||||
|
my $manifest = shift;
|
||||||
|
my $narFiles = shift;
|
||||||
|
my $patches = shift;
|
||||||
|
my $copySources = shift;
|
||||||
|
|
||||||
open MANIFEST, ">$manifest.tmp"; # !!! check exclusive
|
open MANIFEST, ">$manifest.tmp"; # !!! check exclusive
|
||||||
|
|
||||||
@@ -164,9 +190,9 @@ sub writeManifest {
|
|||||||
print MANIFEST "{\n";
|
print MANIFEST "{\n";
|
||||||
print MANIFEST " StorePath: $storePath\n";
|
print MANIFEST " StorePath: $storePath\n";
|
||||||
print MANIFEST " NarURL: $narFile->{url}\n";
|
print MANIFEST " NarURL: $narFile->{url}\n";
|
||||||
print MANIFEST " Hash: $narFile->{hash}\n" if defined $narFile->{hash};
|
print MANIFEST " Hash: $narFile->{hash}\n";
|
||||||
print MANIFEST " NarHash: $narFile->{narHash}\n";
|
print MANIFEST " NarHash: $narFile->{narHash}\n";
|
||||||
print MANIFEST " Size: $narFile->{size}\n" if defined $narFile->{size};
|
print MANIFEST " Size: $narFile->{size}\n";
|
||||||
print MANIFEST " References: $narFile->{references}\n"
|
print MANIFEST " References: $narFile->{references}\n"
|
||||||
if defined $narFile->{references} && $narFile->{references} ne "";
|
if defined $narFile->{references} && $narFile->{references} ne "";
|
||||||
print MANIFEST " Deriver: $narFile->{deriver}\n"
|
print MANIFEST " Deriver: $narFile->{deriver}\n"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
SUBDIRS = format
|
SUBDIRS = format
|
||||||
|
|
||||||
nobase_pkginclude_HEADERS = assert.hpp checked_delete.hpp format.hpp \
|
pkginclude_HEADERS = assert.hpp checked_delete.hpp format.hpp \
|
||||||
shared_ptr.hpp weak_ptr.hpp throw_exception.hpp \
|
shared_ptr.hpp weak_ptr.hpp throw_exception.hpp \
|
||||||
enable_shared_from_this.hpp \
|
enable_shared_from_this.hpp \
|
||||||
detail/shared_count.hpp detail/workaround.hpp
|
detail/shared_count.hpp detail/workaround.hpp
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
static off_t offtin(u_char *buf)
|
static off_t offtin(u_char *buf)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ pkglib_LTLIBRARIES = libexpr.la
|
|||||||
|
|
||||||
libexpr_la_SOURCES = \
|
libexpr_la_SOURCES = \
|
||||||
nixexpr.cc eval.cc primops.cc lexer-tab.cc parser-tab.cc \
|
nixexpr.cc eval.cc primops.cc lexer-tab.cc parser-tab.cc \
|
||||||
get-drvs.cc attr-path.cc expr-to-xml.cc common-opts.cc \
|
get-drvs.cc attr-path.cc expr-to-xml.cc common-opts.cc
|
||||||
names.cc normal-forms.cc
|
|
||||||
|
|
||||||
pkginclude_HEADERS = \
|
pkginclude_HEADERS = \
|
||||||
nixexpr.hh eval.hh parser.hh lexer-tab.hh parser-tab.hh \
|
nixexpr.hh eval.hh parser.hh lexer-tab.hh parser-tab.hh \
|
||||||
get-drvs.hh attr-path.hh expr-to-xml.hh common-opts.hh \
|
get-drvs.hh attr-path.hh expr-to-xml.hh common-opts.hh
|
||||||
names.hh nixexpr-ast.hh
|
|
||||||
|
|
||||||
libexpr_la_LIBADD = ../libutil/libutil.la ../libstore/libstore.la \
|
libexpr_la_LIBADD = ../libutil/libutil.la ../libstore/libstore.la \
|
||||||
../boost/format/libformat.la
|
../boost/format/libformat.la
|
||||||
|
|||||||
+278
-212
@@ -1,3 +1,5 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
@@ -13,26 +15,38 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
|
int cacheTerms;
|
||||||
|
|
||||||
|
bool shortCircuit;
|
||||||
|
bool closedTerms; // don't substitute under terms known to be closed
|
||||||
|
bool substCache; // memoization of the term substitution function
|
||||||
|
bool posInfo; // attach position info to functions, assertions, attributes
|
||||||
|
|
||||||
|
#define maxActiveCalls 4096
|
||||||
|
|
||||||
|
ATerm activeCalls[maxActiveCalls];
|
||||||
|
unsigned int activeCallsCount = 0;
|
||||||
|
|
||||||
|
|
||||||
EvalState::EvalState()
|
EvalState::EvalState()
|
||||||
: sessionNormalForms(32768), normalForms(32768), primOps(128)
|
: normalForms(32768), primOps(128)
|
||||||
{
|
{
|
||||||
nrEvaluated = nrCached = nrDepthAfterReset = 0;
|
nrEvaluated = nrCached = 0;
|
||||||
|
|
||||||
initNixExprHelpers();
|
initNixExprHelpers();
|
||||||
|
|
||||||
addPrimOps();
|
addPrimOps();
|
||||||
|
|
||||||
allowUnsafeEquality = getEnv("NIX_NO_UNSAFE_EQ", "") == "";
|
if (!string2Int(getEnv("NIX_TERM_CACHE"), cacheTerms)) cacheTerms = 1;
|
||||||
safeCache = true;
|
shortCircuit = getEnv("NIX_SHORT_CIRCUIT", "0") == "1";
|
||||||
|
strictMode = getEnv("NIX_STRICT", "0") == "1";
|
||||||
|
closedTerms = getEnv("NIX_CLOSED_TERMS", "1") == "1";
|
||||||
|
substCache = getEnv("NIX_SUBST_CACHE", "1") == "1";
|
||||||
|
posInfo = getEnv("NIX_POS_INFO", "1") == "1";
|
||||||
|
|
||||||
loadNormalForms();
|
ATprotectMemory(activeCalls, maxActiveCalls);
|
||||||
}
|
|
||||||
|
|
||||||
EvalState::~EvalState()
|
|
||||||
{
|
|
||||||
saveNormalForms();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -58,11 +72,6 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2))
|
|||||||
throw EvalError(format(s) % s2);
|
throw EvalError(format(s) % s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwTypeError(const char * s))
|
|
||||||
{
|
|
||||||
throw TypeError(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s2))
|
LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s2))
|
||||||
{
|
{
|
||||||
throw TypeError(format(s) % s2);
|
throw TypeError(format(s) % s2);
|
||||||
@@ -84,91 +93,90 @@ LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Pattern-match `pat' against `arg'. The result is a set of
|
Expr speculativeEval(EvalState & state, Expr e)
|
||||||
substitutions (`subs') and a set of recursive substitutions
|
|
||||||
(`subsRecursive'). The latter can refer to the variables bound by
|
|
||||||
both `subs' and `subsRecursive'. */
|
|
||||||
static void patternMatch(EvalState & state,
|
|
||||||
Pattern pat, Expr arg, ATermMap & subs, ATermMap & subsRecursive)
|
|
||||||
{
|
{
|
||||||
ATerm name;
|
if (!state.strictMode) return e;
|
||||||
ATermList formals;
|
try {
|
||||||
Pattern pat1, pat2;
|
return evalExpr(state, e);
|
||||||
ATermBool ellipsis;
|
} catch (EvalError & err) {
|
||||||
|
/* ignore, pass the original arg and depend on
|
||||||
if (matchVarPat(pat, name))
|
laziness */
|
||||||
subs.set(name, arg);
|
return e;
|
||||||
|
|
||||||
else if (matchAttrsPat(pat, formals, ellipsis)) {
|
|
||||||
|
|
||||||
arg = evalExpr(state, arg);
|
|
||||||
|
|
||||||
/* Get the actual arguments. */
|
|
||||||
ATermMap attrs;
|
|
||||||
queryAllAttrs(arg, attrs);
|
|
||||||
unsigned int nrAttrs = attrs.size();
|
|
||||||
|
|
||||||
/* For each formal argument, get the actual argument. If
|
|
||||||
there is no matching actual argument but the formal
|
|
||||||
argument has a default, use the default. */
|
|
||||||
unsigned int attrsUsed = 0;
|
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
|
||||||
Expr name, def;
|
|
||||||
DefaultValue def2;
|
|
||||||
if (!matchFormal(*i, name, def2)) abort(); /* can't happen */
|
|
||||||
|
|
||||||
Expr value = attrs[name];
|
|
||||||
|
|
||||||
if (value == 0) {
|
|
||||||
if (!matchDefaultValue(def2, def)) def = 0;
|
|
||||||
if (def == 0) throw TypeError(format("the argument named `%1%' required by the function is missing")
|
|
||||||
% aterm2String(name));
|
|
||||||
subsRecursive.set(name, def);
|
|
||||||
} else {
|
|
||||||
attrsUsed++;
|
|
||||||
attrs.remove(name);
|
|
||||||
subs.set(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check that each actual argument is listed as a formal
|
|
||||||
argument (unless the attribute match specifies a `...'). */
|
|
||||||
if (ellipsis == eFalse && attrsUsed != nrAttrs)
|
|
||||||
throw TypeError(format("the function does not expect an argument named `%1%'")
|
|
||||||
% aterm2String(attrs.begin()->key));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (matchAtPat(pat, pat1, pat2)) {
|
|
||||||
patternMatch(state, pat1, arg, subs, subsRecursive);
|
|
||||||
patternMatch(state, pat2, arg, subs, subsRecursive);
|
|
||||||
}
|
|
||||||
|
|
||||||
else abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Substitute an argument set into the body of a function. */
|
/* Substitute an argument set into the body of a function. */
|
||||||
static Expr substArgs(EvalState & state,
|
static Expr substArgs(EvalState & state,
|
||||||
Expr body, Pattern pat, Expr arg)
|
Expr body, ATermList formals, Expr arg)
|
||||||
{
|
{
|
||||||
ATermMap subs(16), subsRecursive(16);
|
unsigned int nrFormals = ATgetLength(formals);
|
||||||
|
ATermMap subs(nrFormals);
|
||||||
patternMatch(state, pat, arg, subs, subsRecursive);
|
|
||||||
|
|
||||||
/* If we used any default values, make a recursive attribute set
|
/* Get the actual arguments and put them in the substitution. */
|
||||||
out of the (argument-name, value) tuples. This is so that we
|
ATermMap args;
|
||||||
can support default values that refer to each other, e.g. ({x,
|
queryAllAttrs(arg, args);
|
||||||
y ? x + x}: y) {x = "foo";} evaluates to "foofoo". */
|
for (ATermMap::const_iterator i = args.begin(); i != args.end(); ++i)
|
||||||
if (subsRecursive.size() != 0) {
|
subs.set(i->key, speculativeEval(state, i->value));
|
||||||
ATermList recAttrs = ATempty;
|
|
||||||
foreach (ATermMap::const_iterator, i, subs)
|
/* Get the formal arguments. */
|
||||||
recAttrs = ATinsert(recAttrs, makeBind(i->key, i->value, makeNoPos()));
|
ATermVector defsUsed;
|
||||||
foreach (ATermMap::const_iterator, i, subsRecursive)
|
ATermList recAttrs = ATempty;
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
Expr name, def;
|
||||||
|
ValidValues valids2;
|
||||||
|
DefaultValue def2;
|
||||||
|
if (!matchFormal(*i, name, valids2, def2)) abort(); /* can't happen */
|
||||||
|
|
||||||
|
Expr value = subs[name];
|
||||||
|
|
||||||
|
if (value == 0) {
|
||||||
|
if (!matchDefaultValue(def2, def)) def = 0;
|
||||||
|
if (def == 0) throw TypeError(format("the argument named `%1%' required by the function is missing")
|
||||||
|
% aterm2String(name));
|
||||||
|
value = def;
|
||||||
|
defsUsed.push_back(name);
|
||||||
|
recAttrs = ATinsert(recAttrs, makeBind(name, def, makeNoPos()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ATermList valids;
|
||||||
|
if (matchValidValues(valids2, valids)) {
|
||||||
|
value = evalExpr(state, value);
|
||||||
|
bool found = false;
|
||||||
|
for (ATermIterator j(valids); j; ++j) {
|
||||||
|
Expr v = evalExpr(state, *j);
|
||||||
|
if (value == v) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) throw TypeError(format("the argument named `%1%' has an illegal value")
|
||||||
|
% aterm2String(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make a recursive attribute set out of the (argument-name,
|
||||||
|
value) tuples. This is so that we can support default
|
||||||
|
parameters that refer to each other, e.g. ({x, y ? x + x}: y)
|
||||||
|
{x = "foo";} evaluates to "foofoo". */
|
||||||
|
if (defsUsed.size() != 0) {
|
||||||
|
for (ATermMap::const_iterator i = args.begin(); i != args.end(); ++i)
|
||||||
recAttrs = ATinsert(recAttrs, makeBind(i->key, i->value, makeNoPos()));
|
recAttrs = ATinsert(recAttrs, makeBind(i->key, i->value, makeNoPos()));
|
||||||
Expr rec = makeRec(recAttrs, ATempty);
|
Expr rec = makeRec(recAttrs, ATempty);
|
||||||
foreach (ATermMap::const_iterator, i, subsRecursive)
|
for (ATermVector::iterator i = defsUsed.begin(); i != defsUsed.end(); ++i)
|
||||||
subs.set(i->key, makeSelect(rec, i->key));
|
subs.set(*i, makeSelect(rec, *i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subs.size() != nrFormals) {
|
||||||
|
/* One or more actual arguments were not declared as formal
|
||||||
|
arguments. Find out which. */
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
Expr name; ATerm d1, d2;
|
||||||
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
||||||
|
subs.remove(name);
|
||||||
|
}
|
||||||
|
throw TypeError(format("the function does not expect an argument named `%1%'")
|
||||||
|
% aterm2String(subs.begin()->key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return substitute(Substitution(0, &subs), body);
|
return substitute(Substitution(0, &subs), body);
|
||||||
@@ -180,12 +188,11 @@ static Expr substArgs(EvalState & state,
|
|||||||
to attributes substituted with selection expressions on the
|
to attributes substituted with selection expressions on the
|
||||||
original set. E.g., e = `rec {x = f x y; y = x;}' becomes `{x = f
|
original set. E.g., e = `rec {x = f x y; y = x;}' becomes `{x = f
|
||||||
(e.x) (e.y); y = e.x;}'. */
|
(e.x) (e.y); y = e.x;}'. */
|
||||||
LocalNoInline(ATerm expandRec(EvalState & state, ATerm e, ATermList rbnds, ATermList nrbnds))
|
LocalNoInline(ATerm expandRec(ATerm e, ATermList rbnds, ATermList nrbnds))
|
||||||
{
|
{
|
||||||
ATerm name;
|
ATerm name;
|
||||||
Expr e2;
|
Expr e2;
|
||||||
Pos pos;
|
Pos pos;
|
||||||
Expr eOverrides = 0;
|
|
||||||
|
|
||||||
/* Create the substitution list. */
|
/* Create the substitution list. */
|
||||||
ATermMap subs(ATgetLength(rbnds) + ATgetLength(nrbnds));
|
ATermMap subs(ATgetLength(rbnds) + ATgetLength(nrbnds));
|
||||||
@@ -195,26 +202,9 @@ LocalNoInline(ATerm expandRec(EvalState & state, ATerm e, ATermList rbnds, ATerm
|
|||||||
}
|
}
|
||||||
for (ATermIterator i(nrbnds); i; ++i) {
|
for (ATermIterator i(nrbnds); i; ++i) {
|
||||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||||
if (name == sOverrides) eOverrides = e2;
|
|
||||||
subs.set(name, e2);
|
subs.set(name, e2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the rec contains an attribute called `__overrides', then
|
|
||||||
evaluate it, and add the attributes in that set to the rec.
|
|
||||||
This allows overriding of recursive attributes, which is
|
|
||||||
otherwise not possible. (You can use the // operator to
|
|
||||||
replace an attribute, but other attributes in the rec will
|
|
||||||
still reference the original value, because that value has been
|
|
||||||
substituted into the bodies of the other attributes. Hence we
|
|
||||||
need __overrides.) */
|
|
||||||
ATermMap overrides;
|
|
||||||
if (eOverrides) {
|
|
||||||
eOverrides = evalExpr(state, eOverrides);
|
|
||||||
queryAllAttrs(eOverrides, overrides, false);
|
|
||||||
foreach (ATermMap::const_iterator, i, overrides)
|
|
||||||
subs.set(i->key, i->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Substitution subs_(0, &subs);
|
Substitution subs_(0, &subs);
|
||||||
|
|
||||||
/* Create the non-recursive set. */
|
/* Create the non-recursive set. */
|
||||||
@@ -224,10 +214,6 @@ LocalNoInline(ATerm expandRec(EvalState & state, ATerm e, ATermList rbnds, ATerm
|
|||||||
as.set(name, makeAttrRHS(substitute(subs_, e2), pos));
|
as.set(name, makeAttrRHS(substitute(subs_, e2), pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eOverrides)
|
|
||||||
foreach (ATermMap::const_iterator, i, overrides)
|
|
||||||
as.set(i->key, makeAttrRHS(i->value, makeNoPos()));
|
|
||||||
|
|
||||||
/* Copy the non-recursive bindings. !!! inefficient */
|
/* Copy the non-recursive bindings. !!! inefficient */
|
||||||
for (ATermIterator i(nrbnds); i; ++i) {
|
for (ATermIterator i(nrbnds); i; ++i) {
|
||||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||||
@@ -356,11 +342,9 @@ string coerceToString(EvalState & state, Expr e, PathSet & context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ATermList es;
|
ATermList es;
|
||||||
if (matchAttrs(e, es)) {
|
if (matchAttrs(e, es))
|
||||||
Expr e2 = queryAttr(e, "outPath");
|
return coerceToString(state, makeSelect(e, toATerm("outPath")),
|
||||||
if (!e2) throwTypeError("cannot coerce an attribute set (except a derivation) to a string");
|
context, coerceMore, copyToStore);
|
||||||
return coerceToString(state, e2, context, coerceMore, copyToStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (coerceMore) {
|
if (coerceMore) {
|
||||||
|
|
||||||
@@ -432,20 +416,17 @@ Path coerceToPath(EvalState & state, Expr e, PathSet & context)
|
|||||||
|
|
||||||
Expr autoCallFunction(Expr e, const ATermMap & args)
|
Expr autoCallFunction(Expr e, const ATermMap & args)
|
||||||
{
|
{
|
||||||
Pattern pat;
|
|
||||||
ATerm body, pos;
|
|
||||||
ATermList formals;
|
ATermList formals;
|
||||||
ATermBool ellipsis;
|
ATerm body, pos;
|
||||||
|
|
||||||
/* !!! this should be more general */
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
if (matchFunction(e, pat, body, pos) && matchAttrsPat(pat, formals, ellipsis)) {
|
|
||||||
ATermMap actualArgs(ATgetLength(formals));
|
ATermMap actualArgs(ATgetLength(formals));
|
||||||
|
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
Expr name, def, value; ATerm def2;
|
Expr name, def, value; ATerm values, def2;
|
||||||
if (!matchFormal(*i, name, def2)) abort();
|
if (!matchFormal(*i, name, values, def2)) abort();
|
||||||
if ((value = args.get(name)))
|
if ((value = args.get(name)))
|
||||||
actualArgs.set(name, makeAttrRHS(value, makeNoPos()));
|
actualArgs.set(name, makeAttrRHS(allocCell(value), makeNoPos()));
|
||||||
else if (!matchDefaultValue(def2, def))
|
else if (!matchDefaultValue(def2, def))
|
||||||
throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
|
throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')")
|
||||||
% aterm2String(name));
|
% aterm2String(name));
|
||||||
@@ -476,17 +457,15 @@ LocalNoInline(Expr evalVar(EvalState & state, ATerm name))
|
|||||||
if (arity == 0)
|
if (arity == 0)
|
||||||
/* !!! backtrace for primop call */
|
/* !!! backtrace for primop call */
|
||||||
return ((PrimOp) ATgetBlobData(fun)) (state, ATermVector());
|
return ((PrimOp) ATgetBlobData(fun)) (state, ATermVector());
|
||||||
else {
|
else
|
||||||
state.safeCache = false;
|
|
||||||
return makePrimOp(arity, fun, ATempty);
|
return makePrimOp(arity, fun, ATempty);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocalNoInline(Expr evalCall(EvalState & state, Expr fun, Expr arg))
|
LocalNoInline(Expr evalCall(EvalState & state, Expr fun, Expr arg))
|
||||||
{
|
{
|
||||||
Pattern pat;
|
ATermList formals;
|
||||||
ATerm pos;
|
ATerm pos, name;
|
||||||
Expr body;
|
Expr body;
|
||||||
|
|
||||||
/* Evaluate the left-hand side. */
|
/* Evaluate the left-hand side. */
|
||||||
@@ -505,7 +484,6 @@ LocalNoInline(Expr evalCall(EvalState & state, Expr fun, Expr arg))
|
|||||||
for (ATermIterator i(args); i; ++i)
|
for (ATermIterator i(args); i; ++i)
|
||||||
args2[--arity] = *i;
|
args2[--arity] = *i;
|
||||||
/* !!! backtrace for primop call */
|
/* !!! backtrace for primop call */
|
||||||
state.safeCache = true;
|
|
||||||
return ((PrimOp) ATgetBlobData(funBlob))
|
return ((PrimOp) ATgetBlobData(funBlob))
|
||||||
(state, args2);
|
(state, args2);
|
||||||
} else
|
} else
|
||||||
@@ -513,9 +491,10 @@ LocalNoInline(Expr evalCall(EvalState & state, Expr fun, Expr arg))
|
|||||||
return makePrimOp(arity, funBlob, args);
|
return makePrimOp(arity, funBlob, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (matchFunction(fun, pat, body, pos)) {
|
else if (matchFunction(fun, formals, body, pos)) {
|
||||||
|
arg = evalExpr(state, arg);
|
||||||
try {
|
try {
|
||||||
return evalExpr(state, substArgs(state, body, pat, arg));
|
return evalExpr(state, substArgs(state, allocCells(body), formals, arg));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
addErrorPrefix(e, "while evaluating the function at %1%:\n",
|
addErrorPrefix(e, "while evaluating the function at %1%:\n",
|
||||||
showPos(pos));
|
showPos(pos));
|
||||||
@@ -523,6 +502,19 @@ LocalNoInline(Expr evalCall(EvalState & state, Expr fun, Expr arg))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (matchFunction1(fun, name, body, pos)) {
|
||||||
|
try {
|
||||||
|
arg = speculativeEval(state, arg);
|
||||||
|
ATermMap subs(1);
|
||||||
|
subs.set(name, allocCell(arg));
|
||||||
|
return evalExpr(state, substitute(Substitution(0, &subs), allocCells(body)));
|
||||||
|
} catch (Error & e) {
|
||||||
|
addErrorPrefix(e, "while evaluating the function at %1%:\n",
|
||||||
|
showPos(pos));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else throwTypeError(
|
else throwTypeError(
|
||||||
"attempt to call something which is neither a function nor a primop (built-in operation) but %1%",
|
"attempt to call something which is neither a function nor a primop (built-in operation) but %1%",
|
||||||
showType(fun));
|
showType(fun));
|
||||||
@@ -657,48 +649,6 @@ LocalNoInline(Expr evalOpConcat(EvalState & state, Expr e1, Expr e2))
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Implementation of the `==' and `!=' operators. */
|
|
||||||
LocalNoInline(bool areEqual(EvalState & state, Expr e1, Expr e2))
|
|
||||||
{
|
|
||||||
e1 = evalExpr(state, e1);
|
|
||||||
e2 = evalExpr(state, e2);
|
|
||||||
|
|
||||||
/* We cannot test functions/primops for equality, and we currently
|
|
||||||
don't support testing equality between attribute sets or lists
|
|
||||||
- that would have to be a deep equality test to be sound. */
|
|
||||||
AFun sym1 = ATgetAFun(e1);
|
|
||||||
AFun sym2 = ATgetAFun(e2);
|
|
||||||
|
|
||||||
if (sym1 != sym2) return false;
|
|
||||||
|
|
||||||
/* Functions are incomparable. */
|
|
||||||
if (sym1 == symFunction || sym1 == symPrimOp) return false;
|
|
||||||
|
|
||||||
if (!state.allowUnsafeEquality && sym1 == symAttrs)
|
|
||||||
throw EvalError("comparison of attribute sets is not implemented");
|
|
||||||
|
|
||||||
/* !!! This allows comparisons of infinite data structures to
|
|
||||||
succeed, such as `let x = [x]; in x == x'. This is
|
|
||||||
undesirable, since equivalent (?) terms such as `let x = [x]; y
|
|
||||||
= [y]; in x == y' don't terminate. */
|
|
||||||
if (e1 == e2) return true;
|
|
||||||
|
|
||||||
if (sym1 == symList) {
|
|
||||||
ATermList es1; matchList(e1, es1);
|
|
||||||
ATermList es2; matchList(e2, es2);
|
|
||||||
if (ATgetLength(es1) != ATgetLength(es2)) return false;
|
|
||||||
ATermIterator i(es1), j(es2);
|
|
||||||
while (*i) {
|
|
||||||
if (!areEqual(state, *i, *j)) return false;
|
|
||||||
++i; ++j;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char * deepestStack = (char *) -1; /* for measuring stack usage */
|
static char * deepestStack = (char *) -1; /* for measuring stack usage */
|
||||||
|
|
||||||
|
|
||||||
@@ -712,6 +662,10 @@ Expr evalExpr2(EvalState & state, Expr e)
|
|||||||
|
|
||||||
Expr e1, e2, e3;
|
Expr e1, e2, e3;
|
||||||
ATerm name, pos;
|
ATerm name, pos;
|
||||||
|
|
||||||
|
int bla;
|
||||||
|
if (matchCell(e, bla, e1)) e = e1;
|
||||||
|
|
||||||
AFun sym = ATgetAFun(e);
|
AFun sym = ATgetAFun(e);
|
||||||
|
|
||||||
/* Normal forms. */
|
/* Normal forms. */
|
||||||
@@ -721,6 +675,7 @@ Expr evalExpr2(EvalState & state, Expr e)
|
|||||||
sym == symInt ||
|
sym == symInt ||
|
||||||
sym == symBool ||
|
sym == symBool ||
|
||||||
sym == symFunction ||
|
sym == symFunction ||
|
||||||
|
sym == symFunction1 ||
|
||||||
sym == symAttrs ||
|
sym == symAttrs ||
|
||||||
sym == symList ||
|
sym == symList ||
|
||||||
sym == symPrimOp)
|
sym == symPrimOp)
|
||||||
@@ -744,7 +699,7 @@ Expr evalExpr2(EvalState & state, Expr e)
|
|||||||
/* Mutually recursive sets. */
|
/* Mutually recursive sets. */
|
||||||
ATermList rbnds, nrbnds;
|
ATermList rbnds, nrbnds;
|
||||||
if (matchRec(e, rbnds, nrbnds))
|
if (matchRec(e, rbnds, nrbnds))
|
||||||
return expandRec(state, e, rbnds, nrbnds);
|
return expandRec(e, rbnds, nrbnds);
|
||||||
|
|
||||||
/* Conditionals. */
|
/* Conditionals. */
|
||||||
if (matchIf(e, e1, e2, e3))
|
if (matchIf(e, e1, e2, e3))
|
||||||
@@ -762,10 +717,12 @@ Expr evalExpr2(EvalState & state, Expr e)
|
|||||||
However, we don't want to make (==) strict, because that would
|
However, we don't want to make (==) strict, because that would
|
||||||
make operations like `big_derivation == null' very slow (unless
|
make operations like `big_derivation == null' very slow (unless
|
||||||
we were to evaluate them side-by-side). */
|
we were to evaluate them side-by-side). */
|
||||||
if (matchOpEq(e, e1, e2)) return makeBool(areEqual(state, e1, e2));
|
if (matchOpEq(e, e1, e2))
|
||||||
|
return makeBool(evalExpr(state, e1) == evalExpr(state, e2));
|
||||||
if (matchOpNEq(e, e1, e2)) return makeBool(!areEqual(state, e1, e2));
|
|
||||||
|
if (matchOpNEq(e, e1, e2))
|
||||||
|
return makeBool(evalExpr(state, e1) != evalExpr(state, e2));
|
||||||
|
|
||||||
/* Negation. */
|
/* Negation. */
|
||||||
if (matchOpNot(e, e1))
|
if (matchOpNot(e, e1))
|
||||||
return makeBool(!evalBool(state, e1));
|
return makeBool(!evalBool(state, e1));
|
||||||
@@ -800,67 +757,147 @@ Expr evalExpr2(EvalState & state, Expr e)
|
|||||||
if (matchOpConcat(e, e1, e2)) return evalOpConcat(state, e1, e2);
|
if (matchOpConcat(e, e1, e2)) return evalOpConcat(state, e1, e2);
|
||||||
|
|
||||||
/* Barf. */
|
/* Barf. */
|
||||||
|
//printMsg(lvlError, format("%1%") % e);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ShortCircuit
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int fnord;
|
||||||
|
|
||||||
|
|
||||||
|
void maybeShortCircuit(EvalState & state, Expr e, Expr nf)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < activeCallsCount; ++i) {
|
||||||
|
Expr fun, arg;
|
||||||
|
if (!matchCall(activeCalls[i], fun, arg)) abort();
|
||||||
|
if (arg == e) {
|
||||||
|
//printMsg(lvlError, format("blaat"));
|
||||||
|
//printMsg(lvlError, format("blaat %1% %2% %3%") % fun % arg % e);
|
||||||
|
Expr res = state.normalForms.get(makeCall(fun, nf));
|
||||||
|
if (res) {
|
||||||
|
fnord++;
|
||||||
|
//printMsg(lvlError, format("blaat"));
|
||||||
|
throw ShortCircuit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Expr evalExpr(EvalState & state, Expr e)
|
Expr evalExpr(EvalState & state, Expr e)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
startNest(nest, lvlVomit,
|
startNest(nest, lvlVomit,
|
||||||
format("evaluating expression: %1%") % e);
|
format("evaluating expression: %1%") % e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const unsigned int hugeEvalExpr = 100;
|
state.nrEvaluated++;
|
||||||
unsigned int nrEvaluated = state.nrEvaluated++;
|
|
||||||
state.nrDepthAfterReset++;
|
|
||||||
|
|
||||||
|
if (cacheTerms == 0) return evalExpr2(state, e);
|
||||||
|
|
||||||
|
if (cacheTerms == 2) {
|
||||||
|
int pseudoAddr;
|
||||||
|
Expr e2;
|
||||||
|
if (!matchCell(e, pseudoAddr, e2)) return evalExpr2(state, e);
|
||||||
|
}
|
||||||
|
|
||||||
/* Consult the memo table to quickly get the normal form of
|
/* Consult the memo table to quickly get the normal form of
|
||||||
previously evaluated expressions. */
|
previously evaluated expressions. */
|
||||||
Expr nf = state.normalForms.get(e);
|
Expr nf = state.normalForms.get(e);
|
||||||
if (nf) {
|
if (nf) {
|
||||||
|
//if (nf == makeBlackHole())
|
||||||
|
// throwEvalError("infinite recursion encountered");
|
||||||
state.nrCached++;
|
state.nrCached++;
|
||||||
return nf;
|
return nf;
|
||||||
}
|
}
|
||||||
|
|
||||||
nf = state.sessionNormalForms.get(e);
|
Expr fun, arg;
|
||||||
if (nf) {
|
if (shortCircuit && matchCall(e, fun, arg)) {
|
||||||
if (nf == makeBlackHole())
|
|
||||||
throwEvalError("infinite recursion encountered");
|
|
||||||
state.nrCached++;
|
|
||||||
return nf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Otherwise, evaluate and memoize. */
|
#if 0
|
||||||
state.sessionNormalForms.set(e, makeBlackHole());
|
Expr arg2 = state.normalForms.get(arg);
|
||||||
try {
|
if (arg2) { /* the evaluated argument is now known */
|
||||||
nf = evalExpr2(state, e);
|
//printMsg(lvlError, "foo");
|
||||||
} catch (Error & err) {
|
/* do we know the result of the same function called
|
||||||
state.sessionNormalForms.remove(e);
|
with the evaluated argument? */
|
||||||
throw;
|
Expr res = state.normalForms.get(makeCall(fun, arg2));
|
||||||
}
|
if (res) { /* woohoo! */
|
||||||
|
printMsg(lvlError, "dingdong");
|
||||||
|
state.normalForms.set(e, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// session independent condition
|
assert(activeCallsCount < maxActiveCalls);
|
||||||
if (state.nrDepthAfterReset && state.safeCache &&
|
activeCalls[activeCallsCount++] = e;
|
||||||
// heuristic condition
|
|
||||||
state.nrEvaluated - nrEvaluated > hugeEvalExpr) {
|
//state.normalForms.set(e, makeBlackHole());
|
||||||
state.sessionNormalForms.remove(e);
|
try {
|
||||||
|
nf = evalExpr2(state, e);
|
||||||
|
}
|
||||||
|
catch (ShortCircuit & exception) {
|
||||||
|
//printMsg(lvlError, "catch!");
|
||||||
|
Expr arg2 = state.normalForms.get(arg);
|
||||||
|
if (arg2) { /* the evaluated argument is now known */
|
||||||
|
/* do we know the result of the same function called
|
||||||
|
with the evaluated argument? */
|
||||||
|
Expr res = state.normalForms.get(makeCall(fun, arg2));
|
||||||
|
if (res) { /* woohoo! */
|
||||||
|
//printMsg(lvlError, "woohoo!");
|
||||||
|
//printMsg(lvlError, format("woohoo! %1% %2% %3% %4%") % fun % arg % arg2 % res);
|
||||||
|
activeCallsCount--;
|
||||||
|
state.normalForms.set(e, res);
|
||||||
|
maybeShortCircuit(state, e, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activeCallsCount--;
|
||||||
|
state.normalForms.remove(e);
|
||||||
|
throw; /* not for us */
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
activeCallsCount--;
|
||||||
|
state.normalForms.remove(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
activeCallsCount--;
|
||||||
state.normalForms.set(e, nf);
|
state.normalForms.set(e, nf);
|
||||||
state.nrDepthAfterReset--;
|
Expr arg2 = state.normalForms.get(arg);
|
||||||
} else {
|
if (arg2) state.normalForms.set(makeCall(fun, arg2), nf);
|
||||||
state.sessionNormalForms.set(e, nf);
|
maybeShortCircuit(state, e, nf);
|
||||||
|
return nf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nf;
|
else {
|
||||||
|
|
||||||
|
/* Otherwise, evaluate and memoize. */
|
||||||
|
//state.normalForms.set(e, makeBlackHole());
|
||||||
|
try {
|
||||||
|
nf = evalExpr2(state, e);
|
||||||
|
} catch (...) {
|
||||||
|
state.normalForms.remove(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
state.normalForms.set(e, nf);
|
||||||
|
if (shortCircuit) maybeShortCircuit(state, e, nf);
|
||||||
|
return nf;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Expr evalFile(EvalState & state, const Path & path)
|
Expr evalFile(EvalState & state, const Path & path)
|
||||||
{
|
{
|
||||||
startNest(nest, lvlTalkative, format("evaluating file `%1%'") % path);
|
startNest(nest, lvlTalkative, format("evaluating file `%1%'") % path);
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
Expr e = parseExprFromFile(state, path);
|
Expr e = parseExprFromFile(state, path);
|
||||||
try {
|
try {
|
||||||
return evalExpr(state, e);
|
return evalExpr(state, e);
|
||||||
@@ -898,6 +935,29 @@ static Expr strictEvalExpr_(EvalState & state, Expr e, ATermMap & nfs)
|
|||||||
return makeList(ATreverse(es2));
|
return makeList(ATreverse(es2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATermList formals;
|
||||||
|
ATerm body, pos;
|
||||||
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
|
ATermList formals2 = ATempty;
|
||||||
|
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
Expr name; ValidValues valids; ATerm dummy;
|
||||||
|
if (!matchFormal(*i, name, valids, dummy)) abort();
|
||||||
|
|
||||||
|
ATermList valids2;
|
||||||
|
if (matchValidValues(valids, valids2)) {
|
||||||
|
ATermList valids3 = ATempty;
|
||||||
|
for (ATermIterator j(valids2); j; ++j)
|
||||||
|
valids3 = ATinsert(valids3, strictEvalExpr(state, *j, nfs));
|
||||||
|
valids = makeValidValues(ATreverse(valids3));
|
||||||
|
}
|
||||||
|
|
||||||
|
formals2 = ATinsert(formals2, makeFormal(name, valids, dummy));
|
||||||
|
}
|
||||||
|
|
||||||
|
return makeFunction(ATreverse(formals2), body, pos);
|
||||||
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -927,18 +987,24 @@ extern "C" {
|
|||||||
unsigned long AT_calcAllocatedSize();
|
unsigned long AT_calcAllocatedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int substs = 0;
|
||||||
|
unsigned int substsCached = 0;
|
||||||
|
|
||||||
|
|
||||||
void printEvalStats(EvalState & state)
|
void printEvalStats(EvalState & state)
|
||||||
{
|
{
|
||||||
char x;
|
char x;
|
||||||
bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0";
|
bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0";
|
||||||
|
printMsg(lvlError, format("FNORD %1%") % fnord);
|
||||||
printMsg(showStats ? lvlInfo : lvlDebug,
|
printMsg(showStats ? lvlInfo : lvlDebug,
|
||||||
format("evaluated %1% expressions, %2% cache hits, %3%%% efficiency, used %4% ATerm bytes, used %5% bytes of stack space, %6% cached normal reduction, %7% session dependent reduction.")
|
format("evaluated %1% expressions, %2% cache hits, %3%%% efficiency, used %4% ATerm bytes, used %5% bytes of stack space, %6% substitutions (%7% cached)")
|
||||||
% state.nrEvaluated % state.nrCached
|
% state.nrEvaluated % state.nrCached
|
||||||
% ((float) state.nrCached / (float) state.nrEvaluated * 100)
|
% ((float) state.nrCached / (float) state.nrEvaluated * 100)
|
||||||
% AT_calcAllocatedSize()
|
% AT_calcAllocatedSize()
|
||||||
% (&x - deepestStack)
|
% (&x - deepestStack)
|
||||||
% state.normalForms.size()
|
% substs
|
||||||
% state.sessionNormalForms.size());
|
% substsCached);
|
||||||
if (showStats)
|
if (showStats)
|
||||||
printATermMapStats();
|
printATermMapStats();
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -27,10 +27,12 @@ struct EvalState;
|
|||||||
typedef Expr (* PrimOp) (EvalState &, const ATermVector & args);
|
typedef Expr (* PrimOp) (EvalState &, const ATermVector & args);
|
||||||
|
|
||||||
|
|
||||||
|
extern int cacheTerms; // 0 = don't, 1 = do, 2 = "cell" terms only
|
||||||
|
|
||||||
|
|
||||||
struct EvalState
|
struct EvalState
|
||||||
{
|
{
|
||||||
ATermMap normalForms;
|
ATermMap normalForms;
|
||||||
ATermMap sessionNormalForms;
|
|
||||||
ATermMap primOps;
|
ATermMap primOps;
|
||||||
DrvRoots drvRoots;
|
DrvRoots drvRoots;
|
||||||
DrvHashes drvHashes; /* normalised derivation hashes */
|
DrvHashes drvHashes; /* normalised derivation hashes */
|
||||||
@@ -38,19 +40,16 @@ struct EvalState
|
|||||||
|
|
||||||
unsigned int nrEvaluated;
|
unsigned int nrEvaluated;
|
||||||
unsigned int nrCached;
|
unsigned int nrCached;
|
||||||
unsigned int nrDepthAfterReset;
|
|
||||||
|
|
||||||
bool allowUnsafeEquality;
|
bool strictMode;
|
||||||
bool safeCache;
|
|
||||||
|
ATermMap parsings; /* path -> expr mapping */
|
||||||
|
|
||||||
EvalState();
|
EvalState();
|
||||||
~EvalState();
|
|
||||||
|
|
||||||
void addPrimOps();
|
void addPrimOps();
|
||||||
void addPrimOp(const string & name,
|
void addPrimOp(const string & name,
|
||||||
unsigned int arity, PrimOp primOp);
|
unsigned int arity, PrimOp primOp);
|
||||||
void loadNormalForms();
|
|
||||||
void saveNormalForms();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-31
@@ -4,8 +4,6 @@
|
|||||||
#include "aterm.hh"
|
#include "aterm.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
@@ -40,31 +38,6 @@ static void showAttrs(const ATermMap & attrs, XMLWriter & doc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void printPatternAsXML(Pattern pat, XMLWriter & doc)
|
|
||||||
{
|
|
||||||
ATerm name;
|
|
||||||
ATermList formals;
|
|
||||||
Pattern pat1, pat2;
|
|
||||||
ATermBool ellipsis;
|
|
||||||
if (matchVarPat(pat, name))
|
|
||||||
doc.writeEmptyElement("varpat", singletonAttrs("name", aterm2String(name)));
|
|
||||||
else if (matchAttrsPat(pat, formals, ellipsis)) {
|
|
||||||
XMLOpenElement _(doc, "attrspat");
|
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
|
||||||
Expr name; ATerm dummy;
|
|
||||||
if (!matchFormal(*i, name, dummy)) abort();
|
|
||||||
doc.writeEmptyElement("attr", singletonAttrs("name", aterm2String(name)));
|
|
||||||
}
|
|
||||||
if (ellipsis == eTrue) doc.writeEmptyElement("ellipsis");
|
|
||||||
}
|
|
||||||
else if (matchAtPat(pat, pat1, pat2)) {
|
|
||||||
XMLOpenElement _(doc, "at");
|
|
||||||
printPatternAsXML(pat1, doc);
|
|
||||||
printPatternAsXML(pat2, doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
|
static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
|
||||||
ExprSet & drvsSeen)
|
ExprSet & drvsSeen)
|
||||||
{
|
{
|
||||||
@@ -72,8 +45,8 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
|
|||||||
string s;
|
string s;
|
||||||
ATerm s2;
|
ATerm s2;
|
||||||
int i;
|
int i;
|
||||||
ATermList as, es;
|
ATermList as, es, formals;
|
||||||
ATerm pat, body, pos;
|
ATerm body, pos;
|
||||||
|
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
@@ -134,9 +107,22 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
|
|||||||
printTermAsXML(*i, doc, context, drvsSeen);
|
printTermAsXML(*i, doc, context, drvsSeen);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (matchFunction(e, pat, body, pos)) {
|
else if (matchFunction(e, formals, body, pos)) {
|
||||||
XMLOpenElement _(doc, "function");
|
XMLOpenElement _(doc, "function");
|
||||||
printPatternAsXML(pat, doc);
|
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
Expr name; ValidValues valids; ATerm dummy;
|
||||||
|
if (!matchFormal(*i, name, valids, dummy)) abort();
|
||||||
|
XMLOpenElement _(doc, "arg", singletonAttrs("name", aterm2String(name)));
|
||||||
|
|
||||||
|
ATermList valids2;
|
||||||
|
if (matchValidValues(valids, valids2)) {
|
||||||
|
for (ATermIterator j(valids2); j; ++j) {
|
||||||
|
XMLOpenElement _(doc, "value");
|
||||||
|
printTermAsXML(*j, doc, context, drvsSeen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
+25
-55
@@ -50,55 +50,31 @@ MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const
|
|||||||
Expr e = evalExpr(state, i->value);
|
Expr e = evalExpr(state, i->value);
|
||||||
string s;
|
string s;
|
||||||
PathSet context;
|
PathSet context;
|
||||||
MetaValue value;
|
if (matchStr(e, s, context))
|
||||||
int n;
|
meta[aterm2String(i->key)] = s;
|
||||||
ATermList es;
|
/* For future compatibility, ignore attribute values that are
|
||||||
if (matchStr(e, s, context)) {
|
not strings. */
|
||||||
value.type = MetaValue::tpString;
|
|
||||||
value.stringValue = s;
|
|
||||||
meta[aterm2String(i->key)] = value;
|
|
||||||
} else if (matchInt(e, n)) {
|
|
||||||
value.type = MetaValue::tpInt;
|
|
||||||
value.intValue = n;
|
|
||||||
meta[aterm2String(i->key)] = value;
|
|
||||||
} else if (matchList(e, es)) {
|
|
||||||
value.type = MetaValue::tpStrings;
|
|
||||||
for (ATermIterator j(es); j; ++j)
|
|
||||||
value.stringValues.push_back(evalStringNoCtx(state, *j));
|
|
||||||
meta[aterm2String(i->key)] = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MetaValue DrvInfo::queryMetaInfo(EvalState & state, const string & name) const
|
string DrvInfo::queryMetaInfo(EvalState & state, const string & name) const
|
||||||
{
|
{
|
||||||
/* !!! evaluates all meta attributes => inefficient */
|
/* !!! evaluates all meta attributes => inefficient */
|
||||||
return queryMetaInfo(state)[name];
|
MetaInfo meta = queryMetaInfo(state);
|
||||||
|
MetaInfo::iterator i = meta.find(name);
|
||||||
|
return i == meta.end() ? "" : i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DrvInfo::setMetaInfo(const MetaInfo & meta)
|
void DrvInfo::setMetaInfo(const MetaInfo & meta)
|
||||||
{
|
{
|
||||||
ATermMap metaAttrs;
|
ATermMap metaAttrs;
|
||||||
foreach (MetaInfo::const_iterator, i, meta) {
|
for (MetaInfo::const_iterator i = meta.begin(); i != meta.end(); ++i)
|
||||||
Expr e;
|
metaAttrs.set(toATerm(i->first),
|
||||||
switch (i->second.type) {
|
makeAttrRHS(makeStr(i->second), makeNoPos()));
|
||||||
case MetaValue::tpInt: e = makeInt(i->second.intValue); break;
|
|
||||||
case MetaValue::tpString: e = makeStr(i->second.stringValue); break;
|
|
||||||
case MetaValue::tpStrings: {
|
|
||||||
ATermList es = ATempty;
|
|
||||||
foreach (Strings::const_iterator, j, i->second.stringValues)
|
|
||||||
es = ATinsert(es, makeStr(*j));
|
|
||||||
e = makeList(ATreverse(es));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: abort();
|
|
||||||
}
|
|
||||||
metaAttrs.set(toATerm(i->first), makeAttrRHS(e, makeNoPos()));
|
|
||||||
}
|
|
||||||
attrs->set(toATerm("meta"), makeAttrs(metaAttrs));
|
attrs->set(toATerm("meta"), makeAttrs(metaAttrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +102,7 @@ static bool getDerivation(EvalState & state, Expr e,
|
|||||||
|
|
||||||
boost::shared_ptr<ATermMap> attrs(new ATermMap());
|
boost::shared_ptr<ATermMap> attrs(new ATermMap());
|
||||||
queryAllAttrs(e, *attrs, false);
|
queryAllAttrs(e, *attrs, false);
|
||||||
|
|
||||||
Expr a = attrs->get(toATerm("type"));
|
Expr a = attrs->get(toATerm("type"));
|
||||||
if (!a || evalStringNoCtx(state, a) != "derivation") return true;
|
if (!a || evalStringNoCtx(state, a) != "derivation") return true;
|
||||||
|
|
||||||
@@ -197,30 +173,24 @@ static void getDerivations(EvalState & state, Expr e,
|
|||||||
|
|
||||||
/* !!! undocumented hackery to support combining channels in
|
/* !!! undocumented hackery to support combining channels in
|
||||||
nix-env.cc. */
|
nix-env.cc. */
|
||||||
bool combineChannels = drvMap.get(toATerm("_combineChannels"));
|
Expr e2 = drvMap.get(toATerm("_combineChannels"));
|
||||||
|
bool combineChannels = e2 && evalBool(state, e2);
|
||||||
/* Consider the attributes in sorted order to get more
|
|
||||||
deterministic behaviour in nix-env operations (e.g. when
|
for (ATermMap::const_iterator i = drvMap.begin(); i != drvMap.end(); ++i) {
|
||||||
there are names clashes between derivations, the derivation
|
startNest(nest, lvlDebug,
|
||||||
bound to the attribute with the "lower" name should take
|
format("evaluating attribute `%1%'") % aterm2String(i->key));
|
||||||
precedence). */
|
string pathPrefix2 = addToPath(pathPrefix, aterm2String(i->key));
|
||||||
typedef std::map<string, Expr> AttrsSorted;
|
if (combineChannels) {
|
||||||
AttrsSorted attrsSorted;
|
if (((string) aterm2String(i->key)) != "_combineChannels")
|
||||||
foreach (ATermMap::const_iterator, i, drvMap)
|
getDerivations(state, i->value, pathPrefix2, autoArgs, drvs, doneExprs);
|
||||||
attrsSorted[aterm2String(i->key)] = i->value;
|
}
|
||||||
|
else if (getDerivation(state, i->value, pathPrefix2, drvs, doneExprs)) {
|
||||||
foreach (AttrsSorted::iterator, i, attrsSorted) {
|
|
||||||
startNest(nest, lvlDebug, format("evaluating attribute `%1%'") % i->first);
|
|
||||||
string pathPrefix2 = addToPath(pathPrefix, i->first);
|
|
||||||
if (combineChannels)
|
|
||||||
getDerivations(state, i->second, pathPrefix2, autoArgs, drvs, doneExprs);
|
|
||||||
else if (getDerivation(state, i->second, pathPrefix2, drvs, doneExprs)) {
|
|
||||||
/* If the value of this attribute is itself an
|
/* If the value of this attribute is itself an
|
||||||
attribute set, should we recurse into it? => Only
|
attribute set, should we recurse into it? => Only
|
||||||
if it has a `recurseForDerivations = true'
|
if it has a `recurseForDerivations = true'
|
||||||
attribute. */
|
attribute. */
|
||||||
ATermList es;
|
ATermList es;
|
||||||
Expr e = evalExpr(state, i->second), e2;
|
Expr e = evalExpr(state, i->value);
|
||||||
if (matchAttrs(e, es)) {
|
if (matchAttrs(e, es)) {
|
||||||
ATermMap attrs(ATgetLength(es));
|
ATermMap attrs(ATgetLength(es));
|
||||||
queryAllAttrs(e, attrs, false);
|
queryAllAttrs(e, attrs, false);
|
||||||
|
|||||||
+2
-11
@@ -12,16 +12,7 @@
|
|||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
struct MetaValue
|
typedef std::map<string, string> MetaInfo;
|
||||||
{
|
|
||||||
enum { tpNone, tpString, tpStrings, tpInt } type;
|
|
||||||
string stringValue;
|
|
||||||
Strings stringValues;
|
|
||||||
int intValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<string, MetaValue> MetaInfo;
|
|
||||||
|
|
||||||
|
|
||||||
struct DrvInfo
|
struct DrvInfo
|
||||||
@@ -43,7 +34,7 @@ public:
|
|||||||
string queryDrvPath(EvalState & state) const;
|
string queryDrvPath(EvalState & state) const;
|
||||||
string queryOutPath(EvalState & state) const;
|
string queryOutPath(EvalState & state) const;
|
||||||
MetaInfo queryMetaInfo(EvalState & state) const;
|
MetaInfo queryMetaInfo(EvalState & state) const;
|
||||||
MetaValue queryMetaInfo(EvalState & state, const string & name) const;
|
string queryMetaInfo(EvalState & state, const string & name) const;
|
||||||
|
|
||||||
void setDrvPath(const string & s)
|
void setDrvPath(const string & s)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
|
|
||||||
%x STRING
|
%x STRING
|
||||||
%x IND_STRING
|
|
||||||
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
@@ -95,7 +94,6 @@ let { return LET; }
|
|||||||
in { return IN; }
|
in { return IN; }
|
||||||
rec { return REC; }
|
rec { return REC; }
|
||||||
inherit { return INHERIT; }
|
inherit { return INHERIT; }
|
||||||
\.\.\. { return ELLIPSIS; }
|
|
||||||
|
|
||||||
\=\= { return EQ; }
|
\=\= { return EQ; }
|
||||||
\!\= { return NEQ; }
|
\!\= { return NEQ; }
|
||||||
@@ -124,30 +122,6 @@ inherit { return INHERIT; }
|
|||||||
<STRING>\" { BEGIN(INITIAL); return '"'; }
|
<STRING>\" { BEGIN(INITIAL); return '"'; }
|
||||||
<STRING>. return yytext[0]; /* just in case: shouldn't be reached */
|
<STRING>. return yytext[0]; /* just in case: shouldn't be reached */
|
||||||
|
|
||||||
\'\'(\ *\n)? { BEGIN(IND_STRING); return IND_STRING_OPEN; }
|
|
||||||
<IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
|
|
||||||
yylval->t = makeIndStr(toATerm(yytext));
|
|
||||||
return IND_STR;
|
|
||||||
}
|
|
||||||
<IND_STRING>\'\'\$ {
|
|
||||||
yylval->t = makeIndStr(toATerm("$"));
|
|
||||||
return IND_STR;
|
|
||||||
}
|
|
||||||
<IND_STRING>\'\'\' {
|
|
||||||
yylval->t = makeIndStr(toATerm("''"));
|
|
||||||
return IND_STR;
|
|
||||||
}
|
|
||||||
<IND_STRING>\'\'\\. {
|
|
||||||
yylval->t = unescapeStr(yytext + 2);
|
|
||||||
return IND_STR;
|
|
||||||
}
|
|
||||||
<IND_STRING>\$\{ { BEGIN(INITIAL); return DOLLAR_CURLY; }
|
|
||||||
<IND_STRING>\'\' { BEGIN(INITIAL); return IND_STRING_CLOSE; }
|
|
||||||
<IND_STRING>\' {
|
|
||||||
yylval->t = makeIndStr(toATerm("'"));
|
|
||||||
return IND_STR;
|
|
||||||
}
|
|
||||||
<IND_STRING>. return yytext[0]; /* just in case: shouldn't be reached */
|
|
||||||
|
|
||||||
{PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ }
|
{PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ }
|
||||||
{URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ }
|
{URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ }
|
||||||
@@ -174,10 +148,4 @@ void backToString(yyscan_t scanner)
|
|||||||
BEGIN(STRING);
|
BEGIN(STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void backToIndString(yyscan_t scanner)
|
|
||||||
{
|
|
||||||
struct yyguts_t * yyg = (struct yyguts_t *) scanner;
|
|
||||||
BEGIN(IND_STRING);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-7
@@ -1,13 +1,10 @@
|
|||||||
%% Note: this SDF grammar is no longer used in the Nix expression
|
|
||||||
%% parser and may not be up to date.
|
|
||||||
|
|
||||||
definition
|
definition
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%% Top level syntax.
|
%% Top level syntax.
|
||||||
|
|
||||||
module Main
|
module Nix
|
||||||
imports Nix-Exprs Nix-Layout
|
imports Nix-Exprs Nix-Layout
|
||||||
|
|
||||||
|
|
||||||
@@ -41,7 +38,6 @@ exports
|
|||||||
"with" Expr ";" Expr -> Expr {cons("With")}
|
"with" Expr ";" Expr -> Expr {cons("With")}
|
||||||
|
|
||||||
"rec" "{" Bind* "}" -> Expr {cons("Rec")}
|
"rec" "{" Bind* "}" -> Expr {cons("Rec")}
|
||||||
"let" Bind* "in" Expr -> Expr {cons("Let")}
|
|
||||||
"let" "{" Bind* "}" -> Expr {cons("LetRec")}
|
"let" "{" Bind* "}" -> Expr {cons("LetRec")}
|
||||||
"{" Bind* "}" -> Expr {cons("Attrs")}
|
"{" Bind* "}" -> Expr {cons("Attrs")}
|
||||||
|
|
||||||
@@ -106,8 +102,7 @@ exports
|
|||||||
|
|
||||||
[0-9]+ -> Int
|
[0-9]+ -> Int
|
||||||
|
|
||||||
"\"" (~[\"\\] | ("\\" ~[]) )* "\"" -> Str
|
"\"" ~[\n\"]* "\"" -> Str
|
||||||
"''" (~[\"\\] | ("\\" ~[]) )* "''" -> Str
|
|
||||||
|
|
||||||
[a-zA-Z0-9\.\_\-\+]* ("/"[a-zA-Z0-9\.\_\-\+]+)+ -> Path
|
[a-zA-Z0-9\.\_\-\+]* ("/"[a-zA-Z0-9\.\_\-\+]+)+ -> Path
|
||||||
|
|
||||||
|
|||||||
+10
-13
@@ -3,7 +3,8 @@ init initNixExprHelpers
|
|||||||
Pos | string int int | Pos |
|
Pos | string int int | Pos |
|
||||||
NoPos | | Pos |
|
NoPos | | Pos |
|
||||||
|
|
||||||
Function | Pattern Expr Pos | Expr |
|
Function | ATermList Expr Pos | Expr |
|
||||||
|
Function1 | string Expr Pos | Expr |
|
||||||
Assert | Expr Expr Pos | Expr |
|
Assert | Expr Expr Pos | Expr |
|
||||||
With | Expr Expr Pos | Expr |
|
With | Expr Expr Pos | Expr |
|
||||||
If | Expr Expr Expr | Expr |
|
If | Expr Expr Expr | Expr |
|
||||||
@@ -45,9 +46,6 @@ Int | int | Expr |
|
|||||||
Str | string ATermList | Expr |
|
Str | string ATermList | Expr |
|
||||||
Str | string | Expr | ObsoleteStr
|
Str | string | Expr | ObsoleteStr
|
||||||
|
|
||||||
# Internal to the parser, doesn't occur in ASTs.
|
|
||||||
IndStr | string | Expr |
|
|
||||||
|
|
||||||
# A path is a reference to a file system object that is to be copied
|
# A path is a reference to a file system object that is to be copied
|
||||||
# to the Nix store when used as a derivation attribute. When it is
|
# to the Nix store when used as a derivation attribute. When it is
|
||||||
# concatenated to a string (i.e., `str + path'), it is also copied and
|
# concatenated to a string (i.e., `str + path'), it is also copied and
|
||||||
@@ -66,27 +64,27 @@ PrimOp | int ATermBlob ATermList | Expr |
|
|||||||
Attrs | ATermList | Expr |
|
Attrs | ATermList | Expr |
|
||||||
Closed | Expr | Expr |
|
Closed | Expr | Expr |
|
||||||
Rec | ATermList ATermList | Expr |
|
Rec | ATermList ATermList | Expr |
|
||||||
Bool | ATermBool | Expr |
|
Bool | ATerm | Expr |
|
||||||
Null | | Expr |
|
Null | | Expr |
|
||||||
|
|
||||||
Bind | string Expr Pos | ATerm |
|
Bind | string Expr Pos | ATerm |
|
||||||
BindAttrPath | ATermList Expr Pos | ATerm | # desugared during parsing
|
|
||||||
Bind | string Expr | ATerm | ObsoleteBind
|
Bind | string Expr | ATerm | ObsoleteBind
|
||||||
Inherit | Expr ATermList Pos | ATerm |
|
Inherit | Expr ATermList Pos | ATerm |
|
||||||
|
|
||||||
Scope | | Expr |
|
Scope | | Expr |
|
||||||
|
|
||||||
VarPat | string | Pattern |
|
Cell | int Expr | Expr |
|
||||||
AttrsPat | ATermList ATermBool | Pattern | # bool = `...'
|
|
||||||
AtPat | Pattern Pattern | Pattern |
|
|
||||||
|
|
||||||
Formal | string DefaultValue | ATerm |
|
Formal | string ValidValues DefaultValue | ATerm |
|
||||||
|
|
||||||
|
ValidValues | ATermList | ValidValues |
|
||||||
|
UnrestrictedValues | | ValidValues |
|
||||||
|
|
||||||
DefaultValue | Expr | DefaultValue |
|
DefaultValue | Expr | DefaultValue |
|
||||||
NoDefaultValue | | DefaultValue |
|
NoDefaultValue | | DefaultValue |
|
||||||
|
|
||||||
True | | ATermBool |
|
True | | ATerm |
|
||||||
False | | ATermBool |
|
False | | ATerm |
|
||||||
|
|
||||||
PrimOpDef | int ATermBlob | ATerm |
|
PrimOpDef | int ATermBlob | ATerm |
|
||||||
|
|
||||||
@@ -94,4 +92,3 @@ AttrRHS | Expr Pos | ATerm |
|
|||||||
|
|
||||||
eTrue = makeBool(makeTrue())
|
eTrue = makeBool(makeTrue())
|
||||||
eFalse = makeBool(makeFalse())
|
eFalse = makeBool(makeFalse())
|
||||||
sOverrides = toATerm("__overrides")
|
|
||||||
+164
-59
@@ -2,12 +2,11 @@
|
|||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "aterm.hh"
|
#include "aterm.hh"
|
||||||
|
#include "eval.hh" // !!! urgh
|
||||||
|
|
||||||
#include "nixexpr-ast.hh"
|
#include "nixexpr-ast.hh"
|
||||||
#include "nixexpr-ast.cc"
|
#include "nixexpr-ast.cc"
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
@@ -19,7 +18,7 @@ string showPos(ATerm pos)
|
|||||||
if (matchNoPos(pos)) return "undefined position";
|
if (matchNoPos(pos)) return "undefined position";
|
||||||
if (!matchPos(pos, path, line, column))
|
if (!matchPos(pos, path, line, column))
|
||||||
throw badTerm("position expected", pos);
|
throw badTerm("position expected", pos);
|
||||||
return (format("`%1%:%2%:%3%'") % aterm2String(path) % line % column).str();
|
return (format("`%1%', line %2%") % aterm2String(path) % line).str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -110,32 +109,16 @@ Expr makeAttrs(const ATermMap & attrs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void varsBoundByPattern(ATermMap & map, Pattern pat)
|
extern unsigned int substs;
|
||||||
{
|
extern unsigned int substsCached;
|
||||||
ATerm name;
|
extern bool closedTerms;
|
||||||
ATermList formals;
|
extern bool substCache;
|
||||||
Pattern pat1, pat2;
|
|
||||||
ATermBool ellipsis;
|
|
||||||
/* Use makeRemoved() so that it can be used directly in
|
|
||||||
substitute(). */
|
|
||||||
if (matchVarPat(pat, name))
|
|
||||||
map.set(name, makeRemoved());
|
|
||||||
else if (matchAttrsPat(pat, formals, ellipsis)) {
|
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
|
||||||
ATerm d1;
|
|
||||||
if (!matchFormal(*i, name, d1)) abort();
|
|
||||||
map.set(name, makeRemoved());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (matchAtPat(pat, pat1, pat2)) {
|
|
||||||
varsBoundByPattern(map, pat1);
|
|
||||||
varsBoundByPattern(map, pat2);
|
|
||||||
}
|
|
||||||
else abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Expr substitute(const Substitution & subs, Expr e)
|
static Expr substitute(ATermMap & done, const Substitution & subs, Expr e);
|
||||||
|
|
||||||
|
|
||||||
|
static Expr substitute2(ATermMap & done, const Substitution & subs, Expr e)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
@@ -143,47 +126,77 @@ Expr substitute(const Substitution & subs, Expr e)
|
|||||||
|
|
||||||
ATerm name, pos, e2;
|
ATerm name, pos, e2;
|
||||||
|
|
||||||
|
substs++;
|
||||||
|
|
||||||
/* As an optimisation, don't substitute in subterms known to be
|
/* As an optimisation, don't substitute in subterms known to be
|
||||||
closed. */
|
closed. */
|
||||||
if (matchClosed(e, e2)) return e;
|
if (closedTerms && matchClosed(e, e2)) return e;
|
||||||
|
|
||||||
if (matchVar(e, name)) {
|
if (matchVar(e, name)) {
|
||||||
Expr sub = subs.lookup(name);
|
Expr sub = subs.lookup(name);
|
||||||
if (sub == makeRemoved()) sub = 0;
|
|
||||||
Expr wrapped;
|
Expr wrapped;
|
||||||
/* Add a "closed" wrapper around terms that aren't already
|
/* Add a "closed" wrapper around terms that aren't already
|
||||||
closed. The check is necessary to prevent repeated
|
closed. The check is necessary to prevent repeated
|
||||||
wrapping, e.g., closed(closed(closed(...))), which kills
|
wrapping, e.g., closed(closed(closed(...))), which kills
|
||||||
caching. */
|
caching. */
|
||||||
return sub ? (matchClosed(sub, wrapped) ? sub : makeClosed(sub)) : e;
|
return sub ? ((!closedTerms || matchClosed(sub, wrapped)) ? sub : makeClosed(sub)) : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In case of a function, filter out all variables bound by this
|
/* In case of a function, filter out all variables bound by this
|
||||||
function. */
|
function. */
|
||||||
Pattern pat;
|
ATermList formals;
|
||||||
ATerm body;
|
ATerm body;
|
||||||
if (matchFunction(e, pat, body, pos)) {
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
ATermMap map(16);
|
ATermMap map(ATgetLength(formals));
|
||||||
varsBoundByPattern(map, pat);
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
Substitution subs2(&subs, &map);
|
ATerm d1, d2;
|
||||||
return makeFunction(
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
||||||
(Pattern) substitute(subs2, (Expr) pat),
|
if (subs.lookup(name))
|
||||||
substitute(subs2, body), pos);
|
map.set(name, constRemoved);
|
||||||
|
}
|
||||||
|
if (map.size() == 0)
|
||||||
|
return makeFunction(
|
||||||
|
(ATermList) substitute(done, subs, (ATerm) formals),
|
||||||
|
substitute(done, subs, body), pos);
|
||||||
|
else {
|
||||||
|
Substitution subs2(&subs, &map);
|
||||||
|
ATermMap done2(128);
|
||||||
|
return makeFunction(
|
||||||
|
(ATermList) substitute(done2, subs2, (ATerm) formals),
|
||||||
|
substitute(done2, subs2, body), pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matchFunction1(e, name, body, pos)) {
|
||||||
|
if (subs.lookup(name)) {
|
||||||
|
ATermMap map(1);
|
||||||
|
map.set(name, constRemoved);
|
||||||
|
ATermMap done2(128);
|
||||||
|
return makeFunction1(name, substitute(done2, Substitution(&subs, &map), body), pos);
|
||||||
|
} else
|
||||||
|
return makeFunction1(name, substitute(done, subs, body), pos);
|
||||||
|
}
|
||||||
|
|
||||||
/* Idem for a mutually recursive attribute set. */
|
/* Idem for a mutually recursive attribute set. */
|
||||||
ATermList rbnds, nrbnds;
|
ATermList rbnds, nrbnds;
|
||||||
if (matchRec(e, rbnds, nrbnds)) {
|
if (matchRec(e, rbnds, nrbnds)) {
|
||||||
ATermMap map(ATgetLength(rbnds) + ATgetLength(nrbnds));
|
ATermMap map(ATgetLength(rbnds) + ATgetLength(nrbnds));
|
||||||
for (ATermIterator i(rbnds); i; ++i)
|
for (ATermIterator i(rbnds); i; ++i)
|
||||||
if (matchBind(*i, name, e2, pos)) map.set(name, makeRemoved());
|
if (matchBind(*i, name, e2, pos) && subs.lookup(name))
|
||||||
else abort(); /* can't happen */
|
map.set(name, constRemoved);
|
||||||
for (ATermIterator i(nrbnds); i; ++i)
|
for (ATermIterator i(nrbnds); i; ++i)
|
||||||
if (matchBind(*i, name, e2, pos)) map.set(name, makeRemoved());
|
if (matchBind(*i, name, e2, pos) && subs.lookup(name))
|
||||||
else abort(); /* can't happen */
|
map.set(name, constRemoved);
|
||||||
return makeRec(
|
if (map.size() == 0)
|
||||||
(ATermList) substitute(Substitution(&subs, &map), (ATerm) rbnds),
|
return makeRec(
|
||||||
(ATermList) substitute(subs, (ATerm) nrbnds));
|
(ATermList) substitute(done, subs, (ATerm) rbnds),
|
||||||
|
(ATermList) substitute(done, subs, (ATerm) nrbnds));
|
||||||
|
else {
|
||||||
|
ATermMap done2(128);
|
||||||
|
return makeRec(
|
||||||
|
(ATermList) substitute(done2, Substitution(&subs, &map), (ATerm) rbnds),
|
||||||
|
(ATermList) substitute(done, subs, (ATerm) nrbnds));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ATgetType(e) == AT_APPL) {
|
if (ATgetType(e) == AT_APPL) {
|
||||||
@@ -194,7 +207,73 @@ Expr substitute(const Substitution & subs, Expr e)
|
|||||||
|
|
||||||
for (int i = 0; i < arity; ++i) {
|
for (int i = 0; i < arity; ++i) {
|
||||||
ATerm arg = ATgetArgument(e, i);
|
ATerm arg = ATgetArgument(e, i);
|
||||||
args[i] = substitute(subs, arg);
|
args[i] = substitute(done, subs, arg);
|
||||||
|
if (args[i] != arg) changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed ? (ATerm) ATmakeApplArray(fun, args) : e;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ATgetType(e) == AT_LIST) {
|
||||||
|
unsigned int len = ATgetLength((ATermList) e);
|
||||||
|
ATerm es[len];
|
||||||
|
ATermIterator i((ATermList) e);
|
||||||
|
bool changed = false;
|
||||||
|
for (unsigned int j = 0; i; ++i, ++j) {
|
||||||
|
es[j] = substitute(done, subs, *i);
|
||||||
|
if (es[j] != *i) changed = true;
|
||||||
|
}
|
||||||
|
if (!changed) return e;
|
||||||
|
ATermList out = ATempty;
|
||||||
|
for (unsigned int j = len; j; --j)
|
||||||
|
out = ATinsert(out, es[j - 1]);
|
||||||
|
return (ATerm) out;
|
||||||
|
}
|
||||||
|
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Expr substitute(ATermMap & done, const Substitution & subs, Expr e)
|
||||||
|
{
|
||||||
|
Expr res = done[e];
|
||||||
|
if (substCache && res) {
|
||||||
|
substsCached++;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
res = substitute2(done, subs, e);
|
||||||
|
done.set(e, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr substitute(const Substitution & subs, Expr e)
|
||||||
|
{
|
||||||
|
ATermMap done(256);
|
||||||
|
return substitute(done, subs, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Expr allocCells(Expr e)
|
||||||
|
{
|
||||||
|
checkInterrupt();
|
||||||
|
|
||||||
|
ATerm e2;
|
||||||
|
if (matchClosed(e, e2)) return e;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
if (matchCell(e, i, e2))
|
||||||
|
return allocCell(allocCells(e2));
|
||||||
|
|
||||||
|
if (ATgetType(e) == AT_APPL) {
|
||||||
|
AFun fun = ATgetAFun(e);
|
||||||
|
int arity = ATgetArity(fun);
|
||||||
|
ATerm args[arity];
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < arity; ++i) {
|
||||||
|
ATerm arg = ATgetArgument(e, i);
|
||||||
|
args[i] = allocCells(arg);
|
||||||
if (args[i] != arg) changed = true;
|
if (args[i] != arg) changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +285,7 @@ Expr substitute(const Substitution & subs, Expr e)
|
|||||||
ATerm es[len];
|
ATerm es[len];
|
||||||
ATermIterator i((ATermList) e);
|
ATermIterator i((ATermList) e);
|
||||||
for (unsigned int j = 0; i; ++i, ++j)
|
for (unsigned int j = 0; i; ++i, ++j)
|
||||||
es[j] = substitute(subs, *i);
|
es[j] = allocCells(*i);
|
||||||
ATermList out = ATempty;
|
ATermList out = ATempty;
|
||||||
for (unsigned int j = len; j; --j)
|
for (unsigned int j = len; j; --j)
|
||||||
out = ATinsert(out, es[j - 1]);
|
out = ATinsert(out, es[j - 1]);
|
||||||
@@ -228,25 +307,38 @@ static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e)
|
|||||||
done.insert(e);
|
done.insert(e);
|
||||||
|
|
||||||
ATerm name, pos, value;
|
ATerm name, pos, value;
|
||||||
|
ATermList formals;
|
||||||
ATerm with, body;
|
ATerm with, body;
|
||||||
ATermList rbnds, nrbnds;
|
ATermList rbnds, nrbnds;
|
||||||
Pattern pat;
|
|
||||||
|
|
||||||
/* Closed terms don't have free variables, so we don't have to
|
if (matchVar(e, name)) {
|
||||||
check by definition. */
|
|
||||||
if (matchClosed(e, value)) return;
|
|
||||||
|
|
||||||
else if (matchVar(e, name)) {
|
|
||||||
if (!defs.get(name))
|
if (!defs.get(name))
|
||||||
throw EvalError(format("undefined variable `%1%'")
|
throw EvalError(format("undefined variable `%1%'")
|
||||||
% aterm2String(name));
|
% aterm2String(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (matchFunction(e, pat, body, pos)) {
|
else if (matchFunction(e, formals, body, pos)) {
|
||||||
ATermMap defs2(defs);
|
ATermMap defs2(defs);
|
||||||
varsBoundByPattern(defs2, pat);
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
ATerm d1, d2;
|
||||||
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
||||||
|
defs2.set(name, (ATerm) ATempty);
|
||||||
|
}
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
ATerm valids, deflt;
|
||||||
|
set<Expr> done2;
|
||||||
|
if (!matchFormal(*i, name, valids, deflt)) abort();
|
||||||
|
checkVarDefs2(done, defs, valids);
|
||||||
|
checkVarDefs2(done2, defs2, deflt);
|
||||||
|
}
|
||||||
|
set<Expr> done2;
|
||||||
|
checkVarDefs2(done2, defs2, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (matchFunction1(e, name, body, pos)) {
|
||||||
|
ATermMap defs2(defs);
|
||||||
|
defs2.set(name, (ATerm) ATempty);
|
||||||
set<Expr> done2;
|
set<Expr> done2;
|
||||||
checkVarDefs2(done2, defs2, pat);
|
|
||||||
checkVarDefs2(done2, defs2, body);
|
checkVarDefs2(done2, defs2, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,17 +452,17 @@ Expr makeStr(const string & s, const PathSet & context)
|
|||||||
|
|
||||||
string showType(Expr e)
|
string showType(Expr e)
|
||||||
{
|
{
|
||||||
ATerm t1, t2;
|
ATerm t1, t2, t3;
|
||||||
ATermList l1;
|
ATermList l1;
|
||||||
ATermBlob b1;
|
ATermBlob b1;
|
||||||
int i1;
|
int i1;
|
||||||
Pattern p1;
|
|
||||||
if (matchStr(e, t1, l1)) return "a string";
|
if (matchStr(e, t1, l1)) return "a string";
|
||||||
if (matchPath(e, t1)) return "a path";
|
if (matchPath(e, t1)) return "a path";
|
||||||
if (matchNull(e)) return "null";
|
if (matchNull(e)) return "null";
|
||||||
if (matchInt(e, i1)) return "an integer";
|
if (matchInt(e, i1)) return "an integer";
|
||||||
if (matchBool(e, t1)) return "a boolean";
|
if (matchBool(e, t1)) return "a boolean";
|
||||||
if (matchFunction(e, p1, t1, t2)) return "a function";
|
if (matchFunction(e, l1, t1, t2)) return "a function";
|
||||||
|
if (matchFunction1(e, t1, t2, t3)) return "a function";
|
||||||
if (matchAttrs(e, l1)) return "an attribute set";
|
if (matchAttrs(e, l1)) return "an attribute set";
|
||||||
if (matchList(e, l1)) return "a list";
|
if (matchList(e, l1)) return "a list";
|
||||||
if (matchPrimOp(e, i1, b1, l1)) return "a partially applied built-in function";
|
if (matchPrimOp(e, i1, b1, l1)) return "a partially applied built-in function";
|
||||||
@@ -403,5 +495,18 @@ string showValue(Expr e)
|
|||||||
return "<unknown>";
|
return "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned int cellCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
Expr allocCell(Expr e)
|
||||||
|
{
|
||||||
|
if (cacheTerms != 2) return e;
|
||||||
|
int i;
|
||||||
|
Expr e2;
|
||||||
|
if (matchCell(e, i, e2)) return e;
|
||||||
|
return makeCell(cellCount++, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+13
-4
@@ -11,7 +11,6 @@ namespace nix {
|
|||||||
|
|
||||||
|
|
||||||
MakeError(EvalError, Error)
|
MakeError(EvalError, Error)
|
||||||
MakeError(ParseError, Error)
|
|
||||||
MakeError(AssertionError, EvalError)
|
MakeError(AssertionError, EvalError)
|
||||||
MakeError(ThrownError, AssertionError)
|
MakeError(ThrownError, AssertionError)
|
||||||
MakeError(Abort, EvalError)
|
MakeError(Abort, EvalError)
|
||||||
@@ -22,10 +21,11 @@ MakeError(TypeError, EvalError)
|
|||||||
property of the ATerm library allows us to implement caching of
|
property of the ATerm library allows us to implement caching of
|
||||||
normals forms efficiently. */
|
normals forms efficiently. */
|
||||||
typedef ATerm Expr;
|
typedef ATerm Expr;
|
||||||
|
|
||||||
typedef ATerm DefaultValue;
|
typedef ATerm DefaultValue;
|
||||||
|
typedef ATerm ValidValues;
|
||||||
|
|
||||||
typedef ATerm Pos;
|
typedef ATerm Pos;
|
||||||
typedef ATerm Pattern;
|
|
||||||
typedef ATerm ATermBool;
|
|
||||||
|
|
||||||
|
|
||||||
/* A STL vector of ATerms. Should be used with great care since it's
|
/* A STL vector of ATerms. Should be used with great care since it's
|
||||||
@@ -34,6 +34,9 @@ typedef ATerm ATermBool;
|
|||||||
typedef vector<ATerm> ATermVector;
|
typedef vector<ATerm> ATermVector;
|
||||||
|
|
||||||
|
|
||||||
|
extern Expr constRemoved;
|
||||||
|
|
||||||
|
|
||||||
/* A substitution is a linked list of ATermMaps that map names to
|
/* A substitution is a linked list of ATermMaps that map names to
|
||||||
identifiers. We use a list of ATermMaps rather than a single to
|
identifiers. We use a list of ATermMaps rather than a single to
|
||||||
make it easy to grow or shrink a substitution when entering a
|
make it easy to grow or shrink a substitution when entering a
|
||||||
@@ -53,7 +56,8 @@ struct Substitution
|
|||||||
{
|
{
|
||||||
Expr x;
|
Expr x;
|
||||||
for (const Substitution * s(this); s; s = s->prev)
|
for (const Substitution * s(this); s; s = s->prev)
|
||||||
if ((x = s->map->get(name))) return x;
|
if ((x = s->map->get(name)))
|
||||||
|
return x == constRemoved ? 0 : x;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -116,6 +120,11 @@ string showType(Expr e);
|
|||||||
|
|
||||||
string showValue(Expr e);
|
string showValue(Expr e);
|
||||||
|
|
||||||
|
|
||||||
|
Expr allocCell(Expr e); // make an updateable cell (for simulating conventional laziness)
|
||||||
|
|
||||||
|
Expr allocCells(Expr e); // re-allocate all cells in e
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
#include "eval.hh"
|
|
||||||
#include "util.hh"
|
|
||||||
#include "globals.hh"
|
|
||||||
#include "serialise.hh"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
|
|
||||||
void EvalState::loadNormalForms()
|
|
||||||
{
|
|
||||||
// nixCacheFile = getEnv("NIX_CACHE_FILE", nixStateDir + "/reduce-cache");
|
|
||||||
nixCacheFile = getEnv("NIX_CACHE_FILE");
|
|
||||||
string loadFlag = getEnv("NIX_CACHE_FILE_LOAD", "1");
|
|
||||||
|
|
||||||
if(nixCacheFile == "" || loadFlag == "")
|
|
||||||
return;
|
|
||||||
if(!pathExists(nixCacheFile))
|
|
||||||
return;
|
|
||||||
|
|
||||||
printMsg(lvlInfo, format("Load cache: ..."));
|
|
||||||
try {
|
|
||||||
int fd = open(nixCacheFile.c_str(), O_RDONLY);
|
|
||||||
if (fd == -1)
|
|
||||||
throw SysError(format("opening file `%1%'") % nixCacheFile);
|
|
||||||
AutoCloseFD auto_fd = fd;
|
|
||||||
|
|
||||||
FdSource source = fd;
|
|
||||||
normalForms = readATermMap(source);
|
|
||||||
} catch (Error & e) {
|
|
||||||
e.addPrefix(format("Cannot load cached reduce operations from %1%:\n") % nixCacheFile);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
printMsg(lvlInfo, format("Load cache: end"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void EvalState::saveNormalForms()
|
|
||||||
{
|
|
||||||
string saveFlag = getEnv("NIX_CACHE_FILE_SAVE", "");
|
|
||||||
|
|
||||||
if(nixCacheFile == "" || saveFlag == "")
|
|
||||||
return;
|
|
||||||
|
|
||||||
printMsg(lvlInfo, format("Save cache: ..."));
|
|
||||||
try {
|
|
||||||
int fd = open(nixCacheFile.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
|
||||||
if (fd == -1)
|
|
||||||
throw SysError(format("opening file `%1%'") % nixCacheFile);
|
|
||||||
AutoCloseFD auto_fd = fd;
|
|
||||||
|
|
||||||
FdSink sink = fd;
|
|
||||||
writeATermMap(normalForms, sink);
|
|
||||||
} catch (Error & e) {
|
|
||||||
e.addPrefix(format("Cannot save cached reduce operations to %1%:\n") % nixCacheFile);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
printMsg(lvlInfo, format("Save cache: end"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+108
-265
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "parser-tab.hh"
|
#include "parser-tab.hh"
|
||||||
#include "lexer-tab.hh"
|
#include "lexer-tab.hh"
|
||||||
#define YYSTYPE YYSTYPE // workaround a bug in Bison 2.4
|
|
||||||
|
|
||||||
#include "nixexpr.hh"
|
#include "nixexpr.hh"
|
||||||
#include "nixexpr-ast.hh"
|
#include "nixexpr-ast.hh"
|
||||||
@@ -44,229 +43,40 @@ struct ParseData
|
|||||||
Path path;
|
Path path;
|
||||||
string error;
|
string error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static string showAttrPath(ATermList attrPath)
|
|
||||||
|
static Expr fixAttrs(int recursive, ATermList as)
|
||||||
{
|
{
|
||||||
string s;
|
ATermList bs = ATempty, cs = ATempty;
|
||||||
for (ATermIterator i(attrPath); i; ++i) {
|
ATermList * is = recursive ? &cs : &bs;
|
||||||
if (!s.empty()) s += '.';
|
|
||||||
s += aterm2String(*i);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct Tree
|
|
||||||
{
|
|
||||||
Expr leaf; ATerm pos; bool recursive;
|
|
||||||
typedef std::map<ATerm, Tree> Children;
|
|
||||||
Children children;
|
|
||||||
Tree() { leaf = 0; recursive = true; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static ATermList buildAttrs(const Tree & t, ATermList & nonrec)
|
|
||||||
{
|
|
||||||
ATermList res = ATempty;
|
|
||||||
for (Tree::Children::const_reverse_iterator i = t.children.rbegin();
|
|
||||||
i != t.children.rend(); ++i)
|
|
||||||
if (!i->second.recursive)
|
|
||||||
nonrec = ATinsert(nonrec, makeBind(i->first, i->second.leaf, i->second.pos));
|
|
||||||
else
|
|
||||||
res = ATinsert(res, i->second.leaf
|
|
||||||
? makeBind(i->first, i->second.leaf, i->second.pos)
|
|
||||||
: makeBind(i->first, makeAttrs(buildAttrs(i->second, nonrec)), makeNoPos()));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr fixAttrs(bool recursive, ATermList as)
|
|
||||||
{
|
|
||||||
Tree attrs;
|
|
||||||
|
|
||||||
for (ATermIterator i(as); i; ++i) {
|
for (ATermIterator i(as); i; ++i) {
|
||||||
ATermList names, attrPath; Expr src, e; ATerm name, pos;
|
ATermList names;
|
||||||
|
Expr src;
|
||||||
|
ATerm pos;
|
||||||
if (matchInherit(*i, src, names, pos)) {
|
if (matchInherit(*i, src, names, pos)) {
|
||||||
bool fromScope = matchScope(src);
|
bool fromScope = matchScope(src);
|
||||||
for (ATermIterator j(names); j; ++j) {
|
for (ATermIterator j(names); j; ++j) {
|
||||||
if (attrs.children.find(*j) != attrs.children.end())
|
Expr rhs = fromScope ? makeVar(*j) : makeSelect(src, *j);
|
||||||
throw ParseError(format("duplicate definition of attribute `%1%' at %2%")
|
*is = ATinsert(*is, makeBind(*j, allocCell(rhs), pos));
|
||||||
% showAttrPath(ATmakeList1(*j)) % showPos(pos));
|
|
||||||
Tree & t(attrs.children[*j]);
|
|
||||||
t.leaf = fromScope ? makeVar(*j) : makeSelect(src, *j);
|
|
||||||
t.pos = pos;
|
|
||||||
if (recursive && fromScope) t.recursive = false;
|
|
||||||
}
|
}
|
||||||
}
|
} else bs = ATinsert(bs, *i);
|
||||||
|
|
||||||
else if (matchBindAttrPath(*i, attrPath, e, pos)) {
|
|
||||||
|
|
||||||
Tree * t(&attrs);
|
|
||||||
|
|
||||||
for (ATermIterator j(attrPath); j; ) {
|
|
||||||
name = *j; ++j;
|
|
||||||
if (t->leaf) throw ParseError(format("attribute set containing `%1%' at %2% already defined at %3%")
|
|
||||||
% showAttrPath(attrPath) % showPos(pos) % showPos (t->pos));
|
|
||||||
t = &(t->children[name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t->leaf)
|
|
||||||
throw ParseError(format("duplicate definition of attribute `%1%' at %2% and %3%")
|
|
||||||
% showAttrPath(attrPath) % showPos(pos) % showPos (t->pos));
|
|
||||||
if (!t->children.empty())
|
|
||||||
throw ParseError(format("duplicate definition of attribute `%1%' at %2%")
|
|
||||||
% showAttrPath(attrPath) % showPos(pos));
|
|
||||||
|
|
||||||
t->leaf = e; t->pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
else abort(); /* can't happen */
|
|
||||||
}
|
}
|
||||||
|
if (recursive)
|
||||||
ATermList nonrec = ATempty;
|
return makeRec(bs, cs);
|
||||||
ATermList rec = buildAttrs(attrs, nonrec);
|
else
|
||||||
|
return makeAttrs(bs);
|
||||||
return recursive ? makeRec(rec, nonrec) : makeAttrs(rec);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void checkPatternVars(ATerm pos, ATermMap & map, Pattern pat)
|
|
||||||
{
|
|
||||||
ATerm name;
|
|
||||||
ATermList formals;
|
|
||||||
Pattern pat1, pat2;
|
|
||||||
ATermBool ellipsis;
|
|
||||||
if (matchVarPat(pat, name)) {
|
|
||||||
if (map.get(name))
|
|
||||||
throw ParseError(format("duplicate formal function argument `%1%' at %2%")
|
|
||||||
% aterm2String(name) % showPos(pos));
|
|
||||||
map.set(name, name);
|
|
||||||
}
|
|
||||||
else if (matchAttrsPat(pat, formals, ellipsis)) {
|
|
||||||
for (ATermIterator i(formals); i; ++i) {
|
|
||||||
ATerm d1;
|
|
||||||
if (!matchFormal(*i, name, d1)) abort();
|
|
||||||
if (map.get(name))
|
|
||||||
throw ParseError(format("duplicate formal function argument `%1%' at %2%")
|
|
||||||
% aterm2String(name) % showPos(pos));
|
|
||||||
map.set(name, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (matchAtPat(pat, pat1, pat2)) {
|
|
||||||
checkPatternVars(pos, map, pat1);
|
|
||||||
checkPatternVars(pos, map, pat2);
|
|
||||||
}
|
|
||||||
else abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void checkPatternVars(ATerm pos, Pattern pat)
|
|
||||||
{
|
|
||||||
ATermMap map;
|
|
||||||
checkPatternVars(pos, map, pat);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr stripIndentation(ATermList es)
|
|
||||||
{
|
|
||||||
if (es == ATempty) return makeStr("");
|
|
||||||
|
|
||||||
/* Figure out the minimum indentation. Note that by design
|
|
||||||
whitespace-only final lines are not taken into account. (So
|
|
||||||
the " " in "\n ''" is ignored, but the " " in "\n foo''" is.) */
|
|
||||||
bool atStartOfLine = true; /* = seen only whitespace in the current line */
|
|
||||||
unsigned int minIndent = 1000000;
|
|
||||||
unsigned int curIndent = 0;
|
|
||||||
ATerm e;
|
|
||||||
for (ATermIterator i(es); i; ++i) {
|
|
||||||
if (!matchIndStr(*i, e)) {
|
|
||||||
/* Anti-quotations end the current start-of-line whitespace. */
|
|
||||||
if (atStartOfLine) {
|
|
||||||
atStartOfLine = false;
|
|
||||||
if (curIndent < minIndent) minIndent = curIndent;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
string s = aterm2String(e);
|
|
||||||
for (unsigned int j = 0; j < s.size(); ++j) {
|
|
||||||
if (atStartOfLine) {
|
|
||||||
if (s[j] == ' ')
|
|
||||||
curIndent++;
|
|
||||||
else if (s[j] == '\n') {
|
|
||||||
/* Empty line, doesn't influence minimum
|
|
||||||
indentation. */
|
|
||||||
curIndent = 0;
|
|
||||||
} else {
|
|
||||||
atStartOfLine = false;
|
|
||||||
if (curIndent < minIndent) minIndent = curIndent;
|
|
||||||
}
|
|
||||||
} else if (s[j] == '\n') {
|
|
||||||
atStartOfLine = true;
|
|
||||||
curIndent = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Strip spaces from each line. */
|
|
||||||
ATermList es2 = ATempty;
|
|
||||||
atStartOfLine = true;
|
|
||||||
unsigned int curDropped = 0;
|
|
||||||
unsigned int n = ATgetLength(es);
|
|
||||||
for (ATermIterator i(es); i; ++i, --n) {
|
|
||||||
if (!matchIndStr(*i, e)) {
|
|
||||||
atStartOfLine = false;
|
|
||||||
curDropped = 0;
|
|
||||||
es2 = ATinsert(es2, *i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string s = aterm2String(e);
|
|
||||||
string s2;
|
|
||||||
for (unsigned int j = 0; j < s.size(); ++j) {
|
|
||||||
if (atStartOfLine) {
|
|
||||||
if (s[j] == ' ') {
|
|
||||||
if (curDropped++ >= minIndent)
|
|
||||||
s2 += s[j];
|
|
||||||
}
|
|
||||||
else if (s[j] == '\n') {
|
|
||||||
curDropped = 0;
|
|
||||||
s2 += s[j];
|
|
||||||
} else {
|
|
||||||
atStartOfLine = false;
|
|
||||||
curDropped = 0;
|
|
||||||
s2 += s[j];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
s2 += s[j];
|
|
||||||
if (s[j] == '\n') atStartOfLine = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove the last line if it is empty and consists only of
|
|
||||||
spaces. */
|
|
||||||
if (n == 1) {
|
|
||||||
string::size_type p = s2.find_last_of('\n');
|
|
||||||
if (p != string::npos && s2.find_first_not_of(' ', p + 1) == string::npos)
|
|
||||||
s2 = string(s2, 0, p + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
es2 = ATinsert(es2, makeStr(s2));
|
|
||||||
}
|
|
||||||
|
|
||||||
return makeConcatStrings(ATreverse(es2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void backToString(yyscan_t scanner);
|
void backToString(yyscan_t scanner);
|
||||||
void backToIndString(yyscan_t scanner);
|
|
||||||
|
|
||||||
|
|
||||||
|
extern bool posInfo;
|
||||||
|
|
||||||
static Pos makeCurPos(YYLTYPE * loc, ParseData * data)
|
static Pos makeCurPos(YYLTYPE * loc, ParseData * data)
|
||||||
{
|
{
|
||||||
return makePos(toATerm(data->path),
|
return posInfo ? makePos(toATerm(data->path),
|
||||||
loc->first_line, loc->first_column);
|
loc->first_line, loc->first_column) : makeNoPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CUR_POS makeCurPos(yylocp, data)
|
#define CUR_POS makeCurPos(yylocp, data)
|
||||||
@@ -309,22 +119,14 @@ static void freeAndUnprotect(void * p)
|
|||||||
%union {
|
%union {
|
||||||
ATerm t;
|
ATerm t;
|
||||||
ATermList ts;
|
ATermList ts;
|
||||||
struct {
|
|
||||||
ATermList formals;
|
|
||||||
bool ellipsis;
|
|
||||||
} formals;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%type <t> start expr expr_function expr_if expr_op
|
%type <t> start expr expr_function expr_if expr_op
|
||||||
%type <t> expr_app expr_select expr_simple bind inheritsrc formal
|
%type <t> expr_app expr_select expr_simple bind inheritsrc formal
|
||||||
%type <t> pattern pattern2
|
%type <ts> binds ids expr_list formals string_parts
|
||||||
%type <ts> binds ids attrpath expr_list string_parts ind_string_parts
|
%token <t> ID INT STR PATH URI
|
||||||
%type <formals> formals
|
|
||||||
%token <t> ID INT STR IND_STR PATH URI
|
|
||||||
%token IF THEN ELSE ASSERT WITH LET IN REC INHERIT EQ NEQ AND OR IMPL
|
%token IF THEN ELSE ASSERT WITH LET IN REC INHERIT EQ NEQ AND OR IMPL
|
||||||
%token DOLLAR_CURLY /* == ${ */
|
%token DOLLAR_CURLY /* == ${ */
|
||||||
%token IND_STRING_OPEN IND_STRING_CLOSE
|
|
||||||
%token ELLIPSIS
|
|
||||||
|
|
||||||
%nonassoc IMPL
|
%nonassoc IMPL
|
||||||
%left OR
|
%left OR
|
||||||
@@ -344,14 +146,16 @@ start: expr { data->result = $1; };
|
|||||||
expr: expr_function;
|
expr: expr_function;
|
||||||
|
|
||||||
expr_function
|
expr_function
|
||||||
: pattern ':' expr_function
|
: '{' formals '}' ':' expr_function
|
||||||
{ checkPatternVars(CUR_POS, $1); $$ = makeFunction($1, $3, CUR_POS); }
|
{ $$ = makeFunction($2, $5, CUR_POS); }
|
||||||
|
| ID ':' expr_function
|
||||||
|
{ $$ = makeFunction1($1, $3, CUR_POS); }
|
||||||
| ASSERT expr ';' expr_function
|
| ASSERT expr ';' expr_function
|
||||||
{ $$ = makeAssert($2, $4, CUR_POS); }
|
{ $$ = makeAssert($2, $4, CUR_POS); }
|
||||||
| WITH expr ';' expr_function
|
| WITH expr ';' expr_function
|
||||||
{ $$ = makeWith($2, $4, CUR_POS); }
|
{ $$ = makeWith($2, $4, CUR_POS); }
|
||||||
| LET binds IN expr_function
|
| LET binds IN expr_function
|
||||||
{ $$ = makeSelect(fixAttrs(true, ATinsert($2, makeBindAttrPath(ATmakeList1(toATerm("<let-body>")), $4, CUR_POS))), toATerm("<let-body>")); }
|
{ $$ = makeSelect(fixAttrs(1, ATinsert($2, makeBind(toATerm("<let-body>"), $4, CUR_POS))), toATerm("<let-body>")); }
|
||||||
| expr_if
|
| expr_if
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -397,21 +201,18 @@ expr_simple
|
|||||||
else if (ATgetNext($2) == ATempty) $$ = ATgetFirst($2);
|
else if (ATgetNext($2) == ATempty) $$ = ATgetFirst($2);
|
||||||
else $$ = makeConcatStrings(ATreverse($2));
|
else $$ = makeConcatStrings(ATreverse($2));
|
||||||
}
|
}
|
||||||
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {
|
|
||||||
$$ = stripIndentation(ATreverse($2));
|
|
||||||
}
|
|
||||||
| PATH { $$ = makePath(toATerm(absPath(aterm2String($1), data->basePath))); }
|
| PATH { $$ = makePath(toATerm(absPath(aterm2String($1), data->basePath))); }
|
||||||
| URI { $$ = makeStr($1, ATempty); }
|
| URI { $$ = makeStr($1, ATempty); }
|
||||||
| '(' expr ')' { $$ = $2; }
|
| '(' expr ')' { $$ = $2; }
|
||||||
/* Let expressions `let {..., body = ...}' are just desugared
|
/* Let expressions `let {..., body = ...}' are just desugared
|
||||||
into `(rec {..., body = ...}).body'. */
|
into `(rec {..., body = ...}).body'. */
|
||||||
| LET '{' binds '}'
|
| LET '{' binds '}'
|
||||||
{ $$ = makeSelect(fixAttrs(true, $3), toATerm("body")); }
|
{ $$ = makeSelect(fixAttrs(1, $3), toATerm("body")); }
|
||||||
| REC '{' binds '}'
|
| REC '{' binds '}'
|
||||||
{ $$ = fixAttrs(true, $3); }
|
{ $$ = fixAttrs(1, $3); }
|
||||||
| '{' binds '}'
|
| '{' binds '}'
|
||||||
{ $$ = fixAttrs(false, $2); }
|
{ $$ = fixAttrs(0, $2); }
|
||||||
| '[' expr_list ']' { $$ = makeList(ATreverse($2)); }
|
| '[' expr_list ']' { $$ = makeList($2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
string_parts
|
string_parts
|
||||||
@@ -420,30 +221,14 @@ string_parts
|
|||||||
| { $$ = ATempty; }
|
| { $$ = ATempty; }
|
||||||
;
|
;
|
||||||
|
|
||||||
ind_string_parts
|
|
||||||
: ind_string_parts IND_STR { $$ = ATinsert($1, $2); }
|
|
||||||
| ind_string_parts DOLLAR_CURLY expr '}' { backToIndString(scanner); $$ = ATinsert($1, $3); }
|
|
||||||
| { $$ = ATempty; }
|
|
||||||
;
|
|
||||||
|
|
||||||
pattern
|
|
||||||
: pattern2 '@' pattern { $$ = makeAtPat($1, $3); }
|
|
||||||
| pattern2
|
|
||||||
;
|
|
||||||
|
|
||||||
pattern2
|
|
||||||
: ID { $$ = makeVarPat($1); }
|
|
||||||
| '{' formals '}' { $$ = makeAttrsPat($2.formals, $2.ellipsis ? eTrue : eFalse); }
|
|
||||||
;
|
|
||||||
|
|
||||||
binds
|
binds
|
||||||
: binds bind { $$ = ATinsert($1, $2); }
|
: binds bind { $$ = ATinsert($1, $2); }
|
||||||
| { $$ = ATempty; }
|
| { $$ = ATempty; }
|
||||||
;
|
;
|
||||||
|
|
||||||
bind
|
bind
|
||||||
: attrpath '=' expr ';'
|
: ID '=' expr ';'
|
||||||
{ $$ = makeBindAttrPath(ATreverse($1), $3, CUR_POS); }
|
{ $$ = makeBind($1, allocCell($3), CUR_POS); }
|
||||||
| INHERIT inheritsrc ids ';'
|
| INHERIT inheritsrc ids ';'
|
||||||
{ $$ = makeInherit($2, $3, CUR_POS); }
|
{ $$ = makeInherit($2, $3, CUR_POS); }
|
||||||
;
|
;
|
||||||
@@ -455,30 +240,24 @@ inheritsrc
|
|||||||
|
|
||||||
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };
|
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };
|
||||||
|
|
||||||
attrpath
|
|
||||||
: attrpath '.' ID { $$ = ATinsert($1, $3); }
|
|
||||||
| ID { $$ = ATmakeList1($1); }
|
|
||||||
;
|
|
||||||
|
|
||||||
expr_list
|
expr_list
|
||||||
: expr_list expr_select { $$ = ATinsert($1, $2); }
|
: expr_select expr_list { $$ = ATinsert($2, $1); }
|
||||||
|
/* yes, this is right-recursive, but it doesn't matter since
|
||||||
|
otherwise we would need ATreverse which requires unbounded
|
||||||
|
stack space */
|
||||||
| { $$ = ATempty; }
|
| { $$ = ATempty; }
|
||||||
;
|
;
|
||||||
|
|
||||||
formals
|
formals
|
||||||
: formal ',' formals /* !!! right recursive */
|
: formal ',' formals { $$ = ATinsert($3, $1); } /* idem - right recursive */
|
||||||
{ $$.formals = ATinsert($3.formals, $1); $$.ellipsis = $3.ellipsis; }
|
| formal { $$ = ATinsert(ATempty, $1); }
|
||||||
| formal
|
| { $$ = ATempty; }
|
||||||
{ $$.formals = ATinsert(ATempty, $1); $$.ellipsis = false; }
|
|
||||||
|
|
|
||||||
{ $$.formals = ATempty; $$.ellipsis = false; }
|
|
||||||
| ELLIPSIS
|
|
||||||
{ $$.formals = ATempty; $$.ellipsis = true; }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
formal
|
formal
|
||||||
: ID { $$ = makeFormal($1, makeNoDefaultValue()); }
|
: ID { $$ = makeFormal($1, makeUnrestrictedValues(), makeNoDefaultValue()); }
|
||||||
| ID '?' expr { $$ = makeFormal($1, makeDefaultValue($3)); }
|
| ID ':' '[' expr_list ']' { $$ = makeFormal($1, makeValidValues($4), makeNoDefaultValue()); }
|
||||||
|
| ID '?' expr { $$ = makeFormal($1, makeUnrestrictedValues(), makeDefaultValue($3)); }
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@@ -495,6 +274,63 @@ formal
|
|||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
|
static void checkAttrs(ATermMap & names, ATermList bnds)
|
||||||
|
{
|
||||||
|
for (ATermIterator i(bnds); i; ++i) {
|
||||||
|
ATerm name;
|
||||||
|
Expr e;
|
||||||
|
ATerm pos;
|
||||||
|
if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */
|
||||||
|
if (names.get(name))
|
||||||
|
throw EvalError(format("duplicate attribute `%1%' at %2%")
|
||||||
|
% aterm2String(name) % showPos(pos));
|
||||||
|
names.set(name, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void checkAttrSets(ATerm e)
|
||||||
|
{
|
||||||
|
ATermList formals;
|
||||||
|
ATerm body, pos;
|
||||||
|
if (matchFunction(e, formals, body, pos)) {
|
||||||
|
ATermMap names(ATgetLength(formals));
|
||||||
|
for (ATermIterator i(formals); i; ++i) {
|
||||||
|
ATerm name;
|
||||||
|
ATerm d1, d2;
|
||||||
|
if (!matchFormal(*i, name, d1, d2)) abort();
|
||||||
|
if (names.get(name))
|
||||||
|
throw EvalError(format("duplicate formal function argument `%1%' at %2%")
|
||||||
|
% aterm2String(name) % showPos(pos));
|
||||||
|
names.set(name, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ATermList bnds;
|
||||||
|
if (matchAttrs(e, bnds)) {
|
||||||
|
ATermMap names(ATgetLength(bnds));
|
||||||
|
checkAttrs(names, bnds);
|
||||||
|
}
|
||||||
|
|
||||||
|
ATermList rbnds, nrbnds;
|
||||||
|
if (matchRec(e, rbnds, nrbnds)) {
|
||||||
|
ATermMap names(ATgetLength(rbnds) + ATgetLength(nrbnds));
|
||||||
|
checkAttrs(names, rbnds);
|
||||||
|
checkAttrs(names, nrbnds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ATgetType(e) == AT_APPL) {
|
||||||
|
int arity = ATgetArity(ATgetAFun(e));
|
||||||
|
for (int i = 0; i < arity; ++i)
|
||||||
|
checkAttrSets(ATgetArgument(e, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (ATgetType(e) == AT_LIST)
|
||||||
|
for (ATermIterator i((ATermList) e); i; ++i)
|
||||||
|
checkAttrSets(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr parse(EvalState & state,
|
static Expr parse(EvalState & state,
|
||||||
const char * text, const Path & path,
|
const char * text, const Path & path,
|
||||||
const Path & basePath)
|
const Path & basePath)
|
||||||
@@ -509,14 +345,16 @@ static Expr parse(EvalState & state,
|
|||||||
int res = yyparse(scanner, &data);
|
int res = yyparse(scanner, &data);
|
||||||
yylex_destroy(scanner);
|
yylex_destroy(scanner);
|
||||||
|
|
||||||
if (res) throw ParseError(data.error);
|
if (res) throw EvalError(data.error);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkVarDefs(state.primOps, data.result);
|
checkVarDefs(state.primOps, data.result);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
throw ParseError(format("%1%, in `%2%'") % e.msg() % path);
|
throw EvalError(format("%1%, in `%2%'") % e.msg() % path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkAttrSets(data.result);
|
||||||
|
|
||||||
return data.result;
|
return data.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,8 +385,13 @@ Expr parseExprFromFile(EvalState & state, Path path)
|
|||||||
if (S_ISDIR(st.st_mode))
|
if (S_ISDIR(st.st_mode))
|
||||||
path = canonPath(path + "/default.nix");
|
path = canonPath(path + "/default.nix");
|
||||||
|
|
||||||
|
Expr cached = state.parsings.get(toATerm(path));
|
||||||
|
if (cached) return cached;
|
||||||
|
|
||||||
/* Read and parse the input file. */
|
/* Read and parse the input file. */
|
||||||
return parse(state, readFile(path).c_str(), path, dirOf(path));
|
cached = parse(state, readFile(path).c_str(), path, dirOf(path));
|
||||||
|
state.parsings.set(toATerm(path), cached);
|
||||||
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+192
-270
@@ -6,8 +6,6 @@
|
|||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "expr-to-xml.hh"
|
#include "expr-to-xml.hh"
|
||||||
#include "nixexpr-ast.hh"
|
#include "nixexpr-ast.hh"
|
||||||
#include "parser.hh"
|
|
||||||
#include "names.hh"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -74,14 +72,12 @@ static Expr prim_null(EvalState & state, const ATermVector & args)
|
|||||||
platforms. */
|
platforms. */
|
||||||
static Expr prim_currentSystem(EvalState & state, const ATermVector & args)
|
static Expr prim_currentSystem(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
return makeStr(thisSystem);
|
return makeStr(thisSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_currentTime(EvalState & state, const ATermVector & args)
|
static Expr prim_currentTime(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
return ATmake("Int(<int>)", time(0));
|
return ATmake("Int(<int>)", time(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,34 +118,67 @@ static Expr prim_isNull(EvalState & state, const ATermVector & args)
|
|||||||
static Expr prim_isFunction(EvalState & state, const ATermVector & args)
|
static Expr prim_isFunction(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
Expr e = evalExpr(state, args[0]);
|
Expr e = evalExpr(state, args[0]);
|
||||||
Pattern pat;
|
ATermList formals;
|
||||||
ATerm body, pos;
|
ATerm name, body, pos;
|
||||||
return makeBool(matchFunction(e, pat, body, pos));
|
return makeBool(
|
||||||
|
matchFunction(e, formals, body, pos) ||
|
||||||
|
matchFunction1(e, name, body, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine whether the argument is an Int. */
|
|
||||||
static Expr prim_isInt(EvalState & state, const ATermVector & args)
|
static Path findDependency(Path dir, string dep)
|
||||||
{
|
{
|
||||||
int i;
|
if (dep[0] == '/') throw EvalError(
|
||||||
return makeBool(matchInt(evalExpr(state, args[0]), i));
|
format("illegal absolute dependency `%1%'") % dep);
|
||||||
|
|
||||||
|
Path p = canonPath(dir + "/" + dep);
|
||||||
|
|
||||||
|
if (pathExists(p))
|
||||||
|
return p;
|
||||||
|
else
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine whether the argument is an String. */
|
|
||||||
static Expr prim_isString(EvalState & state, const ATermVector & args)
|
/* Make path `p' relative to directory `pivot'. E.g.,
|
||||||
|
relativise("/a/b/c", "a/b/x/y") => "../x/y". Both input paths
|
||||||
|
should be in absolute canonical form. */
|
||||||
|
static string relativise(Path pivot, Path p)
|
||||||
{
|
{
|
||||||
string s;
|
assert(pivot.size() > 0 && pivot[0] == '/');
|
||||||
PathSet l;
|
assert(p.size() > 0 && p[0] == '/');
|
||||||
return makeBool(matchStr(evalExpr(state, args[0]), s, l));
|
|
||||||
|
if (pivot == p) return ".";
|
||||||
|
|
||||||
|
/* `p' is in `pivot'? */
|
||||||
|
Path pivot2 = pivot + "/";
|
||||||
|
if (p.substr(0, pivot2.size()) == pivot2) {
|
||||||
|
return p.substr(pivot2.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, `p' is in a parent of `pivot'. Find up till which
|
||||||
|
path component `p' and `pivot' match, and add an appropriate
|
||||||
|
number of `..' components. */
|
||||||
|
string::size_type i = 1;
|
||||||
|
while (1) {
|
||||||
|
string::size_type j = pivot.find('/', i);
|
||||||
|
if (j == string::npos) break;
|
||||||
|
j++;
|
||||||
|
if (pivot.substr(0, j) != p.substr(0, j)) break;
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
string prefix;
|
||||||
|
unsigned int slashes = count(pivot.begin() + i, pivot.end(), '/') + 1;
|
||||||
|
while (slashes--) {
|
||||||
|
prefix += "../";
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefix + p.substr(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine whether the argument is an Bool. */
|
|
||||||
static Expr prim_isBool(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
ATermBool b;
|
|
||||||
return makeBool(matchBool(evalExpr(state, args[0]), b));
|
|
||||||
}
|
|
||||||
|
|
||||||
static Expr prim_genericClosure(EvalState & state, const ATermVector & args)
|
static Expr prim_dependencyClosure(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
startNest(nest, lvlDebug, "finding dependencies");
|
startNest(nest, lvlDebug, "finding dependencies");
|
||||||
|
|
||||||
@@ -160,40 +189,87 @@ static Expr prim_genericClosure(EvalState & state, const ATermVector & args)
|
|||||||
if (!startSet) throw EvalError("attribute `startSet' required");
|
if (!startSet) throw EvalError("attribute `startSet' required");
|
||||||
ATermList startSet2 = evalList(state, startSet);
|
ATermList startSet2 = evalList(state, startSet);
|
||||||
|
|
||||||
set<Expr> workSet; // !!! gc roots
|
Path pivot;
|
||||||
for (ATermIterator i(startSet2); i; ++i) workSet.insert(*i);
|
PathSet workSet;
|
||||||
|
for (ATermIterator i(startSet2); i; ++i) {
|
||||||
/* Get the operator. */
|
PathSet context; /* !!! what to do? */
|
||||||
Expr op = queryAttr(attrs, "operator");
|
Path p = coerceToPath(state, *i, context);
|
||||||
if (!op) throw EvalError("attribute `operator' required");
|
workSet.insert(p);
|
||||||
|
pivot = dirOf(p);
|
||||||
/* Construct the closure by applying the operator to element of
|
|
||||||
`workSet', adding the result to `workSet', continuing until
|
|
||||||
no new elements are found. */
|
|
||||||
ATermList res = ATempty;
|
|
||||||
set<Expr> doneKeys; // !!! gc roots
|
|
||||||
while (!workSet.empty()) {
|
|
||||||
Expr e = *(workSet.begin());
|
|
||||||
workSet.erase(e);
|
|
||||||
|
|
||||||
e = strictEvalExpr(state, e);
|
|
||||||
|
|
||||||
Expr key = queryAttr(e, "key");
|
|
||||||
if (!key) throw EvalError("attribute `key' required");
|
|
||||||
|
|
||||||
if (doneKeys.find(key) != doneKeys.end()) continue;
|
|
||||||
doneKeys.insert(key);
|
|
||||||
res = ATinsert(res, e);
|
|
||||||
|
|
||||||
/* Call the `operator' function with `e' as argument. */
|
|
||||||
ATermList res = evalList(state, makeCall(op, e));
|
|
||||||
|
|
||||||
/* Try to find the dependencies relative to the `path'. */
|
|
||||||
for (ATermIterator i(res); i; ++i)
|
|
||||||
workSet.insert(evalExpr(state, *i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return makeList(res);
|
/* Get the search path. */
|
||||||
|
PathSet searchPath;
|
||||||
|
Expr e = queryAttr(attrs, "searchPath");
|
||||||
|
if (e) {
|
||||||
|
ATermList list = evalList(state, e);
|
||||||
|
for (ATermIterator i(list); i; ++i) {
|
||||||
|
PathSet context; /* !!! what to do? */
|
||||||
|
Path p = coerceToPath(state, *i, context);
|
||||||
|
searchPath.insert(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr scanner = queryAttr(attrs, "scanner");
|
||||||
|
if (!scanner) throw EvalError("attribute `scanner' required");
|
||||||
|
|
||||||
|
/* Construct the dependency closure by querying the dependency of
|
||||||
|
each path in `workSet', adding the dependencies to
|
||||||
|
`workSet'. */
|
||||||
|
PathSet doneSet;
|
||||||
|
while (!workSet.empty()) {
|
||||||
|
Path path = *(workSet.begin());
|
||||||
|
workSet.erase(path);
|
||||||
|
|
||||||
|
if (doneSet.find(path) != doneSet.end()) continue;
|
||||||
|
doneSet.insert(path);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
/* Call the `scanner' function with `path' as argument. */
|
||||||
|
debug(format("finding dependencies in `%1%'") % path);
|
||||||
|
ATermList deps = evalList(state, makeCall(scanner, makeStr(path)));
|
||||||
|
|
||||||
|
/* Try to find the dependencies relative to the `path'. */
|
||||||
|
for (ATermIterator i(deps); i; ++i) {
|
||||||
|
string s = evalStringNoCtx(state, *i);
|
||||||
|
|
||||||
|
Path dep = findDependency(dirOf(path), s);
|
||||||
|
|
||||||
|
if (dep == "") {
|
||||||
|
for (PathSet::iterator j = searchPath.begin();
|
||||||
|
j != searchPath.end(); ++j)
|
||||||
|
{
|
||||||
|
dep = findDependency(*j, s);
|
||||||
|
if (dep != "") break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dep == "")
|
||||||
|
debug(format("did NOT find dependency `%1%'") % s);
|
||||||
|
else {
|
||||||
|
debug(format("found dependency `%1%'") % dep);
|
||||||
|
workSet.insert(dep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Error & e) {
|
||||||
|
e.addPrefix(format("while finding dependencies in `%1%':\n")
|
||||||
|
% path);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return a list of the dependencies we've just found. */
|
||||||
|
ATermList deps = ATempty;
|
||||||
|
for (PathSet::iterator i = doneSet.begin(); i != doneSet.end(); ++i) {
|
||||||
|
deps = ATinsert(deps, makeStr(relativise(pivot, *i)));
|
||||||
|
deps = ATinsert(deps, makeStr(*i));
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(format("dependency list is `%1%'") % makeList(deps));
|
||||||
|
|
||||||
|
return makeList(deps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,58 +284,44 @@ static Expr prim_abort(EvalState & state, const ATermVector & args)
|
|||||||
static Expr prim_throw(EvalState & state, const ATermVector & args)
|
static Expr prim_throw(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
throw ThrownError(format("user-thrown exception: %1%") %
|
throw ThrownError(format("user-thrown exception: `%1%'") %
|
||||||
evalString(state, args[0], context));
|
evalString(state, args[0], context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_addErrorContext(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
PathSet context;
|
|
||||||
try {
|
|
||||||
return evalExpr(state, args[1]);
|
|
||||||
} catch (Error & e) {
|
|
||||||
e.addPrefix(format("%1%\n") %
|
|
||||||
evalString(state, args[0], context));
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Return an environment variable. Use with care. */
|
/* Return an environment variable. Use with care. */
|
||||||
static Expr prim_getEnv(EvalState & state, const ATermVector & args)
|
static Expr prim_getEnv(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
string name = evalStringNoCtx(state, args[0]);
|
string name = evalStringNoCtx(state, args[0]);
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
return makeStr(getEnv(name));
|
return makeStr(getEnv(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* for debugging purposes. print the first arg on stdout (perhaps stderr should be used?)
|
||||||
/* Evaluate the first expression, and print its abstract syntax tree
|
* and return the second
|
||||||
on standard error. Then return the second expression. Useful for
|
|
||||||
debugging.
|
|
||||||
*/
|
*/
|
||||||
static Expr prim_trace(EvalState & state, const ATermVector & args)
|
static Expr prim_trace(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
Expr e = evalExpr(state, args[0]);
|
//string str = evalStringNoCtx(state, args[0]);
|
||||||
printMsg(lvlError, format("trace: %1%") % e);
|
|
||||||
|
Expr a = evalExpr(state, args[0]);
|
||||||
|
printf("traced value: %s\n", atPrint(a).c_str());
|
||||||
return evalExpr(state, args[1]);
|
return evalExpr(state, args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Expr prim_relativise(EvalState & state, const ATermVector & args)
|
||||||
|
{
|
||||||
|
PathSet context; /* !!! what to do? */
|
||||||
|
Path pivot = coerceToPath(state, args[0], context);
|
||||||
|
Path path = coerceToPath(state, args[1], context);
|
||||||
|
return makeStr(relativise(pivot, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Derivations
|
* Derivations
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
|
|
||||||
|
|
||||||
static bool isFixedOutput(const Derivation & drv)
|
|
||||||
{
|
|
||||||
return drv.outputs.size() == 1 &&
|
|
||||||
drv.outputs.begin()->first == "out" &&
|
|
||||||
drv.outputs.begin()->second.hash != "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns the hash of a derivation modulo fixed-output
|
/* Returns the hash of a derivation modulo fixed-output
|
||||||
subderivations. A fixed-output derivation is a derivation with one
|
subderivations. A fixed-output derivation is a derivation with one
|
||||||
output (`out') for which an expected hash and hash algorithm are
|
output (`out') for which an expected hash and hash algorithm are
|
||||||
@@ -272,29 +334,35 @@ static bool isFixedOutput(const Derivation & drv)
|
|||||||
function, we do not want to rebuild everything depending on it
|
function, we do not want to rebuild everything depending on it
|
||||||
(after all, (the hash of) the file being downloaded is unchanged).
|
(after all, (the hash of) the file being downloaded is unchanged).
|
||||||
So the *output paths* should not change. On the other hand, the
|
So the *output paths* should not change. On the other hand, the
|
||||||
*derivation paths* should change to reflect the new dependency
|
*derivation store expression paths* should change to reflect the
|
||||||
graph.
|
new dependency graph.
|
||||||
|
|
||||||
That's what this function does: it returns a hash which is just the
|
That's what this function does: it returns a hash which is just the
|
||||||
hash of the derivation ATerm, except that any input derivation
|
of the derivation ATerm, except that any input store expression
|
||||||
paths have been replaced by the result of a recursive call to this
|
paths have been replaced by the result of a recursive call to this
|
||||||
function, and that for fixed-output derivations we return a hash of
|
function, and that for fixed-output derivations we return
|
||||||
its output path. */
|
(basically) its outputHash. */
|
||||||
static Hash hashDerivationModulo(EvalState & state, Derivation drv)
|
static Hash hashDerivationModulo(EvalState & state, Derivation drv)
|
||||||
{
|
{
|
||||||
/* Return a fixed hash for fixed-output derivations. */
|
/* Return a fixed hash for fixed-output derivations. */
|
||||||
if (isFixedOutput(drv)) {
|
if (drv.outputs.size() == 1) {
|
||||||
DerivationOutputs::const_iterator i = drv.outputs.begin();
|
DerivationOutputs::const_iterator i = drv.outputs.begin();
|
||||||
return hashString(htSHA256, "fixed:out:"
|
if (i->first == "out" &&
|
||||||
+ i->second.hashAlgo + ":"
|
i->second.hash != "")
|
||||||
+ i->second.hash + ":"
|
{
|
||||||
+ i->second.path);
|
return hashString(htSHA256, "fixed:out:"
|
||||||
|
+ i->second.hashAlgo + ":"
|
||||||
|
+ i->second.hash + ":"
|
||||||
|
+ i->second.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For other derivations, replace the inputs paths with recursive
|
/* For other derivations, replace the inputs paths with recursive
|
||||||
calls to this function.*/
|
calls to this function.*/
|
||||||
DerivationInputs inputs2;
|
DerivationInputs inputs2;
|
||||||
foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) {
|
for (DerivationInputs::iterator i = drv.inputDrvs.begin();
|
||||||
|
i != drv.inputDrvs.end(); ++i)
|
||||||
|
{
|
||||||
Hash h = state.drvHashes[i->first];
|
Hash h = state.drvHashes[i->first];
|
||||||
if (h.type == htUnknown) {
|
if (h.type == htUnknown) {
|
||||||
Derivation drv2 = derivationFromPath(i->first);
|
Derivation drv2 = derivationFromPath(i->first);
|
||||||
@@ -319,7 +387,6 @@ static Hash hashDerivationModulo(EvalState & state, Derivation drv)
|
|||||||
static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
startNest(nest, lvlVomit, "evaluating derivation");
|
startNest(nest, lvlVomit, "evaluating derivation");
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
|
|
||||||
ATermMap attrs;
|
ATermMap attrs;
|
||||||
queryAllAttrs(evalExpr(state, args[0]), attrs, true);
|
queryAllAttrs(evalExpr(state, args[0]), attrs, true);
|
||||||
@@ -344,7 +411,8 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
|||||||
|
|
||||||
PathSet context;
|
PathSet context;
|
||||||
|
|
||||||
string outputHash, outputHashAlgo;
|
string outputHash;
|
||||||
|
string outputHashAlgo;
|
||||||
bool outputHashRecursive = false;
|
bool outputHashRecursive = false;
|
||||||
|
|
||||||
for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
|
for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
|
||||||
@@ -403,32 +471,13 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
|||||||
/* Everything in the context of the strings in the derivation
|
/* Everything in the context of the strings in the derivation
|
||||||
attributes should be added as dependencies of the resulting
|
attributes should be added as dependencies of the resulting
|
||||||
derivation. */
|
derivation. */
|
||||||
foreach (PathSet::iterator, i, context) {
|
for (PathSet::iterator i = context.begin(); i != context.end(); ++i) {
|
||||||
Path path = *i;
|
debug(format("derivation uses `%1%'") % *i);
|
||||||
|
assert(isStorePath(*i));
|
||||||
/* Paths marked with `=' denote that the path of a derivation
|
if (isDerivation(*i))
|
||||||
is explicitly passed to the builder. Since that allows the
|
drv.inputDrvs[*i] = singleton<StringSet>("out");
|
||||||
builder to gain access to every path in the dependency
|
|
||||||
graph of the derivation (including all outputs), all paths
|
|
||||||
in the graph must be added to this derivation's list of
|
|
||||||
inputs to ensure that they are available when the builder
|
|
||||||
runs. */
|
|
||||||
if (path.at(0) == '=') {
|
|
||||||
path = string(path, 1);
|
|
||||||
PathSet refs; computeFSClosure(path, refs);
|
|
||||||
foreach (PathSet::iterator, j, refs) {
|
|
||||||
drv.inputSrcs.insert(*j);
|
|
||||||
if (isDerivation(*j))
|
|
||||||
drv.inputDrvs[*j] = singleton<StringSet>("out");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug(format("derivation uses `%1%'") % path);
|
|
||||||
assert(isStorePath(path));
|
|
||||||
if (isDerivation(path))
|
|
||||||
drv.inputDrvs[path] = singleton<StringSet>("out");
|
|
||||||
else
|
else
|
||||||
drv.inputSrcs.insert(path);
|
drv.inputSrcs.insert(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do we have all required attributes? */
|
/* Do we have all required attributes? */
|
||||||
@@ -438,7 +487,6 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
|||||||
throw EvalError("required attribute `system' missing");
|
throw EvalError("required attribute `system' missing");
|
||||||
|
|
||||||
/* If an output hash was given, check it. */
|
/* If an output hash was given, check it. */
|
||||||
Path outPath;
|
|
||||||
if (outputHash == "")
|
if (outputHash == "")
|
||||||
outputHashAlgo = "";
|
outputHashAlgo = "";
|
||||||
else {
|
else {
|
||||||
@@ -457,7 +505,6 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
|||||||
% outputHash % outputHashAlgo);
|
% outputHash % outputHashAlgo);
|
||||||
string s = outputHash;
|
string s = outputHash;
|
||||||
outputHash = printHash(h);
|
outputHash = printHash(h);
|
||||||
outPath = makeFixedOutputPath(outputHashRecursive, ht, h, drvName);
|
|
||||||
if (outputHashRecursive) outputHashAlgo = "r:" + outputHashAlgo;
|
if (outputHashRecursive) outputHashAlgo = "r:" + outputHashAlgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,12 +520,13 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
|||||||
have an empty value. This ensures that changes in the set of
|
have an empty value. This ensures that changes in the set of
|
||||||
output names do get reflected in the hash. */
|
output names do get reflected in the hash. */
|
||||||
drv.env["out"] = "";
|
drv.env["out"] = "";
|
||||||
drv.outputs["out"] = DerivationOutput("", outputHashAlgo, outputHash);
|
drv.outputs["out"] =
|
||||||
|
DerivationOutput("", outputHashAlgo, outputHash);
|
||||||
|
|
||||||
/* Use the masked derivation expression to compute the output
|
/* Use the masked derivation expression to compute the output
|
||||||
path. */
|
path. */
|
||||||
if (outPath == "")
|
Path outPath = makeStorePath("output:out",
|
||||||
outPath = makeStorePath("output:out", hashDerivationModulo(state, drv), drvName);
|
hashDerivationModulo(state, drv), drvName);
|
||||||
|
|
||||||
/* Construct the final derivation store expression. */
|
/* Construct the final derivation store expression. */
|
||||||
drv.env["out"] = outPath;
|
drv.env["out"] = outPath;
|
||||||
@@ -501,7 +549,7 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
|
|||||||
outAttrs.set(toATerm("outPath"),
|
outAttrs.set(toATerm("outPath"),
|
||||||
makeAttrRHS(makeStr(outPath, singleton<PathSet>(drvPath)), makeNoPos()));
|
makeAttrRHS(makeStr(outPath, singleton<PathSet>(drvPath)), makeNoPos()));
|
||||||
outAttrs.set(toATerm("drvPath"),
|
outAttrs.set(toATerm("drvPath"),
|
||||||
makeAttrRHS(makeStr(drvPath, singleton<PathSet>("=" + drvPath)), makeNoPos()));
|
makeAttrRHS(makeStr(drvPath, singleton<PathSet>(drvPath)), makeNoPos()));
|
||||||
|
|
||||||
return makeAttrs(outAttrs);
|
return makeAttrs(outAttrs);
|
||||||
}
|
}
|
||||||
@@ -516,7 +564,7 @@ static Expr prim_derivationLazy(EvalState & state, const ATermVector & args)
|
|||||||
attrs.set(toATerm("type"),
|
attrs.set(toATerm("type"),
|
||||||
makeAttrRHS(makeStr("derivation"), makeNoPos()));
|
makeAttrRHS(makeStr("derivation"), makeNoPos()));
|
||||||
|
|
||||||
Expr drvStrict = makeCall(makeVar(toATerm("derivation!")), eAttrs);
|
Expr drvStrict = allocCell(makeCall(makeVar(toATerm("derivation!")), eAttrs));
|
||||||
|
|
||||||
attrs.set(toATerm("outPath"),
|
attrs.set(toATerm("outPath"),
|
||||||
makeAttrRHS(makeSelect(drvStrict, toATerm("outPath")), makeNoPos()));
|
makeAttrRHS(makeSelect(drvStrict, toATerm("outPath")), makeNoPos()));
|
||||||
@@ -541,36 +589,12 @@ static Expr prim_toPath(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Allow a valid store path to be used in an expression. This is
|
|
||||||
useful in some generated expressions such as in nix-push, which
|
|
||||||
generates a call to a function with an already existing store path
|
|
||||||
as argument. You don't want to use `toPath' here because it copies
|
|
||||||
the path to the Nix store, which yields a copy like
|
|
||||||
/nix/store/newhash-oldhash-oldname. In the past, `toPath' had
|
|
||||||
special case behaviour for store paths, but that created weird
|
|
||||||
corner cases. */
|
|
||||||
static Expr prim_storePath(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
PathSet context;
|
|
||||||
Path path = canonPath(coerceToPath(state, args[0], context));
|
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
if (!isInStore(path))
|
|
||||||
throw EvalError(format("path `%1%' is not in the Nix store") % path);
|
|
||||||
Path path2 = toStorePath(path);
|
|
||||||
if (!store->isValidPath(path2))
|
|
||||||
throw EvalError(format("store path `%1%' is not valid") % path2);
|
|
||||||
context.insert(path2);
|
|
||||||
return makeStr(path, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_pathExists(EvalState & state, const ATermVector & args)
|
static Expr prim_pathExists(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
Path path = coerceToPath(state, args[0], context);
|
Path path = coerceToPath(state, args[0], context);
|
||||||
if (!context.empty())
|
if (!context.empty())
|
||||||
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
|
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
return makeBool(pathExists(path));
|
return makeBool(pathExists(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,18 +621,6 @@ static Expr prim_dirOf(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return the contents of a file as a string. */
|
|
||||||
static Expr prim_readFile(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
PathSet context;
|
|
||||||
Path path = coerceToPath(state, args[0], context);
|
|
||||||
if (!context.empty())
|
|
||||||
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
|
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
return makeStr(readFile(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Creating files
|
* Creating files
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
@@ -637,14 +649,11 @@ static Expr prim_toFile(EvalState & state, const ATermVector & args)
|
|||||||
PathSet refs;
|
PathSet refs;
|
||||||
|
|
||||||
for (PathSet::iterator i = context.begin(); i != context.end(); ++i) {
|
for (PathSet::iterator i = context.begin(); i != context.end(); ++i) {
|
||||||
Path path = *i;
|
if (isDerivation(*i))
|
||||||
if (path.at(0) == '=') path = string(path, 1);
|
|
||||||
if (isDerivation(path))
|
|
||||||
throw EvalError(format("in `toFile': the file `%1%' cannot refer to derivation outputs") % name);
|
throw EvalError(format("in `toFile': the file `%1%' cannot refer to derivation outputs") % name);
|
||||||
refs.insert(path);
|
refs.insert(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
Path storePath = readOnlyMode
|
Path storePath = readOnlyMode
|
||||||
? computeStorePathForText(name, contents, refs)
|
? computeStorePathForText(name, contents, refs)
|
||||||
: store->addTextToStore(name, contents, refs);
|
: store->addTextToStore(name, contents, refs);
|
||||||
@@ -697,10 +706,9 @@ static Expr prim_filterSource(EvalState & state, const ATermVector & args)
|
|||||||
|
|
||||||
FilterFromExpr filter(state, args[0]);
|
FilterFromExpr filter(state, args[0]);
|
||||||
|
|
||||||
state.nrDepthAfterReset = 0;
|
|
||||||
Path dstPath = readOnlyMode
|
Path dstPath = readOnlyMode
|
||||||
? computeStorePathForPath(path, true, htSHA256, filter).first
|
? computeStorePathForPath(path, false, false, "", filter).first
|
||||||
: store->addToStore(path, true, htSHA256, filter);
|
: store->addToStore(path, false, false, "", filter);
|
||||||
|
|
||||||
return makeStr(dstPath, singleton<PathSet>(dstPath));
|
return makeStr(dstPath, singleton<PathSet>(dstPath));
|
||||||
}
|
}
|
||||||
@@ -765,7 +773,7 @@ static Expr prim_listToAttrs(EvalState & state, const ATermVector & args)
|
|||||||
Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("name")));
|
Expr e = evalExpr(state, makeSelect(evaledExpr, toATerm("name")));
|
||||||
string attr = evalStringNoCtx(state,e);
|
string attr = evalStringNoCtx(state,e);
|
||||||
Expr r = makeSelect(evaledExpr, toATerm("value"));
|
Expr r = makeSelect(evaledExpr, toATerm("value"));
|
||||||
res.set(toATerm(attr), makeAttrRHS(r, makeNoPos()));
|
res.set(toATerm(attr), makeAttrRHS(allocCell(r), makeNoPos()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw TypeError(format("list element in `listToAttrs' is %s, expected a set { name = \"<name>\"; value = <value>; }")
|
throw TypeError(format("list element in `listToAttrs' is %s, expected a set { name = \"<name>\"; value = <value>; }")
|
||||||
@@ -780,7 +788,6 @@ static Expr prim_listToAttrs(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_removeAttrs(EvalState & state, const ATermVector & args)
|
static Expr prim_removeAttrs(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
ATermMap attrs;
|
ATermMap attrs;
|
||||||
@@ -795,15 +802,13 @@ static Expr prim_removeAttrs(EvalState & state, const ATermVector & args)
|
|||||||
return makeAttrs(attrs);
|
return makeAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Determine whether the argument is a list. */
|
||||||
/* Determine whether the argument is an attribute set. */
|
|
||||||
static Expr prim_isAttrs(EvalState & state, const ATermVector & args)
|
static Expr prim_isAttrs(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
ATermList list;
|
ATermList list;
|
||||||
return makeBool(matchAttrs(evalExpr(state, args[0]), list));
|
return makeBool(matchAttrs(evalExpr(state, args[0]), list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Lists
|
* Lists
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
@@ -852,14 +857,6 @@ static Expr prim_map(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return the length of a list. This is an O(1) time operation. */
|
|
||||||
static Expr prim_length(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
ATermList list = evalList(state, args[0]);
|
|
||||||
return makeInt(ATgetLength(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Integer arithmetic
|
* Integer arithmetic
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
@@ -881,23 +878,6 @@ static Expr prim_sub(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_mul(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
int i1 = evalInt(state, args[0]);
|
|
||||||
int i2 = evalInt(state, args[1]);
|
|
||||||
return makeInt(i1 * i2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_div(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
int i1 = evalInt(state, args[0]);
|
|
||||||
int i2 = evalInt(state, args[1]);
|
|
||||||
if (i2 == 0) throw EvalError("division by zero");
|
|
||||||
return makeInt(i1 / i2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_lessThan(EvalState & state, const ATermVector & args)
|
static Expr prim_lessThan(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
int i1 = evalInt(state, args[0]);
|
int i1 = evalInt(state, args[0]);
|
||||||
@@ -922,8 +902,8 @@ static Expr prim_toString(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* `substring start len str' returns the substring of `str' starting
|
/* `substr start len str' returns the substring of `str' starting at
|
||||||
at character position `min(start, stringLength str)' inclusive and
|
character position `min(start, stringLength str)' inclusive and
|
||||||
ending at `min(start + len, stringLength str)'. `start' must be
|
ending at `min(start + len, stringLength str)'. `start' must be
|
||||||
non-negative. */
|
non-negative. */
|
||||||
static Expr prim_substring(EvalState & state, const ATermVector & args)
|
static Expr prim_substring(EvalState & state, const ATermVector & args)
|
||||||
@@ -947,58 +927,14 @@ static Expr prim_stringLength(EvalState & state, const ATermVector & args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_unsafeDiscardStringContext(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
PathSet context;
|
|
||||||
string s = coerceToString(state, args[0], context);
|
|
||||||
return makeStr(s, PathSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Expression serialization/deserialization */
|
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_exprToString(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
/* !!! this disregards context */
|
|
||||||
return makeStr(atPrint(evalExpr(state, args[0])));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_stringToExpr(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
/* !!! this can introduce arbitrary garbage terms in the
|
|
||||||
evaluator! */;
|
|
||||||
string s;
|
|
||||||
PathSet l;
|
|
||||||
if (!matchStr(evalExpr(state, args[0]), s, l))
|
|
||||||
throw EvalError("stringToExpr needs string argument!");
|
|
||||||
return ATreadFromString(s.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Versions
|
* Strictness
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_parseDrvName(EvalState & state, const ATermVector & args)
|
static Expr prim_strict(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
string name = evalStringNoCtx(state, args[0]);
|
return evalExpr(state, makeCall(args[0], evalExpr(state, args[1])));
|
||||||
DrvName parsed(name);
|
|
||||||
ATermMap attrs(2);
|
|
||||||
attrs.set(toATerm("name"), makeAttrRHS(makeStr(parsed.name), makeNoPos()));
|
|
||||||
attrs.set(toATerm("version"), makeAttrRHS(makeStr(parsed.version), makeNoPos()));
|
|
||||||
return makeAttrs(attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr prim_compareVersions(EvalState & state, const ATermVector & args)
|
|
||||||
{
|
|
||||||
string version1 = evalStringNoCtx(state, args[0]);
|
|
||||||
string version2 = evalStringNoCtx(state, args[1]);
|
|
||||||
int d = compareVersions(version1, version2);
|
|
||||||
return makeInt(d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1022,20 +958,13 @@ void EvalState::addPrimOps()
|
|||||||
addPrimOp("import", 1, prim_import);
|
addPrimOp("import", 1, prim_import);
|
||||||
addPrimOp("isNull", 1, prim_isNull);
|
addPrimOp("isNull", 1, prim_isNull);
|
||||||
addPrimOp("__isFunction", 1, prim_isFunction);
|
addPrimOp("__isFunction", 1, prim_isFunction);
|
||||||
addPrimOp("__isString", 1, prim_isString);
|
addPrimOp("dependencyClosure", 1, prim_dependencyClosure);
|
||||||
addPrimOp("__isInt", 1, prim_isInt);
|
|
||||||
addPrimOp("__isBool", 1, prim_isBool);
|
|
||||||
addPrimOp("__genericClosure", 1, prim_genericClosure);
|
|
||||||
addPrimOp("abort", 1, prim_abort);
|
addPrimOp("abort", 1, prim_abort);
|
||||||
addPrimOp("throw", 1, prim_throw);
|
addPrimOp("throw", 1, prim_throw);
|
||||||
addPrimOp("__addErrorContext", 2, prim_addErrorContext);
|
|
||||||
addPrimOp("__getEnv", 1, prim_getEnv);
|
addPrimOp("__getEnv", 1, prim_getEnv);
|
||||||
addPrimOp("__trace", 2, prim_trace);
|
addPrimOp("__trace", 2, prim_trace);
|
||||||
|
|
||||||
|
addPrimOp("relativise", 2, prim_relativise);
|
||||||
// Expr <-> String
|
|
||||||
addPrimOp("__exprToString", 1, prim_exprToString);
|
|
||||||
addPrimOp("__stringToExpr", 1, prim_stringToExpr);
|
|
||||||
|
|
||||||
// Derivations
|
// Derivations
|
||||||
addPrimOp("derivation!", 1, prim_derivationStrict);
|
addPrimOp("derivation!", 1, prim_derivationStrict);
|
||||||
@@ -1043,11 +972,9 @@ void EvalState::addPrimOps()
|
|||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
addPrimOp("__toPath", 1, prim_toPath);
|
addPrimOp("__toPath", 1, prim_toPath);
|
||||||
addPrimOp("__storePath", 1, prim_storePath);
|
|
||||||
addPrimOp("__pathExists", 1, prim_pathExists);
|
addPrimOp("__pathExists", 1, prim_pathExists);
|
||||||
addPrimOp("baseNameOf", 1, prim_baseNameOf);
|
addPrimOp("baseNameOf", 1, prim_baseNameOf);
|
||||||
addPrimOp("dirOf", 1, prim_dirOf);
|
addPrimOp("dirOf", 1, prim_dirOf);
|
||||||
addPrimOp("__readFile", 1, prim_readFile);
|
|
||||||
|
|
||||||
// Creating files
|
// Creating files
|
||||||
addPrimOp("__toXML", 1, prim_toXML);
|
addPrimOp("__toXML", 1, prim_toXML);
|
||||||
@@ -1067,24 +994,19 @@ void EvalState::addPrimOps()
|
|||||||
addPrimOp("__head", 1, prim_head);
|
addPrimOp("__head", 1, prim_head);
|
||||||
addPrimOp("__tail", 1, prim_tail);
|
addPrimOp("__tail", 1, prim_tail);
|
||||||
addPrimOp("map", 2, prim_map);
|
addPrimOp("map", 2, prim_map);
|
||||||
addPrimOp("__length", 1, prim_length);
|
|
||||||
|
|
||||||
// Integer arithmetic
|
// Integer arithmetic
|
||||||
addPrimOp("__add", 2, prim_add);
|
addPrimOp("__add", 2, prim_add);
|
||||||
addPrimOp("__sub", 2, prim_sub);
|
addPrimOp("__sub", 2, prim_sub);
|
||||||
addPrimOp("__mul", 2, prim_mul);
|
|
||||||
addPrimOp("__div", 2, prim_div);
|
|
||||||
addPrimOp("__lessThan", 2, prim_lessThan);
|
addPrimOp("__lessThan", 2, prim_lessThan);
|
||||||
|
|
||||||
// String manipulation
|
// String manipulation
|
||||||
addPrimOp("toString", 1, prim_toString);
|
addPrimOp("toString", 1, prim_toString);
|
||||||
addPrimOp("__substring", 3, prim_substring);
|
addPrimOp("__substring", 3, prim_substring);
|
||||||
addPrimOp("__stringLength", 1, prim_stringLength);
|
addPrimOp("__stringLength", 1, prim_stringLength);
|
||||||
addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext);
|
|
||||||
|
|
||||||
// Versions
|
// Strictness
|
||||||
addPrimOp("__parseDrvName", 1, prim_parseDrvName);
|
addPrimOp("strict", 2, prim_strict);
|
||||||
addPrimOp("__compareVersions", 2, prim_compareVersions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
pkglib_LTLIBRARIES = libmain.la
|
pkglib_LTLIBRARIES = libmain.la
|
||||||
|
|
||||||
libmain_la_SOURCES = shared.cc
|
libmain_la_SOURCES = shared.cc shared.hh
|
||||||
|
|
||||||
libmain_la_LIBADD = ../libstore/libstore.la
|
|
||||||
|
|
||||||
pkginclude_HEADERS = shared.hh
|
|
||||||
|
|
||||||
AM_CXXFLAGS = \
|
AM_CXXFLAGS = \
|
||||||
-DNIX_STORE_DIR=\"$(storedir)\" \
|
-DNIX_STORE_DIR=\"$(storedir)\" \
|
||||||
|
|||||||
+16
-61
@@ -4,7 +4,6 @@
|
|||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "misc.hh"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@@ -50,34 +49,6 @@ void printGCWarning()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printMissing(const PathSet & paths)
|
|
||||||
{
|
|
||||||
unsigned long long downloadSize;
|
|
||||||
PathSet willBuild, willSubstitute, unknown;
|
|
||||||
queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize);
|
|
||||||
|
|
||||||
if (!willBuild.empty()) {
|
|
||||||
printMsg(lvlInfo, format("the following derivations will be built:"));
|
|
||||||
foreach (PathSet::iterator, i, willBuild)
|
|
||||||
printMsg(lvlInfo, format(" %1%") % *i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!willSubstitute.empty()) {
|
|
||||||
printMsg(lvlInfo, format("the following paths will be downloaded/copied (%.2f MiB):") %
|
|
||||||
(downloadSize / (1024.0 * 1024.0)));
|
|
||||||
foreach (PathSet::iterator, i, willSubstitute)
|
|
||||||
printMsg(lvlInfo, format(" %1%") % *i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!unknown.empty()) {
|
|
||||||
printMsg(lvlInfo, format("don't know how to build the following paths%1%:")
|
|
||||||
% (readOnlyMode ? " (may be caused by read-only store access)" : ""));
|
|
||||||
foreach (PathSet::iterator, i, unknown)
|
|
||||||
printMsg(lvlInfo, format(" %1%") % *i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void setLogType(string lt)
|
static void setLogType(string lt)
|
||||||
{
|
{
|
||||||
if (lt == "pretty") logType = ltPretty;
|
if (lt == "pretty") logType = ltPretty;
|
||||||
@@ -87,18 +58,27 @@ static void setLogType(string lt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long getIntArg(const string & opt,
|
static unsigned int getIntArg(const string & opt,
|
||||||
Strings::iterator & i, const Strings::iterator & end)
|
Strings::iterator & i, const Strings::iterator & end)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
if (i == end) throw UsageError(format("`%1%' requires an argument") % opt);
|
if (i == end) throw UsageError(format("`%1%' requires an argument") % opt);
|
||||||
long long n;
|
int n;
|
||||||
if (!string2Int(*i, n) || n < 0)
|
if (!string2Int(*i, n) || n < 0)
|
||||||
throw UsageError(format("`%1%' requires a non-negative integer") % opt);
|
throw UsageError(format("`%1%' requires a non-negative integer") % opt);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct RemoveTempRoots
|
||||||
|
{
|
||||||
|
~RemoveTempRoots()
|
||||||
|
{
|
||||||
|
removeTempRoots();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void initDerivationsHelpers();
|
void initDerivationsHelpers();
|
||||||
|
|
||||||
|
|
||||||
@@ -119,15 +99,6 @@ static void closeStore()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RemoveTempRoots::~RemoveTempRoots()
|
|
||||||
{
|
|
||||||
removeTempRoots();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool showTrace = false;
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize and reorder arguments, then call the actual argument
|
/* Initialize and reorder arguments, then call the actual argument
|
||||||
processor. */
|
processor. */
|
||||||
static void initAndRun(int argc, char * * argv)
|
static void initAndRun(int argc, char * * argv)
|
||||||
@@ -143,10 +114,9 @@ static void initAndRun(int argc, char * * argv)
|
|||||||
nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
|
nixBinDir = canonPath(getEnv("NIX_BIN_DIR", NIX_BIN_DIR));
|
||||||
|
|
||||||
string subs = getEnv("NIX_SUBSTITUTERS", "default");
|
string subs = getEnv("NIX_SUBSTITUTERS", "default");
|
||||||
if (subs == "default") {
|
if (subs == "default")
|
||||||
substituters.push_back(nixLibexecDir + "/nix/substituters/copy-from-other-stores.pl");
|
substituters.push_back(nixLibexecDir + "/nix/download-using-manifests.pl");
|
||||||
substituters.push_back(nixLibexecDir + "/nix/substituters/download-using-manifests.pl");
|
else
|
||||||
} else
|
|
||||||
substituters = tokenizeString(subs, ":");
|
substituters = tokenizeString(subs, ":");
|
||||||
|
|
||||||
/* Get some settings from the configuration file. */
|
/* Get some settings from the configuration file. */
|
||||||
@@ -222,8 +192,6 @@ static void initAndRun(int argc, char * * argv)
|
|||||||
; /* !!! obsolete - remove eventually */
|
; /* !!! obsolete - remove eventually */
|
||||||
else if (arg == "--no-build-output" || arg == "-Q")
|
else if (arg == "--no-build-output" || arg == "-Q")
|
||||||
buildVerbosity = lvlVomit;
|
buildVerbosity = lvlVomit;
|
||||||
else if (arg == "--print-build-trace")
|
|
||||||
printBuildTrace = true;
|
|
||||||
else if (arg == "--help") {
|
else if (arg == "--help") {
|
||||||
printHelp();
|
printHelp();
|
||||||
return;
|
return;
|
||||||
@@ -244,23 +212,12 @@ static void initAndRun(int argc, char * * argv)
|
|||||||
readOnlyMode = true;
|
readOnlyMode = true;
|
||||||
else if (arg == "--max-silent-time")
|
else if (arg == "--max-silent-time")
|
||||||
maxSilentTime = getIntArg(arg, i, args.end());
|
maxSilentTime = getIntArg(arg, i, args.end());
|
||||||
else if (arg == "--no-build-hook")
|
|
||||||
useBuildHook = false;
|
|
||||||
else if (arg == "--show-trace")
|
|
||||||
showTrace = true;
|
|
||||||
else if (arg == "--option") {
|
|
||||||
++i; if (i == args.end()) throw UsageError("`--option' requires two arguments");
|
|
||||||
string name = *i;
|
|
||||||
++i; if (i == args.end()) throw UsageError("`--option' requires two arguments");
|
|
||||||
string value = *i;
|
|
||||||
overrideSetting(name, tokenizeString(value));
|
|
||||||
}
|
|
||||||
else remaining.push_back(arg);
|
else remaining.push_back(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Automatically clean up the temporary roots file when we
|
/* Automatically clean up the temporary roots file when we
|
||||||
exit. */
|
exit. */
|
||||||
RemoveTempRoots removeTempRoots __attribute__((unused));
|
RemoveTempRoots removeTempRoots; /* unused variable - don't remove */
|
||||||
|
|
||||||
/* Make sure that the database gets closed properly, even if
|
/* Make sure that the database gets closed properly, even if
|
||||||
terminate() is called (which happens sometimes due to bugs in
|
terminate() is called (which happens sometimes due to bugs in
|
||||||
@@ -370,9 +327,7 @@ int main(int argc, char * * argv)
|
|||||||
% e.what() % programId);
|
% e.what() % programId);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (BaseError & e) {
|
} catch (BaseError & e) {
|
||||||
printMsg(lvlError, format("error: %1%%2%") % (showTrace ? e.prefix() : "") % e.msg());
|
printMsg(lvlError, format("error: %1%") % e.msg());
|
||||||
if (e.prefix() != "" && !showTrace)
|
|
||||||
printMsg(lvlError, "(use `--show-trace' to show detailed location information)");
|
|
||||||
return 1;
|
return 1;
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
printMsg(lvlError, format("error: %1%") % e.what());
|
printMsg(lvlError, format("error: %1%") % e.what());
|
||||||
|
|||||||
@@ -26,11 +26,6 @@ namespace nix {
|
|||||||
Path makeRootName(const Path & gcRoot, int & counter);
|
Path makeRootName(const Path & gcRoot, int & counter);
|
||||||
void printGCWarning();
|
void printGCWarning();
|
||||||
|
|
||||||
void printMissing(const PathSet & paths);
|
|
||||||
|
|
||||||
unsigned long long getIntArg(const string & opt,
|
|
||||||
Strings::iterator & i, const Strings::iterator & end);
|
|
||||||
|
|
||||||
/* Whether we're running setuid. */
|
/* Whether we're running setuid. */
|
||||||
extern bool setuidMode;
|
extern bool setuidMode;
|
||||||
|
|
||||||
@@ -38,11 +33,6 @@ extern volatile ::sig_atomic_t blockInt;
|
|||||||
|
|
||||||
MakeError(UsageError, nix::Error);
|
MakeError(UsageError, nix::Error);
|
||||||
|
|
||||||
struct RemoveTempRoots
|
|
||||||
{
|
|
||||||
~RemoveTempRoots();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
pkglib_LTLIBRARIES = libstore.la
|
pkglib_LTLIBRARIES = libstore.la
|
||||||
|
|
||||||
libstore_la_SOURCES = \
|
libstore_la_SOURCES = \
|
||||||
store-api.cc local-store.cc remote-store.cc derivations.cc build.cc misc.cc \
|
store-api.cc local-store.cc remote-store.cc derivations.cc build.cc misc.cc \
|
||||||
globals.cc db.cc references.cc pathlocks.cc gc.cc upgrade-schema.cc \
|
globals.cc db.cc references.cc pathlocks.cc gc.cc
|
||||||
optimise-store.cc
|
|
||||||
|
|
||||||
pkginclude_HEADERS = \
|
pkginclude_HEADERS = \
|
||||||
store-api.hh local-store.hh remote-store.hh derivations.hh misc.hh \
|
store-api.hh local-store.hh remote-store.hh derivations.hh misc.hh \
|
||||||
globals.hh db.hh references.hh pathlocks.hh \
|
globals.hh db.hh references.hh pathlocks.hh \
|
||||||
worker-protocol.hh
|
worker-protocol.hh
|
||||||
|
|
||||||
libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la
|
libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la
|
||||||
|
|
||||||
|
|||||||
+616
-663
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,3 @@
|
|||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifdef OLD_DB_COMPAT
|
|
||||||
|
|
||||||
#include "db.hh"
|
#include "db.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "pathlocks.hh"
|
#include "pathlocks.hh"
|
||||||
@@ -470,5 +466,3 @@ void Database::clearTable(const Transaction & txn, TableId table)
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "aterm.hh"
|
#include "aterm.hh"
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "util.hh"
|
|
||||||
|
|
||||||
#include "derivations-ast.hh"
|
#include "derivations-ast.hh"
|
||||||
#include "derivations-ast.cc"
|
#include "derivations-ast.cc"
|
||||||
@@ -21,7 +20,8 @@ Path writeDerivation(const Derivation & drv, const string & name)
|
|||||||
{
|
{
|
||||||
PathSet references;
|
PathSet references;
|
||||||
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
||||||
foreach (DerivationInputs::const_iterator, i, drv.inputDrvs)
|
for (DerivationInputs::const_iterator i = drv.inputDrvs.begin();
|
||||||
|
i != drv.inputDrvs.end(); ++i)
|
||||||
references.insert(i->first);
|
references.insert(i->first);
|
||||||
/* Note that the outputs of a derivation are *not* references
|
/* Note that the outputs of a derivation are *not* references
|
||||||
(that can be missing (of course) and should not necessarily be
|
(that can be missing (of course) and should not necessarily be
|
||||||
@@ -163,7 +163,9 @@ ATerm unparseDerivation(const Derivation & drv)
|
|||||||
|
|
||||||
bool isDerivation(const string & fileName)
|
bool isDerivation(const string & fileName)
|
||||||
{
|
{
|
||||||
return hasSuffix(fileName, drvExtension);
|
return
|
||||||
|
fileName.size() >= drvExtension.size() &&
|
||||||
|
string(fileName, fileName.size() - drvExtension.size()) == drvExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+112
-270
@@ -2,12 +2,11 @@
|
|||||||
#include "misc.hh"
|
#include "misc.hh"
|
||||||
#include "pathlocks.hh"
|
#include "pathlocks.hh"
|
||||||
#include "local-store.hh"
|
#include "local-store.hh"
|
||||||
|
#include "db.hh"
|
||||||
|
#include "util.hh"
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -27,8 +26,6 @@ static string gcLockName = "gc.lock";
|
|||||||
static string tempRootsDir = "temproots";
|
static string tempRootsDir = "temproots";
|
||||||
static string gcRootsDir = "gcroots";
|
static string gcRootsDir = "gcroots";
|
||||||
|
|
||||||
static const int defaultGcLevel = 1000;
|
|
||||||
|
|
||||||
|
|
||||||
/* Acquire the global GC lock. This is used to prevent new Nix
|
/* Acquire the global GC lock. This is used to prevent new Nix
|
||||||
processes from starting after the temporary root files have been
|
processes from starting after the temporary root files have been
|
||||||
@@ -126,11 +123,7 @@ Path addPermRoot(const Path & _storePath, const Path & _gcRoot,
|
|||||||
createSymlink(gcRoot, storePath, false);
|
createSymlink(gcRoot, storePath, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check that the root can be found by the garbage collector.
|
/* Check that the root can be found by the garbage collector. */
|
||||||
!!! This can be very slow on machines that have many roots.
|
|
||||||
Instead of reading all the roots, it would be more efficient to
|
|
||||||
check if the root is in a directory in or linked from the
|
|
||||||
gcroots directory. */
|
|
||||||
if (queryBoolSetting("gc-check-reachability", true)) {
|
if (queryBoolSetting("gc-check-reachability", true)) {
|
||||||
Roots roots = store->findRoots();
|
Roots roots = store->findRoots();
|
||||||
if (roots.find(gcRoot) == roots.end())
|
if (roots.find(gcRoot) == roots.end())
|
||||||
@@ -247,7 +240,9 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
|
|||||||
Strings tempRootFiles = readDirectory(
|
Strings tempRootFiles = readDirectory(
|
||||||
(format("%1%/%2%") % nixStateDir % tempRootsDir).str());
|
(format("%1%/%2%") % nixStateDir % tempRootsDir).str());
|
||||||
|
|
||||||
foreach (Strings::iterator, i, tempRootFiles) {
|
for (Strings::iterator i = tempRootFiles.begin();
|
||||||
|
i != tempRootFiles.end(); ++i)
|
||||||
|
{
|
||||||
Path path = (format("%1%/%2%/%3%") % nixStateDir % tempRootsDir % *i).str();
|
Path path = (format("%1%/%2%/%3%") % nixStateDir % tempRootsDir % *i).str();
|
||||||
|
|
||||||
debug(format("reading temporary root file `%1%'") % path);
|
debug(format("reading temporary root file `%1%'") % path);
|
||||||
@@ -326,7 +321,7 @@ static void findRoots(const Path & path, bool recurseSymlinks,
|
|||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
Strings names = readDirectory(path);
|
Strings names = readDirectory(path);
|
||||||
foreach (Strings::iterator, i, names)
|
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
||||||
findRoots(path + "/" + *i, recurseSymlinks, deleteStale, roots);
|
findRoots(path + "/" + *i, recurseSymlinks, deleteStale, roots);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,7 +392,7 @@ static void addAdditionalRoots(PathSet & roots)
|
|||||||
|
|
||||||
Strings paths = tokenizeString(result, "\n");
|
Strings paths = tokenizeString(result, "\n");
|
||||||
|
|
||||||
foreach (Strings::iterator, i, paths) {
|
for (Strings::iterator i = paths.begin(); i != paths.end(); ++i) {
|
||||||
if (isInStore(*i)) {
|
if (isInStore(*i)) {
|
||||||
Path path = toStorePath(*i);
|
Path path = toStorePath(*i);
|
||||||
if (roots.find(path) == roots.end() && store->isValidPath(path)) {
|
if (roots.find(path) == roots.end() && store->isValidPath(path)) {
|
||||||
@@ -419,7 +414,8 @@ static void dfsVisit(const PathSet & paths, const Path & path,
|
|||||||
if (store->isValidPath(path))
|
if (store->isValidPath(path))
|
||||||
store->queryReferences(path, references);
|
store->queryReferences(path, references);
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, references)
|
for (PathSet::iterator i = references.begin();
|
||||||
|
i != references.end(); ++i)
|
||||||
/* Don't traverse into paths that don't exist. That can
|
/* Don't traverse into paths that don't exist. That can
|
||||||
happen due to substitutes for non-existent paths. */
|
happen due to substitutes for non-existent paths. */
|
||||||
if (*i != path && paths.find(*i) != paths.end())
|
if (*i != path && paths.find(*i) != paths.end())
|
||||||
@@ -433,152 +429,22 @@ Paths topoSortPaths(const PathSet & paths)
|
|||||||
{
|
{
|
||||||
Paths sorted;
|
Paths sorted;
|
||||||
PathSet visited;
|
PathSet visited;
|
||||||
foreach (PathSet::const_iterator, i, paths)
|
for (PathSet::const_iterator i = paths.begin(); i != paths.end(); ++i)
|
||||||
dfsVisit(paths, *i, visited, sorted);
|
dfsVisit(paths, *i, visited, sorted);
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static time_t lastFileAccessTime(const Path & path)
|
void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
result.clear();
|
||||||
|
bytesFreed = 0;
|
||||||
struct stat st;
|
|
||||||
if (lstat(path.c_str(), &st) == -1)
|
|
||||||
throw SysError(format("statting `%1%'") % path);
|
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
|
||||||
time_t last = 0;
|
|
||||||
Strings names = readDirectory(path);
|
|
||||||
foreach (Strings::iterator, i, names) {
|
|
||||||
time_t t = lastFileAccessTime(path + "/" + *i);
|
|
||||||
if (t > last) last = t;
|
|
||||||
}
|
|
||||||
return last;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (S_ISLNK(st.st_mode)) return 0;
|
|
||||||
|
|
||||||
else return st.st_atime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct GCLimitReached { };
|
|
||||||
|
|
||||||
|
|
||||||
void LocalStore::gcPath(const GCOptions & options, GCResults & results,
|
|
||||||
const Path & path)
|
|
||||||
{
|
|
||||||
results.paths.insert(path);
|
|
||||||
|
|
||||||
if (!pathExists(path)) return;
|
|
||||||
|
|
||||||
/* Okay, it's safe to delete. */
|
|
||||||
unsigned long long bytesFreed, blocksFreed;
|
|
||||||
deleteFromStore(path, bytesFreed, blocksFreed);
|
|
||||||
results.bytesFreed += bytesFreed;
|
|
||||||
results.blocksFreed += blocksFreed;
|
|
||||||
|
|
||||||
if (options.maxFreed && results.bytesFreed > options.maxFreed) {
|
|
||||||
printMsg(lvlInfo, format("deleted more than %1% bytes; stopping") % options.maxFreed);
|
|
||||||
throw GCLimitReached();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.maxLinks) {
|
|
||||||
struct stat st;
|
|
||||||
if (stat(nixStore.c_str(), &st) == -1)
|
|
||||||
throw SysError(format("statting `%1%'") % nixStore);
|
|
||||||
if (st.st_nlink < options.maxLinks) {
|
|
||||||
printMsg(lvlInfo, format("link count on the store has dropped below %1%; stopping") % options.maxLinks);
|
|
||||||
throw GCLimitReached();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LocalStore::gcPathRecursive(const GCOptions & options,
|
|
||||||
GCResults & results, PathSet & done, const Path & path)
|
|
||||||
{
|
|
||||||
if (done.find(path) != done.end()) return;
|
|
||||||
done.insert(path);
|
|
||||||
|
|
||||||
startNest(nest, lvlDebug, format("looking at `%1%'") % path);
|
|
||||||
|
|
||||||
/* Delete all the referrers first. They must be garbage too,
|
|
||||||
since if they were live, then the current path would also be
|
|
||||||
live. Note that deleteFromStore() below still makes sure that
|
|
||||||
the referrer set has become empty, just in case. (However that
|
|
||||||
doesn't guard against deleting top-level paths that are only
|
|
||||||
reachable from GC roots.) */
|
|
||||||
PathSet referrers;
|
|
||||||
if (isValidPath(path))
|
|
||||||
queryReferrers(path, referrers);
|
|
||||||
foreach (PathSet::iterator, i, referrers)
|
|
||||||
if (*i != path) gcPathRecursive(options, results, done, *i);
|
|
||||||
|
|
||||||
printMsg(lvlInfo, format("deleting `%1%'") % path);
|
|
||||||
|
|
||||||
gcPath(options, results, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct CachingAtimeComparator : public std::binary_function<Path, Path, bool>
|
|
||||||
{
|
|
||||||
std::map<Path, time_t> cache;
|
|
||||||
|
|
||||||
time_t lookup(const Path & p)
|
|
||||||
{
|
|
||||||
std::map<Path, time_t>::iterator i = cache.find(p);
|
|
||||||
if (i != cache.end()) return i->second;
|
|
||||||
debug(format("computing atime of `%1%'") % p);
|
|
||||||
cache[p] = lastFileAccessTime(p);
|
|
||||||
assert(cache.find(p) != cache.end());
|
|
||||||
return cache[p];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator () (const Path & p1, const Path & p2)
|
|
||||||
{
|
|
||||||
return lookup(p2) < lookup(p1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static string showTime(const string & format, time_t t)
|
|
||||||
{
|
|
||||||
char s[128];
|
|
||||||
strftime(s, sizeof s, format.c_str(), localtime(&t));
|
|
||||||
return string(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool isLive(const Path & path, const PathSet & livePaths,
|
|
||||||
const PathSet & tempRoots, const PathSet & tempRootsClosed)
|
|
||||||
{
|
|
||||||
if (livePaths.find(path) != livePaths.end() ||
|
|
||||||
tempRootsClosed.find(path) != tempRootsClosed.end()) return true;
|
|
||||||
|
|
||||||
/* A lock file belonging to a path that we're building right
|
|
||||||
now isn't garbage. */
|
|
||||||
if (hasSuffix(path, ".lock") && tempRoots.find(string(path, 0, path.size() - 5)) != tempRoots.end())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
/* Don't delete .chroot directories for derivations that are
|
|
||||||
currently being built. */
|
|
||||||
if (hasSuffix(path, ".chroot") && tempRoots.find(string(path, 0, path.size() - 7)) != tempRoots.end())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|
||||||
{
|
|
||||||
bool gcKeepOutputs =
|
bool gcKeepOutputs =
|
||||||
queryBoolSetting("gc-keep-outputs", false);
|
queryBoolSetting("gc-keep-outputs", false);
|
||||||
bool gcKeepDerivations =
|
bool gcKeepDerivations =
|
||||||
queryBoolSetting("gc-keep-derivations", true);
|
queryBoolSetting("gc-keep-derivations", true);
|
||||||
int gcKeepOutputsThreshold =
|
|
||||||
queryIntSetting ("gc-keep-outputs-threshold", defaultGcLevel);
|
|
||||||
|
|
||||||
/* Acquire the global GC root. This prevents
|
/* Acquire the global GC root. This prevents
|
||||||
a) New roots from being added.
|
a) New roots from being added.
|
||||||
@@ -587,62 +453,58 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||||||
|
|
||||||
/* Find the roots. Since we've grabbed the GC lock, the set of
|
/* Find the roots. Since we've grabbed the GC lock, the set of
|
||||||
permanent roots cannot increase now. */
|
permanent roots cannot increase now. */
|
||||||
printMsg(lvlError, format("finding garbage collector roots..."));
|
Roots rootMap = ignoreLiveness ? Roots() : nix::findRoots(true);
|
||||||
Roots rootMap = options.ignoreLiveness ? Roots() : nix::findRoots(true);
|
|
||||||
|
|
||||||
PathSet roots;
|
PathSet roots;
|
||||||
foreach (Roots::iterator, i, rootMap) roots.insert(i->second);
|
for (Roots::iterator i = rootMap.begin(); i != rootMap.end(); ++i)
|
||||||
|
roots.insert(i->second);
|
||||||
|
|
||||||
/* Add additional roots returned by the program specified by the
|
/* Add additional roots returned by the program specified by the
|
||||||
NIX_ROOT_FINDER environment variable. This is typically used
|
NIX_ROOT_FINDER environment variable. This is typically used
|
||||||
to add running programs to the set of roots (to prevent them
|
to add running programs to the set of roots (to prevent them
|
||||||
from being garbage collected). */
|
from being garbage collected). */
|
||||||
if (!options.ignoreLiveness)
|
if (!ignoreLiveness)
|
||||||
addAdditionalRoots(roots);
|
addAdditionalRoots(roots);
|
||||||
|
|
||||||
if (options.action == GCOptions::gcReturnRoots) {
|
if (action == gcReturnRoots) {
|
||||||
results.paths = roots;
|
result = roots;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine the live paths which is just the closure of the
|
/* Determine the live paths which is just the closure of the
|
||||||
roots under the `references' relation. */
|
roots under the `references' relation. */
|
||||||
printMsg(lvlError, format("computing live paths..."));
|
|
||||||
PathSet livePaths;
|
PathSet livePaths;
|
||||||
foreach (PathSet::const_iterator, i, roots)
|
for (PathSet::const_iterator i = roots.begin(); i != roots.end(); ++i)
|
||||||
computeFSClosure(canonPath(*i), livePaths);
|
computeFSClosure(canonPath(*i), livePaths);
|
||||||
|
|
||||||
if (gcKeepDerivations) {
|
if (gcKeepDerivations) {
|
||||||
foreach (PathSet::iterator, i, livePaths) {
|
for (PathSet::iterator i = livePaths.begin();
|
||||||
|
i != livePaths.end(); ++i)
|
||||||
|
{
|
||||||
/* Note that the deriver need not be valid (e.g., if we
|
/* Note that the deriver need not be valid (e.g., if we
|
||||||
previously ran the collector with `gcKeepDerivations'
|
previously ran the collector with `gcKeepDerivations'
|
||||||
turned off). */
|
turned off). */
|
||||||
Path deriver = queryDeriver(*i);
|
Path deriver = store->queryDeriver(*i);
|
||||||
if (deriver != "" && isValidPath(deriver))
|
if (deriver != "" && store->isValidPath(deriver))
|
||||||
computeFSClosure(deriver, livePaths);
|
computeFSClosure(deriver, livePaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gcKeepOutputs) {
|
if (gcKeepOutputs) {
|
||||||
/* Hmz, identical to storePathRequisites in nix-store. */
|
/* Hmz, identical to storePathRequisites in nix-store. */
|
||||||
foreach (PathSet::iterator, i, livePaths)
|
for (PathSet::iterator i = livePaths.begin();
|
||||||
|
i != livePaths.end(); ++i)
|
||||||
if (isDerivation(*i)) {
|
if (isDerivation(*i)) {
|
||||||
Derivation drv = derivationFromPath(*i);
|
Derivation drv = derivationFromPath(*i);
|
||||||
|
for (DerivationOutputs::iterator j = drv.outputs.begin();
|
||||||
string gcLevelStr = drv.env["__gcLevel"];
|
j != drv.outputs.end(); ++j)
|
||||||
int gcLevel;
|
if (store->isValidPath(j->second.path))
|
||||||
if (!string2Int(gcLevelStr, gcLevel))
|
computeFSClosure(j->second.path, livePaths);
|
||||||
gcLevel = defaultGcLevel;
|
|
||||||
|
|
||||||
if (gcLevel >= gcKeepOutputsThreshold)
|
|
||||||
foreach (DerivationOutputs::iterator, j, drv.outputs)
|
|
||||||
if (isValidPath(j->second.path))
|
|
||||||
computeFSClosure(j->second.path, livePaths);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.action == GCOptions::gcReturnLive) {
|
if (action == gcReturnLive) {
|
||||||
results.paths = livePaths;
|
result = livePaths;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,129 +522,109 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||||||
(and computeFSClosure() assumes that the presence of a path
|
(and computeFSClosure() assumes that the presence of a path
|
||||||
means that it has already been closed). */
|
means that it has already been closed). */
|
||||||
PathSet tempRootsClosed;
|
PathSet tempRootsClosed;
|
||||||
foreach (PathSet::iterator, i, tempRoots)
|
for (PathSet::iterator i = tempRoots.begin(); i != tempRoots.end(); ++i)
|
||||||
if (isValidPath(*i))
|
if (store->isValidPath(*i))
|
||||||
computeFSClosure(*i, tempRootsClosed);
|
computeFSClosure(*i, tempRootsClosed);
|
||||||
else
|
else
|
||||||
tempRootsClosed.insert(*i);
|
tempRootsClosed.insert(*i);
|
||||||
|
|
||||||
|
/* For testing - see tests/gc-concurrent.sh. */
|
||||||
|
if (getenv("NIX_DEBUG_GC_WAIT"))
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
/* After this point the set of roots or temporary roots cannot
|
/* After this point the set of roots or temporary roots cannot
|
||||||
increase, since we hold locks on everything. So everything
|
increase, since we hold locks on everything. So everything
|
||||||
that is not currently in in `livePaths' or `tempRootsClosed'
|
that is not currently in in `livePaths' or `tempRootsClosed'
|
||||||
can be deleted. */
|
can be deleted. */
|
||||||
|
|
||||||
/* Read the Nix store directory to find all currently existing
|
/* Read the Nix store directory to find all currently existing
|
||||||
paths and filter out all live paths. */
|
paths. */
|
||||||
printMsg(lvlError, format("reading the Nix store..."));
|
PathSet storePathSet;
|
||||||
PathSet storePaths;
|
if (action != gcDeleteSpecific) {
|
||||||
|
|
||||||
if (options.action != GCOptions::gcDeleteSpecific) {
|
|
||||||
Paths entries = readDirectory(nixStore);
|
Paths entries = readDirectory(nixStore);
|
||||||
foreach (Paths::iterator, i, entries) {
|
for (Paths::iterator i = entries.begin(); i != entries.end(); ++i)
|
||||||
Path path = canonPath(nixStore + "/" + *i);
|
storePathSet.insert(canonPath(nixStore + "/" + *i));
|
||||||
if (!isLive(path, livePaths, tempRoots, tempRootsClosed)) storePaths.insert(path);
|
} else {
|
||||||
}
|
for (PathSet::iterator i = pathsToDelete.begin();
|
||||||
}
|
i != pathsToDelete.end(); ++i)
|
||||||
|
{
|
||||||
else {
|
|
||||||
foreach (PathSet::iterator, i, options.pathsToDelete) {
|
|
||||||
assertStorePath(*i);
|
assertStorePath(*i);
|
||||||
storePaths.insert(*i);
|
storePathSet.insert(*i);
|
||||||
if (isLive(*i, livePaths, tempRoots, tempRootsClosed))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Topologically sort them under the `referrers' relation. That
|
||||||
|
is, a < b iff a is in referrers(b). This gives us the order in
|
||||||
|
which things can be deleted safely. */
|
||||||
|
/* !!! when we have multiple output paths per derivation, this
|
||||||
|
will not work anymore because we get cycles. */
|
||||||
|
Paths storePaths = topoSortPaths(storePathSet);
|
||||||
|
|
||||||
|
/* Try to delete store paths in the topologically sorted order. */
|
||||||
|
for (Paths::iterator i = storePaths.begin(); i != storePaths.end(); ++i) {
|
||||||
|
|
||||||
|
debug(format("considering deletion of `%1%'") % *i);
|
||||||
|
|
||||||
|
if (livePaths.find(*i) != livePaths.end()) {
|
||||||
|
if (action == gcDeleteSpecific)
|
||||||
throw Error(format("cannot delete path `%1%' since it is still alive") % *i);
|
throw Error(format("cannot delete path `%1%' since it is still alive") % *i);
|
||||||
}
|
debug(format("live path `%1%'") % *i);
|
||||||
}
|
continue;
|
||||||
|
|
||||||
if (options.action == GCOptions::gcReturnDead) {
|
|
||||||
results.paths.insert(storePaths.begin(), storePaths.end());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Delete all dead store paths (or until one of the stop
|
|
||||||
conditions is reached). */
|
|
||||||
|
|
||||||
PathSet done;
|
|
||||||
try {
|
|
||||||
|
|
||||||
if (!options.useAtime) {
|
|
||||||
/* Delete the paths, respecting the partial ordering
|
|
||||||
determined by the references graph. */
|
|
||||||
printMsg(lvlError, format("deleting garbage..."));
|
|
||||||
foreach (PathSet::iterator, i, storePaths)
|
|
||||||
gcPathRecursive(options, results, done, *i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
if (tempRootsClosed.find(*i) != tempRootsClosed.end()) {
|
||||||
|
debug(format("temporary root `%1%'") % *i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* Delete in order of ascending last access time, still
|
debug(format("dead path `%1%'") % *i);
|
||||||
maintaining the partial ordering of the reference
|
result.insert(*i);
|
||||||
graph. Note that we can't use a topological sort for
|
|
||||||
this because that takes time O(V+E), and in this case
|
|
||||||
E=O(V^2) (i.e. the graph is dense because of the edges
|
|
||||||
due to the atime ordering). So instead we put all
|
|
||||||
deletable paths in a priority queue (ordered by atime),
|
|
||||||
and after deleting a path, add additional paths that
|
|
||||||
have become deletable to the priority queue. */
|
|
||||||
|
|
||||||
CachingAtimeComparator atimeComp;
|
/* If just returning the set of dead paths, we also return the
|
||||||
|
space that would be freed if we deleted them. */
|
||||||
|
if (action == gcReturnDead)
|
||||||
|
bytesFreed += computePathSize(*i);
|
||||||
|
|
||||||
/* Create a priority queue that orders paths by ascending
|
if (action == gcDeleteDead || action == gcDeleteSpecific) {
|
||||||
atime. This is why C++ needs type inferencing... */
|
|
||||||
std::priority_queue<Path, vector<Path>, binary_function_ref_adapter<CachingAtimeComparator> > prioQueue =
|
|
||||||
std::priority_queue<Path, vector<Path>, binary_function_ref_adapter<CachingAtimeComparator> >(binary_function_ref_adapter<CachingAtimeComparator>(&atimeComp));
|
|
||||||
|
|
||||||
/* Initially put the paths that are invalid or have no
|
#ifndef __CYGWIN__
|
||||||
referrers into the priority queue. */
|
AutoCloseFD fdLock;
|
||||||
printMsg(lvlError, format("finding deletable paths..."));
|
|
||||||
foreach (PathSet::iterator, i, storePaths) {
|
|
||||||
checkInterrupt();
|
|
||||||
/* We can safely delete a path if it's invalid or
|
|
||||||
it has no referrers. Note that all the invalid
|
|
||||||
paths will be deleted in the first round. */
|
|
||||||
if (isValidPath(*i)) {
|
|
||||||
if (queryReferrersNoSelf(*i).empty()) prioQueue.push(*i);
|
|
||||||
} else prioQueue.push(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug(format("%1% initially deletable paths") % prioQueue.size());
|
/* Only delete a lock file if we can acquire a write lock
|
||||||
|
on it. That means that it's either stale, or the
|
||||||
/* Now delete everything in the order of the priority
|
process that created it hasn't locked it yet. In the
|
||||||
queue until nothing is left. */
|
latter case the other process will detect that we
|
||||||
printMsg(lvlError, format("deleting garbage..."));
|
deleted the lock, and retry (see pathlocks.cc). */
|
||||||
while (!prioQueue.empty()) {
|
if (i->size() >= 5 && string(*i, i->size() - 5) == ".lock") {
|
||||||
checkInterrupt();
|
fdLock = openLockFile(*i, false);
|
||||||
Path path = prioQueue.top(); prioQueue.pop();
|
if (fdLock != -1 && !lockFile(fdLock, ltWrite, false)) {
|
||||||
|
debug(format("skipping active lock `%1%'") % *i);
|
||||||
if (options.maxAtime != (time_t) -1 &&
|
|
||||||
atimeComp.lookup(path) > options.maxAtime)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
printMsg(lvlInfo, format("deleting `%1%' (last accessed %2%)") % path % showTime("%F %H:%M:%S", atimeComp.lookup(path)));
|
|
||||||
|
|
||||||
PathSet references;
|
|
||||||
if (isValidPath(path)) references = queryReferencesNoSelf(path);
|
|
||||||
|
|
||||||
gcPath(options, results, path);
|
|
||||||
|
|
||||||
/* For each reference of the current path, see if the
|
|
||||||
reference has now become deletable (i.e. is in the
|
|
||||||
set of dead paths and has no referrers left). If
|
|
||||||
so add it to the priority queue. */
|
|
||||||
foreach (PathSet::iterator, i, references) {
|
|
||||||
if (storePaths.find(*i) != storePaths.end() &&
|
|
||||||
queryReferrersNoSelf(*i).empty())
|
|
||||||
{
|
|
||||||
debug(format("path `%1%' has become deletable") % *i);
|
|
||||||
prioQueue.push(*i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!pathExists(*i)) continue;
|
||||||
|
|
||||||
|
printMsg(lvlInfo, format("deleting `%1%'") % *i);
|
||||||
|
|
||||||
|
/* Okay, it's safe to delete. */
|
||||||
|
try {
|
||||||
|
unsigned long long freed;
|
||||||
|
deleteFromStore(*i, freed);
|
||||||
|
bytesFreed += freed;
|
||||||
|
} catch (PathInUse & e) {
|
||||||
|
printMsg(lvlError, format("warning: %1%") % e.msg());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __CYGWIN__
|
||||||
|
if (fdLock != -1)
|
||||||
|
/* Write token to stale (deleted) lock file. */
|
||||||
|
writeFull(fdLock, (const unsigned char *) "d", 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (GCLimitReached & e) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-23
@@ -13,7 +13,6 @@ string nixDataDir = "/UNINIT";
|
|||||||
string nixLogDir = "/UNINIT";
|
string nixLogDir = "/UNINIT";
|
||||||
string nixStateDir = "/UNINIT";
|
string nixStateDir = "/UNINIT";
|
||||||
string nixDBPath = "/UNINIT";
|
string nixDBPath = "/UNINIT";
|
||||||
string nixCacheFile = "/UNINIT";
|
|
||||||
string nixConfDir = "/UNINIT";
|
string nixConfDir = "/UNINIT";
|
||||||
string nixLibexecDir = "/UNINIT";
|
string nixLibexecDir = "/UNINIT";
|
||||||
string nixBinDir = "/UNINIT";
|
string nixBinDir = "/UNINIT";
|
||||||
@@ -25,19 +24,14 @@ Verbosity buildVerbosity = lvlInfo;
|
|||||||
unsigned int maxBuildJobs = 1;
|
unsigned int maxBuildJobs = 1;
|
||||||
bool readOnlyMode = false;
|
bool readOnlyMode = false;
|
||||||
string thisSystem = "unset";
|
string thisSystem = "unset";
|
||||||
time_t maxSilentTime = 0;
|
unsigned int maxSilentTime = 0;
|
||||||
Paths substituters;
|
Paths substituters;
|
||||||
bool useBuildHook = true;
|
|
||||||
bool printBuildTrace = false;
|
|
||||||
|
|
||||||
|
|
||||||
static bool settingsRead = false;
|
static bool settingsRead = false;
|
||||||
|
|
||||||
static std::map<string, Strings> settings;
|
static std::map<string, Strings> settings;
|
||||||
|
|
||||||
/* Overriden settings. */
|
|
||||||
std::map<string, Strings> settingsCmdline;
|
|
||||||
|
|
||||||
|
|
||||||
string & at(Strings & ss, unsigned int n)
|
string & at(Strings & ss, unsigned int n)
|
||||||
{
|
{
|
||||||
@@ -77,8 +71,6 @@ static void readSettings()
|
|||||||
advance(i, 2);
|
advance(i, 2);
|
||||||
settings[name] = Strings(i, tokens.end());
|
settings[name] = Strings(i, tokens.end());
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.insert(settingsCmdline.begin(), settingsCmdline.end());
|
|
||||||
|
|
||||||
settingsRead = true;
|
settingsRead = true;
|
||||||
}
|
}
|
||||||
@@ -123,19 +115,5 @@ unsigned int queryIntSetting(const string & name, unsigned int def)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void overrideSetting(const string & name, const Strings & value)
|
|
||||||
{
|
|
||||||
if (settingsRead) settings[name] = value;
|
|
||||||
settingsCmdline[name] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void reloadSettings()
|
|
||||||
{
|
|
||||||
settingsRead = false;
|
|
||||||
settings.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-28
@@ -24,9 +24,6 @@ extern string nixStateDir;
|
|||||||
/* nixDBPath is the path name of our Berkeley DB environment. */
|
/* nixDBPath is the path name of our Berkeley DB environment. */
|
||||||
extern string nixDBPath;
|
extern string nixDBPath;
|
||||||
|
|
||||||
/* nixCacheFile is the path name of the normal form cache. */
|
|
||||||
extern string nixCacheFile;
|
|
||||||
|
|
||||||
/* nixConfDir is the directory where configuration files are
|
/* nixConfDir is the directory where configuration files are
|
||||||
stored. */
|
stored. */
|
||||||
extern string nixConfDir;
|
extern string nixConfDir;
|
||||||
@@ -68,33 +65,13 @@ extern string thisSystem;
|
|||||||
/* The maximum time in seconds that a builer can go without producing
|
/* The maximum time in seconds that a builer can go without producing
|
||||||
any output on stdout/stderr before it is killed. 0 means
|
any output on stdout/stderr before it is killed. 0 means
|
||||||
infinity. */
|
infinity. */
|
||||||
extern time_t maxSilentTime;
|
extern unsigned int maxSilentTime;
|
||||||
|
|
||||||
/* The substituters. There are programs that can somehow realise a
|
/* The substituters. There are programs that can somehow realise a
|
||||||
store path without building, e.g., by downloading it or copying it
|
store path without building, e.g., by downloading it or copying it
|
||||||
from a CD. */
|
from a CD. */
|
||||||
extern Paths substituters;
|
extern Paths substituters;
|
||||||
|
|
||||||
/* Whether to use build hooks (for distributed builds). Sometimes
|
|
||||||
users want to disable this from the command-line. */
|
|
||||||
extern bool useBuildHook;
|
|
||||||
|
|
||||||
/* Whether buildDerivations() should print out lines on stderr in a
|
|
||||||
fixed format to allow its progress to be monitored. Each line
|
|
||||||
starts with a "@". The following are defined:
|
|
||||||
|
|
||||||
@ build-started <drvpath> <outpath> <system> <logfile>
|
|
||||||
@ build-failed <drvpath> <outpath> <exitcode> <error text>
|
|
||||||
@ build-succeeded <drvpath> <outpath>
|
|
||||||
@ substituter-started <outpath> <substituter>
|
|
||||||
@ substituter-failed <outpath> <exitcode> <error text>
|
|
||||||
@ substituter-succeeded <outpath>
|
|
||||||
|
|
||||||
Best combined with --no-build-output, otherwise stderr might
|
|
||||||
conceivably contain lines in this format printed by the builders.
|
|
||||||
*/
|
|
||||||
extern bool printBuildTrace;
|
|
||||||
|
|
||||||
|
|
||||||
Strings querySetting(const string & name, const Strings & def);
|
Strings querySetting(const string & name, const Strings & def);
|
||||||
|
|
||||||
@@ -104,10 +81,6 @@ bool queryBoolSetting(const string & name, bool def);
|
|||||||
|
|
||||||
unsigned int queryIntSetting(const string & name, unsigned int def);
|
unsigned int queryIntSetting(const string & name, unsigned int def);
|
||||||
|
|
||||||
void overrideSetting(const string & name, const Strings & value);
|
|
||||||
|
|
||||||
void reloadSettings();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+774
-661
File diff suppressed because it is too large.
Load diff
+57
-105
@@ -4,16 +4,18 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "util.hh"
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction;
|
||||||
|
|
||||||
|
|
||||||
/* Nix store and database schema version. Version 1 (or 0) was Nix <=
|
/* Nix store and database schema version. Version 1 (or 0) was Nix <=
|
||||||
0.7. Version 2 was Nix 0.8 and 0.9. Version 3 is Nix 0.10.
|
0.7. Version 2 was Nix 0.8 and 0.9. Version 3 is Nix 0.10.
|
||||||
Version 4 is Nix 0.11. Version 5 is Nix 0.12*/
|
Version 4 is Nix 0.11. */
|
||||||
const int nixSchemaVersion = 5;
|
const int nixSchemaVersion = 4;
|
||||||
|
|
||||||
|
|
||||||
extern string drvsLogDir;
|
extern string drvsLogDir;
|
||||||
@@ -25,36 +27,31 @@ struct OptimiseStats
|
|||||||
unsigned long sameContents;
|
unsigned long sameContents;
|
||||||
unsigned long filesLinked;
|
unsigned long filesLinked;
|
||||||
unsigned long long bytesFreed;
|
unsigned long long bytesFreed;
|
||||||
unsigned long long blocksFreed;
|
|
||||||
OptimiseStats()
|
OptimiseStats()
|
||||||
{
|
{
|
||||||
totalFiles = sameContents = filesLinked = 0;
|
totalFiles = sameContents = filesLinked = 0;
|
||||||
bytesFreed = blocksFreed = 0;
|
bytesFreed = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct RunningSubstituter
|
|
||||||
{
|
|
||||||
Pid pid;
|
|
||||||
AutoCloseFD to, from;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LocalStore : public StoreAPI
|
class LocalStore : public StoreAPI
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool substitutablePathsLoaded;
|
bool substitutablePathsLoaded;
|
||||||
PathSet substitutablePaths;
|
PathSet substitutablePaths;
|
||||||
|
|
||||||
typedef std::map<Path, RunningSubstituter> RunningSubstituters;
|
|
||||||
RunningSubstituters runningSubstituters;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* Initialise the local store, upgrading the schema if
|
/* Open the database environment. If `reserveSpace' is true, make
|
||||||
necessary. */
|
sure that a big empty file exists in /nix/var/nix/db/reserved.
|
||||||
LocalStore();
|
If `reserveSpace' is false, delete this file if it exists. The
|
||||||
|
idea is that on normal operation, the file exists; but when we
|
||||||
|
run the garbage collector, it is deleted. This is to ensure
|
||||||
|
that the garbage collector has a small amount of disk space
|
||||||
|
available, which is required to open the Berkeley DB
|
||||||
|
environment. */
|
||||||
|
LocalStore(bool reserveSpace);
|
||||||
|
|
||||||
~LocalStore();
|
~LocalStore();
|
||||||
|
|
||||||
@@ -62,8 +59,6 @@ public:
|
|||||||
|
|
||||||
bool isValidPath(const Path & path);
|
bool isValidPath(const Path & path);
|
||||||
|
|
||||||
PathSet queryValidPaths();
|
|
||||||
|
|
||||||
Hash queryPathHash(const Path & path);
|
Hash queryPathHash(const Path & path);
|
||||||
|
|
||||||
void queryReferences(const Path & path, PathSet & references);
|
void queryReferences(const Path & path, PathSet & references);
|
||||||
@@ -75,25 +70,12 @@ public:
|
|||||||
PathSet querySubstitutablePaths();
|
PathSet querySubstitutablePaths();
|
||||||
|
|
||||||
bool hasSubstitutes(const Path & path);
|
bool hasSubstitutes(const Path & path);
|
||||||
|
|
||||||
bool querySubstitutablePathInfo(const Path & path,
|
|
||||||
SubstitutablePathInfo & info);
|
|
||||||
|
|
||||||
bool querySubstitutablePathInfo(const Path & substituter,
|
Path addToStore(const Path & srcPath, bool fixed = false,
|
||||||
const Path & path, SubstitutablePathInfo & info);
|
bool recursive = false, string hashAlgo = "",
|
||||||
|
|
||||||
Path addToStore(const Path & srcPath,
|
|
||||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
/* Like addToStore(), but the contents of the path are contained
|
Path addTextToStore(const string & suffix, const string & s,
|
||||||
in `dump', which is either a NAR serialisation (if recursive ==
|
|
||||||
true) or simply the contents of a regular file (if recursive ==
|
|
||||||
false). */
|
|
||||||
Path addToStoreFromDump(const string & dump, const string & name,
|
|
||||||
bool recursive = true, HashType hashAlgo = htSHA256);
|
|
||||||
|
|
||||||
Path addTextToStore(const string & name, const string & s,
|
|
||||||
const PathSet & references);
|
const PathSet & references);
|
||||||
|
|
||||||
void exportPath(const Path & path, bool sign,
|
void exportPath(const Path & path, bool sign,
|
||||||
@@ -113,95 +95,65 @@ public:
|
|||||||
|
|
||||||
Roots findRoots();
|
Roots findRoots();
|
||||||
|
|
||||||
void collectGarbage(const GCOptions & options, GCResults & results);
|
void collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed);
|
||||||
|
|
||||||
/* Delete a path from the Nix store. */
|
|
||||||
void deleteFromStore(const Path & path, unsigned long long & bytesFreed,
|
|
||||||
unsigned long long & blocksFreed);
|
|
||||||
|
|
||||||
/* Optimise the disk space usage of the Nix store by hard-linking
|
/* Optimise the disk space usage of the Nix store by hard-linking
|
||||||
files with the same contents. */
|
files with the same contents. */
|
||||||
void optimiseStore(bool dryRun, OptimiseStats & stats);
|
void optimiseStore(bool dryRun, OptimiseStats & stats);
|
||||||
|
|
||||||
/* Check the integrity of the Nix store. */
|
|
||||||
void verifyStore(bool checkContents);
|
|
||||||
|
|
||||||
/* Register the validity of a path, i.e., that `path' exists, that
|
|
||||||
the paths referenced by it exists, and in the case of an output
|
|
||||||
path of a derivation, that it has been produced by a succesful
|
|
||||||
execution of the derivation (or something equivalent). Also
|
|
||||||
register the hash of the file system contents of the path. The
|
|
||||||
hash must be a SHA-256 hash. */
|
|
||||||
void registerValidPath(const Path & path,
|
|
||||||
const Hash & hash, const PathSet & references, const Path & deriver);
|
|
||||||
|
|
||||||
void registerValidPaths(const ValidPathInfos & infos);
|
|
||||||
|
|
||||||
/* Register that the build of a derivation with output `path' has
|
|
||||||
failed. */
|
|
||||||
void registerFailedPath(const Path & path);
|
|
||||||
|
|
||||||
/* Query whether `path' previously failed to build. */
|
|
||||||
bool hasPathFailed(const Path & path);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Path schemaPath;
|
|
||||||
|
|
||||||
/* Lock file used for upgrading. */
|
|
||||||
AutoCloseFD globalLock;
|
|
||||||
|
|
||||||
/* !!! The cache can grow very big. Maybe it should be pruned
|
|
||||||
every once in a while. */
|
|
||||||
std::map<Path, ValidPathInfo> pathInfoCache;
|
|
||||||
|
|
||||||
/* Store paths for which the referrers file must be purged. */
|
|
||||||
PathSet delayedUpdates;
|
|
||||||
|
|
||||||
int getSchema();
|
|
||||||
|
|
||||||
void registerValidPath(const ValidPathInfo & info, bool ignoreValidity = false);
|
|
||||||
|
|
||||||
ValidPathInfo queryPathInfo(const Path & path, bool ignoreErrors = false);
|
|
||||||
|
|
||||||
void rewriteReferrers(const Path & path, bool purge, PathSet referrers);
|
|
||||||
|
|
||||||
void flushDelayedUpdates();
|
|
||||||
|
|
||||||
bool queryReferrersInternal(const Path & path, PathSet & referrers);
|
|
||||||
|
|
||||||
void invalidatePath(const Path & path);
|
|
||||||
|
|
||||||
void upgradeStore12();
|
|
||||||
|
|
||||||
void gcPath(const GCOptions & options, GCResults & results,
|
|
||||||
const Path & path);
|
|
||||||
|
|
||||||
void gcPathRecursive(const GCOptions & options,
|
|
||||||
GCResults & results, PathSet & done, const Path & path);
|
|
||||||
|
|
||||||
void startSubstituter(const Path & substituter,
|
|
||||||
RunningSubstituter & runningSubstituter);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Get a transaction object. */
|
||||||
|
void createStoreTransaction(Transaction & txn);
|
||||||
|
|
||||||
/* Copy a path recursively. */
|
/* Copy a path recursively. */
|
||||||
void copyPath(const Path & src, const Path & dst);
|
void copyPath(const Path & src, const Path & dst);
|
||||||
|
|
||||||
|
/* Register the validity of a path, i.e., that `path' exists, that the
|
||||||
|
paths referenced by it exists, and in the case of an output path of
|
||||||
|
a derivation, that it has been produced by a succesful execution of
|
||||||
|
the derivation (or something equivalent). Also register the hash
|
||||||
|
of the file system contents of the path. The hash must be a
|
||||||
|
SHA-256 hash. */
|
||||||
|
void registerValidPath(const Transaction & txn,
|
||||||
|
const Path & path, const Hash & hash, const PathSet & references,
|
||||||
|
const Path & deriver);
|
||||||
|
|
||||||
|
typedef list<ValidPathInfo> ValidPathInfos;
|
||||||
|
|
||||||
|
void registerValidPaths(const Transaction & txn,
|
||||||
|
const ValidPathInfos & infos);
|
||||||
|
|
||||||
/* "Fix", or canonicalise, the meta-data of the files in a store path
|
/* "Fix", or canonicalise, the meta-data of the files in a store path
|
||||||
after it has been built. In particular:
|
after it has been built. In particular:
|
||||||
- the last modification date on each file is set to 1 (i.e.,
|
- the last modification date on each file is set to 0 (i.e.,
|
||||||
00:00:01 1/1/1970 UTC)
|
00:00:00 1/1/1970 UTC)
|
||||||
- the permissions are set of 444 or 555 (i.e., read-only with or
|
- the permissions are set of 444 or 555 (i.e., read-only with or
|
||||||
without execute permission; setuid bits etc. are cleared)
|
without execute permission; setuid bits etc. are cleared)
|
||||||
- the owner and group are set to the Nix user and group, if we're
|
- the owner and group are set to the Nix user and group, if we're
|
||||||
in a setuid Nix installation. */
|
in a setuid Nix installation. */
|
||||||
void canonicalisePathMetaData(const Path & path);
|
void canonicalisePathMetaData(const Path & path);
|
||||||
|
|
||||||
void canonicalisePathMetaData(const Path & path, bool recurse);
|
/* Checks whether a path is valid. */
|
||||||
|
bool isValidPathTxn(const Transaction & txn, const Path & path);
|
||||||
|
|
||||||
|
/* Sets the set of outgoing FS references for a store path. Use with
|
||||||
|
care! */
|
||||||
|
void setReferences(const Transaction & txn, const Path & path,
|
||||||
|
const PathSet & references);
|
||||||
|
|
||||||
|
/* Sets the deriver of a store path. Use with care! */
|
||||||
|
void setDeriver(const Transaction & txn, const Path & path,
|
||||||
|
const Path & deriver);
|
||||||
|
|
||||||
|
/* Delete a value from the nixStore directory. */
|
||||||
|
void deleteFromStore(const Path & path, unsigned long long & bytesFreed);
|
||||||
|
|
||||||
MakeError(PathInUse, Error);
|
MakeError(PathInUse, Error);
|
||||||
|
|
||||||
|
void verifyStore(bool checkContents);
|
||||||
|
|
||||||
/* Whether we are in build users mode. */
|
/* Whether we are in build users mode. */
|
||||||
bool haveBuildUsers();
|
bool haveBuildUsers();
|
||||||
|
|
||||||
@@ -214,7 +166,7 @@ void getOwnership(const Path & path);
|
|||||||
/* Like deletePath(), but changes the ownership of `path' using the
|
/* Like deletePath(), but changes the ownership of `path' using the
|
||||||
setuid wrapper if necessary (and possible). */
|
setuid wrapper if necessary (and possible). */
|
||||||
void deletePathWrapped(const Path & path,
|
void deletePathWrapped(const Path & path,
|
||||||
unsigned long long & bytesFreed, unsigned long long & blocksFreed);
|
unsigned long long & bytesFreed);
|
||||||
|
|
||||||
void deletePathWrapped(const Path & path);
|
void deletePathWrapped(const Path & path);
|
||||||
|
|
||||||
|
|||||||
+16
-20
@@ -1,6 +1,6 @@
|
|||||||
#include "misc.hh"
|
#include "misc.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "local-store.hh"
|
#include "db.hh"
|
||||||
|
|
||||||
#include <aterm2.h>
|
#include <aterm2.h>
|
||||||
|
|
||||||
@@ -30,25 +30,24 @@ void computeFSClosure(const Path & storePath,
|
|||||||
else
|
else
|
||||||
store->queryReferences(storePath, references);
|
store->queryReferences(storePath, references);
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, references)
|
for (PathSet::iterator i = references.begin();
|
||||||
|
i != references.end(); ++i)
|
||||||
computeFSClosure(*i, paths, flipDirection);
|
computeFSClosure(*i, paths, flipDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path findOutput(const Derivation & drv, string id)
|
Path findOutput(const Derivation & drv, string id)
|
||||||
{
|
{
|
||||||
foreach (DerivationOutputs::const_iterator, i, drv.outputs)
|
for (DerivationOutputs::const_iterator i = drv.outputs.begin();
|
||||||
|
i != drv.outputs.end(); ++i)
|
||||||
if (i->first == id) return i->second.path;
|
if (i->first == id) return i->second.path;
|
||||||
throw Error(format("derivation has no output `%1%'") % id);
|
throw Error(format("derivation has no output `%1%'") % id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void queryMissing(const PathSet & targets,
|
void queryMissing(const PathSet & targets,
|
||||||
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
|
PathSet & willBuild, PathSet & willSubstitute)
|
||||||
unsigned long long & downloadSize)
|
|
||||||
{
|
{
|
||||||
downloadSize = 0;
|
|
||||||
|
|
||||||
PathSet todo(targets.begin(), targets.end()), done;
|
PathSet todo(targets.begin(), targets.end()), done;
|
||||||
|
|
||||||
while (!todo.empty()) {
|
while (!todo.empty()) {
|
||||||
@@ -58,36 +57,33 @@ void queryMissing(const PathSet & targets,
|
|||||||
done.insert(p);
|
done.insert(p);
|
||||||
|
|
||||||
if (isDerivation(p)) {
|
if (isDerivation(p)) {
|
||||||
if (!store->isValidPath(p)) {
|
if (!store->isValidPath(p)) continue;
|
||||||
unknown.insert(p);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Derivation drv = derivationFromPath(p);
|
Derivation drv = derivationFromPath(p);
|
||||||
|
|
||||||
bool mustBuild = false;
|
bool mustBuild = false;
|
||||||
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
||||||
|
i != drv.outputs.end(); ++i)
|
||||||
if (!store->isValidPath(i->second.path) && !store->hasSubstitutes(i->second.path))
|
if (!store->isValidPath(i->second.path) && !store->hasSubstitutes(i->second.path))
|
||||||
mustBuild = true;
|
mustBuild = true;
|
||||||
|
|
||||||
if (mustBuild) {
|
if (mustBuild) {
|
||||||
willBuild.insert(p);
|
willBuild.insert(p);
|
||||||
todo.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
todo.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
||||||
foreach (DerivationInputs::iterator, i, drv.inputDrvs)
|
for (DerivationInputs::iterator i = drv.inputDrvs.begin();
|
||||||
|
i != drv.inputDrvs.end(); ++i)
|
||||||
todo.insert(i->first);
|
todo.insert(i->first);
|
||||||
} else
|
} else
|
||||||
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
||||||
|
i != drv.outputs.end(); ++i)
|
||||||
todo.insert(i->second.path);
|
todo.insert(i->second.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
if (store->isValidPath(p)) continue;
|
if (store->isValidPath(p)) continue;
|
||||||
SubstitutablePathInfo info;
|
if (store->hasSubstitutes(p))
|
||||||
if (store->querySubstitutablePathInfo(p, info)) {
|
|
||||||
willSubstitute.insert(p);
|
willSubstitute.insert(p);
|
||||||
downloadSize += info.downloadSize;
|
// XXX call the substituters
|
||||||
todo.insert(info.references.begin(), info.references.end());
|
// store->queryReferences(p, todo);
|
||||||
} else
|
|
||||||
unknown.insert(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ Path findOutput(const Derivation & drv, string id);
|
|||||||
derivations that will be built, and the set of output paths that
|
derivations that will be built, and the set of output paths that
|
||||||
will be substituted. */
|
will be substituted. */
|
||||||
void queryMissing(const PathSet & targets,
|
void queryMissing(const PathSet & targets,
|
||||||
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
|
PathSet & willBuild, PathSet & willSubstitute);
|
||||||
unsigned long long & downloadSize);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,155 +0,0 @@
|
|||||||
#include "util.hh"
|
|
||||||
#include "local-store.hh"
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<Hash, std::pair<Path, ino_t> > HashToPath;
|
|
||||||
|
|
||||||
|
|
||||||
static void makeWritable(const Path & path)
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
if (lstat(path.c_str(), &st))
|
|
||||||
throw SysError(format("getting attributes of path `%1%'") % path);
|
|
||||||
if (chmod(path.c_str(), st.st_mode | S_IWUSR) == -1)
|
|
||||||
throw SysError(format("changing writability of `%1%'") % path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct MakeReadOnly
|
|
||||||
{
|
|
||||||
Path path;
|
|
||||||
MakeReadOnly(const Path & path) : path(path) { }
|
|
||||||
~MakeReadOnly()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (path != "") canonicalisePathMetaData(path, false);
|
|
||||||
} catch (...) {
|
|
||||||
ignoreException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void hashAndLink(bool dryRun, HashToPath & hashToPath,
|
|
||||||
OptimiseStats & stats, const Path & path)
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
if (lstat(path.c_str(), &st))
|
|
||||||
throw SysError(format("getting attributes of path `%1%'") % path);
|
|
||||||
|
|
||||||
/* Sometimes SNAFUs can cause files in the Nix store to be
|
|
||||||
modified, in particular when running programs as root under
|
|
||||||
NixOS (example: $fontconfig/var/cache being modified). Skip
|
|
||||||
those files. */
|
|
||||||
if (S_ISREG(st.st_mode) && (st.st_mode & S_IWUSR)) {
|
|
||||||
printMsg(lvlError, format("skipping suspicious writable file `%1%'") % path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We can hard link regular files and symlinks. */
|
|
||||||
if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
|
|
||||||
|
|
||||||
/* Hash the file. Note that hashPath() returns the hash over
|
|
||||||
the NAR serialisation, which includes the execute bit on
|
|
||||||
the file. Thus, executable and non-executable files with
|
|
||||||
the same contents *won't* be linked (which is good because
|
|
||||||
otherwise the permissions would be screwed up).
|
|
||||||
|
|
||||||
Also note that if `path' is a symlink, then we're hashing
|
|
||||||
the contents of the symlink (i.e. the result of
|
|
||||||
readlink()), not the contents of the target (which may not
|
|
||||||
even exist). */
|
|
||||||
Hash hash = hashPath(htSHA256, path);
|
|
||||||
stats.totalFiles++;
|
|
||||||
printMsg(lvlDebug, format("`%1%' has hash `%2%'") % path % printHash(hash));
|
|
||||||
|
|
||||||
std::pair<Path, ino_t> prevPath = hashToPath[hash];
|
|
||||||
|
|
||||||
if (prevPath.first == "") {
|
|
||||||
hashToPath[hash] = std::pair<Path, ino_t>(path, st.st_ino);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Yes! We've seen a file with the same contents. Replace
|
|
||||||
the current file with a hard link to that file. */
|
|
||||||
stats.sameContents++;
|
|
||||||
if (prevPath.second == st.st_ino) {
|
|
||||||
printMsg(lvlDebug, format("`%1%' is already linked to `%2%'") % path % prevPath.first);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dryRun) {
|
|
||||||
|
|
||||||
printMsg(lvlTalkative, format("linking `%1%' to `%2%'") % path % prevPath.first);
|
|
||||||
|
|
||||||
Path tempLink = (format("%1%.tmp-%2%-%3%")
|
|
||||||
% path % getpid() % rand()).str();
|
|
||||||
|
|
||||||
/* Make the containing directory writable, but only if
|
|
||||||
it's not the store itself (we don't want or need to
|
|
||||||
mess with its permissions). */
|
|
||||||
bool mustToggle = !isStorePath(path);
|
|
||||||
if (mustToggle) makeWritable(dirOf(path));
|
|
||||||
|
|
||||||
/* When we're done, make the directory read-only again and
|
|
||||||
reset its timestamp back to 0. */
|
|
||||||
MakeReadOnly makeReadOnly(mustToggle ? dirOf(path) : "");
|
|
||||||
|
|
||||||
if (link(prevPath.first.c_str(), tempLink.c_str()) == -1) {
|
|
||||||
if (errno == EMLINK) {
|
|
||||||
/* Too many links to the same file (>= 32000 on
|
|
||||||
most file systems). This is likely to happen
|
|
||||||
with empty files. Just start over, creating
|
|
||||||
links to the current file. */
|
|
||||||
printMsg(lvlInfo, format("`%1%' has maximum number of links") % prevPath.first);
|
|
||||||
hashToPath[hash] = std::pair<Path, ino_t>(path, st.st_ino);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw SysError(format("cannot link `%1%' to `%2%'")
|
|
||||||
% tempLink % prevPath.first);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Atomically replace the old file with the new hard link. */
|
|
||||||
if (rename(tempLink.c_str(), path.c_str()) == -1)
|
|
||||||
throw SysError(format("cannot rename `%1%' to `%2%'")
|
|
||||||
% tempLink % path);
|
|
||||||
} else
|
|
||||||
printMsg(lvlTalkative, format("would link `%1%' to `%2%'") % path % prevPath.first);
|
|
||||||
|
|
||||||
stats.filesLinked++;
|
|
||||||
stats.bytesFreed += st.st_size;
|
|
||||||
stats.blocksFreed += st.st_blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
|
||||||
Strings names = readDirectory(path);
|
|
||||||
foreach (Strings::iterator, i, names)
|
|
||||||
hashAndLink(dryRun, hashToPath, stats, path + "/" + *i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LocalStore::optimiseStore(bool dryRun, OptimiseStats & stats)
|
|
||||||
{
|
|
||||||
HashToPath hashToPath;
|
|
||||||
|
|
||||||
PathSet paths = queryValidPaths();
|
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, paths) {
|
|
||||||
addTempRoot(*i);
|
|
||||||
if (!isValidPath(*i)) continue; /* path was GC'ed, probably */
|
|
||||||
startNest(nest, lvlChatty, format("hashing files in `%1%'") % *i);
|
|
||||||
hashAndLink(dryRun, hashToPath, stats, *i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -141,9 +140,9 @@ PathLocks::PathLocks(const PathSet & paths, const string & waitMsg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PathLocks::lockPaths(const PathSet & _paths,
|
void PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg)
|
||||||
const string & waitMsg, bool wait)
|
|
||||||
{
|
{
|
||||||
|
/* May be called only once! */
|
||||||
assert(fds.empty());
|
assert(fds.empty());
|
||||||
|
|
||||||
/* Note that `fds' is built incrementally so that the destructor
|
/* Note that `fds' is built incrementally so that the destructor
|
||||||
@@ -155,7 +154,7 @@ bool PathLocks::lockPaths(const PathSet & _paths,
|
|||||||
paths.sort();
|
paths.sort();
|
||||||
|
|
||||||
/* Acquire the lock for each path. */
|
/* Acquire the lock for each path. */
|
||||||
foreach (Paths::iterator, i, paths) {
|
for (Paths::iterator i = paths.begin(); i != paths.end(); i++) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
Path path = *i;
|
Path path = *i;
|
||||||
Path lockPath = path + ".lock";
|
Path lockPath = path + ".lock";
|
||||||
@@ -174,15 +173,8 @@ bool PathLocks::lockPaths(const PathSet & _paths,
|
|||||||
|
|
||||||
/* Acquire an exclusive lock. */
|
/* Acquire an exclusive lock. */
|
||||||
if (!lockFile(fd, ltWrite, false)) {
|
if (!lockFile(fd, ltWrite, false)) {
|
||||||
if (wait) {
|
if (waitMsg != "") printMsg(lvlError, waitMsg);
|
||||||
if (waitMsg != "") printMsg(lvlError, waitMsg);
|
lockFile(fd, ltWrite, true);
|
||||||
lockFile(fd, ltWrite, true);
|
|
||||||
} else {
|
|
||||||
/* Failed to lock this path; release all other
|
|
||||||
locks. */
|
|
||||||
unlock();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(format("lock acquired on `%1%'") % lockPath);
|
debug(format("lock acquired on `%1%'") % lockPath);
|
||||||
@@ -206,20 +198,12 @@ bool PathLocks::lockPaths(const PathSet & _paths,
|
|||||||
fds.push_back(FDPair(fd.borrow(), lockPath));
|
fds.push_back(FDPair(fd.borrow(), lockPath));
|
||||||
lockedPaths.insert(lockPath);
|
lockedPaths.insert(lockPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PathLocks::~PathLocks()
|
PathLocks::~PathLocks()
|
||||||
{
|
{
|
||||||
unlock();
|
for (list<FDPair>::iterator i = fds.begin(); i != fds.end(); i++) {
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PathLocks::unlock()
|
|
||||||
{
|
|
||||||
foreach (list<FDPair>::iterator, i, fds) {
|
|
||||||
if (deletePaths) deleteLockFilePreClose(i->second, i->first);
|
if (deletePaths) deleteLockFilePreClose(i->second, i->first);
|
||||||
|
|
||||||
lockedPaths.erase(i->second);
|
lockedPaths.erase(i->second);
|
||||||
@@ -231,8 +215,6 @@ void PathLocks::unlock()
|
|||||||
|
|
||||||
debug(format("lock released on `%1%'") % i->second);
|
debug(format("lock released on `%1%'") % i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
fds.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ int openLockFile(const Path & path, bool create);
|
|||||||
void deleteLockFilePreClose(const Path & path, int fd);
|
void deleteLockFilePreClose(const Path & path, int fd);
|
||||||
void deleteLockFilePostClose(const Path & path);
|
void deleteLockFilePostClose(const Path & path);
|
||||||
|
|
||||||
enum LockType { ltRead, ltWrite, ltNone };
|
typedef enum LockType { ltRead, ltWrite, ltNone };
|
||||||
|
|
||||||
bool lockFile(int fd, LockType lockType, bool wait);
|
bool lockFile(int fd, LockType lockType, bool wait);
|
||||||
|
|
||||||
@@ -33,11 +33,9 @@ public:
|
|||||||
PathLocks();
|
PathLocks();
|
||||||
PathLocks(const PathSet & paths,
|
PathLocks(const PathSet & paths,
|
||||||
const string & waitMsg = "");
|
const string & waitMsg = "");
|
||||||
bool lockPaths(const PathSet & _paths,
|
void lockPaths(const PathSet & _paths,
|
||||||
const string & waitMsg = "",
|
const string & waitMsg = "");
|
||||||
bool wait = true);
|
|
||||||
~PathLocks();
|
~PathLocks();
|
||||||
void unlock();
|
|
||||||
void setDeletion(bool deletePaths);
|
void setDeletion(bool deletePaths);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+75
-41
@@ -1,10 +1,15 @@
|
|||||||
#include "references.hh"
|
#include "references.hh"
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "archive.hh"
|
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cstdlib>
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
@@ -13,8 +18,8 @@ namespace nix {
|
|||||||
static unsigned int refLength = 32; /* characters */
|
static unsigned int refLength = 32; /* characters */
|
||||||
|
|
||||||
|
|
||||||
static void search(const unsigned char * s, unsigned int len,
|
static void search(size_t len, const unsigned char * s,
|
||||||
StringSet & hashes, StringSet & seen)
|
StringSet & ids, StringSet & seen)
|
||||||
{
|
{
|
||||||
static bool initialised = false;
|
static bool initialised = false;
|
||||||
static bool isBase32[256];
|
static bool isBase32[256];
|
||||||
@@ -36,60 +41,93 @@ static void search(const unsigned char * s, unsigned int len,
|
|||||||
}
|
}
|
||||||
if (!match) continue;
|
if (!match) continue;
|
||||||
string ref((const char *) s + i, refLength);
|
string ref((const char *) s + i, refLength);
|
||||||
if (hashes.find(ref) != hashes.end()) {
|
if (ids.find(ref) != ids.end()) {
|
||||||
debug(format("found reference to `%1%' at offset `%2%'")
|
debug(format("found reference to `%1%' at offset `%2%'")
|
||||||
% ref % i);
|
% ref % i);
|
||||||
seen.insert(ref);
|
seen.insert(ref);
|
||||||
hashes.erase(ref);
|
ids.erase(ref);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct RefScanSink : Sink
|
void checkPath(const string & path,
|
||||||
|
StringSet & ids, StringSet & seen)
|
||||||
{
|
{
|
||||||
HashSink hashSink;
|
checkInterrupt();
|
||||||
StringSet hashes;
|
|
||||||
StringSet seen;
|
|
||||||
|
|
||||||
string tail;
|
|
||||||
|
|
||||||
RefScanSink() : hashSink(htSHA256) { }
|
|
||||||
|
|
||||||
void operator () (const unsigned char * data, unsigned int len);
|
debug(format("checking `%1%'") % path);
|
||||||
};
|
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if (lstat(path.c_str(), &st))
|
||||||
|
throw SysError(format("getting attributes of path `%1%'") % path);
|
||||||
|
|
||||||
void RefScanSink::operator () (const unsigned char * data, unsigned int len)
|
if (S_ISDIR(st.st_mode)) {
|
||||||
{
|
Strings names = readDirectory(path);
|
||||||
hashSink(data, len);
|
for (Strings::iterator i = names.begin(); i != names.end(); i++) {
|
||||||
|
search(i->size(), (const unsigned char *) i->c_str(), ids, seen);
|
||||||
|
checkPath(path + "/" + *i, ids, seen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* It's possible that a reference spans the previous and current
|
else if (S_ISREG(st.st_mode)) {
|
||||||
fragment, so search in the concatenation of the tail of the
|
|
||||||
previous fragment and the start of the current fragment. */
|
AutoCloseFD fd = open(path.c_str(), O_RDONLY);
|
||||||
string s = tail + string((const char *) data, len > refLength ? refLength : len);
|
if (fd == -1) throw SysError(format("opening file `%1%'") % path);
|
||||||
search((const unsigned char *) s.c_str(), s.size(), hashes, seen);
|
|
||||||
|
|
||||||
search(data, len, hashes, seen);
|
size_t bufSize = 1024 * 1024;
|
||||||
|
assert(refLength <= bufSize);
|
||||||
|
unsigned char * buf = new unsigned char[bufSize];
|
||||||
|
|
||||||
unsigned int tailLen = len <= refLength ? len : refLength;
|
size_t left = st.st_size;
|
||||||
tail =
|
bool firstBlock = true;
|
||||||
string(tail, tail.size() < refLength - tailLen ? 0 : tail.size() - (refLength - tailLen)) +
|
|
||||||
string((const char *) data + len - tailLen, tailLen);
|
while (left > 0) {
|
||||||
|
checkInterrupt();
|
||||||
|
|
||||||
|
size_t read = left > bufSize ? bufSize : left;
|
||||||
|
size_t copiedBytes = 0;
|
||||||
|
|
||||||
|
if (!firstBlock) {
|
||||||
|
/* Move the last (refLength - 1) bytes from the last
|
||||||
|
block to the start of the buffer to deal with
|
||||||
|
references that cross block boundaries. */
|
||||||
|
copiedBytes = refLength - 1;
|
||||||
|
if (read + copiedBytes > bufSize)
|
||||||
|
read -= copiedBytes;
|
||||||
|
memcpy(buf, buf + (bufSize - copiedBytes), copiedBytes);
|
||||||
|
}
|
||||||
|
firstBlock = false;
|
||||||
|
|
||||||
|
readFull(fd, buf + copiedBytes, read);
|
||||||
|
left -= read;
|
||||||
|
|
||||||
|
search(copiedBytes + read, buf, ids, seen);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] buf; /* !!! autodelete */
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (S_ISLNK(st.st_mode)) {
|
||||||
|
string target = readLink(path);
|
||||||
|
search(target.size(), (const unsigned char *) target.c_str(), ids, seen);
|
||||||
|
}
|
||||||
|
|
||||||
|
else throw Error(format("unknown file type: %1%") % path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PathSet scanForReferences(const string & path,
|
PathSet scanForReferences(const string & path, const PathSet & paths)
|
||||||
const PathSet & refs, Hash & hash)
|
|
||||||
{
|
{
|
||||||
RefScanSink sink;
|
|
||||||
std::map<string, Path> backMap;
|
std::map<string, Path> backMap;
|
||||||
|
StringSet ids;
|
||||||
|
StringSet seen;
|
||||||
|
|
||||||
/* For efficiency (and a higher hit rate), just search for the
|
/* For efficiency (and a higher hit rate), just search for the
|
||||||
hash part of the file name. (This assumes that all references
|
hash part of the file name. (This assumes that all references
|
||||||
have the form `HASH-bla'). */
|
have the form `HASH-bla'). */
|
||||||
foreach (PathSet::const_iterator, i, refs) {
|
for (PathSet::const_iterator i = paths.begin(); i != paths.end(); i++) {
|
||||||
string baseName = baseNameOf(*i);
|
string baseName = baseNameOf(*i);
|
||||||
string::size_type pos = baseName.find('-');
|
string::size_type pos = baseName.find('-');
|
||||||
if (pos == string::npos)
|
if (pos == string::npos)
|
||||||
@@ -98,25 +136,21 @@ PathSet scanForReferences(const string & path,
|
|||||||
assert(s.size() == refLength);
|
assert(s.size() == refLength);
|
||||||
assert(backMap.find(s) == backMap.end());
|
assert(backMap.find(s) == backMap.end());
|
||||||
// parseHash(htSHA256, s);
|
// parseHash(htSHA256, s);
|
||||||
sink.hashes.insert(s);
|
ids.insert(s);
|
||||||
backMap[s] = *i;
|
backMap[s] = *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for the hashes in the NAR dump of the path. */
|
checkPath(path, ids, seen);
|
||||||
dumpPath(path, sink);
|
|
||||||
|
|
||||||
/* Map the hashes found back to their store paths. */
|
|
||||||
PathSet found;
|
PathSet found;
|
||||||
foreach (StringSet::iterator, i, sink.seen) {
|
for (StringSet::iterator i = seen.begin(); i != seen.end(); i++) {
|
||||||
std::map<string, Path>::iterator j;
|
std::map<string, Path>::iterator j;
|
||||||
if ((j = backMap.find(*i)) == backMap.end()) abort();
|
if ((j = backMap.find(*i)) == backMap.end()) abort();
|
||||||
found.insert(j->second);
|
found.insert(j->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = sink.hashSink.finish();
|
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,10 @@
|
|||||||
#define __REFERENCES_H
|
#define __REFERENCES_H
|
||||||
|
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include "hash.hh"
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
PathSet scanForReferences(const Path & path, const PathSet & refs,
|
PathSet scanForReferences(const Path & path, const PathSet & refs);
|
||||||
Hash & hash);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+36
-103
@@ -29,22 +29,14 @@ Path readStorePath(Source & from)
|
|||||||
PathSet readStorePaths(Source & from)
|
PathSet readStorePaths(Source & from)
|
||||||
{
|
{
|
||||||
PathSet paths = readStringSet(from);
|
PathSet paths = readStringSet(from);
|
||||||
foreach (PathSet::iterator, i, paths) assertStorePath(*i);
|
for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i)
|
||||||
|
assertStorePath(*i);
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RemoteStore::RemoteStore()
|
RemoteStore::RemoteStore()
|
||||||
{
|
{
|
||||||
initialised = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void RemoteStore::openConnection()
|
|
||||||
{
|
|
||||||
if (initialised) return;
|
|
||||||
initialised = true;
|
|
||||||
|
|
||||||
string remoteMode = getEnv("NIX_REMOTE");
|
string remoteMode = getEnv("NIX_REMOTE");
|
||||||
|
|
||||||
if (remoteMode == "slave")
|
if (remoteMode == "slave")
|
||||||
@@ -67,13 +59,13 @@ void RemoteStore::openConnection()
|
|||||||
unsigned int magic = readInt(from);
|
unsigned int magic = readInt(from);
|
||||||
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
|
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
|
||||||
|
|
||||||
daemonVersion = readInt(from);
|
unsigned int daemonVersion = readInt(from);
|
||||||
if (GET_PROTOCOL_MAJOR(daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION))
|
if (GET_PROTOCOL_MAJOR(daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION))
|
||||||
throw Error("Nix daemon protocol version not supported");
|
throw Error("Nix daemon protocol version not supported");
|
||||||
writeInt(PROTOCOL_VERSION, to);
|
writeInt(PROTOCOL_VERSION, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
}
|
|
||||||
catch (Error & e) {
|
} catch (Error & e) {
|
||||||
throw Error(format("cannot start worker (%1%)")
|
throw Error(format("cannot start worker (%1%)")
|
||||||
% e.msg());
|
% e.msg());
|
||||||
}
|
}
|
||||||
@@ -145,26 +137,14 @@ void RemoteStore::connectToDaemon()
|
|||||||
|
|
||||||
string socketPath = nixStateDir + DEFAULT_SOCKET_PATH;
|
string socketPath = nixStateDir + DEFAULT_SOCKET_PATH;
|
||||||
|
|
||||||
/* Urgh, sockaddr_un allows path names of only 108 characters. So
|
|
||||||
chdir to the socket directory so that we can pass a relative
|
|
||||||
path name. !!! this is probably a bad idea in multi-threaded
|
|
||||||
applications... */
|
|
||||||
AutoCloseFD fdPrevDir = open(".", O_RDONLY);
|
|
||||||
if (fdPrevDir == -1) throw SysError("couldn't open current directory");
|
|
||||||
chdir(dirOf(socketPath).c_str());
|
|
||||||
Path socketPathRel = "./" + baseNameOf(socketPath);
|
|
||||||
|
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
if (socketPathRel.size() >= sizeof(addr.sun_path))
|
if (socketPath.size() >= sizeof(addr.sun_path))
|
||||||
throw Error(format("socket path `%1%' is too long") % socketPathRel);
|
throw Error(format("socket path `%1%' is too long") % socketPath);
|
||||||
strcpy(addr.sun_path, socketPathRel.c_str());
|
strcpy(addr.sun_path, socketPath.c_str());
|
||||||
|
|
||||||
if (connect(fdSocket, (struct sockaddr *) &addr, sizeof(addr)) == -1)
|
if (connect(fdSocket, (struct sockaddr *) &addr, sizeof(addr)) == -1)
|
||||||
throw SysError(format("cannot connect to daemon at `%1%'") % socketPath);
|
throw SysError(format("cannot connect to daemon at `%1%'") % socketPath);
|
||||||
|
|
||||||
if (fchdir(fdPrevDir) == -1)
|
|
||||||
throw SysError("couldn't change back to previous directory");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -189,20 +169,12 @@ void RemoteStore::setOptions()
|
|||||||
writeInt(verbosity, to);
|
writeInt(verbosity, to);
|
||||||
writeInt(maxBuildJobs, to);
|
writeInt(maxBuildJobs, to);
|
||||||
writeInt(maxSilentTime, to);
|
writeInt(maxSilentTime, to);
|
||||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 2)
|
|
||||||
writeInt(useBuildHook, to);
|
|
||||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 4) {
|
|
||||||
writeInt(buildVerbosity, to);
|
|
||||||
writeInt(logType, to);
|
|
||||||
writeInt(printBuildTrace, to);
|
|
||||||
}
|
|
||||||
processStderr();
|
processStderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RemoteStore::isValidPath(const Path & path)
|
bool RemoteStore::isValidPath(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopIsValidPath, to);
|
writeInt(wopIsValidPath, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -211,16 +183,8 @@ bool RemoteStore::isValidPath(const Path & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PathSet RemoteStore::queryValidPaths()
|
|
||||||
{
|
|
||||||
openConnection();
|
|
||||||
throw Error("not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool RemoteStore::hasSubstitutes(const Path & path)
|
bool RemoteStore::hasSubstitutes(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopHasSubstitutes, to);
|
writeInt(wopHasSubstitutes, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -229,27 +193,8 @@ bool RemoteStore::hasSubstitutes(const Path & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RemoteStore::querySubstitutablePathInfo(const Path & path,
|
|
||||||
SubstitutablePathInfo & info)
|
|
||||||
{
|
|
||||||
openConnection();
|
|
||||||
if (GET_PROTOCOL_MINOR(daemonVersion) < 3) return false;
|
|
||||||
writeInt(wopQuerySubstitutablePathInfo, to);
|
|
||||||
writeString(path, to);
|
|
||||||
processStderr();
|
|
||||||
unsigned int reply = readInt(from);
|
|
||||||
if (reply == 0) return false;
|
|
||||||
info.deriver = readString(from);
|
|
||||||
if (info.deriver != "") assertStorePath(info.deriver);
|
|
||||||
info.references = readStorePaths(from);
|
|
||||||
info.downloadSize = readLongLong(from);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Hash RemoteStore::queryPathHash(const Path & path)
|
Hash RemoteStore::queryPathHash(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopQueryPathHash, to);
|
writeInt(wopQueryPathHash, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -261,7 +206,6 @@ Hash RemoteStore::queryPathHash(const Path & path)
|
|||||||
void RemoteStore::queryReferences(const Path & path,
|
void RemoteStore::queryReferences(const Path & path,
|
||||||
PathSet & references)
|
PathSet & references)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopQueryReferences, to);
|
writeInt(wopQueryReferences, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -273,7 +217,6 @@ void RemoteStore::queryReferences(const Path & path,
|
|||||||
void RemoteStore::queryReferrers(const Path & path,
|
void RemoteStore::queryReferrers(const Path & path,
|
||||||
PathSet & referrers)
|
PathSet & referrers)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopQueryReferrers, to);
|
writeInt(wopQueryReferrers, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -284,41 +227,40 @@ void RemoteStore::queryReferrers(const Path & path,
|
|||||||
|
|
||||||
Path RemoteStore::queryDeriver(const Path & path)
|
Path RemoteStore::queryDeriver(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopQueryDeriver, to);
|
writeInt(wopQueryDeriver, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
Path drvPath = readString(from);
|
return readStorePath(from);
|
||||||
if (drvPath != "") assertStorePath(drvPath);
|
|
||||||
return drvPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path RemoteStore::addToStore(const Path & _srcPath,
|
PathSet RemoteStore::querySubstitutablePaths()
|
||||||
bool recursive, HashType hashAlgo, PathFilter & filter)
|
{
|
||||||
|
throw Error("not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Path RemoteStore::addToStore(const Path & _srcPath, bool fixed,
|
||||||
|
bool recursive, string hashAlgo, PathFilter & filter)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
|
|
||||||
Path srcPath(absPath(_srcPath));
|
Path srcPath(absPath(_srcPath));
|
||||||
|
|
||||||
writeInt(wopAddToStore, to);
|
writeInt(wopAddToStore, to);
|
||||||
writeString(baseNameOf(srcPath), to);
|
writeString(baseNameOf(srcPath), to);
|
||||||
/* backwards compatibility hack */
|
writeInt(fixed ? 1 : 0, to);
|
||||||
writeInt((hashAlgo == htSHA256 && recursive) ? 0 : 1, to);
|
|
||||||
writeInt(recursive ? 1 : 0, to);
|
writeInt(recursive ? 1 : 0, to);
|
||||||
writeString(printHashType(hashAlgo), to);
|
writeString(hashAlgo, to);
|
||||||
dumpPath(srcPath, to, filter);
|
dumpPath(srcPath, to, filter);
|
||||||
processStderr();
|
processStderr();
|
||||||
return readStorePath(from);
|
return readStorePath(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path RemoteStore::addTextToStore(const string & name, const string & s,
|
Path RemoteStore::addTextToStore(const string & suffix, const string & s,
|
||||||
const PathSet & references)
|
const PathSet & references)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopAddTextToStore, to);
|
writeInt(wopAddTextToStore, to);
|
||||||
writeString(name, to);
|
writeString(suffix, to);
|
||||||
writeString(s, to);
|
writeString(s, to);
|
||||||
writeStringSet(references, to);
|
writeStringSet(references, to);
|
||||||
|
|
||||||
@@ -330,7 +272,6 @@ Path RemoteStore::addTextToStore(const string & name, const string & s,
|
|||||||
void RemoteStore::exportPath(const Path & path, bool sign,
|
void RemoteStore::exportPath(const Path & path, bool sign,
|
||||||
Sink & sink)
|
Sink & sink)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopExportPath, to);
|
writeInt(wopExportPath, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
writeInt(sign ? 1 : 0, to);
|
writeInt(sign ? 1 : 0, to);
|
||||||
@@ -341,10 +282,10 @@ void RemoteStore::exportPath(const Path & path, bool sign,
|
|||||||
|
|
||||||
Path RemoteStore::importPath(bool requireSignature, Source & source)
|
Path RemoteStore::importPath(bool requireSignature, Source & source)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopImportPath, to);
|
writeInt(wopImportPath, to);
|
||||||
/* We ignore requireSignature, since the worker forces it to true
|
/* We ignore requireSignature, since the worker forces it to true
|
||||||
anyway. */
|
anyway. */
|
||||||
|
|
||||||
processStderr(0, &source);
|
processStderr(0, &source);
|
||||||
return readStorePath(from);
|
return readStorePath(from);
|
||||||
}
|
}
|
||||||
@@ -352,7 +293,6 @@ Path RemoteStore::importPath(bool requireSignature, Source & source)
|
|||||||
|
|
||||||
void RemoteStore::buildDerivations(const PathSet & drvPaths)
|
void RemoteStore::buildDerivations(const PathSet & drvPaths)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopBuildDerivations, to);
|
writeInt(wopBuildDerivations, to);
|
||||||
writeStringSet(drvPaths, to);
|
writeStringSet(drvPaths, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -362,7 +302,6 @@ void RemoteStore::buildDerivations(const PathSet & drvPaths)
|
|||||||
|
|
||||||
void RemoteStore::ensurePath(const Path & path)
|
void RemoteStore::ensurePath(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopEnsurePath, to);
|
writeInt(wopEnsurePath, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -372,7 +311,6 @@ void RemoteStore::ensurePath(const Path & path)
|
|||||||
|
|
||||||
void RemoteStore::addTempRoot(const Path & path)
|
void RemoteStore::addTempRoot(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopAddTempRoot, to);
|
writeInt(wopAddTempRoot, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -382,7 +320,6 @@ void RemoteStore::addTempRoot(const Path & path)
|
|||||||
|
|
||||||
void RemoteStore::addIndirectRoot(const Path & path)
|
void RemoteStore::addIndirectRoot(const Path & path)
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopAddIndirectRoot, to);
|
writeInt(wopAddIndirectRoot, to);
|
||||||
writeString(path, to);
|
writeString(path, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
@@ -392,7 +329,6 @@ void RemoteStore::addIndirectRoot(const Path & path)
|
|||||||
|
|
||||||
void RemoteStore::syncWithGC()
|
void RemoteStore::syncWithGC()
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopSyncWithGC, to);
|
writeInt(wopSyncWithGC, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
readInt(from);
|
readInt(from);
|
||||||
@@ -401,7 +337,6 @@ void RemoteStore::syncWithGC()
|
|||||||
|
|
||||||
Roots RemoteStore::findRoots()
|
Roots RemoteStore::findRoots()
|
||||||
{
|
{
|
||||||
openConnection();
|
|
||||||
writeInt(wopFindRoots, to);
|
writeInt(wopFindRoots, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
unsigned int count = readInt(from);
|
unsigned int count = readInt(from);
|
||||||
@@ -415,26 +350,24 @@ Roots RemoteStore::findRoots()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
|
void RemoteStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed)
|
||||||
{
|
{
|
||||||
openConnection();
|
result.clear();
|
||||||
|
bytesFreed = 0;
|
||||||
writeInt(wopCollectGarbage, to);
|
writeInt(wopCollectGarbage, to);
|
||||||
writeInt(options.action, to);
|
writeInt(action, to);
|
||||||
writeStringSet(options.pathsToDelete, to);
|
writeStringSet(pathsToDelete, to);
|
||||||
writeInt(options.ignoreLiveness, to);
|
writeInt(ignoreLiveness, to);
|
||||||
writeLongLong(options.maxFreed, to);
|
|
||||||
writeInt(options.maxLinks, to);
|
|
||||||
if (GET_PROTOCOL_MINOR(daemonVersion) >= 5) {
|
|
||||||
writeInt(options.useAtime, to);
|
|
||||||
writeInt(options.maxAtime, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
processStderr();
|
processStderr();
|
||||||
|
|
||||||
results.paths = readStringSet(from);
|
result = readStringSet(from);
|
||||||
results.bytesFreed = readLongLong(from);
|
|
||||||
results.blocksFreed = readLongLong(from);
|
/* Ugh - NAR integers are 64 bits, but read/writeInt() aren't. */
|
||||||
|
unsigned int lo = readInt(from);
|
||||||
|
unsigned int hi = readInt(from);
|
||||||
|
bytesFreed = (((unsigned long long) hi) << 32) | lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ public:
|
|||||||
|
|
||||||
bool isValidPath(const Path & path);
|
bool isValidPath(const Path & path);
|
||||||
|
|
||||||
PathSet queryValidPaths();
|
|
||||||
|
|
||||||
Hash queryPathHash(const Path & path);
|
Hash queryPathHash(const Path & path);
|
||||||
|
|
||||||
void queryReferences(const Path & path, PathSet & references);
|
void queryReferences(const Path & path, PathSet & references);
|
||||||
@@ -37,16 +35,15 @@ public:
|
|||||||
|
|
||||||
Path queryDeriver(const Path & path);
|
Path queryDeriver(const Path & path);
|
||||||
|
|
||||||
|
PathSet querySubstitutablePaths();
|
||||||
|
|
||||||
bool hasSubstitutes(const Path & path);
|
bool hasSubstitutes(const Path & path);
|
||||||
|
|
||||||
bool querySubstitutablePathInfo(const Path & path,
|
Path addToStore(const Path & srcPath, bool fixed = false,
|
||||||
SubstitutablePathInfo & info);
|
bool recursive = false, string hashAlgo = "",
|
||||||
|
|
||||||
Path addToStore(const Path & srcPath,
|
|
||||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
Path addTextToStore(const string & name, const string & s,
|
Path addTextToStore(const string & suffix, const string & s,
|
||||||
const PathSet & references);
|
const PathSet & references);
|
||||||
|
|
||||||
void exportPath(const Path & path, bool sign,
|
void exportPath(const Path & path, bool sign,
|
||||||
@@ -66,17 +63,14 @@ public:
|
|||||||
|
|
||||||
Roots findRoots();
|
Roots findRoots();
|
||||||
|
|
||||||
void collectGarbage(const GCOptions & options, GCResults & results);
|
void collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AutoCloseFD fdSocket;
|
AutoCloseFD fdSocket;
|
||||||
FdSink to;
|
FdSink to;
|
||||||
FdSource from;
|
FdSource from;
|
||||||
Pid child;
|
Pid child;
|
||||||
unsigned int daemonVersion;
|
|
||||||
bool initialised;
|
|
||||||
|
|
||||||
void openConnection();
|
|
||||||
|
|
||||||
void processStderr(Sink * sink = 0, Source * source = 0);
|
void processStderr(Sink * sink = 0, Source * source = 0);
|
||||||
|
|
||||||
|
|||||||
+36
-166
@@ -2,20 +2,14 @@
|
|||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
GCOptions::GCOptions()
|
bool StoreAPI::hasSubstitutes(const Path & path)
|
||||||
{
|
{
|
||||||
action = gcDeleteDead;
|
PathSet paths = querySubstitutablePaths();
|
||||||
ignoreLiveness = false;
|
return paths.find(path) != paths.end();
|
||||||
maxFreed = 0;
|
|
||||||
maxLinks = 0;
|
|
||||||
useAtime = false;
|
|
||||||
maxAtime = (time_t) -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,26 +48,6 @@ Path toStorePath(const Path & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path followLinksToStore(const Path & _path)
|
|
||||||
{
|
|
||||||
Path path = absPath(_path);
|
|
||||||
while (!isInStore(path)) {
|
|
||||||
if (!isLink(path)) break;
|
|
||||||
string target = readLink(path);
|
|
||||||
path = absPath(target, dirOf(path));
|
|
||||||
}
|
|
||||||
if (!isInStore(path))
|
|
||||||
throw Error(format("path `%1%' is not in the Nix store") % path);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Path followLinksToStorePath(const Path & path)
|
|
||||||
{
|
|
||||||
return toStorePath(followLinksToStore(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void checkStoreName(const string & name)
|
void checkStoreName(const string & name)
|
||||||
{
|
{
|
||||||
string validChars = "+-._?=";
|
string validChars = "+-._?=";
|
||||||
@@ -81,7 +55,7 @@ void checkStoreName(const string & name)
|
|||||||
reasons (e.g., "." and ".."). */
|
reasons (e.g., "." and ".."). */
|
||||||
if (string(name, 0, 1) == ".")
|
if (string(name, 0, 1) == ".")
|
||||||
throw Error(format("illegal name: `%1%'") % name);
|
throw Error(format("illegal name: `%1%'") % name);
|
||||||
foreach (string::const_iterator, i, name)
|
for (string::const_iterator i = name.begin(); i != name.end(); ++i)
|
||||||
if (!((*i >= 'A' && *i <= 'Z') ||
|
if (!((*i >= 'A' && *i <= 'Z') ||
|
||||||
(*i >= 'a' && *i <= 'z') ||
|
(*i >= 'a' && *i <= 'z') ||
|
||||||
(*i >= '0' && *i <= '9') ||
|
(*i >= '0' && *i <= '9') ||
|
||||||
@@ -93,113 +67,55 @@ void checkStoreName(const string & name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Store paths have the following form:
|
|
||||||
|
|
||||||
<store>/<h>-<name>
|
|
||||||
|
|
||||||
where
|
|
||||||
|
|
||||||
<store> = the location of the Nix store, usually /nix/store
|
|
||||||
|
|
||||||
<name> = a human readable name for the path, typically obtained
|
|
||||||
from the name attribute of the derivation, or the name of the
|
|
||||||
source file from which the store path is created
|
|
||||||
|
|
||||||
<h> = base-32 representation of the first 160 bits of a SHA-256
|
|
||||||
hash of <s>; the hash part of the store name
|
|
||||||
|
|
||||||
<s> = the string "<type>:sha256:<h2>:<store>:<name>";
|
|
||||||
note that it includes the location of the store as well as the
|
|
||||||
name to make sure that changes to either of those are reflected
|
|
||||||
in the hash (e.g. you won't get /nix/store/<h>-name1 and
|
|
||||||
/nix/store/<h>-name2 with equal hash parts).
|
|
||||||
|
|
||||||
<type> = one of:
|
|
||||||
"text:<r1>:<r2>:...<rN>"
|
|
||||||
for plain text files written to the store using
|
|
||||||
addTextToStore(); <r1> ... <rN> are the references of the
|
|
||||||
path.
|
|
||||||
"source"
|
|
||||||
for paths copied to the store using addToStore() when recursive
|
|
||||||
= true and hashAlgo = "sha256"
|
|
||||||
"output:out"
|
|
||||||
for either the outputs created by derivations, OR paths copied
|
|
||||||
to the store using addToStore() with recursive != true or
|
|
||||||
hashAlgo != "sha256" (in that case "source" is used; it's
|
|
||||||
silly, but it's done that way for compatibility).
|
|
||||||
|
|
||||||
<h2> = base-16 representation of a SHA-256 hash of:
|
|
||||||
if <type> = "text:...":
|
|
||||||
the string written to the resulting store path
|
|
||||||
if <type> = "source":
|
|
||||||
the serialisation of the path from which this store path is
|
|
||||||
copied, as returned by hashPath()
|
|
||||||
if <type> = "output:out":
|
|
||||||
for non-fixed derivation outputs:
|
|
||||||
the derivation (see hashDerivationModulo() in
|
|
||||||
primops.cc)
|
|
||||||
for paths copied by addToStore() or produced by fixed-output
|
|
||||||
derivations:
|
|
||||||
the string "fixed:out:<rec><algo>:<hash>:", where
|
|
||||||
<rec> = "r:" for recursive (path) hashes, or "" or flat
|
|
||||||
(file) hashes
|
|
||||||
<algo> = "md5", "sha1" or "sha256"
|
|
||||||
<hash> = base-16 representation of the path or flat hash of
|
|
||||||
the contents of the path (or expected contents of the
|
|
||||||
path for fixed-output derivations)
|
|
||||||
|
|
||||||
It would have been nicer to handle fixed-output derivations under
|
|
||||||
"source", e.g. have something like "source:<rec><algo>", but we're
|
|
||||||
stuck with this for now...
|
|
||||||
|
|
||||||
The main reason for this way of computing names is to prevent name
|
|
||||||
collisions (for security). For instance, it shouldn't be feasible
|
|
||||||
to come up with a derivation whose output path collides with the
|
|
||||||
path for a copied source. The former would have a <s> starting with
|
|
||||||
"output:out:", while the latter would have a <2> starting with
|
|
||||||
"source:".
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
Path makeStorePath(const string & type,
|
Path makeStorePath(const string & type,
|
||||||
const Hash & hash, const string & name)
|
const Hash & hash, const string & suffix)
|
||||||
{
|
{
|
||||||
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
||||||
string s = type + ":sha256:" + printHash(hash) + ":"
|
string s = type + ":sha256:" + printHash(hash) + ":"
|
||||||
+ nixStore + ":" + name;
|
+ nixStore + ":" + suffix;
|
||||||
|
|
||||||
checkStoreName(name);
|
checkStoreName(suffix);
|
||||||
|
|
||||||
return nixStore + "/"
|
return nixStore + "/"
|
||||||
+ printHash32(compressHash(hashString(htSHA256, s), 20))
|
+ printHash32(compressHash(hashString(htSHA256, s), 20))
|
||||||
+ "-" + name;
|
+ "-" + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path makeFixedOutputPath(bool recursive,
|
Path makeFixedOutputPath(bool recursive,
|
||||||
HashType hashAlgo, Hash hash, string name)
|
string hashAlgo, Hash hash, string name)
|
||||||
{
|
{
|
||||||
return hashAlgo == htSHA256 && recursive
|
/* !!! copy/paste from primops.cc */
|
||||||
? makeStorePath("source", hash, name)
|
Hash h = hashString(htSHA256, "fixed:out:"
|
||||||
: makeStorePath("output:out", hashString(htSHA256,
|
+ (recursive ? (string) "r:" : "") + hashAlgo + ":"
|
||||||
"fixed:out:" + (recursive ? (string) "r:" : "") +
|
+ printHash(hash) + ":"
|
||||||
printHashType(hashAlgo) + ":" + printHash(hash) + ":"),
|
+ "");
|
||||||
name);
|
return makeStorePath("output:out", h, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
||||||
bool recursive, HashType hashAlgo, PathFilter & filter)
|
bool fixed, bool recursive, string hashAlgo, PathFilter & filter)
|
||||||
{
|
{
|
||||||
HashType ht(hashAlgo);
|
Hash h = hashPath(htSHA256, srcPath, filter);
|
||||||
Hash h = recursive ? hashPath(ht, srcPath, filter) : hashFile(ht, srcPath);
|
|
||||||
string name = baseNameOf(srcPath);
|
string baseName = baseNameOf(srcPath);
|
||||||
Path dstPath = makeFixedOutputPath(recursive, hashAlgo, h, name);
|
|
||||||
|
Path dstPath;
|
||||||
|
|
||||||
|
if (fixed) {
|
||||||
|
HashType ht(parseHashType(hashAlgo));
|
||||||
|
Hash h2 = recursive ? hashPath(ht, srcPath, filter) : hashFile(ht, srcPath);
|
||||||
|
dstPath = makeFixedOutputPath(recursive, hashAlgo, h2, baseName);
|
||||||
|
}
|
||||||
|
|
||||||
|
else dstPath = makeStorePath("source", h, baseName);
|
||||||
|
|
||||||
return std::pair<Path, Hash>(dstPath, h);
|
return std::pair<Path, Hash>(dstPath, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path computeStorePathForText(const string & name, const string & s,
|
Path computeStorePathForText(const string & suffix, const string & s,
|
||||||
const PathSet & references)
|
const PathSet & references)
|
||||||
{
|
{
|
||||||
Hash hash = hashString(htSHA256, s);
|
Hash hash = hashString(htSHA256, s);
|
||||||
@@ -207,54 +123,19 @@ Path computeStorePathForText(const string & name, const string & s,
|
|||||||
hacky, but we can't put them in `s' since that would be
|
hacky, but we can't put them in `s' since that would be
|
||||||
ambiguous. */
|
ambiguous. */
|
||||||
string type = "text";
|
string type = "text";
|
||||||
foreach (PathSet::const_iterator, i, references) {
|
for (PathSet::const_iterator i = references.begin(); i != references.end(); ++i) {
|
||||||
type += ":";
|
type += ":";
|
||||||
type += *i;
|
type += *i;
|
||||||
}
|
}
|
||||||
return makeStorePath(type, hash, name);
|
return makeStorePath(type, hash, suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return a string accepted by decodeValidPathInfo() that
|
ValidPathInfo decodeValidPathInfo(std::istream & str)
|
||||||
registers the specified paths as valid. Note: it's the
|
|
||||||
responsibility of the caller to provide a closure. */
|
|
||||||
string makeValidityRegistration(const PathSet & paths,
|
|
||||||
bool showDerivers, bool showHash)
|
|
||||||
{
|
|
||||||
string s = "";
|
|
||||||
|
|
||||||
foreach (PathSet::iterator, i, paths) {
|
|
||||||
s += *i + "\n";
|
|
||||||
|
|
||||||
if (showHash)
|
|
||||||
s += printHash(store->queryPathHash(*i)) + "\n";
|
|
||||||
|
|
||||||
Path deriver = showDerivers ? store->queryDeriver(*i) : "";
|
|
||||||
s += deriver + "\n";
|
|
||||||
|
|
||||||
PathSet references;
|
|
||||||
store->queryReferences(*i, references);
|
|
||||||
|
|
||||||
s += (format("%1%\n") % references.size()).str();
|
|
||||||
|
|
||||||
foreach (PathSet::iterator, j, references)
|
|
||||||
s += *j + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven)
|
|
||||||
{
|
{
|
||||||
ValidPathInfo info;
|
ValidPathInfo info;
|
||||||
getline(str, info.path);
|
getline(str, info.path);
|
||||||
if (str.eof()) { info.path = ""; return info; }
|
if (str.eof()) { info.path = ""; return info; }
|
||||||
if (hashGiven) {
|
|
||||||
string s;
|
|
||||||
getline(str, s);
|
|
||||||
info.hash = parseHash(htSHA256, s);
|
|
||||||
}
|
|
||||||
getline(str, info.deriver);
|
getline(str, info.deriver);
|
||||||
string s; int n;
|
string s; int n;
|
||||||
getline(str, s);
|
getline(str, s);
|
||||||
@@ -268,17 +149,6 @@ ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string showPaths(const PathSet & paths)
|
|
||||||
{
|
|
||||||
string s;
|
|
||||||
foreach (PathSet::const_iterator, i, paths) {
|
|
||||||
if (s.size() != 0) s += ", ";
|
|
||||||
s += "`" + *i + "'";
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -293,10 +163,10 @@ namespace nix {
|
|||||||
boost::shared_ptr<StoreAPI> store;
|
boost::shared_ptr<StoreAPI> store;
|
||||||
|
|
||||||
|
|
||||||
boost::shared_ptr<StoreAPI> openStore()
|
boost::shared_ptr<StoreAPI> openStore(bool reserveSpace)
|
||||||
{
|
{
|
||||||
if (getEnv("NIX_REMOTE") == "")
|
if (getEnv("NIX_REMOTE") == "")
|
||||||
return boost::shared_ptr<StoreAPI>(new LocalStore());
|
return boost::shared_ptr<StoreAPI>(new LocalStore(reserveSpace));
|
||||||
else
|
else
|
||||||
return boost::shared_ptr<StoreAPI>(new RemoteStore());
|
return boost::shared_ptr<StoreAPI>(new RemoteStore());
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-156
@@ -16,101 +16,14 @@ namespace nix {
|
|||||||
typedef std::map<Path, Path> Roots;
|
typedef std::map<Path, Path> Roots;
|
||||||
|
|
||||||
|
|
||||||
|
/* Garbage collector operation. */
|
||||||
|
typedef enum {
|
||||||
struct GCOptions
|
gcReturnRoots,
|
||||||
{
|
gcReturnLive,
|
||||||
/* Garbage collector operation:
|
gcReturnDead,
|
||||||
|
gcDeleteDead,
|
||||||
- `gcReturnRoots': find and return the set of roots for the
|
gcDeleteSpecific,
|
||||||
garbage collector. These are the store paths symlinked to in
|
} GCAction;
|
||||||
the `gcroots' directory.
|
|
||||||
|
|
||||||
- `gcReturnLive': return the set of paths reachable from
|
|
||||||
(i.e. in the closure of) the roots.
|
|
||||||
|
|
||||||
- `gcReturnDead': return the set of paths not reachable from
|
|
||||||
the roots.
|
|
||||||
|
|
||||||
- `gcDeleteDead': actually delete the latter set.
|
|
||||||
|
|
||||||
- `gcDeleteSpecific': delete the paths listed in
|
|
||||||
`pathsToDelete', insofar as they are not reachable.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
gcReturnRoots,
|
|
||||||
gcReturnLive,
|
|
||||||
gcReturnDead,
|
|
||||||
gcDeleteDead,
|
|
||||||
gcDeleteSpecific,
|
|
||||||
} GCAction;
|
|
||||||
|
|
||||||
GCAction action;
|
|
||||||
|
|
||||||
/* If `ignoreLiveness' is set, then reachability from the roots is
|
|
||||||
ignored (dangerous!). However, the paths must still be
|
|
||||||
unreferenced *within* the store (i.e., there can be no other
|
|
||||||
store paths that depend on them). */
|
|
||||||
bool ignoreLiveness;
|
|
||||||
|
|
||||||
/* For `gcDeleteSpecific', the paths to delete. */
|
|
||||||
PathSet pathsToDelete;
|
|
||||||
|
|
||||||
/* Stop after at least `maxFreed' bytes have been freed. 0 means
|
|
||||||
no limit. */
|
|
||||||
unsigned long long maxFreed;
|
|
||||||
|
|
||||||
/* Stop after the number of hard links to the Nix store directory
|
|
||||||
has dropped below `maxLinks'. */
|
|
||||||
unsigned int maxLinks;
|
|
||||||
|
|
||||||
/* Delete paths in order of ascending last access time. I.e.,
|
|
||||||
prefer deleting unrecently used paths. Useful in conjunction
|
|
||||||
with `maxFreed' and `maxLinks' (or manual interruption). The
|
|
||||||
access time of a path is defined as the highest atime of any
|
|
||||||
non-directory, non-symlink file under that path. Directories
|
|
||||||
and symlinks are ignored because their atimes are frequently
|
|
||||||
mass-updated, e.g. by `locate'. Note that optimiseStore()
|
|
||||||
somewhat reduces the usefulness of this option: it hard-links
|
|
||||||
regular files and symlink together, giving them a "shared"
|
|
||||||
atime. */
|
|
||||||
bool useAtime;
|
|
||||||
|
|
||||||
/* Do not delete paths newer than `maxAtime'. -1 means no age
|
|
||||||
limit. */
|
|
||||||
time_t maxAtime;
|
|
||||||
|
|
||||||
GCOptions();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct GCResults
|
|
||||||
{
|
|
||||||
/* Depending on the action, the GC roots, or the paths that would
|
|
||||||
be or have been deleted. */
|
|
||||||
PathSet paths;
|
|
||||||
|
|
||||||
/* For `gcReturnDead', `gcDeleteDead' and `gcDeleteSpecific', the
|
|
||||||
number of bytes that would be or was freed. */
|
|
||||||
unsigned long long bytesFreed;
|
|
||||||
|
|
||||||
/* The number of file system blocks that would be or was freed. */
|
|
||||||
unsigned long long blocksFreed;
|
|
||||||
|
|
||||||
GCResults()
|
|
||||||
{
|
|
||||||
bytesFreed = 0;
|
|
||||||
blocksFreed = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct SubstitutablePathInfo
|
|
||||||
{
|
|
||||||
Path deriver;
|
|
||||||
PathSet references;
|
|
||||||
unsigned long long downloadSize; /* 0 = unknown or inapplicable */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class StoreAPI
|
class StoreAPI
|
||||||
@@ -122,9 +35,6 @@ public:
|
|||||||
/* Checks whether a path is valid. */
|
/* Checks whether a path is valid. */
|
||||||
virtual bool isValidPath(const Path & path) = 0;
|
virtual bool isValidPath(const Path & path) = 0;
|
||||||
|
|
||||||
/* Query the set of valid paths. */
|
|
||||||
virtual PathSet queryValidPaths() = 0;
|
|
||||||
|
|
||||||
/* Queries the hash of a valid path. */
|
/* Queries the hash of a valid path. */
|
||||||
virtual Hash queryPathHash(const Path & path) = 0;
|
virtual Hash queryPathHash(const Path & path) = 0;
|
||||||
|
|
||||||
@@ -133,40 +43,21 @@ public:
|
|||||||
virtual void queryReferences(const Path & path,
|
virtual void queryReferences(const Path & path,
|
||||||
PathSet & references) = 0;
|
PathSet & references) = 0;
|
||||||
|
|
||||||
/* Like queryReferences, but with self-references filtered out. */
|
|
||||||
PathSet queryReferencesNoSelf(const Path & path)
|
|
||||||
{
|
|
||||||
PathSet res;
|
|
||||||
queryReferences(path, res);
|
|
||||||
res.erase(path);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Queries the set of incoming FS references for a store path.
|
/* Queries the set of incoming FS references for a store path.
|
||||||
The result is not cleared. */
|
The result is not cleared. */
|
||||||
virtual void queryReferrers(const Path & path,
|
virtual void queryReferrers(const Path & path,
|
||||||
PathSet & referrers) = 0;
|
PathSet & referrers) = 0;
|
||||||
|
|
||||||
/* Like queryReferrers, but with self-references filtered out. */
|
|
||||||
PathSet queryReferrersNoSelf(const Path & path)
|
|
||||||
{
|
|
||||||
PathSet res;
|
|
||||||
queryReferrers(path, res);
|
|
||||||
res.erase(path);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Query the deriver of a store path. Return the empty string if
|
/* Query the deriver of a store path. Return the empty string if
|
||||||
no deriver has been set. */
|
no deriver has been set. */
|
||||||
virtual Path queryDeriver(const Path & path) = 0;
|
virtual Path queryDeriver(const Path & path) = 0;
|
||||||
|
|
||||||
/* Query whether a path has substitutes. */
|
/* Query the set of substitutable paths. */
|
||||||
virtual bool hasSubstitutes(const Path & path) = 0;
|
virtual PathSet querySubstitutablePaths() = 0;
|
||||||
|
|
||||||
/* Query the references, deriver and download size of a
|
/* More efficient variant if we just want to know if a path has
|
||||||
substitutable path. */
|
substitutes. */
|
||||||
virtual bool querySubstitutablePathInfo(const Path & path,
|
virtual bool hasSubstitutes(const Path & path);
|
||||||
SubstitutablePathInfo & info) = 0;
|
|
||||||
|
|
||||||
/* Copy the contents of a path to the store and register the
|
/* Copy the contents of a path to the store and register the
|
||||||
validity the resulting path. The resulting path is returned.
|
validity the resulting path. The resulting path is returned.
|
||||||
@@ -174,13 +65,13 @@ public:
|
|||||||
derivation is pre-loaded into the Nix store. The function
|
derivation is pre-loaded into the Nix store. The function
|
||||||
object `filter' can be used to exclude files (see
|
object `filter' can be used to exclude files (see
|
||||||
libutil/archive.hh). */
|
libutil/archive.hh). */
|
||||||
virtual Path addToStore(const Path & srcPath,
|
virtual Path addToStore(const Path & srcPath, bool fixed = false,
|
||||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
bool recursive = false, string hashAlgo = "",
|
||||||
PathFilter & filter = defaultPathFilter) = 0;
|
PathFilter & filter = defaultPathFilter) = 0;
|
||||||
|
|
||||||
/* Like addToStore, but the contents written to the output path is
|
/* Like addToStore, but the contents written to the output path is
|
||||||
a regular file containing the given string. */
|
a regular file containing the given string. */
|
||||||
virtual Path addTextToStore(const string & name, const string & s,
|
virtual Path addTextToStore(const string & suffix, const string & s,
|
||||||
const PathSet & references) = 0;
|
const PathSet & references) = 0;
|
||||||
|
|
||||||
/* Export a store path, that is, create a NAR dump of the store
|
/* Export a store path, that is, create a NAR dump of the store
|
||||||
@@ -243,8 +134,33 @@ public:
|
|||||||
outside of the Nix store that point to `storePath'. */
|
outside of the Nix store that point to `storePath'. */
|
||||||
virtual Roots findRoots() = 0;
|
virtual Roots findRoots() = 0;
|
||||||
|
|
||||||
/* Perform a garbage collection. */
|
/* Depending on `action', this function does the following:
|
||||||
virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0;
|
|
||||||
|
- `gcReturnRoots': find and return the set of roots for the
|
||||||
|
garbage collector. These are the store paths symlinked to in
|
||||||
|
the `gcroots' directory.
|
||||||
|
|
||||||
|
- `gcReturnLive': return the set of paths reachable from
|
||||||
|
(i.e. in the closure of) the roots.
|
||||||
|
|
||||||
|
- `gcReturnDead': return the set of paths not reachable from
|
||||||
|
the roots.
|
||||||
|
|
||||||
|
- `gcDeleteDead': actually delete the latter set.
|
||||||
|
|
||||||
|
- `gcDeleteSpecific': delete the paths listed in
|
||||||
|
`pathsToDelete', insofar as they are not reachable.
|
||||||
|
|
||||||
|
If `ignoreLiveness' is set, then reachability from the roots is
|
||||||
|
ignored (dangerous!). However, the paths must still be
|
||||||
|
unreferenced *within* the store (i.e., there can be no other
|
||||||
|
store paths that depend on them).
|
||||||
|
|
||||||
|
For `gcReturnDead', `gcDeleteDead' and `gcDeleteSpecific', the
|
||||||
|
number of bytes that would be or was freed is returned in
|
||||||
|
`bytesFreed'. */
|
||||||
|
virtual void collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -258,27 +174,17 @@ bool isStorePath(const Path & path);
|
|||||||
|
|
||||||
void checkStoreName(const string & name);
|
void checkStoreName(const string & name);
|
||||||
|
|
||||||
|
|
||||||
/* Chop off the parts after the top-level store name, e.g.,
|
/* Chop off the parts after the top-level store name, e.g.,
|
||||||
/nix/store/abcd-foo/bar => /nix/store/abcd-foo. */
|
/nix/store/abcd-foo/bar => /nix/store/abcd-foo. */
|
||||||
Path toStorePath(const Path & path);
|
Path toStorePath(const Path & path);
|
||||||
|
|
||||||
|
|
||||||
/* Follow symlinks until we end up with a path in the Nix store. */
|
|
||||||
Path followLinksToStore(const Path & path);
|
|
||||||
|
|
||||||
|
|
||||||
/* Same as followLinksToStore(), but apply toStorePath() to the
|
|
||||||
result. */
|
|
||||||
Path followLinksToStorePath(const Path & path);
|
|
||||||
|
|
||||||
|
|
||||||
/* Constructs a unique store path name. */
|
/* Constructs a unique store path name. */
|
||||||
Path makeStorePath(const string & type,
|
Path makeStorePath(const string & type,
|
||||||
const Hash & hash, const string & name);
|
const Hash & hash, const string & suffix);
|
||||||
|
|
||||||
Path makeFixedOutputPath(bool recursive,
|
Path makeFixedOutputPath(bool recursive,
|
||||||
HashType hashAlgo, Hash hash, string name);
|
string hashAlgo, Hash hash, string name);
|
||||||
|
|
||||||
|
|
||||||
/* This is the preparatory part of addToStore() and addToStoreFixed();
|
/* This is the preparatory part of addToStore() and addToStoreFixed();
|
||||||
@@ -286,7 +192,7 @@ Path makeFixedOutputPath(bool recursive,
|
|||||||
Returns the store path and the cryptographic hash of the
|
Returns the store path and the cryptographic hash of the
|
||||||
contents of srcPath. */
|
contents of srcPath. */
|
||||||
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
||||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
bool fixed = false, bool recursive = false, string hashAlgo = "",
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
/* Preparatory part of addTextToStore().
|
/* Preparatory part of addTextToStore().
|
||||||
@@ -303,7 +209,7 @@ std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
|||||||
simply yield a different store path, so other users wouldn't be
|
simply yield a different store path, so other users wouldn't be
|
||||||
affected), but it has some backwards compatibility issues (the
|
affected), but it has some backwards compatibility issues (the
|
||||||
hashing scheme changes), so I'm not doing that for now. */
|
hashing scheme changes), so I'm not doing that for now. */
|
||||||
Path computeStorePathForText(const string & name, const string & s,
|
Path computeStorePathForText(const string & suffix, const string & s,
|
||||||
const PathSet & references);
|
const PathSet & references);
|
||||||
|
|
||||||
|
|
||||||
@@ -330,31 +236,18 @@ extern boost::shared_ptr<StoreAPI> store;
|
|||||||
|
|
||||||
/* Factory method: open the Nix database, either through the local or
|
/* Factory method: open the Nix database, either through the local or
|
||||||
remote implementation. */
|
remote implementation. */
|
||||||
boost::shared_ptr<StoreAPI> openStore();
|
boost::shared_ptr<StoreAPI> openStore(bool reserveSpace = true);
|
||||||
|
|
||||||
|
|
||||||
/* Display a set of paths in human-readable form (i.e., between quotes
|
|
||||||
and separated by commas). */
|
|
||||||
string showPaths(const PathSet & paths);
|
|
||||||
|
|
||||||
|
|
||||||
string makeValidityRegistration(const PathSet & paths,
|
|
||||||
bool showDerivers, bool showHash);
|
|
||||||
|
|
||||||
struct ValidPathInfo
|
struct ValidPathInfo
|
||||||
{
|
{
|
||||||
Path path;
|
Path path;
|
||||||
Path deriver;
|
Path deriver;
|
||||||
Hash hash;
|
Hash hash;
|
||||||
PathSet references;
|
PathSet references;
|
||||||
time_t registrationTime;
|
|
||||||
ValidPathInfo() : registrationTime(0) { }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef list<ValidPathInfo> ValidPathInfos;
|
ValidPathInfo decodeValidPathInfo(std::istream & str);
|
||||||
|
|
||||||
ValidPathInfo decodeValidPathInfo(std::istream & str,
|
|
||||||
bool hashGiven = false);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
#include "db.hh"
|
|
||||||
#include "hash.hh"
|
|
||||||
#include "util.hh"
|
|
||||||
#include "local-store.hh"
|
|
||||||
#include "globals.hh"
|
|
||||||
#include "pathlocks.hh"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
|
|
||||||
Hash parseHashField(const Path & path, const string & s);
|
|
||||||
|
|
||||||
|
|
||||||
/* Upgrade from schema 4 (Nix 0.11) to schema 5 (Nix >= 0.12). The
|
|
||||||
old schema uses Berkeley DB, the new one stores store path
|
|
||||||
meta-information in files. */
|
|
||||||
void LocalStore::upgradeStore12()
|
|
||||||
{
|
|
||||||
#if OLD_DB_COMPAT
|
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
|
||||||
/* Cygwin can't upgrade a read lock to a write lock... */
|
|
||||||
lockFile(globalLock, ltNone, true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!lockFile(globalLock, ltWrite, false)) {
|
|
||||||
printMsg(lvlError, "waiting for exclusive access to the Nix store...");
|
|
||||||
lockFile(globalLock, ltWrite, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
|
|
||||||
|
|
||||||
if (getSchema() >= nixSchemaVersion) return; /* somebody else beat us to it */
|
|
||||||
|
|
||||||
/* Open the old Nix database and tables. */
|
|
||||||
Database nixDB;
|
|
||||||
nixDB.open(nixDBPath);
|
|
||||||
|
|
||||||
/* dbValidPaths :: Path -> ()
|
|
||||||
|
|
||||||
The existence of a key $p$ indicates that path $p$ is valid
|
|
||||||
(that is, produced by a succesful build). */
|
|
||||||
TableId dbValidPaths = nixDB.openTable("validpaths");
|
|
||||||
|
|
||||||
/* dbReferences :: Path -> [Path]
|
|
||||||
|
|
||||||
This table lists the outgoing file system references for each
|
|
||||||
output path that has been built by a Nix derivation. These are
|
|
||||||
found by scanning the path for the hash components of input
|
|
||||||
paths. */
|
|
||||||
TableId dbReferences = nixDB.openTable("references");
|
|
||||||
|
|
||||||
/* dbReferrers :: Path -> Path
|
|
||||||
|
|
||||||
This table is just the reverse mapping of dbReferences. This
|
|
||||||
table can have duplicate keys, each corresponding value
|
|
||||||
denoting a single referrer. */
|
|
||||||
// Not needed for conversion: it's just the inverse of
|
|
||||||
// references.
|
|
||||||
// TableId dbReferrers = nixDB.openTable("referrers");
|
|
||||||
|
|
||||||
/* dbDerivers :: Path -> [Path]
|
|
||||||
|
|
||||||
This table lists the derivation used to build a path. There
|
|
||||||
can only be multiple such paths for fixed-output derivations
|
|
||||||
(i.e., derivations specifying an expected hash). */
|
|
||||||
TableId dbDerivers = nixDB.openTable("derivers");
|
|
||||||
|
|
||||||
Paths paths;
|
|
||||||
nixDB.enumTable(noTxn, dbValidPaths, paths);
|
|
||||||
|
|
||||||
foreach (Paths::iterator, i, paths) {
|
|
||||||
ValidPathInfo info;
|
|
||||||
info.path = *i;
|
|
||||||
|
|
||||||
Paths references;
|
|
||||||
nixDB.queryStrings(noTxn, dbReferences, *i, references);
|
|
||||||
info.references.insert(references.begin(), references.end());
|
|
||||||
|
|
||||||
string s;
|
|
||||||
nixDB.queryString(noTxn, dbValidPaths, *i, s);
|
|
||||||
info.hash = parseHashField(*i, s);
|
|
||||||
|
|
||||||
nixDB.queryString(noTxn, dbDerivers, *i, info.deriver);
|
|
||||||
|
|
||||||
registerValidPath(info, true);
|
|
||||||
std::cerr << ".";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
writeFile(schemaPath, (format("%1%") % nixSchemaVersion).str());
|
|
||||||
|
|
||||||
lockFile(globalLock, ltRead, true);
|
|
||||||
|
|
||||||
#else
|
|
||||||
throw Error(
|
|
||||||
"Your Nix store has a database in Berkeley DB format. To convert\n"
|
|
||||||
"to the new format, please compile Nix with Berkeley DB support.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,32 +8,30 @@ namespace nix {
|
|||||||
#define WORKER_MAGIC_1 0x6e697863
|
#define WORKER_MAGIC_1 0x6e697863
|
||||||
#define WORKER_MAGIC_2 0x6478696f
|
#define WORKER_MAGIC_2 0x6478696f
|
||||||
|
|
||||||
#define PROTOCOL_VERSION 0x105
|
#define PROTOCOL_VERSION 0x101
|
||||||
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
|
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
|
||||||
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
wopQuit = 0,
|
wopQuit = 0,
|
||||||
wopIsValidPath = 1,
|
wopIsValidPath,
|
||||||
wopHasSubstitutes = 3,
|
wopHasSubstitutes = 3,
|
||||||
wopQueryPathHash = 4,
|
wopQueryPathHash,
|
||||||
wopQueryReferences = 5,
|
wopQueryReferences,
|
||||||
wopQueryReferrers = 6,
|
wopQueryReferrers,
|
||||||
wopAddToStore = 7,
|
wopAddToStore,
|
||||||
wopAddTextToStore = 8,
|
wopAddTextToStore,
|
||||||
wopBuildDerivations = 9,
|
wopBuildDerivations,
|
||||||
wopEnsurePath = 10,
|
wopEnsurePath,
|
||||||
wopAddTempRoot = 11,
|
wopAddTempRoot,
|
||||||
wopAddIndirectRoot = 12,
|
wopAddIndirectRoot,
|
||||||
wopSyncWithGC = 13,
|
wopSyncWithGC,
|
||||||
wopFindRoots = 14,
|
wopFindRoots,
|
||||||
wopExportPath = 16,
|
wopCollectGarbage,
|
||||||
wopImportPath = 17,
|
wopExportPath,
|
||||||
wopQueryDeriver = 18,
|
wopImportPath,
|
||||||
wopSetOptions = 19,
|
wopQueryDeriver,
|
||||||
wopCollectGarbage = 20,
|
wopSetOptions,
|
||||||
wopQuerySubstitutablePathInfo = 21,
|
|
||||||
} WorkerOp;
|
} WorkerOp;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+35
-107
@@ -2,7 +2,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define _XOPEN_SOURCE 600
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -12,8 +11,6 @@
|
|||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
@@ -50,17 +47,17 @@ static void dumpEntries(const Path & path, Sink & sink, PathFilter & filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void dumpContents(const Path & path, size_t size,
|
static void dumpContents(const Path & path, unsigned int size,
|
||||||
Sink & sink)
|
Sink & sink)
|
||||||
{
|
{
|
||||||
writeString("contents", sink);
|
writeString("contents", sink);
|
||||||
writeLongLong(size, sink);
|
writeInt(size, sink);
|
||||||
|
|
||||||
AutoCloseFD fd = open(path.c_str(), O_RDONLY);
|
AutoCloseFD fd = open(path.c_str(), O_RDONLY);
|
||||||
if (fd == -1) throw SysError(format("opening file `%1%'") % path);
|
if (fd == -1) throw SysError(format("opening file `%1%'") % path);
|
||||||
|
|
||||||
unsigned char buf[65536];
|
unsigned char buf[65536];
|
||||||
size_t left = size;
|
unsigned int left = size;
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
size_t n = left > sizeof(buf) ? sizeof(buf) : left;
|
size_t n = left > sizeof(buf) ? sizeof(buf) : left;
|
||||||
@@ -88,7 +85,7 @@ static void dump(const Path & path, Sink & sink, PathFilter & filter)
|
|||||||
writeString("executable", sink);
|
writeString("executable", sink);
|
||||||
writeString("", sink);
|
writeString("", sink);
|
||||||
}
|
}
|
||||||
dumpContents(path, (size_t) st.st_size, sink);
|
dumpContents(path, st.st_size, sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (S_ISDIR(st.st_mode)) {
|
else if (S_ISDIR(st.st_mode)) {
|
||||||
@@ -104,7 +101,7 @@ static void dump(const Path & path, Sink & sink, PathFilter & filter)
|
|||||||
writeString(readLink(path), sink);
|
writeString(readLink(path), sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
else throw Error(format("file `%1%' has an unknown type") % path);
|
else throw Error("unknown file type: " + path);
|
||||||
|
|
||||||
writeString(")", sink);
|
writeString(")", sink);
|
||||||
}
|
}
|
||||||
@@ -117,9 +114,9 @@ void dumpPath(const Path & path, Sink & sink, PathFilter & filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static SerialisationError badArchive(string s)
|
static Error badArchive(string s)
|
||||||
{
|
{
|
||||||
return SerialisationError("bad archive: " + s);
|
return Error("bad archive: " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,11 +129,10 @@ static void skipGeneric(Source & source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void parse(ParseSink & sink, Source & source, const Path & path);
|
static void restore(const Path & path, Source & source);
|
||||||
|
|
||||||
|
|
||||||
|
static void restoreEntry(const Path & path, Source & source)
|
||||||
static void parseEntry(ParseSink & sink, Source & source, const Path & path)
|
|
||||||
{
|
{
|
||||||
string s, name;
|
string s, name;
|
||||||
|
|
||||||
@@ -154,7 +150,7 @@ static void parseEntry(ParseSink & sink, Source & source, const Path & path)
|
|||||||
name = readString(source);
|
name = readString(source);
|
||||||
} else if (s == "node") {
|
} else if (s == "node") {
|
||||||
if (s == "") throw badArchive("entry name missing");
|
if (s == "") throw badArchive("entry name missing");
|
||||||
parse(sink, source, path + "/" + name);
|
restore(path + "/" + name, source);
|
||||||
} else {
|
} else {
|
||||||
throw badArchive("unknown field " + s);
|
throw badArchive("unknown field " + s);
|
||||||
skipGeneric(source);
|
skipGeneric(source);
|
||||||
@@ -163,31 +159,26 @@ static void parseEntry(ParseSink & sink, Source & source, const Path & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void parseContents(ParseSink & sink, Source & source, const Path & path)
|
static void restoreContents(int fd, const Path & path, Source & source)
|
||||||
{
|
{
|
||||||
unsigned long long size = readLongLong(source);
|
unsigned int size = readInt(source);
|
||||||
|
unsigned int left = size;
|
||||||
sink.preallocateContents(size);
|
|
||||||
|
|
||||||
unsigned long long left = size;
|
|
||||||
unsigned char buf[65536];
|
unsigned char buf[65536];
|
||||||
|
|
||||||
while (left) {
|
while (left) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
unsigned int n = sizeof(buf);
|
unsigned int n = sizeof(buf);
|
||||||
if ((unsigned long long) n > left) n = left;
|
if (n > left) n = left;
|
||||||
source(buf, n);
|
source(buf, n);
|
||||||
sink.receiveContents(buf, n);
|
writeFull(fd, buf, n);
|
||||||
left -= n;
|
left -= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
sink.finalizeContents(size);
|
|
||||||
|
|
||||||
readPadding(size, source);
|
readPadding(size, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void parse(ParseSink & sink, Source & source, const Path & path)
|
static void restore(const Path & path, Source & source)
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
|
|
||||||
@@ -195,6 +186,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
|
|||||||
if (s != "(") throw badArchive("expected open tag");
|
if (s != "(") throw badArchive("expected open tag");
|
||||||
|
|
||||||
enum { tpUnknown, tpRegular, tpDirectory, tpSymlink } type = tpUnknown;
|
enum { tpUnknown, tpRegular, tpDirectory, tpSymlink } type = tpUnknown;
|
||||||
|
AutoCloseFD fd;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
@@ -212,12 +204,15 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
|
|||||||
|
|
||||||
if (t == "regular") {
|
if (t == "regular") {
|
||||||
type = tpRegular;
|
type = tpRegular;
|
||||||
sink.createRegularFile(path);
|
fd = open(path.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666);
|
||||||
|
if (fd == -1)
|
||||||
|
throw SysError("creating file " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t == "directory") {
|
else if (t == "directory") {
|
||||||
sink.createDirectory(path);
|
|
||||||
type = tpDirectory;
|
type = tpDirectory;
|
||||||
|
if (mkdir(path.c_str(), 0777) == -1)
|
||||||
|
throw SysError("creating directory " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (t == "symlink") {
|
else if (t == "symlink") {
|
||||||
@@ -229,109 +224,42 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (s == "contents" && type == tpRegular) {
|
else if (s == "contents" && type == tpRegular) {
|
||||||
parseContents(sink, source, path);
|
restoreContents(fd, path, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (s == "executable" && type == tpRegular) {
|
else if (s == "executable" && type == tpRegular) {
|
||||||
readString(source);
|
readString(source);
|
||||||
sink.isExecutable();
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) == -1)
|
||||||
|
throw SysError("fstat");
|
||||||
|
if (fchmod(fd, st.st_mode | (S_IXUSR | S_IXGRP | S_IXOTH)) == -1)
|
||||||
|
throw SysError("fchmod");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (s == "entry" && type == tpDirectory) {
|
else if (s == "entry" && type == tpDirectory) {
|
||||||
parseEntry(sink, source, path);
|
restoreEntry(path, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (s == "target" && type == tpSymlink) {
|
else if (s == "target" && type == tpSymlink) {
|
||||||
string target = readString(source);
|
string target = readString(source);
|
||||||
sink.createSymlink(path, target);
|
if (symlink(target.c_str(), path.c_str()) == -1)
|
||||||
|
throw SysError("creating symlink " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
throw badArchive("unknown field " + s);
|
throw badArchive("unknown field " + s);
|
||||||
skipGeneric(source);
|
skipGeneric(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void parseDump(ParseSink & sink, Source & source)
|
|
||||||
{
|
|
||||||
string version;
|
|
||||||
try {
|
|
||||||
version = readString(source);
|
|
||||||
} catch (SerialisationError & e) {
|
|
||||||
/* This generally means the integer at the start couldn't be
|
|
||||||
decoded. Ignore and throw the exception below. */
|
|
||||||
}
|
|
||||||
if (version != archiveVersion1)
|
|
||||||
throw badArchive("input doesn't look like a Nix archive");
|
|
||||||
parse(sink, source, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct RestoreSink : ParseSink
|
|
||||||
{
|
|
||||||
Path dstPath;
|
|
||||||
AutoCloseFD fd;
|
|
||||||
|
|
||||||
void createDirectory(const Path & path)
|
|
||||||
{
|
|
||||||
Path p = dstPath + path;
|
|
||||||
if (mkdir(p.c_str(), 0777) == -1)
|
|
||||||
throw SysError(format("creating directory `%1%'") % p);
|
|
||||||
};
|
|
||||||
|
|
||||||
void createRegularFile(const Path & path)
|
|
||||||
{
|
|
||||||
Path p = dstPath + path;
|
|
||||||
fd = open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666);
|
|
||||||
if (fd == -1) throw SysError(format("creating file `%1%'") % p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void isExecutable()
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
if (fstat(fd, &st) == -1)
|
|
||||||
throw SysError("fstat");
|
|
||||||
if (fchmod(fd, st.st_mode | (S_IXUSR | S_IXGRP | S_IXOTH)) == -1)
|
|
||||||
throw SysError("fchmod");
|
|
||||||
}
|
|
||||||
|
|
||||||
void preallocateContents(unsigned long long len)
|
|
||||||
{
|
|
||||||
#if HAVE_POSIX_FALLOCATE
|
|
||||||
if (len) {
|
|
||||||
errno = posix_fallocate(fd, 0, len);
|
|
||||||
if (errno) throw SysError(format("preallocating file of %1% bytes") % len);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void receiveContents(unsigned char * data, unsigned int len)
|
|
||||||
{
|
|
||||||
writeFull(fd, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void finalizeContents(unsigned long long size)
|
|
||||||
{
|
|
||||||
errno = ftruncate(fd, size);
|
|
||||||
if (errno) throw SysError(format("truncating file to its allocated length of %1% bytes") % size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void createSymlink(const Path & path, const string & target)
|
|
||||||
{
|
|
||||||
Path p = dstPath + path;
|
|
||||||
if (symlink(target.c_str(), p.c_str()) == -1)
|
|
||||||
throw SysError(format("creating symlink `%1%'") % p);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void restorePath(const Path & path, Source & source)
|
void restorePath(const Path & path, Source & source)
|
||||||
{
|
{
|
||||||
RestoreSink sink;
|
if (readString(source) != archiveVersion1)
|
||||||
sink.dstPath = path;
|
throw badArchive("expected Nix archive");
|
||||||
parseDump(sink, source);
|
restore(path, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,21 +56,6 @@ extern PathFilter defaultPathFilter;
|
|||||||
void dumpPath(const Path & path, Sink & sink,
|
void dumpPath(const Path & path, Sink & sink,
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
struct ParseSink
|
|
||||||
{
|
|
||||||
virtual void createDirectory(const Path & path) { };
|
|
||||||
|
|
||||||
virtual void createRegularFile(const Path & path) { };
|
|
||||||
virtual void isExecutable() { };
|
|
||||||
virtual void preallocateContents(unsigned long long size) { };
|
|
||||||
virtual void receiveContents(unsigned char * data, unsigned int len) { };
|
|
||||||
virtual void finalizeContents(unsigned long long size) { };
|
|
||||||
|
|
||||||
virtual void createSymlink(const Path & path, const string & target) { };
|
|
||||||
};
|
|
||||||
|
|
||||||
void parseDump(ParseSink & sink, Source & source);
|
|
||||||
|
|
||||||
void restorePath(const Path & path, Source & source);
|
void restorePath(const Path & path, Source & source);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ void ATermMap::remove(ATerm key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int ATermMap::size() const
|
unsigned int ATermMap::size()
|
||||||
{
|
{
|
||||||
return count; /* STL nomenclature */
|
return count; /* STL nomenclature */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
|
|
||||||
void remove(ATerm key);
|
void remove(ATerm key);
|
||||||
|
|
||||||
unsigned int size() const;
|
unsigned int size();
|
||||||
|
|
||||||
struct const_iterator
|
struct const_iterator
|
||||||
{
|
{
|
||||||
|
|||||||
Loaded 100 of 201 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user