Compare commits
134
Commits
nix-make
...
0.7-release
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73db7ab626 | ||
|
|
65348516c5 | ||
|
|
b17e7cf979 | ||
|
|
0bc41f632b | ||
|
|
7d75616f2c | ||
|
|
6af4a5a71f | ||
|
|
a03397be4c | ||
|
|
f28ea27d83 | ||
|
|
c53898cb65 | ||
|
|
35b76a81c4 | ||
|
|
3745cecc6a | ||
|
|
581bcb986f | ||
|
|
6270aa727d | ||
|
|
4f07ebc67e | ||
|
|
54d8f08588 | ||
|
|
2fdb27e7f2 | ||
|
|
e1e9c036f9 | ||
|
|
77fc1c6c5c | ||
|
|
9022cf9adf | ||
|
|
4bf58d5379 | ||
|
|
3d1b2101cc | ||
|
|
7eed57e784 | ||
|
|
96c3d8a615 | ||
|
|
8b9697e575 | ||
|
|
fa9259f5f5 | ||
|
|
015beb7cd0 | ||
|
|
4d25b0b0bb | ||
|
|
f4041cc175 | ||
|
|
77970f8daf | ||
|
|
e3b051aeeb | ||
|
|
862f4c154e | ||
|
|
dca48aed34 | ||
|
|
71926ee188 | ||
|
|
13f77276d1 | ||
|
|
eee6fe478e | ||
|
|
f17553a212 | ||
|
|
4115d8d8ce | ||
|
|
5d5318c2ff | ||
|
|
9f8964a062 | ||
|
|
0b79a12082 | ||
|
|
54c7a870d5 | ||
|
|
c2b0d6b02f | ||
|
|
32c7326850 | ||
|
|
92ee003dc9 | ||
|
|
d6db574ec1 | ||
|
|
b8aaef5e4e | ||
|
|
2c3b29c5ca | ||
|
|
ea6581b691 | ||
|
|
09e7f06818 | ||
|
|
1bac7a10e6 | ||
|
|
55b35d6d77 | ||
|
|
0b1ee4802b | ||
|
|
5f0300d18c | ||
|
|
3e9d2038b4 | ||
|
|
6ca9c7f0a9 | ||
|
|
8b934694f2 | ||
|
|
feb3ceaee0 | ||
|
|
cb7ccb528b | ||
|
|
4cbd845aa4 | ||
|
|
5f2c5a306c | ||
|
|
0913f5a615 | ||
|
|
ee5dcfade2 | ||
|
|
cbe8de592d | ||
|
|
b05a596d61 | ||
|
|
0d80d237c5 | ||
|
|
2aa1f4717b | ||
|
|
f8ac8d1ec8 | ||
|
|
a69534fc21 | ||
|
|
ed09821859 | ||
|
|
3277c9432a | ||
|
|
463e2817c5 | ||
|
|
f09618b63a | ||
|
|
c7bea941b0 | ||
|
|
210ab0296d | ||
|
|
c52dda95a6 | ||
|
|
5fe9222b36 | ||
|
|
eb8284ddaa | ||
|
|
033d7c6593 | ||
|
|
9fa07b376d | ||
|
|
ee401afad8 | ||
|
|
37d7abd694 | ||
|
|
f4d44a0026 | ||
|
|
3ade3e7721 | ||
|
|
2248becfd3 | ||
|
|
50b9caac14 | ||
|
|
2155c0a673 | ||
|
|
88888160d2 | ||
|
|
99da51d4de | ||
|
|
2cd590d96c | ||
|
|
692204e0c5 | ||
|
|
d830b2c1df | ||
|
|
febd8bed1b | ||
|
|
98c69e5172 | ||
|
|
371c57d8a7 | ||
|
|
2b20701f78 | ||
|
|
1317242780 | ||
|
|
995d08208e | ||
|
|
b357284a32 | ||
|
|
dcc433de47 | ||
|
|
c16be6ac92 | ||
|
|
47f87072ad | ||
|
|
5396304c73 | ||
|
|
e043fc7d0b | ||
|
|
550d960586 | ||
|
|
17c8252fc9 | ||
|
|
fb28cfc86d | ||
|
|
5c443b6550 | ||
|
|
c25f2883b1 | ||
|
|
fe122c5a15 | ||
|
|
eb233e728f | ||
|
|
fdec72c6cc | ||
|
|
818047881e | ||
|
|
9994c1dd9f | ||
|
|
8f58733ef1 | ||
|
|
1c90fabccc | ||
|
|
e77fbe0fa2 | ||
|
|
2d35116c13 | ||
|
|
8f1dcdfc0a | ||
|
|
1eddee59f2 | ||
|
|
937ce0cd21 | ||
|
|
966bd9d19f | ||
|
|
62fe5c4a22 | ||
|
|
ae1a1efa41 | ||
|
|
d8989b1fb4 | ||
|
|
bbfdd64741 | ||
|
|
e3a50f7e25 | ||
|
|
18ebd7b030 | ||
|
|
5373aed1a8 | ||
|
|
16c8b4c8e5 | ||
|
|
e8a95108c0 | ||
|
|
9bf7a5f516 | ||
|
|
39eaecbc98 | ||
|
|
064a36cb54 | ||
|
|
c1a18f543e |
No files matched your search
@@ -0,0 +1,8 @@
|
||||
The following people contributed to Nix, in alphabetical order:
|
||||
|
||||
Martin Bravenboer
|
||||
Eelco Dolstra
|
||||
Niels Janssen
|
||||
Armijn Hemel
|
||||
Rob Vermaas
|
||||
Eelco Visser
|
||||
+17
-8
@@ -1,5 +1,5 @@
|
||||
SUBDIRS = externals src scripts corepkgs doc misc tests
|
||||
EXTRA_DIST = substitute.mk nix.spec nix.spec.in
|
||||
EXTRA_DIST = substitute.mk nix.spec nix.spec.in bootstrap.sh svn-revision
|
||||
|
||||
include ./substitute.mk
|
||||
|
||||
@@ -14,17 +14,26 @@ relname:
|
||||
install-data-local: init-state
|
||||
|
||||
if INIT_STATE
|
||||
if SETUID_HACK
|
||||
INIT_FLAGS = -g @NIX_GROUP@ -o @NIX_USER@
|
||||
GROUP_WRITABLE = -m 775
|
||||
endif
|
||||
init-state:
|
||||
$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix
|
||||
$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/db
|
||||
$(INSTALL) -d $(DESTDIR)$(localstatedir)/log/nix
|
||||
$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/profiles
|
||||
$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/gcroots
|
||||
$(INSTALL) -d $(DESTDIR)$(localstatedir)/nix/gcroots/tmp
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/db
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/log/nix
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/profiles
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(localstatedir)/nix/gcroots
|
||||
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/tmp
|
||||
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/gcroots/channels
|
||||
rm -f $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||
ln -s $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||
$(INSTALL) -d $(DESTDIR)$(prefix)/store
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(prefix)/store
|
||||
$(INSTALL) $(INIT_FLAGS) $(GROUP_WRITABLE) -d $(DESTDIR)$(localstatedir)/nix/manifests
|
||||
# $(bindir)/nix-store --init
|
||||
else
|
||||
init-state:
|
||||
endif
|
||||
|
||||
svn-revision:
|
||||
svnversion . > svn-revision
|
||||
@@ -0,0 +1,91 @@
|
||||
Version 0.7
|
||||
|
||||
* Binary patching. When upgrading components using pre-built binaries
|
||||
(through nix-pull / nix-channel), Nix can automatically download and
|
||||
apply binary patches to already installed components instead of full
|
||||
downloads. Patching is "smart": if there is a *sequence* of patches
|
||||
to an installed component, Nix will use it. Patches are currently
|
||||
generated automatically between Nixpkgs (pre-)releases.
|
||||
|
||||
* Simplifications to the substitute mechanism.
|
||||
|
||||
* Nix-pull now stores downloaded manifests in /nix/var/nix/manifests.
|
||||
|
||||
* Metadata on files in the Nix store is canonicalised after builds:
|
||||
the last-modified timestamp is set to 0 (00:00:00 1/1/1970), the
|
||||
mode is set to 0444 or 0555 (readable and possibly executable by
|
||||
all; setuid/setgid bits are dropped), and the group is set to the
|
||||
default. This ensures that the result of a build and an
|
||||
installation through a substitute is the same; and that timestamp
|
||||
dependencies are revealed.
|
||||
|
||||
|
||||
Version 0.6
|
||||
|
||||
Major changes include the following:
|
||||
|
||||
* Rewrite of the normalisation engine.
|
||||
|
||||
* Multiple builds can now be performed in parallel (option `-j').
|
||||
|
||||
* Distributed builds. Nix can now call a shell script to forward
|
||||
builds to Nix installations on remote machines, which may or may
|
||||
not be of the same platform type.
|
||||
|
||||
* Option `--fallback' allows recovery from broken substitutes.
|
||||
|
||||
* Option `--keep-going' causes building of other (unaffected)
|
||||
derivations to continue if one failed.
|
||||
|
||||
* Improvements to the garbage collector (i.e., it should actually work
|
||||
now).
|
||||
|
||||
* Setuid Nix installations allow a Nix store to be shared among
|
||||
multiple users.
|
||||
|
||||
* Substitute registration is much faster now.
|
||||
|
||||
* A utility `nix-build' to build a Nix expression and create a symlink
|
||||
to the result int the current directory; useful for testing Nix
|
||||
derivations.
|
||||
|
||||
* Manual updates.
|
||||
|
||||
* `nix-env' changes:
|
||||
|
||||
* Derivations for other platforms are filtered out (which can be
|
||||
overriden using `--system-filter').
|
||||
|
||||
* `--install' by default now uninstall previous derivations with the
|
||||
same name.
|
||||
|
||||
* `--upgrade' allows upgrading to a specific version.
|
||||
|
||||
* New operation `--delete-generations' to remove profile
|
||||
generations (necessary for effective garbage collection).
|
||||
|
||||
* Nicer output (sorted, columnised).
|
||||
|
||||
* More sensible verbosity levels all around (builder output is now
|
||||
shown always, unless `-Q' is given).
|
||||
|
||||
* Nix expression language changes:
|
||||
|
||||
* New language construct: `with E1; E2' brings all attributes
|
||||
defined in the attribute set E1 in scope in E2.
|
||||
|
||||
* Added a `map' function.
|
||||
|
||||
* Various new operators (e.g., string concatenation).
|
||||
|
||||
* Expression evaluation is much faster.
|
||||
|
||||
* An Emacs mode for editing Nix expressions (with syntax highlighting
|
||||
and indentation) has been added.
|
||||
|
||||
* Many bug fixes.
|
||||
|
||||
|
||||
Version 0.5 and earlier
|
||||
|
||||
Please refer to the Subversion commit log messages.
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#! /bin/sh -e
|
||||
aclocal
|
||||
autoheader
|
||||
automake --add-missing --copy
|
||||
autoconf
|
||||
+51
-8
@@ -1,11 +1,11 @@
|
||||
AC_INIT(nix, "0.6")
|
||||
AC_INIT(nix, "0.7")
|
||||
AC_CONFIG_SRCDIR(README)
|
||||
AC_CONFIG_AUX_DIR(config)
|
||||
AM_INIT_AUTOMAKE
|
||||
|
||||
# Change to `1' to produce a `stable' release (i.e., the `preREVISION'
|
||||
# suffix is not added).
|
||||
STABLE=0
|
||||
STABLE=1
|
||||
|
||||
# Put the revision number in the version.
|
||||
if test "$STABLE" != "1"; then
|
||||
@@ -22,12 +22,24 @@ AC_CANONICAL_HOST
|
||||
|
||||
# Construct a Nix system name (like "i686-linux").
|
||||
AC_MSG_CHECKING([for the canonical Nix system name])
|
||||
#machine_name=`uname -m`
|
||||
#sys_name=`uname -s | tr [A-Z] [a-z]`
|
||||
#system="${machine_name}-${sys_name}"
|
||||
cpu_name=$(uname -p | tr 'A-Z ' 'a-z_')
|
||||
machine_name=$(uname -m | tr 'A-Z ' 'a-z_')
|
||||
|
||||
case $machine_name in
|
||||
i*86)
|
||||
machine_name=i686
|
||||
;;
|
||||
*)
|
||||
if test "$cpu_name" != "unknown"; then
|
||||
machine_name=$cpu_name
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
sys_name=$(uname -s | tr 'A-Z ' 'a-z_')
|
||||
AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
|
||||
[platform identifier (e.g., `i686-linux')]),
|
||||
system=$withval, system="$host_cpu-$host_os")
|
||||
system=$withval, system="${machine_name}-${sys_name}")
|
||||
AC_MSG_RESULT($system)
|
||||
AC_SUBST(system)
|
||||
AC_DEFINE_UNQUOTED(SYSTEM, ["$system"], [platform identifier (`cpu-os')])
|
||||
@@ -56,7 +68,7 @@ AC_DEFUN([NEED_PROG],
|
||||
[
|
||||
AC_PATH_PROG($1, $2)
|
||||
if test -z "$$1"; then
|
||||
AC_MSG_ERROR([$1 is required])
|
||||
AC_MSG_ERROR([$2 is required])
|
||||
fi
|
||||
])
|
||||
|
||||
@@ -116,12 +128,15 @@ AM_CONDITIONAL(HAVE_ATERM, test -n "$aterm")
|
||||
if test -z "$aterm"; then
|
||||
aterm_lib='-L${top_builddir}/externals/inst-aterm/lib -lATerm'
|
||||
aterm_include='-I${top_builddir}/externals/inst-aterm/include'
|
||||
aterm_bin='${top_builddir}/externals/inst-aterm/bin'
|
||||
else
|
||||
aterm_lib="-L$aterm/lib -lATerm"
|
||||
aterm_include="-I$aterm/include"
|
||||
aterm_bin="$aterm/bin"
|
||||
fi
|
||||
AC_SUBST(aterm_lib)
|
||||
AC_SUBST(aterm_include)
|
||||
AC_SUBST(aterm_bin)
|
||||
|
||||
AC_CHECK_LIB(pthread, pthread_mutex_init)
|
||||
|
||||
@@ -130,6 +145,34 @@ AC_ARG_ENABLE(init-state, AC_HELP_STRING([--disable-init-state],
|
||||
init_state=$enableval, init_state=yes)
|
||||
AM_CONDITIONAL(INIT_STATE, test "$init_state" = "yes")
|
||||
|
||||
|
||||
AC_ARG_ENABLE(setuid, AC_HELP_STRING([--enable-setuid],
|
||||
[install Nix setuid]),
|
||||
setuid_hack=$enableval, setuid_hack=no)
|
||||
AM_CONDITIONAL(SETUID_HACK, test "$setuid_hack" = "yes")
|
||||
if test "$setuid_hack" = "yes"; then
|
||||
AC_DEFINE(SETUID_HACK, 1, [whether to install Nix setuid])
|
||||
fi
|
||||
|
||||
AC_CHECK_FUNC(setresuid, [HAVE_SETRESUID=1], [HAVE_SETRESUID=])
|
||||
AM_CONDITIONAL(HAVE_SETRESUID, test "$HAVE_SETRESUID" = "1")
|
||||
if test "$HAVE_SETRESUID" = "1"; then
|
||||
AC_DEFINE(HAVE_SETRESUID, 1, [whether we have setresuid()])
|
||||
fi
|
||||
|
||||
AC_ARG_WITH(nix-user, AC_HELP_STRING([--with-nix-user=USER],
|
||||
[user for Nix setuid binaries]),
|
||||
NIX_USER=$withval, NIX_USER=nix)
|
||||
AC_SUBST(NIX_USER)
|
||||
AC_DEFINE_UNQUOTED(NIX_USER, ["$NIX_USER"], [Nix user])
|
||||
|
||||
AC_ARG_WITH(nix-group, AC_HELP_STRING([--with-nix-group=USER],
|
||||
[group for Nix setuid binaries]),
|
||||
NIX_GROUP=$withval, NIX_GROUP=nix)
|
||||
AC_SUBST(NIX_GROUP)
|
||||
AC_DEFINE_UNQUOTED(NIX_GROUP, ["$NIX_GROUP"], [Nix group])
|
||||
|
||||
|
||||
AM_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_FILES([Makefile
|
||||
externals/Makefile
|
||||
@@ -146,13 +189,13 @@ AC_CONFIG_FILES([Makefile
|
||||
src/nix-instantiate/Makefile
|
||||
src/nix-env/Makefile
|
||||
src/log2xml/Makefile
|
||||
src/bsdiff-4.2/Makefile
|
||||
scripts/Makefile
|
||||
corepkgs/Makefile
|
||||
corepkgs/fetchurl/Makefile
|
||||
corepkgs/nar/Makefile
|
||||
corepkgs/buildenv/Makefile
|
||||
corepkgs/channels/Makefile
|
||||
corepkgs/nix-pull/Makefile
|
||||
doc/Makefile
|
||||
doc/manual/Makefile
|
||||
misc/Makefile
|
||||
|
||||
@@ -1 +1 @@
|
||||
SUBDIRS = fetchurl nar buildenv channels nix-pull
|
||||
SUBDIRS = fetchurl nar buildenv channels
|
||||
@@ -24,9 +24,10 @@ sub createLinks {
|
||||
my $dstFile = "$dstDir/$baseName";
|
||||
|
||||
if ($srcFile =~ /\/propagated-build-inputs$/ ||
|
||||
$srcFile =~ /\/nix-support$/)
|
||||
$srcFile =~ /\/nix-support$/ ||
|
||||
$srcFile =~ /\/log$/)
|
||||
{
|
||||
# Do noting.
|
||||
# Do nothing.
|
||||
}
|
||||
|
||||
elsif (-d $srcFile) {
|
||||
|
||||
@@ -6,8 +6,14 @@ export PATH=/bin:/usr/bin
|
||||
echo "packing $path into $out..."
|
||||
mkdir $out
|
||||
dst=$out/$(basename $path).nar.bz2
|
||||
@bindir@/nix-store --dump "$path" | @bzip2@ > $dst
|
||||
@bindir@/nix-store --dump "$path" > tmp
|
||||
|
||||
md5=$(md5sum -b $dst | cut -c1-32)
|
||||
@bzip2@ < tmp > $dst
|
||||
|
||||
narHash=$(md5sum -b tmp | cut -c1-32)
|
||||
if test $? != 0; then exit 1; fi
|
||||
echo $md5 > $out/md5
|
||||
echo $narHash > $out/nar-hash
|
||||
|
||||
narbz2Hash=$(md5sum -b $dst | cut -c1-32)
|
||||
if test $? != 0; then exit 1; fi
|
||||
echo $narbz2Hash > $out/narbz2-hash
|
||||
@@ -1,11 +0,0 @@
|
||||
all-local: builder.sh
|
||||
|
||||
install-exec-local:
|
||||
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs
|
||||
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/corepkgs/nix-pull
|
||||
$(INSTALL_DATA) default.nix $(DESTDIR)$(datadir)/nix/corepkgs/nix-pull
|
||||
$(INSTALL_PROGRAM) builder.sh $(DESTDIR)$(datadir)/nix/corepkgs/nix-pull
|
||||
|
||||
include ../../substitute.mk
|
||||
|
||||
EXTRA_DIST = default.nix builder.sh.in
|
||||
@@ -1,34 +0,0 @@
|
||||
#! @shell@ -e
|
||||
|
||||
export PATH=/bin:/usr/bin
|
||||
|
||||
mkdir $out
|
||||
|
||||
cat > $out/fetch <<EOF
|
||||
#! @shell@ -e
|
||||
|
||||
export PATH=/bin:/usr/bin
|
||||
|
||||
echo "downloading \$2..."
|
||||
|
||||
export PRINT_PATH=1
|
||||
result=(\$(@bindir@/nix-prefetch-url \$2))
|
||||
|
||||
hash=\${result[0]}
|
||||
path=\${result[1]}
|
||||
|
||||
if test "\$hash" != "\$3"; then
|
||||
echo "hash is \$hash, expected \$3"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "unpacking into \$1..."
|
||||
|
||||
if ! @bunzip2@ < "\$path" | @bindir@/nix-store --restore "\$1"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
chmod +x $out/fetch
|
||||
@@ -1,7 +0,0 @@
|
||||
{system}:
|
||||
|
||||
derivation {
|
||||
name = "nix-pull";
|
||||
builder = ./builder.sh;
|
||||
inherit system;
|
||||
}
|
||||
+10
-3
@@ -4,13 +4,18 @@ XMLLINT = $(ENV) $(xmllint) $(xmlflags) --catalogs
|
||||
XSLTPROC = $(ENV) $(xsltproc) $(xmlflags) --catalogs \
|
||||
--param section.autolabel 1 \
|
||||
--param section.label.includes.component.label 1 \
|
||||
--param html.stylesheet \'style.css\'
|
||||
--param html.stylesheet \'style.css\' \
|
||||
--param xref.with.number.and.title 0
|
||||
|
||||
man1_MANS = nix-env.1 nix-store.1 nix-instantiate.1 \
|
||||
nix-collect-garbage.1 nix-push.1 nix-pull.1 \
|
||||
nix-prefetch-url.1
|
||||
|
||||
SOURCES = manual.xml introduction.xml installation.xml overview.xml \
|
||||
FIGURES = figures/user-environments.png
|
||||
|
||||
SOURCES = manual.xml introduction.xml installation.xml \
|
||||
package-management.xml writing-nix-expressions.xml \
|
||||
build-farm.xml \
|
||||
$(man1_MANS:.1=.xml) \
|
||||
troubleshooting.xml bugs.xml opt-common.xml opt-common-syn.xml \
|
||||
quick-start.xml nix-lang-ref.xml style.css images
|
||||
@@ -35,6 +40,8 @@ install-data-local: manual.html
|
||||
$(INSTALL_DATA) manual.html $(DESTDIR)$(datadir)/nix/manual
|
||||
$(INSTALL_DATA) style.css $(DESTDIR)$(datadir)/nix/manual
|
||||
cp -r images $(DESTDIR)$(datadir)/nix/manual/images
|
||||
$(INSTALL) -d $(DESTDIR)$(datadir)/nix/manual/figures
|
||||
$(INSTALL_DATA) $(FIGURES) $(DESTDIR)$(datadir)/nix/manual/figures
|
||||
|
||||
images:
|
||||
mkdir images
|
||||
@@ -45,6 +52,6 @@ images:
|
||||
|
||||
KEEP = manual.html manual.is-valid version.xml $(MANS)
|
||||
|
||||
EXTRA_DIST = $(SOURCES) $(KEEP)
|
||||
EXTRA_DIST = $(SOURCES) $(FIGURES) $(KEEP)
|
||||
|
||||
DISTCLEANFILES = $(KEEP)
|
||||
+18
-25
@@ -1,7 +1,6 @@
|
||||
<appendix>
|
||||
<title>Bugs / To-Do</title>
|
||||
<appendix><title>Bugs / To-Do</title>
|
||||
|
||||
<itemizedlist>
|
||||
<itemizedlist>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
@@ -53,17 +52,6 @@
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The current garbage collector is a hack. It should be
|
||||
integrated into <command>nix-store</command>. It should
|
||||
delete derivations in an order determined by topologically
|
||||
sorting derivations under the points-to relation. This
|
||||
ensures that no store paths ever exist that point to
|
||||
non-existant store paths.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
There are race conditions between the garbage collector and
|
||||
@@ -99,17 +87,22 @@ $ nix-store -r $(cat /nix/var/nix/roots/bla)</screen>
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
For security, <command>nix-push</command> manifests should be
|
||||
digitally signed, and <command>nix-pull</command> should
|
||||
verify the signatures. The actual NAR archives in the cache
|
||||
do not need to be signed, since the manifest contains
|
||||
cryptographic hashes of these files (and
|
||||
<filename>fetchurl.nix</filename> checks them).
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem><para>For security, <command>nix-push</command> manifests
|
||||
should be digitally signed, and <command>nix-pull</command> should
|
||||
verify the signatures. The actual NAR archives in the cache do not
|
||||
need to be signed, since the manifest contains cryptographic hashes of
|
||||
these files (and <filename>fetchurl.nix</filename> checks
|
||||
them).</para></listitem>
|
||||
|
||||
</itemizedlist>
|
||||
<listitem><para>We should switch away from MD5, since it has been
|
||||
more-or-less cracked. We don't currently depend very much on the
|
||||
collision-resistance of MD5, but we will once we start sharing build
|
||||
results between users.</para></listitem>
|
||||
|
||||
<listitem><para>It would be useful to have an option in
|
||||
<command>nix-env --delete-generations</command> to remove non-current
|
||||
generations older than a certain age.</para></listitem>
|
||||
|
||||
</itemizedlist>
|
||||
|
||||
</appendix>
|
||||
@@ -0,0 +1,129 @@
|
||||
<chapter id='chap-build-farm'><title>Setting up a Build Farm</title>
|
||||
|
||||
<para>This chapter provides some sketchy information on how to set up
|
||||
a Nix-based build farm. Nix is particularly suited as a basis for a
|
||||
build farm, since:
|
||||
|
||||
<itemizedlist>
|
||||
|
||||
<listitem><para>Nix supports distributed builds: a local Nix
|
||||
installation can forward Nix builds to other machines over the
|
||||
network. This allows multiple builds to be performed in parallel
|
||||
(thus improving performance), but more in importantly, it allows Nix
|
||||
to perform multi-platform builds in a semi-transparent way. For
|
||||
instance, if you perform a build for a
|
||||
<literal>powerpc-darwin</literal> on an
|
||||
<literal>i686-linux</literal> machine, Nix can automatically forward
|
||||
the build to a <literal>powerpc-darwin</literal> machine, if
|
||||
available.</para></listitem>
|
||||
|
||||
<listitem><para>The Nix expression language is ideal for describing
|
||||
build jobs, plus all their dependencies. For instance, if your
|
||||
package has some dependency, you don't have to manually install it
|
||||
on all the machines in the build farm; they will be built
|
||||
automatically.</para></listitem>
|
||||
|
||||
<listitem><para>Proper release management requires that builds (if
|
||||
deployed) are traceable: it should be possible to figure out from
|
||||
exactly what sources they were built, in what configuration, etc.;
|
||||
and it should be possible to reproduce the build, if necessary. Nix
|
||||
makes this possible since Nix's hashing scheme uniquely identifies
|
||||
builds, and Nix expressions are self-contained.</para></listitem>
|
||||
|
||||
<listitem><para>Nix will only rebuild things that have actually
|
||||
changed. For instance, if the sources of a component haven't
|
||||
changed between runs of the build farm, the component won't be
|
||||
rebuild (unless it was garbage-collected). Also, dependencies
|
||||
typically don't change very often, so they only need to be built
|
||||
once.</para></listitem>
|
||||
|
||||
<listitem><para>The results of a Nix build farm can be made
|
||||
available through a channel, so successful builds can be deployed to
|
||||
users immediately.</para></listitem>
|
||||
|
||||
</itemizedlist>
|
||||
|
||||
</para>
|
||||
|
||||
|
||||
<section><title>Overview</title>
|
||||
|
||||
<para>TODO</para>
|
||||
|
||||
<para>The sources of the Nix build farm are at <ulink
|
||||
url='https://svn.cs.uu.nl:12443/repos/trace/release/trunk' />.</para>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<section id='sec-distributed-builds'><title>Setting up distributed builds</title>
|
||||
|
||||
<para>You can enable distributed builds by setting the environment
|
||||
variable <envar>NIX_BUILD_HOOK</envar> to point to a program that Nix
|
||||
will call whenever it wants to build a derivation. The build hook
|
||||
(typically a shell or Perl script) can decline the build, in which Nix
|
||||
will perform it in the usual way if possible, or it can accept it, in
|
||||
which case it is responsible for somehow getting the inputs of the
|
||||
build to another machine, doing the build there, and getting the
|
||||
results back.</para>
|
||||
|
||||
<example id='ex-remote-systems'><title>Remote machine configuration:
|
||||
<filename>remote-systems.conf</filename></title>
|
||||
<programlisting>
|
||||
nix@mcflurry.labs.cs.uu.nl powerpc-darwin /home/nix/.ssh/id_quarterpounder_auto 2
|
||||
nix@scratchy.labs.cs.uu.nl i686-linux /home/nix/.ssh/id_scratchy_auto 1
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<para>An example build hook can be found in the Nix build farm
|
||||
sources: <ulink
|
||||
url='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
|
||||
adjustments. It uses <command>ssh</command> and
|
||||
<command>rsync</command> to copy the build inputs and outputs and
|
||||
perform the remote build. You should define a list of available build
|
||||
machines and set the environment variable
|
||||
<envar>REMOTE_SYSTEMS</envar> to point to it. An example
|
||||
configuration is shown in <xref linkend='ex-remote-systems' />. Each
|
||||
line in the file specifies a machine, with the following bits of
|
||||
information:
|
||||
|
||||
<orderedlist>
|
||||
|
||||
<listitem><para>The name of the remote machine, with optionally the
|
||||
user under which the remote build should be performed. This is
|
||||
actually passed as an argument to <command>ssh</command>, so it can
|
||||
be an alias defined in your
|
||||
<filename>~/.ssh/config</filename>.</para></listitem>
|
||||
|
||||
<listitem><para>The Nix platform type identifier, such as
|
||||
<literal>powerpc-darwin</literal>.</para></listitem>
|
||||
|
||||
<listitem><para>The SSH private key to be used to log in to the
|
||||
remote machine. Since builds should be non-interactive, this key
|
||||
should not have a passphrase!</para></listitem>
|
||||
|
||||
<listitem><para>The maximum <quote>load</quote> of the remote
|
||||
machine. This is just the maximum number of jobs that
|
||||
<filename>build-remote.pl</filename> will execute in parallel on the
|
||||
machine. Typically this should be equal to the number of
|
||||
CPUs.</para></listitem>
|
||||
|
||||
</orderedlist>
|
||||
|
||||
You should also set up the environment variable
|
||||
<envar>CURRENT_LOAD</envar> to point at a file that
|
||||
<filename>build-remote.pl</filename> uses to remember how many jobs it
|
||||
is currently executing remotely. It doesn't look at the actual load
|
||||
on the remote machine, so if you have multiple instances of Nix
|
||||
running, they should use the same <envar>CURRENT_LOAD</envar>
|
||||
file<footnote><para>Although there are probably some race conditions
|
||||
in the script right now.</para></footnote>. Maybe in the future
|
||||
<filename>build-remote.pl</filename> will look at the actual remote
|
||||
load. The load file should exist, so you should just create it as an
|
||||
empty file initially.</para>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
</chapter>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
+176
-175
@@ -1,211 +1,212 @@
|
||||
<chapter id='chap-installation'>
|
||||
<title>Installation</title>
|
||||
<chapter id='chap-installation'><title>Installation</title>
|
||||
|
||||
<sect1>
|
||||
<title>Obtaining Nix</title>
|
||||
|
||||
<para>
|
||||
The easiest way to obtain Nix is to download a <ulink
|
||||
url='http://www.cs.uu.nl/groups/ST/Trace/Nix'>source
|
||||
distribution</ulink>. RPMs for SuSE and Red Hat are also
|
||||
available. These distributions are generated automatically.
|
||||
</para>
|
||||
<sect1><title>Obtaining Nix</title>
|
||||
|
||||
<para>
|
||||
Alternatively, the most recent sources of Nix can be obtained from its
|
||||
<ulink url='https://svn.cs.uu.nl:12443/repos/trace/nix/trunk'>Subversion
|
||||
repository</ulink>. For example, the following command will check out
|
||||
the latest revision into a directory called <filename>nix</filename>:
|
||||
</para>
|
||||
<para>The easiest way to obtain Nix is to download a <ulink
|
||||
url='http://www.cs.uu.nl/groups/ST/Trace/Nix'>source
|
||||
distribution</ulink>. RPMs for Red Hat 9 are also available. These
|
||||
distributions are generated automatically.</para>
|
||||
|
||||
<screen>
|
||||
<para>Alternatively, the most recent sources of Nix can be obtained
|
||||
from its <ulink
|
||||
url='https://svn.cs.uu.nl:12443/repos/trace/nix/trunk'>Subversion
|
||||
repository</ulink>. For example, the following command will check out
|
||||
the latest revision into a directory called <filename>nix</filename>:</para>
|
||||
|
||||
<screen>
|
||||
$ svn checkout https://svn.cs.uu.nl:12443/repos/trace/nix/trunk nix</screen>
|
||||
|
||||
<para>
|
||||
Likewise, specific releases can be obtained from the <ulink
|
||||
url='https://svn.cs.uu.nl:12443/repos/trace/nix/tags'>tags
|
||||
directory</ulink> of the repository. If you don't have Subversion, you
|
||||
can also download an automatically generated <ulink
|
||||
url='https://svn.cs.uu.nl:12443/dist/trace/'>compressed
|
||||
tar-file</ulink> of the head revision of the trunk.
|
||||
<para>Likewise, specific releases can be obtained from the <ulink
|
||||
url='https://svn.cs.uu.nl:12443/repos/trace/nix/tags'>tags
|
||||
directory</ulink> of the repository. If you don't have Subversion,
|
||||
you can also download an automatically generated <ulink
|
||||
url='https://svn.cs.uu.nl:12443/dist/trace/'>compressed
|
||||
tar-file</ulink> of the head revision of the trunk.</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1><title>Prerequisites</title>
|
||||
|
||||
<para>The following prerequisites only apply when you build from
|
||||
source. Binary releases (e.g., RPMs) have no prerequisites.</para>
|
||||
|
||||
<para>A fairly recent version of GCC/G++ is required. Version 2.95
|
||||
and higher should work.</para>
|
||||
|
||||
<para>To build this manual and the man-pages you need the
|
||||
<command>xmllint</command> and <command>xsltproc</command> programs,
|
||||
which are part of the <literal>libxml2</literal> and
|
||||
<literal>libxslt</literal> packages, respectively. You also need the
|
||||
<ulink url='http://docbook.sourceforge.net/projects/xsl/'>DocBook XSL
|
||||
stylesheets</ulink> and optionally the <ulink
|
||||
url='http://www.oasis-open.org/docbook/xml/4.2/docbook-xml-4.2.zip'>
|
||||
DocBook XML 4.2 DTD</ulink>. Note that these are only required if you
|
||||
modify the manual sources or when you are building from the Subversion
|
||||
repository.</para>
|
||||
|
||||
<para>To build the parser, very <emphasis>recent</emphasis> versions
|
||||
of Bison and Flex are required. (This is because Nix needs GLR
|
||||
support in Bison and reentrancy support in Flex.) For Bison, you need
|
||||
version 1.875c or higher (1.875 does <emphasis>not</emphasis> work),
|
||||
which can be obtained from the <ulink
|
||||
url='ftp://alpha.gnu.org/pub/gnu/bison'>GNU FTP server</ulink>. For
|
||||
Flex, you need version 2.5.31, which is available on <ulink
|
||||
url='http://lex.sourceforge.net/'>SourceForge</ulink>. Slightly older
|
||||
versions may also work, but ancient versions like the ubiquitous
|
||||
2.5.4a won't. Note that these are only required if you modify the
|
||||
parser or when you are building from the Subversion repository.</para>
|
||||
|
||||
<para>Nix uses Sleepycat's Berkeley DB and CWI's ATerm library. These
|
||||
are included in the Nix source distribution. If you build from the
|
||||
Subversion repository, you must download them yourself and place them
|
||||
in the <filename>externals/</filename> directory. See
|
||||
<filename>externals/Makefile.am</filename> for the precise URLs of
|
||||
these packages. Alternatively, if you already have them installed,
|
||||
you can use <command>configure</command>'s <option>--with-bdb</option>
|
||||
and <option>--with-aterm</option> options to point to their respective
|
||||
locations. Note that Berkeley DB <emphasis>must</emphasis> be version
|
||||
4.2; other versions may not have compatible database formats.</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1><title>Building Nix from source</title>
|
||||
|
||||
<para>After unpacking or checking out the Nix sources, issue the
|
||||
following commands:
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
<title>Prerequisites</title>
|
||||
|
||||
<para>
|
||||
The following prerequisites only apply when you build from
|
||||
source. Binary releases (e.g., RPMs) have no prerequisites.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
A fairly recent version of GCC/G++ is required. Version 2.95
|
||||
and higher should work.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To build this manual and the man-pages you need the
|
||||
<command>xmllint</command> and <command>xsltproc</command>
|
||||
programs, which are part of the <literal>libxml2</literal> and
|
||||
<literal>libxslt</literal> packages, respectively. You also
|
||||
need the <ulink
|
||||
url='http://docbook.sourceforge.net/projects/xsl/'>DocBook XSL
|
||||
stylesheets</ulink> and optionally the <ulink
|
||||
url='http://www.oasis-open.org/docbook/xml/4.2/docbook-xml-4.2.zip'>
|
||||
DocBook XML 4.2 DTD</ulink>. Note that these are only required
|
||||
if you modify the manual sources or when you are building from
|
||||
the Subversion repository.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To build the parser, very <emphasis>recent</emphasis> versions
|
||||
of Bison and Flex are required. (This is because Nix needs GLR
|
||||
support in Bison and reentrancy support in Flex.) For Bison,
|
||||
you need version 1.875c or higher (1.875 does
|
||||
<emphasis>not</emphasis> work), which can be obtained from the
|
||||
<ulink url='ftp://alpha.gnu.org/pub/gnu/bison'>GNU FTP
|
||||
server</ulink>. For Flex, you need version 2.5.31, which is
|
||||
available on <ulink
|
||||
url='http://lex.sourceforge.net/'>SourceForge</ulink>. Slightly
|
||||
older versions may also work, but ancient versions like the
|
||||
ubiquitous 2.5.4a won't. Note that these are only required if
|
||||
you modify the parser or when you are building from the
|
||||
Subversion repository.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Nix uses Sleepycat's Berkeley DB and CWI's ATerm library. These
|
||||
are included in the Nix source distribution. If you build from
|
||||
the Subversion repository, you must download them yourself and
|
||||
place them in the <filename>externals/</filename> directory.
|
||||
See <filename>externals/Makefile.am</filename> for the precise
|
||||
URLs of these packages.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
<title>Building Nix from source</title>
|
||||
|
||||
<para>
|
||||
After unpacking or checking out the Nix sources, issue the following
|
||||
commands:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
<screen>
|
||||
$ ./configure <replaceable>options...</replaceable>
|
||||
$ make
|
||||
$ make install</screen>
|
||||
|
||||
<para>
|
||||
When building from the Subversion repository, these should be preceded by
|
||||
the command:
|
||||
<para>When building from the Subversion repository, these should be
|
||||
preceded by the command:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
<screen>
|
||||
$ autoreconf -i</screen>
|
||||
|
||||
<para>
|
||||
The installation path can be specified by passing the
|
||||
<option>--prefix=<replaceable>prefix</replaceable></option> to
|
||||
<command>configure</command>. The default installation directory is
|
||||
<filename>/nix</filename>. You can change this to any location you like.
|
||||
You must have write permission to the <replaceable>prefix</replaceable>
|
||||
path.
|
||||
</para>
|
||||
<para>The installation path can be specified by passing the
|
||||
<option>--prefix=<replaceable>prefix</replaceable></option> to
|
||||
<command>configure</command>. The default installation directory is
|
||||
<filename>/nix</filename>. You can change this to any location you
|
||||
like. You must have write permission to the
|
||||
<replaceable>prefix</replaceable> path.</para>
|
||||
|
||||
<warning>
|
||||
<para>
|
||||
It is advisable <emphasis>not</emphasis> to change the installation
|
||||
prefix from its default, since doing so will in all likelihood make it
|
||||
impossible to use derivations built on other systems.
|
||||
</para>
|
||||
</warning>
|
||||
<warning><para>It is advisable <emphasis>not</emphasis> to change the
|
||||
installation prefix from its default, since doing so will in all
|
||||
likelihood make it impossible to use derivations built on other
|
||||
systems.</para></warning>
|
||||
|
||||
<para>
|
||||
If you want to rebuilt the documentation, pass the full path to the
|
||||
DocBook XML catalog file (<filename>docbook.cat</filename>) and to the
|
||||
DocBook XSL stylesheets using the
|
||||
<option>--with-docbook-catalog=<replaceable>path</replaceable></option>
|
||||
and <option>--with-docbook-xsl=<replaceable>path</replaceable></option>
|
||||
options.
|
||||
</para>
|
||||
<para>If you want to rebuilt the documentation, pass the full path to
|
||||
the DocBook XML catalog file (<filename>docbook.cat</filename>) and to
|
||||
the DocBook XSL stylesheets using the
|
||||
<option>--with-docbook-catalog=<replaceable>path</replaceable></option>
|
||||
and
|
||||
<option>--with-docbook-xsl=<replaceable>path</replaceable></option>
|
||||
options.</para>
|
||||
|
||||
</sect1>
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1>
|
||||
<title>Installing from RPMs</title>
|
||||
<sect1><title>Installing from RPMs</title>
|
||||
|
||||
<para>
|
||||
RPM packages of Nix can be downloaded from <ulink
|
||||
url='http://www.cs.uu.nl/groups/ST/Trace/Nix' />. These RPMs
|
||||
should work for most fairly recent releases of SuSE and Red Hat
|
||||
Linux. They have been known to work work on SuSE Linux 8.1 and
|
||||
9.0, and Red Hat 9.0. In fact, it should work on any RPM-based
|
||||
Linux distribution based on <literal>glibc</literal> 2.3 or
|
||||
later.
|
||||
</para>
|
||||
<para>RPM packages of Nix can be downloaded from <ulink
|
||||
url='http://www.cs.uu.nl/groups/ST/Trace/Nix' />. These RPMs should
|
||||
work for most fairly recent releases of SuSE and Red Hat Linux. They
|
||||
have been known to work work on SuSE Linux 8.1 and 9.0, and Red Hat
|
||||
9.0. In fact, it should work on any RPM-based Linux distribution
|
||||
based on <literal>glibc</literal> 2.3 or later.</para>
|
||||
|
||||
<para>
|
||||
Once downloaded, the RPMs can be installed or upgraded using
|
||||
<command>rpm -U</command>. For example,
|
||||
</para>
|
||||
<para>Once downloaded, the RPMs can be installed or upgraded using
|
||||
<command>rpm -U</command>. For example,</para>
|
||||
|
||||
<screen>
|
||||
rpm -U nix-0.5pre664-1.i386.rpm</screen>
|
||||
<screen>
|
||||
$ rpm -U nix-0.5pre664-1.i386.rpm</screen>
|
||||
|
||||
<para>
|
||||
The RPMs install into the directory <filename>/nix</filename>.
|
||||
Nix can be uninstalled using <command>rpm -e nix</command>.
|
||||
After this it will be necessary to manually remove the Nix store
|
||||
and other auxiliary data:
|
||||
</para>
|
||||
<para>The RPMs install into the directory <filename>/nix</filename>.
|
||||
Nix can be uninstalled using <command>rpm -e nix</command>. After
|
||||
this it will be necessary to manually remove the Nix store and other
|
||||
auxiliary data:</para>
|
||||
|
||||
<screen>
|
||||
rm -rf /nix/store
|
||||
rm -rf /nix/var</screen>
|
||||
<screen>
|
||||
$ rm -rf /nix/store
|
||||
$ rm -rf /nix/var</screen>
|
||||
|
||||
</sect1>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
<title>Permissions</title>
|
||||
|
||||
<para>
|
||||
All Nix operations must be performed under the user ID that owns
|
||||
the Nix store and database
|
||||
(<filename><replaceable>prefix</replaceable>/store</filename>
|
||||
and
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/db</filename>,
|
||||
respectively). When installed from the RPM packages, these
|
||||
directories are owned by <systemitem
|
||||
class='username'>root</systemitem>.
|
||||
</para>
|
||||
<sect1><title>Permissions</title>
|
||||
|
||||
</sect1>
|
||||
<para>All Nix operations must be performed under the user ID that owns
|
||||
the Nix store and database
|
||||
(<filename><replaceable>prefix</replaceable>/store</filename> and
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/db</filename>,
|
||||
respectively). When installed from the RPM packages, these
|
||||
directories are owned by <systemitem
|
||||
class='username'>root</systemitem>.</para>
|
||||
|
||||
<sect1>
|
||||
<title>Using Nix</title>
|
||||
<sect2><title>Setuid installation</title>
|
||||
|
||||
<para>
|
||||
To use Nix, some environment variables should be set. In
|
||||
particular, <envar>PATH</envar> should contain the directories
|
||||
<filename><replaceable>prefix</replaceable>/bin</filename> and
|
||||
<filename>~/.nix-profile/bin</filename>. The first directory
|
||||
contains the Nix tools themselves, while
|
||||
<filename>~/.nix-profile</filename> is a symbolic link to the
|
||||
current <emphasis>user environment</emphasis> (an automatically
|
||||
generated package consisting of symlinks to installed packages).
|
||||
The simplest way to set the required environment variables is to
|
||||
include the file
|
||||
<filename><replaceable>prefix</replaceable>/etc/profile.d/nix.sh</filename>
|
||||
in your <filename>~/.bashrc</filename> (or similar), like this:
|
||||
</para>
|
||||
<para>As a somewhat <emphasis>ad hoc</emphasis> hack, you can also
|
||||
install the Nix binaries <quote>setuid</quote> so that a Nix store can
|
||||
be shared among several users. To do this, configure Nix with the
|
||||
<emphasis>--enable-setuid</emphasis> option. Nix will be installed as
|
||||
owned by a user and group specified by the
|
||||
<option>--with-nix-user=<parameter>user</parameter></option> and
|
||||
<option>--with-nix-group=<parameter>group</parameter></option>
|
||||
options. E.g.,
|
||||
|
||||
<screen>
|
||||
. <replaceable>prefix</replaceable>/etc/profile.d/nix.sh</screen>
|
||||
<screen>
|
||||
$ ./configure --enable-setuid --with-nix-user=my_nix_user --with-nix-group=my_nix_group</screen>
|
||||
|
||||
The user and group default to <literal>nix</literal>. You should make
|
||||
sure that both the user and the group exist. Any <quote>real</quote>
|
||||
users that you want to allow access should be added to the Nix
|
||||
group.</para>
|
||||
|
||||
<warning><para>A setuid installation should only by used if the users
|
||||
in the Nix group are mutually trusted, since any user in that group
|
||||
has the ability to change anything in the Nix store or database. For
|
||||
instance, they could install a trojan horse in executables used by
|
||||
other users.</para></warning>
|
||||
|
||||
<warning><para>On some platforms, the Nix binaries will be installed
|
||||
as setuid <literal>root</literal>. They drop root privileges
|
||||
immediately after startup and switch to the Nix user. The reason for
|
||||
this is that both the real and effective user must be set to the Nix
|
||||
user, and POSIX has no system call to do this. This is not the case
|
||||
on systems that have the <function>setresuid()</function> system call
|
||||
(such as Linux and FreeBSD), so on those systems the binaries are
|
||||
simply owned by the Nix user.</para></warning>
|
||||
|
||||
</sect2>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1><title>Using Nix</title>
|
||||
|
||||
<para>To use Nix, some environment variables should be set. In
|
||||
particular, <envar>PATH</envar> should contain the directories
|
||||
<filename><replaceable>prefix</replaceable>/bin</filename> and
|
||||
<filename>~/.nix-profile/bin</filename>. The first directory contains
|
||||
the Nix tools themselves, while <filename>~/.nix-profile</filename> is
|
||||
a symbolic link to the current <emphasis>user environment</emphasis>
|
||||
(an automatically generated package consisting of symlinks to
|
||||
installed packages). The simplest way to set the required environment
|
||||
variables is to include the file
|
||||
<filename><replaceable>prefix</replaceable>/etc/profile.d/nix.sh</filename>
|
||||
in your <filename>~/.bashrc</filename> (or similar), like this:</para>
|
||||
|
||||
<screen>
|
||||
source <replaceable>prefix</replaceable>/etc/profile.d/nix.sh</screen>
|
||||
|
||||
</sect1>
|
||||
|
||||
</sect1>
|
||||
|
||||
</chapter>
|
||||
+135
-78
@@ -1,93 +1,150 @@
|
||||
<chapter>
|
||||
<title>Introduction</title>
|
||||
<chapter><title>Introduction</title>
|
||||
|
||||
<epigraph>
|
||||
<para><quote>The number of Nix installations in the world has grown to 5,
|
||||
with more expected.</quote></para>
|
||||
</epigraph>
|
||||
<!--
|
||||
<epigraph><para><quote>The number of Nix installations in the world
|
||||
has grown to 5, with more expected.</quote></para></epigraph>
|
||||
-->
|
||||
|
||||
<para>
|
||||
Nix is a system for software deployment. It supports the
|
||||
creation and distribution of software packages, as well as the installation
|
||||
and subsequent management of these on target machines (i.e., it is also a
|
||||
package manager).
|
||||
</para>
|
||||
<para>Nix is a system for the deployment of software. Software
|
||||
deployment is concerned with the creation, distribution, and
|
||||
management of software components (<quote>packages</quote>). Its main
|
||||
features are:
|
||||
|
||||
<para>
|
||||
Nix solves some large problems that exist in most current deployment and
|
||||
package management systems. <emphasis>Dependency determination</emphasis>
|
||||
is a big one: the correct installation of a software component requires
|
||||
that all dependencies of that component (i.e., other components used by it)
|
||||
are also installed. Most systems have no way to verify that the specified
|
||||
dependencies of a component are actually sufficient.
|
||||
</para>
|
||||
<itemizedlist>
|
||||
|
||||
<para>
|
||||
Another big problem is the lack of support for concurrent availability of
|
||||
multiple <emphasis>variants</emphasis> of a component. It must be possible
|
||||
to have several versions of a component installed at the same time, or
|
||||
several instances of the same version built with different parameters.
|
||||
Unfortunately, components are in general not properly isolated from each
|
||||
other. For instance, upgrading a component that is a dependency for some
|
||||
other component might break the latter.
|
||||
</para>
|
||||
<listitem><para>It helps you make sure that dependency specifications
|
||||
are complete. In general in a deployment system you have to specify
|
||||
for each component what its dependencies are, but there are no
|
||||
guarantees that this specification is complete. If you forget a
|
||||
dependency, then the component will build and work correctly on
|
||||
<emphasis>your</emphasis> machine if you have the dependency
|
||||
installed, but not on the end user's machine if it's not
|
||||
there.</para></listitem>
|
||||
|
||||
<para>
|
||||
Nix solves these problems by building and storing packages in paths that
|
||||
are infeasible to predict in advance. For example, the artifacts of a
|
||||
package <literal>X</literal> might be stored in
|
||||
<filename>/nix/store/d58a0606ed616820de291d594602665d-X</filename>, rather
|
||||
than in, say, <filename>/usr/lib</filename>. The path component
|
||||
<filename>d58a...</filename> is actually a cryptographic hash of all the
|
||||
inputs (i.e., sources, requisites, and build flags) used in building
|
||||
<literal>X</literal>, and as such is very fragile: any change to the inputs
|
||||
will change the hash. Therefore it is not sensible to
|
||||
<emphasis>hard-code</emphasis> such a path into the build scripts of a
|
||||
package <literal>Y</literal> that uses <literal>X</literal> (as does happen
|
||||
with <quote>fixed</quote> paths such as <filename>/usr/lib</filename>).
|
||||
Rather, the build script of package <literal>Y</literal> is parameterised
|
||||
with the actual location of <literal>X</literal>, which is supplied by the
|
||||
Nix system.
|
||||
</para>
|
||||
<listitem><para>It is possible to have <emphasis>multiple versions or
|
||||
variants</emphasis> of a component installed at the same time. In
|
||||
contrast, in systems such as RPM different versions of the same
|
||||
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
|
||||
requirements on different versions of a component (e.g., application A
|
||||
requires version 1.0 of library X, while application B requires a
|
||||
non-backwards compatible version 1.1).</para></listitem>
|
||||
|
||||
<para>
|
||||
As stated above, the path name of a file system object contain a
|
||||
cryptographic hash of all inputs involved in building it. A change to any
|
||||
of the inputs will cause the hash to change--and by extension, the path
|
||||
name. These inputs include both sources (variation in time) and
|
||||
configuration options (variation in space). Therefore variants of the same
|
||||
package don't clash---they can co-exist peacefully within the same file
|
||||
system.
|
||||
</para>
|
||||
<listitem><para>Users can have different <quote>views</quote>
|
||||
(<quote>profiles</quote> in Nix parlance) on the set of installed
|
||||
applications in a system. For instance, one user can have version 1.0
|
||||
of some package visible, while another is using version 1.1, and a
|
||||
third doesn't use it at all.</para></listitem>
|
||||
|
||||
<para>
|
||||
Other features:
|
||||
</para>
|
||||
<listitem><para>It is possible to atomically
|
||||
<emphasis>upgrade</emphasis> software. I.e., there is no time window
|
||||
during an upgrade in which part of the old version and part of the new
|
||||
version are simultaneously visible (which might well cause the
|
||||
component to fail).</para></listitem>
|
||||
|
||||
<para>
|
||||
<emphasis>Transparent source/binary deployment.</emphasis>
|
||||
</para>
|
||||
<listitem><para>Likewise, it is possible to atomically roll back after
|
||||
an install, upgrade, or uninstall action. That is, in a fast (O(1))
|
||||
operation the previous configuration of the system can be restored.
|
||||
This is because upgrade or uninstall actions don't actually remove
|
||||
components from the system.</para></listitem>
|
||||
|
||||
<para>
|
||||
<emphasis>Unambiguous identification of configuration.</emphasis>
|
||||
</para>
|
||||
<listitem><para>Unused components can be
|
||||
<emphasis>garbage-collected</emphasis> automatically and safely: when
|
||||
you remove an application from a profile, its dependencies will be
|
||||
deleted by the garbage collector only if there are no other active
|
||||
applications using them.</para></listitem>
|
||||
|
||||
<para>
|
||||
<emphasis>Automatic storage management.</emphasis>
|
||||
</para>
|
||||
<listitem><para>Nix supports both source-based deployment models
|
||||
(where you distribute <emphasis>Nix expressions</emphasis> that tell
|
||||
Nix how to build software from source) and binary-based deployment
|
||||
models. The latter is more-or-less transparent: installation of
|
||||
components is always based on Nix expressions, but if the expressions
|
||||
have been built before and Nix knows that the resulting binaries are
|
||||
available somewhere, it will use those instead.</para></listitem>
|
||||
|
||||
<para>
|
||||
<emphasis>Atomic upgrades and rollbacks.</emphasis>
|
||||
</para>
|
||||
<listitem><para>Nix is flexible in the deployment policies that it
|
||||
supports. There is a clear separation between the tools that
|
||||
implement basic Nix <emphasis>mechanisms</emphasis> (e.g., building
|
||||
Nix expressions), and the tools that implement various deployment
|
||||
<emphasis>policies</emphasis>. For instance, there is a concept of
|
||||
<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
|
||||
be adapted easily to achieve similar policies.</para></listitem>
|
||||
|
||||
<para>
|
||||
<emphasis>Support for many simultaneous configurations.</emphasis>
|
||||
</para>
|
||||
<listitem><para>Nix component builds aim to be <quote>pure</quote>;
|
||||
that is, unaffected by anything other than the declared dependencies.
|
||||
This means that if a component was built successfully once, it can be
|
||||
rebuilt again on another machine and the result will be the same. We
|
||||
cannot <emphasis>guarantee</emphasis> this (e.g., if the build depends
|
||||
on the time-of-day), but Nix (and the tools in the Nix Packages
|
||||
collection) takes special care to help achieve this.</para></listitem>
|
||||
|
||||
<para>
|
||||
<emphasis>Portability.</emphasis> Nix is quite portable. Contrary to
|
||||
build systems like those in, e.g., Vesta and ClearCase, it does not rely on
|
||||
operating system extensions.
|
||||
</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
|
||||
how to build all the dependencies. This is in contrast to component
|
||||
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
|
||||
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
|
||||
deployed using Nix.</para></listitem>
|
||||
|
||||
<listitem><para>The Nix expression language makes it easy to describe
|
||||
variability in components (e.g., optional features or
|
||||
dependencies).</para></listitem>
|
||||
|
||||
<listitem><para>Nix is ideal for building build farms that do
|
||||
continuous builds of software from a version management system, since
|
||||
it can take care of building all the dependencies as well. Also, Nix
|
||||
only rebuilds components that have changed, so there are no
|
||||
unnecessary builds. In addition, Nix can transparently distribute
|
||||
build jobs over different machines, including different
|
||||
platforms.</para></listitem>
|
||||
|
||||
<listitem><para>Nix can be used not only for software deployment, but
|
||||
also for <emphasis>service deployment</emphasis>, such as the
|
||||
deployment of a complete web server with all its configuration files,
|
||||
static pages, software dependencies, and so on. Nix's advantages for
|
||||
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>
|
||||
|
||||
<listitem><para>Nix can efficiently upgrade between different versions
|
||||
of a component through <emphasis>binary patching</emphasis>. If
|
||||
patches are available on a server, and you try to install a new
|
||||
version of some component, Nix will automatically apply a patch (or
|
||||
sequence of patches), if available, to transform the installed
|
||||
component into the new version.</para></listitem>
|
||||
|
||||
</itemizedlist>
|
||||
|
||||
</para>
|
||||
|
||||
<para>This manual tells you how to install and use Nix and how to
|
||||
write Nix expressions for software not already in the Nix Packages
|
||||
collection. It also discusses some advanced topics, such as setting
|
||||
up a Nix-based build farm, and doing service deployment using
|
||||
Nix.</para>
|
||||
|
||||
<warning><para>This manual is a work in progress. It's quite likely
|
||||
to be incomplete, inconsistent with the current implementation, or
|
||||
simply wrong.</para></warning>
|
||||
|
||||
<note><para>Some background information on Nix can be found in two
|
||||
papers. The ICSE 2004 paper <ulink
|
||||
url='http://www.cs.uu.nl/~eelco/pubs/immdsd-icse2004-final.pdf'><citetitle>Imposing
|
||||
a Memory Management Discipline on Software
|
||||
Deployment</citetitle></ulink> discusses the hashing mechanism used to
|
||||
ensure reliable dependency identification and non-interference between
|
||||
different versions and variants of packages. The LISA 2004 paper
|
||||
<ulink
|
||||
url='http://www.cs.uu.nl/~eelco/pubs/nspfssd-lisa2004-final.pdf'><citetitle>Nix:
|
||||
A Safe and Policy-Free System for Software
|
||||
Deployment</citetitle></ulink> gives a more general discussion of Nix
|
||||
from a system-administration perspective.</para></note>
|
||||
|
||||
</chapter>
|
||||
+11
-10
@@ -1,15 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE book
|
||||
PUBLIC "-//OASIS//DTD DocBook EBNF Module V1.0//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/ebnf/1.0/dbebnf.dtd"
|
||||
[
|
||||
<!-- <!DOCTYPE book
|
||||
PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
||||
"http://www.docbook.org/xml/4.3/docbook-xml-4.3.zip" -->
|
||||
"http://www.docbook.org/xml/4.3/docbook-xml-4.3.zip"
|
||||
[
|
||||
<!ENTITY introduction SYSTEM "introduction.xml">
|
||||
<!ENTITY quick-start SYSTEM "quick-start.xml">
|
||||
<!ENTITY installation SYSTEM "installation.xml">
|
||||
<!ENTITY overview SYSTEM "overview.xml">
|
||||
<!ENTITY package-management SYSTEM "package-management.xml">
|
||||
<!ENTITY writing-nix-expressions SYSTEM "writing-nix-expressions.xml">
|
||||
<!ENTITY build-farm SYSTEM "build-farm.xml">
|
||||
<!ENTITY opt-common SYSTEM "opt-common.xml">
|
||||
<!ENTITY opt-common-syn SYSTEM "opt-common-syn.xml">
|
||||
<!ENTITY nix-env SYSTEM "nix-env.xml">
|
||||
@@ -19,14 +18,14 @@
|
||||
<!ENTITY nix-push SYSTEM "nix-push.xml">
|
||||
<!ENTITY nix-pull SYSTEM "nix-pull.xml">
|
||||
<!ENTITY nix-prefetch-url SYSTEM "nix-prefetch-url.xml">
|
||||
<!ENTITY nix-lang-ref SYSTEM "nix-lang-ref.xml">
|
||||
<!-- <!ENTITY nix-lang-ref SYSTEM "nix-lang-ref.xml"> -->
|
||||
<!ENTITY troubleshooting SYSTEM "troubleshooting.xml">
|
||||
<!ENTITY bugs SYSTEM "bugs.xml">
|
||||
<!ENTITY version SYSTEM "version.xml">
|
||||
]>
|
||||
|
||||
<book>
|
||||
<title>Nix: A System for Software Deployment</title>
|
||||
<title>Nix User's Guide</title>
|
||||
|
||||
<subtitle>Draft (Version &version;)</subtitle>
|
||||
|
||||
@@ -44,7 +43,9 @@
|
||||
&introduction;
|
||||
&quick-start;
|
||||
&installation;
|
||||
&overview;
|
||||
&package-management;
|
||||
&writing-nix-expressions;
|
||||
&build-farm;
|
||||
|
||||
<appendix>
|
||||
<title>Command Reference</title>
|
||||
@@ -78,7 +79,7 @@
|
||||
</sect1>
|
||||
</appendix>
|
||||
|
||||
&nix-lang-ref;
|
||||
<!-- &nix-lang-ref; -->
|
||||
|
||||
&troubleshooting;
|
||||
&bugs;
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<refentry>
|
||||
<refnamediv>
|
||||
<refname>nix-collect-garbage</refname>
|
||||
<refpurpose>determine the set of unreachable store paths</refpurpose>
|
||||
<refpurpose>remove unreachable store paths</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>nix-collect-garbage</command>
|
||||
<arg><option>--invert</option></arg>
|
||||
<arg><option>--no-successors</option></arg>
|
||||
<group choice='opt'>
|
||||
<arg choice='plain'><option>--print-live</option></arg>
|
||||
<arg choice='plain'><option>--print-dead</option></arg>
|
||||
</group>
|
||||
<arg><option>--min-age</option> <replaceable>age</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
@@ -16,10 +19,22 @@
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
The command <command>nix-collect-garbage</command> determines
|
||||
the paths in the Nix store that are garbage, that is, not
|
||||
reachable from outside of the store. These paths can be safely
|
||||
deleted without affecting the integrity of the system.
|
||||
The command <command>nix-collect-garbage</command> performs a
|
||||
garbage collection on the Nix store: any paths in the Nix store
|
||||
that are garbage (not reachable from a set of root store
|
||||
expressions) are deleted.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The roots of the garbage collector are the store expressions
|
||||
mentioned in the files in the directory
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/gcroots</filename>.
|
||||
By default, the roots are all user environments in
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/profiles</filename>.
|
||||
You can register other store expressions as roots by writing the
|
||||
full path of the store expression to an arbitrary file in the
|
||||
<filename>gcroots</filename> directory (or a subdirectory
|
||||
thereof).
|
||||
</para>
|
||||
|
||||
</refsection>
|
||||
@@ -30,27 +45,24 @@
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--invert</option></term>
|
||||
<term><option>--print-live</option> / <option>--print-dead</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Causes the set of <emphasis>reachable</emphasis> paths to
|
||||
be printed, rather than the unreachable paths. These are
|
||||
the paths that may <emphasis>not</emphasis> be deleted.
|
||||
These options cause the set of live or dead paths to be
|
||||
printed, respectively, rather than performing an actual
|
||||
garbage collector. They correspond exactly with the
|
||||
sub-operations in <command>nix-store
|
||||
<option>--gc</option></command>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--no-successors</option></term>
|
||||
<term><option>--min-age</option> <replaceable>age</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Causes <command>nix-collect-garbage</command> not to
|
||||
follow successor relations. By default, if a derivation
|
||||
store expression is reachable, its successor (i.e., a
|
||||
closure store expression) is also considered to be
|
||||
reachable. This option is always safe, but garbage
|
||||
collecting successors may cause undesirable rebuilds later
|
||||
on.
|
||||
This option corresponds to the <option>--min-age</option>
|
||||
option in <command>nix-store <option>--gc</option></command>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -63,10 +75,10 @@
|
||||
<title>Examples</title>
|
||||
|
||||
<para>
|
||||
To delete all unreachable paths, do the following:
|
||||
To delete all unreachable paths, just do:
|
||||
|
||||
<screen>
|
||||
$ nix-collect-garbage | xargs nix-store --delete</screen>
|
||||
$ nix-collect-garbage</screen>
|
||||
|
||||
</para>
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
</group>
|
||||
<replaceable>path</replaceable>
|
||||
</arg>
|
||||
<arg><option>--preserve-installed</option></arg>
|
||||
<arg>
|
||||
<arg choice='plain'><option>--system-filter</option></arg>
|
||||
<replaceable>system</replaceable>
|
||||
</arg>
|
||||
<arg><option>--dry-run</option></arg>
|
||||
<arg choice='plain'><replaceable>operation</replaceable></arg>
|
||||
<arg rep='repeat'><replaceable>options</replaceable></arg>
|
||||
@@ -121,6 +126,38 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--preserve-installed</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
By default, when you install a derivation with the
|
||||
<option>--install</option> operation, it will replace
|
||||
previously installed versions with the same derivation
|
||||
name (regardless of the version number). This option
|
||||
causes those previously installed versions to be kept in
|
||||
the new generation of the profile. Note that this will
|
||||
generally cause conflicts in the creation of the user
|
||||
environment (since multiple versions of a package
|
||||
typically contain the same programs).
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--system-filter</option> <replaceable>system</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
By default, operations such as <option>--query
|
||||
--available</option> only include derivations matching the
|
||||
current platform. This option allows you to use
|
||||
derivations for the specified platform
|
||||
<replaceable>system</replaceable>. The special value
|
||||
<literal>*</literal> causes derivations for any platform
|
||||
to be included.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
</refsection>
|
||||
@@ -719,6 +756,47 @@ $ nix-env --list-generations
|
||||
|
||||
|
||||
|
||||
<!--######################################################################-->
|
||||
|
||||
<refsection>
|
||||
<title>Operation <option>--delete-generations</option></title>
|
||||
|
||||
<refsection>
|
||||
<title>Synopsis</title>
|
||||
<cmdsynopsis>
|
||||
<command>nix-env</command>
|
||||
<arg choice='req'><option>--delete-generations</option></arg>
|
||||
<arg choice='plain' rep='repeat'><replaceable>generations</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsection>
|
||||
|
||||
<refsection>
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
This operation deletes the specified generations of the
|
||||
current profile. The generations can be a list of generation
|
||||
numbers, or the special value <literal>old</literal> to delete
|
||||
all non-current generations. Periodically deleting old
|
||||
generations is important to make garbage collection effective.
|
||||
</para>
|
||||
|
||||
</refsection>
|
||||
|
||||
<refsection>
|
||||
<title>Examples</title>
|
||||
|
||||
<screen>
|
||||
$ nix-env --delete-generations 3 4 8
|
||||
|
||||
$ nix-env -p other_profile --delete-generations old</screen>
|
||||
|
||||
</refsection>
|
||||
|
||||
</refsection>
|
||||
|
||||
|
||||
|
||||
<!--######################################################################-->
|
||||
|
||||
<refsection>
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
<cmdsynopsis>
|
||||
<command>nix-instantiate</command>
|
||||
&opt-common-syn;
|
||||
<group choice='opt'>
|
||||
<arg choice='plain'><option>--parse-only</option></arg>
|
||||
<arg choice='plain'><option>--eval-only</option></arg>
|
||||
</group>
|
||||
<arg choice='plain' rep='repeat'><replaceable>files</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
@@ -39,6 +43,27 @@
|
||||
|
||||
&opt-common;
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--parse-only</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Just parse the input files, and print their abstract
|
||||
syntax trees on standard output in ATerm format.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--eval-only</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Just parse and evaluate the input files, and print the
|
||||
resulting values on standard output. No instantiation of
|
||||
store expressions takes place.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
</refsection>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<chapter>
|
||||
<appendix>
|
||||
<title>Nix Language Reference</title>
|
||||
|
||||
<sect1>
|
||||
@@ -274,4 +274,4 @@
|
||||
</sect1>
|
||||
|
||||
|
||||
</chapter>
|
||||
</appendix>
|
||||
+70
-12
@@ -135,17 +135,19 @@
|
||||
<!--######################################################################-->
|
||||
|
||||
<refsection>
|
||||
<title>Operation <option>--delete</option></title>
|
||||
<title>Operation <option>--gc</option></title>
|
||||
|
||||
<refsection>
|
||||
<title>Synopsis</title>
|
||||
<cmdsynopsis>
|
||||
<command>nix-store</command>
|
||||
<arg choice='plain'><option>--gc</option></arg>
|
||||
<group choice='req'>
|
||||
<arg choice='plain'><option>--print-live</option></arg>
|
||||
<arg choice='plain'><option>--print-dead</option></arg>
|
||||
<arg choice='plain'><option>--delete</option></arg>
|
||||
<arg choice='plain'><option>-d</option></arg>
|
||||
</group>
|
||||
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
||||
<arg><option>--min-age</option> <replaceable>age</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsection>
|
||||
|
||||
@@ -153,19 +155,75 @@
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
The operation <option>--delete</option> unconditionally deletes the
|
||||
paths <replaceable>paths</replaceable> from the Nix store. It is an
|
||||
error to attempt to delete paths outside of the store.
|
||||
The operation <option>--gc</option> performs a garbage
|
||||
collection on the Nix store. What it does specifically is
|
||||
determined by the sub-operation, which is one of the
|
||||
following:
|
||||
</para>
|
||||
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--print-live</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This operation prints on standard output the set of
|
||||
<quote>live</quote> store paths, which are all the store
|
||||
paths reachable from a set of <quote>root</quote> store
|
||||
expressions read from standard input. Live paths should
|
||||
never be deleted, since that would break consistency —
|
||||
it would become possible that applications are installed
|
||||
that reference things that are no longer present in the
|
||||
store.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--print-dead</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This operation prints out on standard output the set of
|
||||
<quote>dead</quote> store paths, which is just the
|
||||
opposite of the set of live paths: any path in the store
|
||||
that is not live (with respect to the roots) is dead.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--delete</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This operation performs an actual garbage collection.
|
||||
All dead paths are removed from the store.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
<para>
|
||||
The set of root store expressions is read from standard input.
|
||||
Each line should contain exactly one store path.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The option <option>--min-age</option> specifies a minimum time
|
||||
in hours that an unreachable store path must not have been
|
||||
used before it is considered dead. The default is 0 (consider
|
||||
all unreachable store paths dead). Whether a store path has
|
||||
been used is determined by looking at its access time
|
||||
(<literal>atime</literal>), so this does not work if the store
|
||||
is located on a file system that has the
|
||||
<literal>noatime</literal> option set.
|
||||
</para>
|
||||
|
||||
<warning>
|
||||
<para>
|
||||
This operation should almost never be called directly, since no
|
||||
attempt is made to verify that no references exist to the paths to
|
||||
be deleted. Therefore, careless deletion can result in an
|
||||
inconsistent system. Deletion of paths in the store is done by the
|
||||
garbage collector (which uses <option>--delete</option> to delete
|
||||
unreferenced paths).
|
||||
You generally will want to use the command
|
||||
<command>nix-collect-garbage</command>, which figures out
|
||||
the roots and then calls this command automatically.
|
||||
</para>
|
||||
</warning>
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<arg><option>--version</option></arg>
|
||||
<arg rep='repeat'><option>--verbose</option></arg>
|
||||
<arg rep='repeat'><option>-v</option></arg>
|
||||
<arg><option>--build-output</option></arg>
|
||||
<arg><option>-B</option></arg>
|
||||
<arg><option>--no-build-output</option></arg>
|
||||
<arg><option>-Q</option></arg>
|
||||
<arg>
|
||||
<group choice='req'>
|
||||
<arg choice='plain'><option>--max-jobs</option></arg>
|
||||
@@ -16,3 +16,4 @@
|
||||
<arg><option>--keep-failed</option></arg>
|
||||
<arg><option>-K</option></arg>
|
||||
<arg><option>--fallback</option></arg>
|
||||
<arg><option>--readonly-mode</option></arg>
|
||||
@@ -50,7 +50,7 @@
|
||||
<para>
|
||||
<quote>Informational</quote>: print
|
||||
<emphasis>useful</emphasis> messages about what Nix is
|
||||
doing.
|
||||
doing. This is the default.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -94,14 +94,13 @@
|
||||
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--build-output</option> / <option>-B</option></term>
|
||||
<term><option>--no-build-output</option> / <option>-Q</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Causes the output written by build actions to standard output
|
||||
and standard error to be echoed to standard error, regardless of
|
||||
verbosity level. By default, it is only echoed at a verbosity
|
||||
level of at least 4 (<quote>Debug</quote>), and is suppressed at
|
||||
lower levels. Note that it is always written to a log file in
|
||||
By default, output written by builders to standard output and
|
||||
standard error is echoed to the Nix command's standard error.
|
||||
This option suppresses this behaviour. Note that the builder's
|
||||
standard output and error are always written to a log file in
|
||||
<filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.
|
||||
</para>
|
||||
</listitem>
|
||||
@@ -172,3 +171,14 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--readonly-mode</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
When this option is used, no attempt is made to open the Nix
|
||||
database. Most Nix operations do need database access, so those
|
||||
operations will fail.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -1,450 +0,0 @@
|
||||
<chapter id='chap-overview'>
|
||||
<title>Overview</title>
|
||||
|
||||
<para>
|
||||
This chapter provides a guided tour of Nix.
|
||||
</para>
|
||||
|
||||
|
||||
|
||||
<!--######################################################################-->
|
||||
|
||||
<sect1>
|
||||
<title>Basic package management</title>
|
||||
|
||||
<para>
|
||||
Let's start from the perspective of an end user. Common operations at
|
||||
this level are to install and remove packages, ask what packages are
|
||||
installed or available for installation, and so on. These are operations
|
||||
on the <emphasis>user environment</emphasis>: the set of packages that a
|
||||
user <quote>sees</quote>. In a command line Unix environment, this means
|
||||
the set of programs that are available through the <envar>PATH</envar>
|
||||
environment variable. (In other environments it might mean the set of
|
||||
programs available on the desktop, through the start menu, and so on.)
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The terms <quote>installation</quote> and <quote>uninstallation</quote>
|
||||
are used in this context to denote the act of adding or removing packages
|
||||
from the user environment. In Nix, these operations are dissociated from
|
||||
the physical copying or deleting of files. Installation requires that
|
||||
the files constituting the package are present, but they may be present
|
||||
beforehand. Likewise, uninstallation does not actually delete any files;
|
||||
this is done automatically by running a garbage collector.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
User environments are manipulated through the <command>nix-env</command>
|
||||
command. The query operation can be used to see what packages are
|
||||
currently installed.
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-env -q
|
||||
MozillaFirebird-0.7
|
||||
sylpheed-0.9.7
|
||||
pan-0.14.2</screen>
|
||||
|
||||
<para>
|
||||
(<option>-q</option> is actually short for <option>--query
|
||||
--installed</option>.) The package names are symbolic: they don't have
|
||||
any particular significance to Nix (as they shouldn't, since they are not
|
||||
unique—there can be many derivations with the same name). Note that
|
||||
these packages have many dependencies (e.g., Mozilla uses the
|
||||
<literal>gtk+</literal> package) but these have not been installed in the
|
||||
user environment, though they are present on the system. Generally,
|
||||
there is no need to install such packages; only packages containing
|
||||
programs should be installed.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To install packages, a <emphasis>Nix expression</emphasis> is required
|
||||
that tells Nix how to build that package. There is a <ulink
|
||||
url='https://svn.cs.uu.nl:12443/dist/trace/trace-nixpkgs-trunk.tar.bz2'>set
|
||||
of standard of Nix expressions</ulink> for many common packages.
|
||||
Assuming that you have downloaded and unpacked these, you can view the
|
||||
set of available packages:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-env -qaf pkgs/system/i686-linux.nix
|
||||
gettext-0.12.1
|
||||
sylpheed-0.9.7
|
||||
aterm-2.0
|
||||
gtk+-1.2.10
|
||||
apache-httpd-2.0.48
|
||||
pan-0.14.2
|
||||
...</screen>
|
||||
|
||||
<para>
|
||||
The Nix expression in the file <filename>i686-linux.nix</filename> yields
|
||||
the set of packages for a Linux system running on x86 hardware. For
|
||||
other platforms, copy and modify this file for your platform as
|
||||
appropriate. [TODO: improve this]
|
||||
</para>
|
||||
|
||||
<para>
|
||||
It is also possible to see the <emphasis>status</emphasis> of available
|
||||
packages, i.e., whether they are installed into the user environment
|
||||
and/or present in the system:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-env -qasf pkgs/system/i686-linux.nix
|
||||
-P gettext-0.12.1
|
||||
IP sylpheed-0.9.7
|
||||
-- aterm-2.0
|
||||
-P gtk+-1.2.10</screen>
|
||||
|
||||
<para>
|
||||
This reveals that the <literal>sylpheed</literal> package is already
|
||||
installed, or more precisely, that exactly the same instantiation of
|
||||
<literal>sylpheed</literal> is installed. This guarantees that the
|
||||
available package is exactly the same as the installed package with
|
||||
regard to sources, dependencies, build flags, and so on. Similarly, we
|
||||
see that the <literal>gettext</literal> and <literal>gtk+</literal>
|
||||
packages are present but not installed in the user environment, while the
|
||||
<literal>aterm</literal> package is not installed or present at all (so,
|
||||
if we were to install it, it would have to be built or downloaded first).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The install operation is used install available packages from a Nix
|
||||
environment. To install the <literal>pan</literal> package (a
|
||||
newsreader), you would do:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-env -if pkgs/system/i686-linux.nix pan</screen>
|
||||
|
||||
<para>
|
||||
Since installation may take a long time, depending on whether any
|
||||
packages need to be built or downloaded, it's a good idea to make
|
||||
<command>nix-env</command> run verbosely by using the <option>-v</option>
|
||||
(<option>--verbose</option>) option. This option may be repeated to
|
||||
increase the level of verbosity. A good value is 3
|
||||
(<option>-vvv</option>).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
In fact, if you run this command verbosely you will observe that Nix
|
||||
starts to build many packages, including large and fundamental ones such
|
||||
as <literal>glibc</literal> and <literal>gcc</literal>. I.e., you are
|
||||
performing a source installation. This is generally undesirable, since
|
||||
installation from sources may require large amounts of disk and CPU
|
||||
resources. Therefore a <quote>binary</quote> installation is generally
|
||||
preferable.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Rather than provide different mechanisms to create and perform
|
||||
the installation of binary packages, Nix supports binary deployment
|
||||
<emphasis>transparently</emphasis> through a generic mechanism of
|
||||
<emphasis>substitute expressions</emphasis>. If an request is made to
|
||||
build some Nix expression, Nix will first try to build any substitutes
|
||||
for that expression. These substitutes presumably perform an identical
|
||||
build operation with respect to the result, but require less resources.
|
||||
For instance, a substitute that downloads a pre-built package from the
|
||||
network requires less CPU and disk resources, and possibly less time.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Nix's use of cryptographic hashes makes this entirely safe. It is not
|
||||
possible, for instance, to accidentally substitute a build of some
|
||||
package for a Solaris or Windows system for a build on a SuSE/x86 system.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
While the substitute mechanism is a generic mechanism, Nix provides two
|
||||
standard tools called <command>nix-pull</command> and
|
||||
<command>nix-push</command> that maintain and use a shared cache of
|
||||
prebuilt derivations on some network site (reachable through HTTP). If
|
||||
you attempt to install some package that someone else has previously
|
||||
built and <quote>pushed</quote> into the cache, and you have done a
|
||||
<quote>pull</quote> to register substitutes that download these prebuilt
|
||||
packages, then the installation will automatically use these.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
For example, to pull from our <ulink
|
||||
url='http://losser.st-lab.cs.uu.nl/~eelco/nix-dist/'>cache</ulink> of
|
||||
prebuilt packages (at the time of writing, for SuSE Linux/x86), use the
|
||||
following command:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-pull http://catamaran.labs.cs.uu.nl/dist/nix/nixpkgs-<replaceable>version</replaceable>/MANIFEST
|
||||
obtaining list of Nix archives at http://catamaran.labs.cs.uu.nl/dist/nix/nixpkgs-<replaceable>version</replaceable>/MANIFEST...
|
||||
...</screen>
|
||||
|
||||
<para>
|
||||
If <command>nix-pull</command> is run without any arguments, it will pull
|
||||
from the URLs specified in the file
|
||||
<filename><replaceable>prefix</replaceable>/etc/nix/prebuilts.conf</filename>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Assuming that the <literal>pan</literal> installation produced no errors,
|
||||
it can be used immediately, that is, it now appears in a directory in the
|
||||
<envar>PATH</envar> environment variable. Specifically,
|
||||
<envar>PATH</envar> includes the entry
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/profiles/default/bin</filename>,
|
||||
where
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/profiles/default</filename>
|
||||
is just a symlink to the current user environment:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ ls -l /nix/var/nix/profiles/
|
||||
...
|
||||
lrwxrwxrwx 1 eelco ... default-15-link -> /nix/store/1871...12b0-user-environment
|
||||
lrwxrwxrwx 1 eelco ... default-16-link -> /nix/store/59ba...df6b-user-environment
|
||||
lrwxrwxrwx 1 eelco ... default -> default-16-link</screen>
|
||||
|
||||
<para>
|
||||
That is, <filename>default</filename> in this example is a link
|
||||
to <filename>default-16-link</filename>, which is the current
|
||||
user environment. Before the installation, it pointed to
|
||||
<filename>default-15-link</filename>. Note that this means that
|
||||
you can atomically roll-back to the previous user environment by
|
||||
pointing the symlink <filename>default</filename> at
|
||||
<filename>default-15-link</filename> again. This also shows
|
||||
that operations such as installation are atomic in the Nix
|
||||
system: any arbitrarily complex set of installation,
|
||||
uninstallation, or upgrade actions eventually boil down to the
|
||||
single operation of pointing a symlink somewhere else (which can
|
||||
be implemented atomically in Unix).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
What's in a user environment? It's just a set of symlinks to the files
|
||||
that constitute the installed packages. For instance:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ ls -l /nix/var/nix/profiles/default-16-link/bin
|
||||
lrwxrwxrwx 1 eelco ... MozillaFirebird -> /nix/store/35f8...4ae6-MozillaFirebird-0.7/bin/MozillaFirebird
|
||||
lrwxrwxrwx 1 eelco ... svn -> /nix/store/3829...fb5d-subversion-0.32.1/bin/svn
|
||||
...</screen>
|
||||
|
||||
<para>
|
||||
Note that, e.g., <filename>svn</filename> =
|
||||
<filename>/nix/var/nix/profiles/default/bin/svn</filename> =
|
||||
<filename>/nix/var/nix/profiles/default-16-link/bin/svn</filename> =
|
||||
<filename>/nix/store/59ba...df6b-user-environment/bin/svn</filename> =
|
||||
<filename>/nix/store/3829...fb5d-subversion-0.32.1/bin/svn</filename>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Naturally, packages can also be uninstalled:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-env -e pan</screen>
|
||||
|
||||
<para>
|
||||
This means that the package is removed from the user
|
||||
environment. It is <emphasis>not</emphasis> yet removed from
|
||||
the system. When a package is uninstalled from a user
|
||||
environment, it may still be used by other packages, or may
|
||||
still be present in other user environments. Deleting it under
|
||||
such conditions would break those other packages or user
|
||||
environments. To prevent this, packages are only
|
||||
<quote>physically</quote> deleted by running the Nix garbage
|
||||
collector, which searches for all packages in the Nix store that
|
||||
are no longer <quote>reachable</quote> from outside the store.
|
||||
Thus, uninstalling a package is always safe: it cannot break
|
||||
other packages.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Upgrading packages is easy. Given a Nix expression that
|
||||
contains newer versions of installed packages (that is, packages
|
||||
with the same package name, but a higher version number),
|
||||
<command>nix-env -u</command> will replace the installed package
|
||||
in the user environment with the newer package. For example,
|
||||
|
||||
<screen>
|
||||
$ nix-env -uf pkgs/system/i686-linux.nix pan</screen>
|
||||
|
||||
looks for a newer version of Pan, and installs it if found.
|
||||
Also useful is the ability to upgrade <emphasis>all</emphasis>
|
||||
packages:
|
||||
|
||||
<screen>
|
||||
$ nix-env -uf pkgs/system/i686-linux.nix '*'</screen>
|
||||
|
||||
The asterisk matches all installed packages<footnote><para>No,
|
||||
we don't support arbitrary regular
|
||||
expressions</para></footnote>. Note that <literal>*</literal>
|
||||
must be quoted to prevent shell globbing.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
|
||||
<!--######################################################################-->
|
||||
|
||||
<sect1>
|
||||
<title>Writing Nix expressions</title>
|
||||
|
||||
<sect2>
|
||||
<title>A simple Nix expression</title>
|
||||
|
||||
<para>
|
||||
This section shows how to write simple Nix expressions—the things
|
||||
that describe how to build a package.
|
||||
</para>
|
||||
|
||||
<example id='ex-hello-nix'>
|
||||
<title>Nix expression for GNU Hello</title>
|
||||
<programlisting>
|
||||
{stdenv, fetchurl, perl}: <co id='ex-hello-nix-co-1' />
|
||||
|
||||
derivation { <co id='ex-hello-nix-co-2' />
|
||||
name = "hello-2.1.1"; <co id='ex-hello-nix-co-3' />
|
||||
system = stdenv.system; <co id='ex-hello-nix-co-4' />
|
||||
builder = ./builder.sh; <co id='ex-hello-nix-co-5' />
|
||||
src = fetchurl { <co id='ex-hello-nix-co-6' />
|
||||
url = ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz;
|
||||
md5 = "70c9ccf9fac07f762c24f2df2290784d";
|
||||
};
|
||||
stdenv = stdenv; <co id='ex-hello-nix-co-7' />
|
||||
perl = perl;
|
||||
}</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
A simple Nix expression is shown in <xref linkend='ex-hello-nix' />. It
|
||||
describes how to the build the <ulink
|
||||
url='http://www.gnu.org/directory/GNU/hello.html'>GNU Hello
|
||||
package</ulink>. This package has several dependencies. First, it
|
||||
requires a number of other packages, such as a C compiler, standard
|
||||
Unix shell tools, and Perl. Rather than have this Nix expression refer
|
||||
to and use specific versions of these packages, it should be generic;
|
||||
that is, it should be a <emphasis>function</emphasis> that takes the
|
||||
required packages as inputs and yield a build of the GNU Hello package
|
||||
as a result. This Nix expression defines a function with three
|
||||
arguments <xref linkend='ex-hello-nix-co-1' />, namely:
|
||||
<orderedlist>
|
||||
<listitem><para><varname>stdenv</varname>, which should be a
|
||||
<emphasis>standard environment package</emphasis>. The standard
|
||||
environment is a set of tools and other components that would be
|
||||
expected in a fairly minimal Unix-like environment: a C compiler
|
||||
and linker, Unix shell tools, and so on.</para>
|
||||
</listitem>
|
||||
<listitem><para><varname>fetchurl</varname>, which should be a
|
||||
function that given parameters <varname>url</varname> and
|
||||
<varname>md5</varname>, will fetch a file from the specified
|
||||
location and check that this file has the given MD5 hash code.
|
||||
The hash is required because build operations must be
|
||||
<emphasis>pure</emphasis>: given the same inputs they should
|
||||
always yield the same output. Since network resources can change
|
||||
at any time, we must in some way guarantee what the result will
|
||||
be.</para>
|
||||
</listitem>
|
||||
<listitem><para><varname>perl</varname>, which should be a Perl
|
||||
interpreter.</para>
|
||||
</listitem>
|
||||
</orderedlist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The remainder of the file is the body of the function, which happens to
|
||||
be a <emphasis>derivation</emphasis> <xref
|
||||
linkend='ex-hello-nix-co-2' />, which is the built-in function
|
||||
<varname>derivation</varname> applied to a set of attributes that
|
||||
encode all the necessary information for building the GNU Hello
|
||||
package.
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>Build script (<filename>builder.sh</filename>) for GNU
|
||||
Hello</title>
|
||||
<programlisting>
|
||||
#! /bin/sh
|
||||
|
||||
buildinputs="$perl"
|
||||
. $stdenv/setup || exit 1
|
||||
|
||||
tar xvfz $src || exit 1
|
||||
cd hello-* || exit 1
|
||||
./configure --prefix=$out || exit 1
|
||||
make || exit 1
|
||||
make install || exit 1</programlisting>
|
||||
</example>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2>
|
||||
<title>A more complex Nix expression</title>
|
||||
|
||||
<example id='ex-svn-nix'>
|
||||
<title>Nix expression for Subversion</title>
|
||||
<programlisting>
|
||||
{ localServer ? false <co id='ex-svn-nix-co-1' />
|
||||
, httpServer ? false
|
||||
, sslSupport ? false
|
||||
, swigBindings ? false
|
||||
, stdenv, fetchurl
|
||||
, openssl ? null, httpd ? null, db4 ? null, expat, swig ? null
|
||||
}:
|
||||
|
||||
assert !isNull expat; <co id='ex-svn-nix-co-2' />
|
||||
assert localServer -> !isNull db4;
|
||||
assert httpServer -> !isNull httpd && httpd.expat == expat; <co id='ex-svn-nix-co-3' />
|
||||
assert sslSupport -> !isNull openssl && (httpServer -> httpd.openssl == openssl);
|
||||
assert swigBindings -> !isNull swig;
|
||||
|
||||
derivation {
|
||||
name = "subversion-0.32.1";
|
||||
system = stdenv.system;
|
||||
|
||||
builder = ./builder.sh;
|
||||
src = fetchurl {
|
||||
url = http://svn.collab.net/tarballs/subversion-0.32.1.tar.gz;
|
||||
md5 = "b06717a8ef50db4b5c4d380af00bd901";
|
||||
};
|
||||
|
||||
localServer = localServer;
|
||||
httpServer = httpServer;
|
||||
sslSupport = sslSupport;
|
||||
swigBindings = swigBindings;
|
||||
|
||||
stdenv = stdenv;
|
||||
openssl = if sslSupport then openssl else null; <co id='ex-svn-nix-co-4' />
|
||||
httpd = if httpServer then httpd else null;
|
||||
expat = expat;
|
||||
db4 = if localServer then db4 else null;
|
||||
swig = if swigBindings then swig else null;
|
||||
}</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
This example shows several features. Default parameters <xref
|
||||
linkend='ex-svn-nix-co-1'/> can be used to simplify call sites: if an
|
||||
argument that has a default is omitted, its default value is used.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
You can use <emphasis>assertions</emphasis> to test whether arguments
|
||||
satisfy certain constraints. The simple assertion <xref
|
||||
linkend='ex-svn-nix-co-2'/> tests whether the
|
||||
<varname>expat</varname> argument is not a null value. The more
|
||||
complex assertion <xref linkend='ex-svn-nix-co-3'/> says that if
|
||||
Subversion is built with Apache support, then <varname>httpd</varname>
|
||||
(the Apache package) must not be null and it must have been built using
|
||||
the same instance of the <varname>expat</varname> library as was passed
|
||||
to the Subversion expression. This is since the Subversion code is
|
||||
dynamically linked against the Apache code and they both use Expat,
|
||||
they must be linked against the same instance—otherwise a
|
||||
conflict might occur.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
</chapter>
|
||||
@@ -0,0 +1,455 @@
|
||||
<chapter id='chap-package-management'><title>Package Management</title>
|
||||
|
||||
<para>This chapter discusses how to do package management with Nix,
|
||||
i.e., how to obtain, install, upgrade, and erase components. This is
|
||||
the <quote>user's</quote> perspective of the Nix system — people
|
||||
who want to <emphasis>create</emphasis> components should consult
|
||||
<xref linkend='chap-writing-nix-expressions' />.</para>
|
||||
|
||||
|
||||
<sect1><title>Basic package management</title>
|
||||
|
||||
<para>The main command for package management is
|
||||
<command>nix-env</command>. You can use it to install, upgrade, and
|
||||
erase components, and to query what components are installed or are
|
||||
available for installation.</para>
|
||||
|
||||
<para>In Nix, different users can have different <quote>views</quote>
|
||||
on the set of installed applications. That is, there might be lots of
|
||||
applications present on the system (possibly in many different
|
||||
versions), but users can have a specific selection of those active —
|
||||
where <quote>active</quote> just means that it appears in a directory
|
||||
in the user's <envar>PATH</envar>. Such a view on the set of
|
||||
installed applications is called a <emphasis>user
|
||||
environment</emphasis>, which is just a directory tree consisting of
|
||||
symlinks to the files of the active applications. </para>
|
||||
|
||||
<para>Components are installed from a set of <emphasis>Nix
|
||||
expressions</emphasis> that tell Nix how to build those components,
|
||||
including, if necessary, their dependencies. There is a collection of
|
||||
Nix expressions called the Nix Package collection that contains
|
||||
components ranging from basic development stuff such as GCC and Glibc,
|
||||
to end-user applications like Mozilla Firefox. (Nix is however not
|
||||
tied to the Nix Package collection; you could write your own Nix
|
||||
expression based on it, or completely new ones.) You can download the
|
||||
latest version from <ulink
|
||||
url='http://catamaran.labs.cs.uu.nl/dist/nix' />. You probably want
|
||||
the latest unstable release; currently the stable releases tend to lag
|
||||
behind quite a bit.</para>
|
||||
|
||||
<para>Assuming that you have downloaded and unpacked a release of Nix
|
||||
Packages, you can view the set of available components in the release:
|
||||
|
||||
<screen>
|
||||
$ nix-env -qaf nixpkgs-<replaceable>version</replaceable>
|
||||
ant-blackdown-1.4.2
|
||||
aterm-2.2
|
||||
bash-3.0
|
||||
binutils-2.15
|
||||
bison-1.875d
|
||||
blackdown-1.4.2
|
||||
bzip2-1.0.2
|
||||
...</screen>
|
||||
|
||||
where <literal>nixpkgs-<replaceable>version</replaceable></literal> is
|
||||
where you've unpacked the release.</para>
|
||||
|
||||
<para>It is also possible to see the <emphasis>status</emphasis> of
|
||||
available components, i.e., whether they are installed into the user
|
||||
environment and/or present in the system:
|
||||
|
||||
<screen>
|
||||
$ nix-env -qasf nixpkgs-<replaceable>version</replaceable>
|
||||
...
|
||||
-PS bash-3.0
|
||||
--S binutils-2.15
|
||||
IPS bison-1.875d
|
||||
...</screen>
|
||||
|
||||
The first character (<literal>I</literal>) indicates whether the
|
||||
component is installed in your current user environment. The second
|
||||
(<literal>P</literal>) indicates whether it is present on your system
|
||||
(in which case installing it into your user environment would be a
|
||||
very quick operation). The last one (<literal>S</literal>) indicates
|
||||
whether there is a so-called <emphasis>substitute</emphasis> for the
|
||||
component, which is Nix's mechanism for doing binary deployment. It
|
||||
just means that Nix know that it can fetch a pre-built component from
|
||||
somewhere (typically a network server) instead of building it
|
||||
locally.</para>
|
||||
|
||||
<para>So now that we have a set of Nix expressions we can build the
|
||||
components contained in them. This is done using <literal>nix-env
|
||||
-i</literal>. For instance,
|
||||
|
||||
<screen>
|
||||
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -i subversion</screen>
|
||||
|
||||
will install the component called <literal>subversion</literal> (which
|
||||
is, of course, the <ulink
|
||||
url='http://subversion.tigris.org/'>Subversion version management
|
||||
system</ulink>).</para>
|
||||
|
||||
<para>When you do this for the first time, Nix will start building
|
||||
Subversion and all its dependencies. This will take quite a while —
|
||||
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
|
||||
to tell Nix that pre-built binaries of all those components are
|
||||
available somewhere. This is done using the
|
||||
<command>nix-pull</command> command, which must be supplied with a URL
|
||||
containing a <emphasis>manifest</emphasis> describing what binaries
|
||||
are available. This URL should correspond to the Nix Packages release
|
||||
that you're using. For instance, if you obtained a release from
|
||||
<ulink
|
||||
url='http://catamaran.labs.cs.uu.nl/dist/nix/nixpkgs-0.6pre1554/' />,
|
||||
then you should do:
|
||||
|
||||
<screen>
|
||||
$ nix-pull http://catamaran.labs.cs.uu.nl/dist/nix/nixpkgs-0.6pre1554/MANIFEST</screen>
|
||||
|
||||
If you then issue the installation command, it should start
|
||||
downloading binaries from <systemitem
|
||||
class='fqdomainname'>catamaran.labs.cs.uu.nl</systemitem>, instead of
|
||||
building them from source. This might still take a while since all
|
||||
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>
|
||||
|
||||
<para>Naturally, packages can also be uninstalled:
|
||||
|
||||
<screen>
|
||||
$ nix-env -e subversion</screen>
|
||||
|
||||
</para>
|
||||
|
||||
<para>Upgrading to a new version is just as easy. If you have a new
|
||||
release of Nix Packages, you can do:
|
||||
|
||||
<screen>
|
||||
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -u subversion</screen>
|
||||
|
||||
This will <emphasis>only</emphasis> upgrade Subversion if there is a
|
||||
<quote>newer</quote> version in the new set of Nix expressions, as
|
||||
defined by some pretty arbitrary rules regarding ordering of version
|
||||
numbers (which generally do what you'd expect of them). To just
|
||||
unconditionally replace Subversion with whatever version is in the Nix
|
||||
expressions, use <parameter>-i</parameter> instead of
|
||||
<parameter>-u</parameter>; <parameter>-i</parameter> will remove
|
||||
whatever version is already installed.</para>
|
||||
|
||||
<para>You can also upgrade all components for which there are newer
|
||||
versions:
|
||||
|
||||
<screen>
|
||||
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -u '*'</screen>
|
||||
|
||||
</para>
|
||||
|
||||
<para>Sometimes it's useful to be able to ask what
|
||||
<command>nix-env</command> would do, without actually doing it. For
|
||||
instance, to find out what packages would be upgraded by
|
||||
<literal>nix-env -u '*'</literal>, you can do
|
||||
|
||||
<screen>
|
||||
$ nix-env ... -u '*' --dry-run
|
||||
(dry run; not doing anything)
|
||||
upgrading `libxslt-1.1.0' to `libxslt-1.1.10'
|
||||
upgrading `graphviz-1.10' to `graphviz-1.12'
|
||||
upgrading `coreutils-5.0' to `coreutils-5.2.1'</screen>
|
||||
|
||||
</para>
|
||||
|
||||
<para>If you grow bored of specifying the Nix expressions using
|
||||
<parameter>-f</parameter> all the time, you can set a default
|
||||
location:
|
||||
|
||||
<screen>
|
||||
$ nix-env -I nixpkgs-<replaceable>version</replaceable></screen>
|
||||
|
||||
After this you can just say, for instance, <literal>nix-env -u
|
||||
'*'</literal>.<footnote><para>Setting a default using
|
||||
<parameter>-I</parameter> currently clashes with using Nix channels,
|
||||
since <literal>nix-channel --update</literal> calls <literal>nix-env
|
||||
-I</literal> to set the default to the Nix expressions it downloaded
|
||||
from the channel, replacing whatever default you had
|
||||
set.</para></footnote></para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1><title>Profiles</title>
|
||||
|
||||
<para>Profiles and user environments are Nix's mechanism for
|
||||
implementing the ability to allow differens users to have different
|
||||
configurations, and to do atomic upgrades and rollbacks. To
|
||||
understand how they work, it's useful to know a bit about how Nix
|
||||
works. In Nix, components are stored in unique locations in the
|
||||
<emphasis>Nix store</emphasis> (typically,
|
||||
<filename>/nix/store</filename>). For instance, a particular version
|
||||
of the Subversion component might be stored in a directory
|
||||
<filename>/nix/store/eeeeaf42e56b...-subversion-0.32.1/</filename>,
|
||||
while another version might be stored in
|
||||
<filename>/nix/store/58823d558a6a...-subversion-0.34/</filename>. The
|
||||
long hexadecimal numbers prefixed to the directory names are
|
||||
cryptographic hashes<footnote><para>128 bit MD5 hashes, to be
|
||||
precise.</para></footnote> of <emphasis>all</emphasis> inputs involved
|
||||
in building the component — sources, dependencies, compiler flags, and
|
||||
so on. So if two components differ in any way, they end up in
|
||||
different locations in the file system, so they don't interfere with
|
||||
each other. <xref linkend='fig-user-environments'
|
||||
/><footnote><para>TODO: the figure isn't entirely up to date. It
|
||||
should show multiple profiles and
|
||||
<filename>~/.nix-profile</filename>.</para></footnote> shows a part of
|
||||
a typical Nix store.</para>
|
||||
|
||||
<figure id='fig-user-environments'><title>User environments</title>
|
||||
<mediaobject>
|
||||
<imageobject>
|
||||
<imagedata fileref='figures/user-environments.png' format='PNG' />
|
||||
</imageobject>
|
||||
</mediaobject>
|
||||
</figure>
|
||||
|
||||
<para>Of course, you wouldn't want to type
|
||||
|
||||
<screen>
|
||||
$ /nix/store/eeeeaf42e56b...-subversion-0.32.1/bin/svn</screen>
|
||||
|
||||
every time you want to run Subversion. Of course we could set up the
|
||||
<envar>PATH</envar> environment variable to include the
|
||||
<filename>bin</filename> directory of every component we want to use,
|
||||
but this is not very convenient since changing <envar>PATH</envar>
|
||||
doesn't take effect for already existing processes. The solution Nix
|
||||
uses is to create directory trees of symlinks to
|
||||
<emphasis>activated</emphasis> components. These are called
|
||||
<emphasis>user environments</emphasis> and they are components
|
||||
themselves (though automatically generated by
|
||||
<command>nix-env</command>), so they too reside in the Nix store. For
|
||||
instance, in <xref linkend='fig-user-environments' /> the user
|
||||
environment <filename>/nix/store/068150f63831...-user-env</filename>
|
||||
contains a symlink to just Subversion 0.32.1 (arrows in the figure
|
||||
indicate symlinks). This would be what we would obtain if we had done
|
||||
|
||||
<screen>
|
||||
$ nix-env -i subversion</screen>
|
||||
|
||||
on a set of Nix expressions that contained Subversion 0.32.1.</para>
|
||||
|
||||
<para>This doesn't in itself solve the problem, of course; you
|
||||
wouldn't want to type
|
||||
<filename>/nix/store/068150f63831...-user-env/bin/svn</filename>
|
||||
either. Therefore there are symlinks outside of the store that point
|
||||
to the user environments in the store; for instance, the symlinks
|
||||
<filename>42</filename> and <filename>43</filename> in the example.
|
||||
These are called <emphasis>generations</emphasis> since every time you
|
||||
perform a <command>nix-env</command> operation, a new user environment
|
||||
is generated based on the current one. For instance, generation 43
|
||||
was created from generation 42 when we did
|
||||
|
||||
<screen>
|
||||
$ nix-env -i subversion mozilla</screen>
|
||||
|
||||
on a set of Nix expressions that contained Mozilla and a new version
|
||||
of Subversion.</para>
|
||||
|
||||
<para>Generations are grouped together into
|
||||
<emphasis>profiles</emphasis> so that different users don't interfere
|
||||
with each other if they don't want to. For example:
|
||||
|
||||
<screen>
|
||||
$ ls -l /nix/var/nix/profiles/
|
||||
...
|
||||
lrwxrwxrwx 1 eelco ... default-42-link -> /nix/store/068150f63831...-user-env
|
||||
lrwxrwxrwx 1 eelco ... default-43-link -> /nix/store/84c85f89ddbf...-user-env
|
||||
lrwxrwxrwx 1 eelco ... default -> default-43-link</screen>
|
||||
|
||||
This shows a profile called <filename>default</filename>. The file
|
||||
<filename>default</filename> itself is actually a symlink that points
|
||||
to the current generation. When we do a <command>nix-env</command>
|
||||
operation, a new user environment and generation link are created
|
||||
based on the current one, and finally the <filename>default</filename>
|
||||
symlink is made to point at the new generation. This last step is
|
||||
atomic on Unix, which explains how we can do atomic upgrades. (Note
|
||||
that the building/installing of new components doesn't interfere in
|
||||
any way with old components, since they are stored in different
|
||||
locations in the Nix store.)</para>
|
||||
|
||||
<para>If you find that you want to undo a <command>nix-env</command>
|
||||
operation, you can just do
|
||||
|
||||
<screen>
|
||||
$ nix-env --rollback</screen>
|
||||
|
||||
which will just make the current generation link point at the previous
|
||||
link. E.g., <filename>default</filename> would be made to point at
|
||||
<filename>default-42-link</filename>. You can also switch to a
|
||||
specific generation:
|
||||
|
||||
<screen>
|
||||
$ nix-env --switch-generation 43</screen>
|
||||
|
||||
which in this example would roll forward to generation 43 again. You
|
||||
can also see all available generations:
|
||||
|
||||
<screen>
|
||||
$ nix-env --list-generations</screen></para>
|
||||
|
||||
<para>Actually, there is another level of indirection not shown in the
|
||||
figure above. You generally wouldn't have
|
||||
<filename>/nix/var/nix/profiles/<replaceable>some-profile</replaceable>/bin</filename>
|
||||
in your <envar>PATH</envar>. Rather, there is a symlink
|
||||
<filename>~/.nix-profile</filename> that points to your current
|
||||
profile. This means that you should put
|
||||
<filename>~/.nix-profile/bin</filename> in your <envar>PATH</envar>
|
||||
(and indeed, that's what the initialisation script
|
||||
<filename>/nix/etc/profile.d/nix.sh</filename> does). This makes it
|
||||
easier to switch to a different profile. You can do that using the
|
||||
command <command>nix-env --switch-profile</command>:
|
||||
|
||||
<screen>
|
||||
$ nix-env --switch-profile /nix/var/nix/profiles/my-profile
|
||||
|
||||
$ nix-env --switch-profile /nix/var/nix/profiles/default</screen>
|
||||
|
||||
These commands switch to the <filename>my-profile</filename> and
|
||||
default profile, respectively. If the profile doesn't exist, it will
|
||||
be created automatically. You should be careful about storing a
|
||||
profile in another location than the <filename>profiles</filename>
|
||||
directory, since otherwise it might not be used as a root of the
|
||||
garbage collector (see section <xref linkend='sec-garbage-collection'
|
||||
/>).</para>
|
||||
|
||||
<para>All <command>nix-env</command> operations work on the profile
|
||||
pointed to by <command>~/.nix-profile</command>, but you can override
|
||||
this using the <option>--profile</option> option (abbreviation
|
||||
<option>-p</option>):
|
||||
|
||||
<screen>
|
||||
$ nix-env -p /nix/var/nix/profiles/other-profile -i subversion</screen>
|
||||
|
||||
This will <emphasis>not</emphasis> change the
|
||||
<command>~/.nix-profile</command> symlink.</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1 id='sec-garbage-collection'><title>Garbage collection</title>
|
||||
|
||||
<para><command>nix-env</command> operations such as upgrades
|
||||
(<option>-u</option>) and uninstall (<option>-e</option>) never
|
||||
actually delete components from the system. All they do (as shown
|
||||
above) is to create a new user environment that no longer contains
|
||||
symlinks to the <quote>deleted</quote> components.</para>
|
||||
|
||||
<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
|
||||
garbage collector. It will remove from the Nix store any component
|
||||
not used (directly or indirectly) by any generation of any
|
||||
profile.</para>
|
||||
|
||||
<para>Note however that as long as old generations reference a
|
||||
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
|
||||
effective, you should also delete (some) old generations. Of course,
|
||||
this should only be done if you are certain that you will not need to
|
||||
roll back.</para>
|
||||
|
||||
<para>To delete all old (non-current) generations of your current
|
||||
profile:
|
||||
|
||||
<screen>
|
||||
$ nix-env --delete-generations old</screen>
|
||||
|
||||
Instead of <literal>old</literal> you can also specify a list of
|
||||
generations, e.g.,
|
||||
|
||||
<screen>
|
||||
$ nix-env --delete-generations 10 11 14</screen>
|
||||
|
||||
</para>
|
||||
|
||||
<para>After removing appropriate old generations you can run the
|
||||
garbage collector as follows:
|
||||
|
||||
<screen>
|
||||
$ nix-collect-garbage</screen>
|
||||
|
||||
You can alo first view what files would be deleted:
|
||||
|
||||
<screen>
|
||||
$ nix-collect-garbage --print-dead</screen>
|
||||
|
||||
Likewise, the option <option>--print-live</option> will show the paths
|
||||
that <emphasis>won't</emphasis> be deleted.</para>
|
||||
|
||||
<sect2><title>Garbage collector roots</title>
|
||||
|
||||
<para>TODO</para>
|
||||
|
||||
<para>The garbage collector uses as roots all store expressions
|
||||
mentioned in all files with extension <filename>.gcroot</filename> in
|
||||
the directory
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/gcroots/</filename>,
|
||||
or in any file or directory symlinked to from that directory. E.g.,
|
||||
by default,
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/gcroots/</filename>
|
||||
contains a symlink to
|
||||
<filename><replaceable>prefix</replaceable>/var/nix/profiles/</filename>,
|
||||
so all generations of all profiles are also roots of the collector.</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1><title>Channels</title>
|
||||
|
||||
<para>If you want to stay up to date with a set of packages, it's not
|
||||
very convenient to manually download the latest set of Nix expressions
|
||||
for those packages, use <command>nix-pull</command> to register
|
||||
pre-built binaries (if available), and upgrade using
|
||||
<command>nix-env</command>. Fortunately, there's a better way:
|
||||
<emphasis>Nix channels</emphasis>.</para>
|
||||
|
||||
<para>A Nix channel is just a URL that points to a place that contains
|
||||
a set of Nix expressions and a manifest. Using the command
|
||||
<command>nix-channel</command> you can automatically stay up to date
|
||||
with whatever is available at that URL.</para>
|
||||
|
||||
<para>You can <quote>subscribe</quote> to a channel using
|
||||
<command>nix-channel --add</command>, e.g.,
|
||||
|
||||
<screen>
|
||||
$ nix-channel --add http://catamaran.labs.cs.uu.nl/dist/nix/channels/nixpkgs-unstable</screen>
|
||||
|
||||
subscribes you to a channel that always contains that latest version
|
||||
of the Nix Packages collection. (Instead of
|
||||
<literal>nixpkgs-unstable</literal> you could also subscribe to
|
||||
<literal>nixpkgs-stable</literal>, which should have a higher level of
|
||||
stability, but right now is just outdated.) Subscribing really just
|
||||
means that the URL is added to the file
|
||||
<filename>~/.nix-channels</filename>. Right now there is no command
|
||||
to <quote>unsubscribe</quote>; you should just edit that file manually
|
||||
and delete the offending URL.</para>
|
||||
|
||||
<para>To obtain the latest Nix expressions available in a channel, do
|
||||
|
||||
<screen>
|
||||
$ nix-channel --update</screen>
|
||||
|
||||
This downloads the Nix expressions in every channel (downloaded from
|
||||
<literal><replaceable>url</replaceable>/nixexprs.tar.bz2</literal>)
|
||||
and registers any available pre-built binaries in every channel
|
||||
(by <command>nix-pull</command>ing
|
||||
<literal><replaceable>url</replaceable>/MANIFEST</literal>). It also
|
||||
makes the union of each channel's Nix expressions the default for
|
||||
<command>nix-env</command> operations. Consequently, you can then say
|
||||
|
||||
<screen>
|
||||
$ nix-env -u '*'</screen>
|
||||
|
||||
to upgrade all components in your profile to the latest versions
|
||||
available in the subscribed channels.</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
</chapter>
|
||||
+75
-98
@@ -1,141 +1,118 @@
|
||||
<chapter>
|
||||
<title>Quick Start</title>
|
||||
<chapter><title>Quick Start</title>
|
||||
|
||||
<para>
|
||||
This chapter is for impatient people who don't like reading
|
||||
documentation. For more in-depth information you are kindly
|
||||
referred to <xref linkend='chap-installation' /> and <xref
|
||||
linkend='chap-overview' />.
|
||||
</para>
|
||||
<para>This chapter is for impatient people who don't like reading
|
||||
documentation. For more in-depth information you are kindly referred
|
||||
to the following chapters.</para>
|
||||
|
||||
<orderedlist>
|
||||
<orderedlist>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Download a source tarball or RPM from <ulink
|
||||
url='http://www.cs.uu.nl/groups/ST/Trace/Nix'/>.
|
||||
Build source distributions using the regular sequence:
|
||||
<listitem><para>Download a source tarball or RPM from <ulink
|
||||
url='http://www.cs.uu.nl/groups/ST/Trace/Nix'/>. Build source
|
||||
distributions using the regular sequence:
|
||||
|
||||
<screen>
|
||||
<screen>
|
||||
$ tar xvfj nix-<replaceable>version</replaceable>.tar.bz2
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make install <lineannotation>(as root)</lineannotation></screen>
|
||||
|
||||
This will install Nix in <filename>/nix</filename>. You
|
||||
should also add <filename>/nix/etc/profile.d/nix.sh</filename>
|
||||
to your <filename>~/.bashrc</filename> (or some other login
|
||||
file).
|
||||
</para>
|
||||
</listitem>
|
||||
This will install Nix in <filename>/nix</filename>. You shouldn't
|
||||
change the prefix if at all possible since that will make it
|
||||
impossible to use our pre-built components. Alternatively, you could
|
||||
grab an RPM if you're on an RPM-based system. You should also add
|
||||
<filename>/nix/etc/profile.d/nix.sh</filename> to your
|
||||
<filename>~/.bashrc</filename> (or some other login
|
||||
file).</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Get some Nix expressions for pre-built packages by downloading
|
||||
the latest <literal>nixpkgs</literal> distribution (from the
|
||||
same location), and unpack them.
|
||||
<listitem><para>Subscribe to the Nix Packages channel.
|
||||
|
||||
<screen>
|
||||
$ wget http://<replaceable>...</replaceable>/nix/nixpkgs-<replaceable>version</replaceable>/nixpkgs-<replaceable>version</replaceable>.tar.bz2
|
||||
$ tar xfj nixpkgs-<replaceable>version</replaceable>.tar.bz2</screen>
|
||||
<screen>
|
||||
$ nix-channel --add http://catamaran.labs.cs.uu.nl/dist/nix/channels/nixpkgs-unstable</screen>
|
||||
|
||||
This will unpack the distribution into a directory
|
||||
<filename>nixpkgs-<replaceable>version</replaceable>/</filename>.
|
||||
</para>
|
||||
</listitem>
|
||||
</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Pull the Nix cache. This ensures that when you install
|
||||
packages they are downloaded in pre-built form from the
|
||||
network, rather than built from source.
|
||||
<listitem><para>Download the latest Nix expressions available in the channel.
|
||||
<screen>
|
||||
$ nix-channel --update</screen>
|
||||
|
||||
<screen>
|
||||
$ nix-pull http://<replaceable>...</replaceable>/nix/nixpkgs-<replaceable>version</replaceable>/MANIFEST</screen>
|
||||
Note that this in itself doesn't download any components, it just
|
||||
downloads the Nix expressions that build them and stores them
|
||||
somewhere (under <filename>~/.nix-defexpr</filename>, in case you're
|
||||
curious). Also, it registers the fact that pre-built binaries are
|
||||
available remotely.</para></listitem>
|
||||
|
||||
</para>
|
||||
<listitem><para>See what installable components are currently
|
||||
available in the channel:
|
||||
|
||||
<para>
|
||||
Note that currently we only pre-build for Linux on x86
|
||||
platforms.
|
||||
</para>
|
||||
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
See what's available:
|
||||
|
||||
<screen>
|
||||
$ nix-env -qaf nixpkgs-<replaceable>version</replaceable>/
|
||||
MozillaFirebird-0.7
|
||||
hello-2.1.1
|
||||
<screen>
|
||||
$ nix-env -qa
|
||||
docbook-xml-4.2
|
||||
firefox-1.0pre-PR-0.10.1
|
||||
hello-2.1.1
|
||||
libxslt-1.1.0
|
||||
<replaceable>...</replaceable></screen>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Install some packages:
|
||||
<listitem><para>Install some components from the channel:
|
||||
|
||||
<screen>
|
||||
$ nix-env -iBf nixpkgs-<replaceable>version</replaceable>/ hello MozillaFirebird <replaceable>...</replaceable> </screen>
|
||||
<screen>
|
||||
$ nix-env -i hello firefox <replaceable>...</replaceable> </screen>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
This should download the pre-built components; it should not build
|
||||
them locally (if it does, something went wrong).</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Test that they work:
|
||||
<listitem><para>Test that they work:
|
||||
|
||||
<screen>
|
||||
<screen>
|
||||
$ which hello
|
||||
/home/eelco/.nix-profile/bin/hello
|
||||
$ hello
|
||||
Hello, world!
|
||||
$ MozillaFirebird
|
||||
$ firefox
|
||||
<lineannotation>(read Slashdot or something)</lineannotation></screen>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
Uninstall a package:
|
||||
<listitem><para>Uninstall a package:
|
||||
|
||||
<screen>
|
||||
<screen>
|
||||
$ nix-env -e hello</screen>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
If a new release of <literal>nixpkgs</literal> comes along,
|
||||
you can upgrade all installed packages to the latest versions
|
||||
by downloading and unpacking the new release and doing:
|
||||
<listitem><para>To keep up-to-date with the channel, do:
|
||||
|
||||
<screen>
|
||||
$ nix-env -uBf nixpkgs-<replaceable>version</replaceable>/ '*'</screen>
|
||||
<screen>
|
||||
$ nix-channel --update
|
||||
$ nix-env -u '*'</screen>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
The latter command will upgrade each installed component for which
|
||||
there is a <quote>newer</quote> version (as determined by comparing
|
||||
the version numbers).</para></listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
You should periodically run the Nix garbage collector to get
|
||||
rid of unused packages, since uninstalls or upgrades don't
|
||||
actual delete them:
|
||||
<listitem><para>If you're unhappy with the result of a
|
||||
<command>nix-env</command> action (e.g., an upgraded component turned
|
||||
out not to work properly), you can go back:
|
||||
|
||||
<screen>
|
||||
$ nix-collect-garbage | xargs nix-store --delete</screen>
|
||||
<screen>
|
||||
$ nix-env --rollback</screen>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
</para></listitem>
|
||||
|
||||
</orderedlist>
|
||||
<listitem><para>You should periodically run the Nix garbage collector
|
||||
to get rid of unused packages, since uninstalls or upgrades don't
|
||||
actually delete them:
|
||||
|
||||
</chapter>
|
||||
<screen>
|
||||
$ nix-env --delete-generations old
|
||||
$ nix-collect-garbage</screen>
|
||||
|
||||
The first command deletes old <quote>generations</quote> of your
|
||||
profile (making rollbacks impossible, but also making the components
|
||||
in those old generations available for garbage collection), while the
|
||||
second command actually deletes them.</para></listitem>
|
||||
|
||||
</orderedlist>
|
||||
|
||||
</chapter>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
|
||||
<uri pathSuffix=".xml" typeId="DocBook"/>
|
||||
<uri pattern="*.xml" typeId="DocBook"/>
|
||||
</locatingRules>
|
||||
@@ -112,10 +112,16 @@ div.note,div.warning
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
div.note h3,div.warning h3
|
||||
div.warning h3
|
||||
{
|
||||
color: red;
|
||||
text-decoration: underline;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
div.note h3
|
||||
{
|
||||
color: blue;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
div.navfooter *
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+4
-5
@@ -34,12 +34,12 @@ endif
|
||||
|
||||
# CWI ATerm
|
||||
|
||||
ATERM = aterm-2.1
|
||||
ATERM = aterm-2.3.1
|
||||
|
||||
$(ATERM).tar.gz:
|
||||
@echo "Nix requires the CWI ATerm library to build."
|
||||
@echo "Please download version 2.1 from"
|
||||
@echo " http://www.cwi.nl/projects/MetaEnv/aterm/aterm-2.1.tar.gz"
|
||||
@echo "Please download version 2.3.1 from"
|
||||
@echo " http://www.cwi.nl/projects/MetaEnv/aterm/aterm-2.3.1.tar.gz"
|
||||
@echo "and place it in the externals/ directory."
|
||||
false
|
||||
|
||||
@@ -56,8 +56,7 @@ else
|
||||
build-aterm: have-aterm
|
||||
(pfx=`pwd` && \
|
||||
cd $(ATERM) && \
|
||||
CC="$(CC)" ./configure --prefix=$$pfx/inst-aterm \
|
||||
--with-cflags="-DNDEBUG -DXGC_VERBOSE -DXHASHPEM -DWITH_STATS $(CFLAGS)" && \
|
||||
CC="$(CC)" ./configure --prefix=$$pfx/inst-aterm && \
|
||||
make && \
|
||||
make install)
|
||||
touch build-aterm
|
||||
|
||||
+37
-5
@@ -1,25 +1,47 @@
|
||||
%define enable_setuid ""
|
||||
%define nix_user "nix"
|
||||
%define nix_group "nix"
|
||||
|
||||
# If set, the Nix user and group will be created by the RPM
|
||||
# pre-install script.
|
||||
%define nix_user_uid ""
|
||||
%define nix_group_gid ""
|
||||
|
||||
Summary: The Nix software deployment system
|
||||
Name: nix
|
||||
Version: @version@
|
||||
Release: 1
|
||||
License: GPL
|
||||
Group: WeetNiet
|
||||
URL: http://www.cs.uu.nl/groups/ST/twiki/bin/view/Trace/NixDeploymentSystem
|
||||
Group: Software Deployment
|
||||
URL: http://www.cs.uu.nl/groups/ST/Trace/Nix
|
||||
Source0: %{name}-@version@.tar.gz
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
|
||||
%define _prefix /nix
|
||||
Prefix: %{_prefix}
|
||||
Requires: /usr/bin/perl
|
||||
|
||||
# Hack to make that shitty RPM scanning hack shut up.
|
||||
Provides: perl(readmanifest)
|
||||
|
||||
%description
|
||||
|
||||
Nix is a software deployment system.
|
||||
Nix is a system for software deployment.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
./configure --prefix=%{_prefix}
|
||||
extraFlags=
|
||||
if test -n "%{enable_setuid}"; then
|
||||
extraFlags="$extraFlags --enable-setuid"
|
||||
if test -n "%{nix_user}"; then
|
||||
extraFlags="$extraFlags --with-nix-user=%{nix_user}"
|
||||
fi
|
||||
if test -n "%{nix_group}"; then
|
||||
extraFlags="$extraFlags --with-nix-group=%{nix_group}"
|
||||
fi
|
||||
fi
|
||||
./configure --prefix=%{_prefix} $extraFlags
|
||||
make
|
||||
make check
|
||||
|
||||
@@ -31,8 +53,18 @@ strip $RPM_BUILD_ROOT/%{_prefix}/bin/* || true
|
||||
%clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%pre
|
||||
if test -n "%{nix_group_gid}"; then
|
||||
/usr/sbin/groupadd -g %{nix_group_gid} %{nix_group} || true
|
||||
fi
|
||||
if test -n "%{nix_user_uid}"; then
|
||||
/usr/sbin/useradd -c "Nix" -u %{nix_user_uid} \
|
||||
-s /sbin/nologin -r -d /var/empty %{nix_user} \
|
||||
-g %{nix_group} || true
|
||||
fi
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
#%defattr(-,root,root)
|
||||
%{_prefix}/bin
|
||||
%{_prefix}/libexec
|
||||
%{_prefix}/var
|
||||
|
||||
+6
-6
@@ -4,16 +4,15 @@ bin_SCRIPTS = nix-collect-garbage \
|
||||
|
||||
noinst_SCRIPTS = nix-profile.sh
|
||||
|
||||
nix-pull nix-push: readmanifest.pm
|
||||
nix-pull nix-push: readmanifest.pm download-using-manifests.pl
|
||||
|
||||
install-exec-local: readmanifest.pm
|
||||
install-exec-local: readmanifest.pm download-using-manifests.pl
|
||||
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/profile.d
|
||||
$(INSTALL_PROGRAM) nix-profile.sh $(DESTDIR)$(sysconfdir)/profile.d/nix.sh
|
||||
$(INSTALL) -d $(DESTDIR)$(libexecdir)/nix
|
||||
$(INSTALL_DATA) readmanifest.pm $(DESTDIR)$(libexecdir)/nix
|
||||
$(INSTALL_PROGRAM) download-using-manifests.pl $(DESTDIR)$(libexecdir)/nix
|
||||
$(INSTALL) -d $(DESTDIR)$(sysconfdir)/nix
|
||||
# !!! don't overwrite local modifications
|
||||
$(INSTALL_DATA) prebuilts.conf $(DESTDIR)$(sysconfdir)/nix/prebuilts.conf
|
||||
|
||||
include ../substitute.mk
|
||||
|
||||
@@ -21,5 +20,6 @@ EXTRA_DIST = nix-collect-garbage.in \
|
||||
nix-pull.in nix-push.in nix-profile.sh.in \
|
||||
nix-prefetch-url.in nix-install-package.in \
|
||||
nix-channel.in \
|
||||
prebuilts.conf readmanifest.pm.in \
|
||||
nix-build.in
|
||||
readmanifest.pm.in \
|
||||
nix-build.in \
|
||||
download-using-manifests.pl.in
|
||||
@@ -0,0 +1,246 @@
|
||||
#! @perl@ -w -I@libexecdir@/nix
|
||||
|
||||
use strict;
|
||||
use readmanifest;
|
||||
|
||||
my $manifestDir = "@localstatedir@/nix/manifests";
|
||||
my $logFile = "@localstatedir@/log/nix/downloads";
|
||||
|
||||
open LOGFILE, ">>$logFile" or die "cannot open log file $logFile";
|
||||
|
||||
|
||||
# Check the arguments.
|
||||
die unless scalar @ARGV == 1;
|
||||
my $targetPath = $ARGV[0];
|
||||
|
||||
my $date = `date`;
|
||||
chomp $date;
|
||||
print LOGFILE "$$ get $targetPath $date\n";
|
||||
|
||||
print "\n*** Trying to download/patch `$targetPath'\n";
|
||||
|
||||
|
||||
# Load all manifests.
|
||||
my %narFiles;
|
||||
my %patches;
|
||||
my %successors;
|
||||
|
||||
for my $manifest (glob "$manifestDir/*.nixmanifest") {
|
||||
# print STDERR "reading $manifest\n";
|
||||
readManifest $manifest, \%narFiles, \%patches, \%successors;
|
||||
}
|
||||
|
||||
|
||||
# Build a graph of all store paths that might contribute to the
|
||||
# construction of $targetPath, and the special node "start". The
|
||||
# edges are either patch operations, or downloads of full NAR files.
|
||||
# The latter edges only occur between "start" and a store path.
|
||||
|
||||
my %graph;
|
||||
|
||||
$graph{"start"} = {d => 0, pred => undef, edges => []};
|
||||
|
||||
my @queue = ();
|
||||
my $queueFront = 0;
|
||||
my %done;
|
||||
|
||||
sub addToQueue {
|
||||
my $v = shift;
|
||||
return if defined $done{$v};
|
||||
$done{$v} = 1;
|
||||
push @queue, $v;
|
||||
}
|
||||
|
||||
sub addNode {
|
||||
my $u = shift;
|
||||
$graph{$u} = {d => 999999999999, pred => undef, edges => []}
|
||||
unless defined $graph{$u};
|
||||
}
|
||||
|
||||
sub addEdge {
|
||||
my $u = shift;
|
||||
my $v = shift;
|
||||
my $w = shift;
|
||||
my $type = shift;
|
||||
my $info = shift;
|
||||
addNode $u;
|
||||
push @{$graph{$u}->{edges}},
|
||||
{weight => $w, start => $u, end => $v, type => $type, info => $info};
|
||||
my $n = scalar @{$graph{$u}->{edges}};
|
||||
}
|
||||
|
||||
addToQueue $targetPath;
|
||||
|
||||
sub isValidPath {
|
||||
my $p = shift;
|
||||
system "nix-store --isvalid '$p' 2> /dev/null";
|
||||
return $? == 0;
|
||||
}
|
||||
|
||||
while ($queueFront < scalar @queue) {
|
||||
my $u = $queue[$queueFront++];
|
||||
# print "$u\n";
|
||||
|
||||
addNode $u;
|
||||
|
||||
# If the path already exists, it has distance 0 from the "start"
|
||||
# node.
|
||||
if (isValidPath($u)) {
|
||||
addEdge "start", $u, 0, "present", undef;
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
# Add patch edges.
|
||||
my $patchList = $patches{$u};
|
||||
foreach my $patch (@{$patchList}) {
|
||||
if (isValidPath($patch->{basePath})) {
|
||||
# !!! this should be cached
|
||||
my $hash = `nix-hash "$patch->{basePath}"`;
|
||||
chomp $hash;
|
||||
# print " MY HASH is $hash\n";
|
||||
if ($hash ne $patch->{baseHash}) {
|
||||
print LOGFILE "$$ rejecting $patch->{basePath}\n";
|
||||
next;
|
||||
}
|
||||
}
|
||||
# print " PATCH from $patch->{basePath}\n";
|
||||
addToQueue $patch->{basePath};
|
||||
addEdge $patch->{basePath}, $u, $patch->{size}, "patch", $patch;
|
||||
}
|
||||
|
||||
# Add NAR file edges to the start node.
|
||||
my $narFileList = $narFiles{$u};
|
||||
foreach my $narFile (@{$narFileList}) {
|
||||
# print " NAR from $narFile->{url}\n";
|
||||
addEdge "start", $u, $narFile->{size}, "narfile", $narFile;
|
||||
if ($u eq $targetPath) {
|
||||
print LOGFILE "$$ full-download-would-be $narFile->{size}\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Run Dijkstra's shortest path algorithm to determine the shortest
|
||||
# sequence of download and/or patch actions that will produce
|
||||
# $targetPath.
|
||||
|
||||
sub byDistance { # sort by distance, reversed
|
||||
return -($graph{$a}->{d} <=> $graph{$b}->{d});
|
||||
}
|
||||
|
||||
my @todo = keys %graph;
|
||||
|
||||
while (scalar @todo > 0) {
|
||||
|
||||
# Remove the closest element from the todo list.
|
||||
@todo = sort byDistance @todo;
|
||||
my $u = pop @todo;
|
||||
|
||||
my $u_ = $graph{$u};
|
||||
|
||||
# print "IN $u $u_->{d}\n";
|
||||
|
||||
foreach my $edge (@{$u_->{edges}}) {
|
||||
my $v_ = $graph{$edge->{end}};
|
||||
if ($v_->{d} > $u_->{d} + $edge->{weight}) {
|
||||
$v_->{d} = $u_->{d} + $edge->{weight};
|
||||
# Store the edge; to edge->start is actually the
|
||||
# predecessor.
|
||||
$v_->{pred} = $edge;
|
||||
# print " RELAX $edge->{end} $v_->{d}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Retrieve the shortest path from "start" to $targetPath.
|
||||
my @path = ();
|
||||
my $cur = $targetPath;
|
||||
die "don't know how to produce $targetPath\n"
|
||||
unless defined $graph{$targetPath}->{pred};
|
||||
while ($cur ne "start") {
|
||||
push @path, $graph{$cur}->{pred};
|
||||
$cur = $graph{$cur}->{pred}->{start};
|
||||
}
|
||||
|
||||
|
||||
# Traverse the shortest path, perform the actions described by the
|
||||
# edges.
|
||||
my $curStep = 1;
|
||||
my $maxStep = scalar @path;
|
||||
|
||||
sub downloadFile {
|
||||
my $url = shift;
|
||||
my $hash = shift;
|
||||
$ENV{"PRINT_PATH"} = 1;
|
||||
$ENV{"QUIET"} = 1;
|
||||
my ($hash2, $path) = `nix-prefetch-url '$url' '$hash'`;
|
||||
chomp $hash2;
|
||||
chomp $path;
|
||||
die "hash mismatch" if $hash ne $hash2;
|
||||
return $path;
|
||||
}
|
||||
|
||||
while (scalar @path > 0) {
|
||||
my $edge = pop @path;
|
||||
my $u = $edge->{start};
|
||||
my $v = $edge->{end};
|
||||
|
||||
print "\n*** Step $curStep/$maxStep: ";
|
||||
$curStep++;
|
||||
|
||||
if ($edge->{type} eq "present") {
|
||||
print "using already present path `$v'\n";
|
||||
print LOGFILE "$$ present $v\n";
|
||||
}
|
||||
|
||||
elsif ($edge->{type} eq "patch") {
|
||||
my $patch = $edge->{info};
|
||||
print "applying patch `$patch->{url}' to `$u' to create `$v'\n";
|
||||
|
||||
print LOGFILE "$$ patch $patch->{url} $patch->{size} $patch->{baseHash} $u $v\n";
|
||||
|
||||
# Download the patch.
|
||||
print " downloading patch...\n";
|
||||
my $patchPath = downloadFile "$patch->{url}", "$patch->{hash}";
|
||||
|
||||
# Turn the base path into a NAR archive, to which we can
|
||||
# actually apply the patch.
|
||||
print " packing base path...\n";
|
||||
system "nix-store --dump $patch->{basePath} > /tmp/nar";
|
||||
die "cannot dump `$patch->{basePath}'" if ($? != 0);
|
||||
|
||||
# Apply the patch.
|
||||
print " applying patch...\n";
|
||||
system "@libexecdir@/bspatch /tmp/nar /tmp/nar2 $patchPath";
|
||||
die "cannot apply patch `$patchPath' to /tmp/nar" if ($? != 0);
|
||||
|
||||
# Unpack the resulting NAR archive into the target path.
|
||||
print " unpacking patched archive...\n";
|
||||
system "nix-store --restore $v < /tmp/nar2";
|
||||
die "cannot unpack /tmp/nar2 into `$v'" if ($? != 0);
|
||||
}
|
||||
|
||||
elsif ($edge->{type} eq "narfile") {
|
||||
my $narFile = $edge->{info};
|
||||
print "downloading `$narFile->{url}' into `$v'\n";
|
||||
|
||||
print LOGFILE "$$ narfile $narFile->{url} $narFile->{size} $v\n";
|
||||
|
||||
# Download the archive.
|
||||
print " downloading archive...\n";
|
||||
my $narFilePath = downloadFile "$narFile->{url}", "$narFile->{hash}";
|
||||
|
||||
# Unpack the archive into the target path.
|
||||
print " unpacking archive...\n";
|
||||
system "bunzip2 < '$narFilePath' | nix-store --restore '$v'";
|
||||
die "cannot unpack `$narFilePath' into `$v'" if ($? != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print LOGFILE "$$ success\n";
|
||||
close LOGFILE;
|
||||
Executable
+285
@@ -0,0 +1,285 @@
|
||||
#! /usr/bin/perl -w -I/home/eelco/nix/scripts
|
||||
|
||||
use strict;
|
||||
use POSIX qw(tmpnam);
|
||||
use readmanifest;
|
||||
|
||||
die unless scalar @ARGV == 5;
|
||||
|
||||
my $cacheDir = $ARGV[0];
|
||||
my $patchesDir = $ARGV[1];
|
||||
my $patchesURL = $ARGV[2];
|
||||
my $srcDir = $ARGV[3];
|
||||
my $dstDir = $ARGV[4];
|
||||
|
||||
my $tmpdir;
|
||||
do { $tmpdir = tmpnam(); }
|
||||
until mkdir $tmpdir, 0777;
|
||||
|
||||
print "TEMP = $tmpdir\n";
|
||||
|
||||
#END { rmdir $tmpdir; }
|
||||
|
||||
my %srcNarFiles;
|
||||
my %srcPatches;
|
||||
my %srcSuccessors;
|
||||
|
||||
my %dstNarFiles;
|
||||
my %dstPatches;
|
||||
my %dstSuccessors;
|
||||
|
||||
readManifest "$srcDir/MANIFEST",
|
||||
\%srcNarFiles, \%srcPatches, \%srcSuccessors;
|
||||
|
||||
readManifest "$dstDir/MANIFEST",
|
||||
\%dstNarFiles, \%dstPatches, \%dstSuccessors;
|
||||
|
||||
|
||||
sub findOutputPaths {
|
||||
my $narFiles = shift;
|
||||
my $successors = shift;
|
||||
|
||||
my %outPaths;
|
||||
|
||||
foreach my $p (keys %{$narFiles}) {
|
||||
|
||||
# Ignore store expressions.
|
||||
next if ($p =~ /\.store$/);
|
||||
|
||||
# Ignore builders (too much ambiguity -- they're all called
|
||||
# `builder.sh').
|
||||
next if ($p =~ /\.sh$/);
|
||||
next if ($p =~ /\.patch$/);
|
||||
|
||||
# Don't bother including tar files etc.
|
||||
next if ($p =~ /\.tar\.(gz|bz2)$/ || $p =~ /\.zip$/ || $p =~ /\.bin$/);
|
||||
|
||||
$outPaths{$p} = 1;
|
||||
}
|
||||
|
||||
return %outPaths;
|
||||
}
|
||||
|
||||
print "finding src output paths...\n";
|
||||
my %srcOutPaths = findOutputPaths \%srcNarFiles, \%srcSuccessors;
|
||||
|
||||
print "finding dst output paths...\n";
|
||||
my %dstOutPaths = findOutputPaths \%dstNarFiles, \%dstSuccessors;
|
||||
|
||||
|
||||
sub getNameVersion {
|
||||
my $p = shift;
|
||||
$p =~ /\/[0-9a-f]+((?:-[a-zA-Z][^\/-]*)+)([^\/]*)$/;
|
||||
my $name = $1;
|
||||
my $version = $2;
|
||||
$name =~ s/^-//;
|
||||
$version =~ s/^-//;
|
||||
return ($name, $version);
|
||||
}
|
||||
|
||||
|
||||
# A quick hack to get a measure of the `distance' between two
|
||||
# versions: it's just the position of the first character that differs
|
||||
# (or 999 if they are the same).
|
||||
sub versionDiff {
|
||||
my $s = shift;
|
||||
my $t = shift;
|
||||
my $i;
|
||||
return 999 if $s eq $t;
|
||||
for ($i = 0; $i < length $s; $i++) {
|
||||
return $i if $i >= length $t or
|
||||
substr($s, $i, 1) ne substr($t, $i, 1);
|
||||
}
|
||||
return $i;
|
||||
}
|
||||
|
||||
|
||||
sub getNarBz2 {
|
||||
my $narFiles = shift;
|
||||
my $storePath = shift;
|
||||
|
||||
my $narFileList = $$narFiles{$storePath};
|
||||
die "missing store expression $storePath" unless defined $narFileList;
|
||||
|
||||
my $narFile = @{$narFileList}[0];
|
||||
die unless defined $narFile;
|
||||
|
||||
$narFile->{url} =~ /\/([^\/]+)$/;
|
||||
die unless defined $1;
|
||||
return "$cacheDir/$1";
|
||||
}
|
||||
|
||||
|
||||
sub containsPatch {
|
||||
my $patches = shift;
|
||||
my $storePath = shift;
|
||||
my $basePath = shift;
|
||||
my $patchList = $$patches{$storePath};
|
||||
return 0 if !defined $patchList;
|
||||
my $found = 0;
|
||||
foreach my $patch (@{$patchList}) {
|
||||
# !!! baseHash might differ
|
||||
return 1 if $patch->{basePath} eq $basePath;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
# For each output path in the destination, see if we need to / can
|
||||
# create a patch.
|
||||
|
||||
print "creating patches...\n";
|
||||
|
||||
foreach my $p (keys %dstOutPaths) {
|
||||
|
||||
# If exactly the same path already exists in the source, skip it.
|
||||
next if defined $srcOutPaths{$p};
|
||||
|
||||
# print " $p\n";
|
||||
|
||||
# If not, then we should find the path in the source that is
|
||||
# `most' likely to be present on a system that wants to install
|
||||
# this path.
|
||||
|
||||
(my $name, my $version) = getNameVersion $p;
|
||||
|
||||
my @closest = ();
|
||||
my $closestVersion;
|
||||
my $minDist = -1; # actually, larger means closer
|
||||
|
||||
# Find all source paths with the same name.
|
||||
|
||||
foreach my $q (keys %srcOutPaths) {
|
||||
(my $name2, my $version2) = getNameVersion $q;
|
||||
if ($name eq $name2) {
|
||||
my $dist = versionDiff $version, $version2;
|
||||
if ($dist > $minDist) {
|
||||
$minDist = $dist;
|
||||
@closest = ($q);
|
||||
$closestVersion = $version2;
|
||||
} elsif ($dist == $minDist) {
|
||||
push @closest, $q;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@closest) == 0) {
|
||||
print " NO BASE: $p\n";
|
||||
next;
|
||||
}
|
||||
|
||||
foreach my $closest (@closest) {
|
||||
|
||||
# Generate a patch between $closest and $p.
|
||||
print " $p <- $closest\n";
|
||||
|
||||
# If the patch already exists, skip it.
|
||||
if (containsPatch(\%srcPatches, $p, $closest) ||
|
||||
containsPatch(\%dstPatches, $p, $closest))
|
||||
{
|
||||
print " skipping, already exists\n";
|
||||
next;
|
||||
}
|
||||
|
||||
# next;
|
||||
|
||||
my $srcNarBz2 = getNarBz2 \%srcNarFiles, $closest;
|
||||
my $dstNarBz2 = getNarBz2 \%dstNarFiles, $p;
|
||||
|
||||
system("bunzip2 < $srcNarBz2 > $tmpdir/A") == 0
|
||||
or die "cannot unpack $srcNarBz2";
|
||||
|
||||
system("bunzip2 < $dstNarBz2 > $tmpdir/B") == 0
|
||||
or die "cannot unpack $dstNarBz2";
|
||||
|
||||
system("bsdiff $tmpdir/A $tmpdir/B $tmpdir/DIFF") == 0
|
||||
or die "cannot compute binary diff";
|
||||
|
||||
my $baseHash = `nix-hash --flat $tmpdir/A` or die;
|
||||
chomp $baseHash;
|
||||
|
||||
my $narHash = `nix-hash --flat $tmpdir/B` or die;
|
||||
chomp $narHash;
|
||||
|
||||
my $narDiffHash = `nix-hash --flat $tmpdir/DIFF` or die;
|
||||
chomp $narDiffHash;
|
||||
|
||||
my $narDiffSize = (stat "$tmpdir/DIFF")[7];
|
||||
my $dstNarBz2Size = (stat $dstNarBz2)[7];
|
||||
|
||||
if ($narDiffSize >= $dstNarBz2Size) {
|
||||
print " rejecting; patch bigger than full archive\n";
|
||||
next;
|
||||
}
|
||||
|
||||
my $finalName =
|
||||
"$narDiffHash-$name-$closestVersion-to-$version.nar-bsdiff";
|
||||
|
||||
print " size $narDiffSize; full size $dstNarBz2Size\n";
|
||||
|
||||
if (-e "$patchesDir/$finalName") {
|
||||
print " not copying, already exists\n";
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
system("cp '$tmpdir/DIFF' '$patchesDir/$finalName.tmp'") == 0
|
||||
or die "cannot copy diff";
|
||||
|
||||
rename("$patchesDir/$finalName.tmp", "$patchesDir/$finalName")
|
||||
or die "cannot rename $patchesDir/$finalName.tmp";
|
||||
|
||||
}
|
||||
|
||||
# Add the patch to the manifest.
|
||||
addPatch \%dstPatches, $p,
|
||||
{ url => "$patchesURL/$finalName", hash => $narDiffHash
|
||||
, size => $narDiffSize
|
||||
, basePath => $closest, baseHash => $baseHash
|
||||
, narHash => $narHash, patchType => "nar-bsdiff"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Add in any potentially useful patches in the source (namely, those
|
||||
# patches that produce either paths in the destination or paths that
|
||||
# can be used as the base for other useful patches).
|
||||
|
||||
my $changed;
|
||||
do {
|
||||
# !!! we repeat this to reach the transitive closure; inefficient
|
||||
$changed = 0;
|
||||
|
||||
foreach my $p (keys %srcPatches) {
|
||||
my $patchList = $srcPatches{$p};
|
||||
|
||||
my $include = 0;
|
||||
|
||||
# Is path $p included in the destination? If so, include
|
||||
# patches that produce it.
|
||||
$include = 1 if (defined $dstNarFiles{$p});
|
||||
|
||||
# Is path $p a path that serves as a base for paths in the
|
||||
# destination? If so, include patches that produce it.
|
||||
foreach my $q (keys %dstPatches) {
|
||||
foreach my $patch (@{$dstPatches{$q}}) {
|
||||
# !!! check baseHash
|
||||
$include = 1 if ($p eq $patch->{basePath});
|
||||
}
|
||||
}
|
||||
|
||||
if ($include) {
|
||||
foreach my $patch (@{$patchList}) {
|
||||
$changed = 1 if addPatch \%dstPatches, $p, $patch;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} while $changed;
|
||||
|
||||
|
||||
# Rewrite the manifest of the destination (with the new patches).
|
||||
writeManifest "$dstDir/MANIFEST",
|
||||
\%dstNarFiles, \%dstPatches, \%dstSuccessors;
|
||||
Executable → Regular
+19
-3
@@ -8,18 +8,34 @@ if test -z "$nixExpr"; then
|
||||
fi
|
||||
|
||||
extraArgs=
|
||||
noLink=
|
||||
|
||||
for i in "$@"; do
|
||||
case "$i" in
|
||||
--no-link)
|
||||
noLink=1
|
||||
;;
|
||||
-*)
|
||||
extraArgs="$extraArgs $i"
|
||||
;;
|
||||
*)
|
||||
storeExpr=$(nix-instantiate "$i")
|
||||
for j in $storeExpr; do
|
||||
storeExprs=$(nix-instantiate "$i")
|
||||
for j in $storeExprs; do
|
||||
echo "store expression is $j" >&2
|
||||
done
|
||||
nix-store -qnfv $extraArgs $storeExpr
|
||||
outPaths=$(nix-store -qnfv $extraArgs $storeExprs)
|
||||
for j in $outPaths; do
|
||||
echo "$j"
|
||||
if test -z "$noLink"; then
|
||||
if test -L result; then
|
||||
rm result
|
||||
elif test -e result; then
|
||||
echo "cannot remove \`result' (not a symlink)"
|
||||
exit 1
|
||||
fi
|
||||
ln -s "$j" result
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Executable → Regular
+25
-4
@@ -2,6 +2,8 @@
|
||||
|
||||
use strict;
|
||||
|
||||
my $rootsDir = "@localstatedir@/nix/gcroots/channels";
|
||||
|
||||
|
||||
# Figure out the name of the `.nix-channels' file to use.
|
||||
my $home = $ENV{"HOME"};
|
||||
@@ -15,7 +17,7 @@ my @channels;
|
||||
# Reads the list of channels from the file $channelsList;
|
||||
sub readChannels {
|
||||
return if (!-f $channelsList);
|
||||
open CHANNELS, "<$channelsList" or die "cannot open `$channelsList'";
|
||||
open CHANNELS, "<$channelsList" or die "cannot open `$channelsList': $!";
|
||||
while (<CHANNELS>) {
|
||||
chomp;
|
||||
push @channels, $_;
|
||||
@@ -26,7 +28,7 @@ sub readChannels {
|
||||
|
||||
# Writes the list of channels to the file $channelsList;
|
||||
sub writeChannels {
|
||||
open CHANNELS, ">$channelsList" or die "cannot open `$channelsList'";
|
||||
open CHANNELS, ">$channelsList" or die "cannot open `$channelsList': $!";
|
||||
foreach my $url (@channels) {
|
||||
print CHANNELS "$url\n";
|
||||
}
|
||||
@@ -51,6 +53,10 @@ sub addChannel {
|
||||
sub update {
|
||||
readChannels;
|
||||
|
||||
# Get rid of all the old substitutes.
|
||||
system "@bindir@/nix-store --clear-substitutes";
|
||||
die "cannot clear substitutes" if ($? != 0);
|
||||
|
||||
# Pull cache manifests.
|
||||
foreach my $url (@channels) {
|
||||
print "pulling cache manifest from `$url'\n";
|
||||
@@ -79,18 +85,33 @@ sub update {
|
||||
"(import @datadir@/nix/corepkgs/channels/unpack.nix) " .
|
||||
"{inputs = $nixExpr; system = \"@system@\";}";
|
||||
|
||||
# Instantiate and realise it.
|
||||
# Instantiate the Nix expression.
|
||||
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
||||
or die "cannot instantiate Nix expression";
|
||||
chomp $storeExpr;
|
||||
|
||||
my $outPath = `nix-store -qnfB '$storeExpr'`
|
||||
# Register the store expression as a root of the garbage
|
||||
# collector.
|
||||
my $userName = getpwuid($<);
|
||||
die "who ARE you? go away" unless defined $userName;
|
||||
|
||||
my $rootFile = "$rootsDir/$userName.gcroot";
|
||||
my $tmpRootFile = "$rootsDir/$userName-tmp.gcroot";
|
||||
|
||||
open ROOT, ">$tmpRootFile" or die "cannot create `$tmpRootFile': $!";
|
||||
print ROOT "$storeExpr";
|
||||
close ROOT;
|
||||
|
||||
# Realise the store expression.
|
||||
my $outPath = `nix-store -qnf '$storeExpr'`
|
||||
or die "cannot realise store expression";
|
||||
chomp $outPath;
|
||||
|
||||
# Make it the default Nix expression for `nix-env'.
|
||||
system "@bindir@/nix-env --import '$outPath'";
|
||||
die "cannot pull set default Nix expression to `$outPath'" if ($? != 0);
|
||||
|
||||
rename $tmpRootFile, $rootFile or die "cannot rename `$tmpRootFile' to `$rootFile': $!";
|
||||
}
|
||||
|
||||
|
||||
|
||||
Executable → Regular
+22
-32
@@ -8,16 +8,24 @@ my $storeDir = "@storedir@";
|
||||
|
||||
my %alive;
|
||||
|
||||
my $keepSuccessors = 1;
|
||||
my $invert = 0;
|
||||
my $gcOper = "--delete";
|
||||
my $minAge = 0;
|
||||
|
||||
my @roots = ();
|
||||
|
||||
|
||||
# Parse the command line.
|
||||
foreach my $arg (@ARGV) {
|
||||
if ($arg eq "--no-successors") { $keepSuccessors = 0; }
|
||||
elsif ($arg eq "--invert") { $invert = 1; }
|
||||
for (my $i = 0; $i < scalar @ARGV; $i++) {
|
||||
my $arg = $ARGV[$i];
|
||||
if ($arg eq "--delete" || $arg eq "--print-live" || $arg eq "--print-dead") {
|
||||
$gcOper = $arg;
|
||||
}
|
||||
elsif ($arg eq "--min-age") {
|
||||
$i++;
|
||||
$minAge = undef;
|
||||
$minAge = $ARGV[$i];
|
||||
die "invalid minimum age" unless defined $minAge && $minAge =~ /^\d*$/;
|
||||
}
|
||||
else { die "unknown argument `$arg'" };
|
||||
}
|
||||
|
||||
@@ -68,33 +76,15 @@ sub findRoots {
|
||||
findRoots 1, $rootsDir;
|
||||
|
||||
|
||||
# Determine all store paths reachable from the roots.
|
||||
my $extraarg = "";
|
||||
if ($keepSuccessors) { $extraarg = "--include-successors"; };
|
||||
my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-store --query --requisites $extraarg @roots")
|
||||
or die "determining live paths";
|
||||
close WRITE;
|
||||
while (<READ>) {
|
||||
chomp;
|
||||
$alive{$_} = 1;
|
||||
if ($invert) { print "$_\n"; };
|
||||
# Run the collector with the roots we found.
|
||||
my $pid = open2(">&1", \*WRITE, "@bindir@/nix-store --gc $gcOper --min-age $minAge")
|
||||
or die "cannot run `nix-store --gc'";
|
||||
|
||||
foreach my $root (@roots) {
|
||||
print WRITE "$root\n";
|
||||
}
|
||||
close READ;
|
||||
|
||||
close WRITE;
|
||||
|
||||
waitpid $pid, 0;
|
||||
$? == 0 or die "determining live paths";
|
||||
|
||||
exit 0 if ($invert);
|
||||
|
||||
|
||||
# Using that information, find all store paths *not* reachable from
|
||||
# the roots.
|
||||
opendir(DIR, $storeDir) or die "cannot open directory $storeDir: $!";
|
||||
foreach my $name (readdir DIR) {
|
||||
next if ($name eq "." || $name eq "..");
|
||||
$name = "$storeDir/$name";
|
||||
if (!$alive{$name}) {
|
||||
print "$name\n";
|
||||
}
|
||||
}
|
||||
closedir DIR;
|
||||
$? == 0 or die "`nix-store --gc' failed";
|
||||
+35
-16
@@ -1,38 +1,57 @@
|
||||
#! @shell@ -e
|
||||
|
||||
url=$1
|
||||
hash=$2
|
||||
|
||||
if test -z "$url"; then
|
||||
echo "syntax: nix-prefetch-url URL" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
|
||||
tmpPath1=@storedir@/nix-prefetch-url-$$
|
||||
# Determine the hash, unless it was given.
|
||||
if test -z "$hash"; then
|
||||
|
||||
# Perform the checkout.
|
||||
@curl@ --fail --location --max-redirs 20 "$url" > $tmpPath1
|
||||
# !!! race
|
||||
tmpPath1=@storedir@/nix-prefetch-url-$$
|
||||
|
||||
# Compute the hash.
|
||||
hash=$(@bindir@/nix-hash --flat $tmpPath1)
|
||||
echo "hash is $hash" >&2
|
||||
# Test whether we have write permission in the store. If not,
|
||||
# fetch to /tmp and don't copy to the store. This is a hack to
|
||||
# make this script at least work somewhat in setuid installations.
|
||||
if ! touch $tmpPath1 2> /dev/null; then
|
||||
echo "(cannot write to the store, result won't be cached)" >&2
|
||||
dummyMode=1
|
||||
tmpPath1=/tmp/nix-prefetch-url-$$ # !!! security?
|
||||
fi
|
||||
|
||||
# Rename it so that the fetchsvn builder can find it.
|
||||
tmpPath2=@storedir@/nix-prefetch-url-$hash
|
||||
test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
||||
# Perform the checkout.
|
||||
@curl@ --fail --location --max-redirs 20 "$url" > $tmpPath1
|
||||
|
||||
# Create a Nix expression that does a fetchsvn.
|
||||
# Compute the hash.
|
||||
hash=$(@bindir@/nix-hash --flat $tmpPath1)
|
||||
if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
|
||||
|
||||
# Rename it so that the fetchurl builder can find it.
|
||||
if test "$dummyMode" != 1; then
|
||||
tmpPath2=@storedir@/nix-prefetch-url-$hash
|
||||
test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Create a Nix expression that does a fetchurl.
|
||||
storeExpr=$( \
|
||||
echo "(import @datadir@/nix/corepkgs/fetchurl) \
|
||||
echo "(import @datadir@/nix/corepkgs/fetchurl) \
|
||||
{url = $url; md5 = \"$hash\"; system = \"@system@\";}" \
|
||||
| @bindir@/nix-instantiate -)
|
||||
| @bindir@/nix-instantiate -)
|
||||
|
||||
# Realise it.
|
||||
finalPath=$(@bindir@/nix-store -qnB --force-realise $storeExpr)
|
||||
|
||||
if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
|
||||
|
||||
echo "path is $finalPath" >&2
|
||||
|
||||
rm -rf $tmpPath2 || true
|
||||
if test -n "$tmpPath1" -o -n "$tmpPath2"; then
|
||||
rm -rf $tmpPath1 $tmpPath2 || true
|
||||
fi
|
||||
|
||||
echo $hash
|
||||
|
||||
|
||||
+40
-41
@@ -10,53 +10,52 @@ do { $tmpdir = tmpnam(); }
|
||||
until mkdir $tmpdir, 0777;
|
||||
|
||||
my $manifest = "$tmpdir/manifest";
|
||||
my $confFile = "@sysconfdir@/nix/prebuilts.conf";
|
||||
|
||||
#END { unlink $manifest; rmdir $tmpdir; }
|
||||
END { unlink $manifest; rmdir $tmpdir; }
|
||||
|
||||
|
||||
# Obtain URLs either from the command line or from a configuration file.
|
||||
my %storePaths2urls;
|
||||
my %urls2hashes;
|
||||
my %narFiles;
|
||||
my %patches;
|
||||
my %successors;
|
||||
sub doURL {
|
||||
|
||||
sub processURL {
|
||||
my $url = shift;
|
||||
processURL $manifest, $url, \%storePaths2urls, \%urls2hashes, \%successors;
|
||||
|
||||
$url =~ s/\/$//;
|
||||
print "obtaining list of Nix archives at $url...\n";
|
||||
|
||||
system("@curl@ --fail --silent --show-error --location --max-redirs 20 " .
|
||||
"'$url' > '$manifest'") == 0
|
||||
or die "curl failed: $?";
|
||||
|
||||
readManifest $manifest, \%narFiles, \%patches, \%successors;
|
||||
|
||||
my $baseName = "unnamed";
|
||||
if ($url =~ /\/([^\/]+)\/[^\/]+$/) { # get the forelast component
|
||||
$baseName = $1;
|
||||
}
|
||||
|
||||
my $hash = `@bindir@/nix-hash --flat '$manifest'`
|
||||
or die "cannot hash `$manifest'";
|
||||
chomp $hash;
|
||||
|
||||
my $finalPath = "@localstatedir@/nix/manifests/$baseName-$hash.nixmanifest";
|
||||
|
||||
system("mv '$manifest' '$finalPath'") == 0
|
||||
or die "cannot move `$manifest' to `$finalPath";
|
||||
}
|
||||
if (scalar @ARGV > 0) {
|
||||
while (@ARGV) {
|
||||
my $url = shift @ARGV;
|
||||
doURL $url;
|
||||
}
|
||||
} else {
|
||||
open CONFFILE, "<$confFile";
|
||||
while (<CONFFILE>) {
|
||||
chomp;
|
||||
if (/^\s*(\S+)\s*(\#.*)?$/) {
|
||||
my $url = $1;
|
||||
doURL $url;
|
||||
}
|
||||
}
|
||||
close CONFFILE;
|
||||
|
||||
while (@ARGV) {
|
||||
my $url = shift @ARGV;
|
||||
processURL $url;
|
||||
}
|
||||
|
||||
|
||||
my $size = scalar (keys %storePaths2urls);
|
||||
my $size = scalar (keys %narFiles);
|
||||
print "$size store paths in manifest\n";
|
||||
|
||||
|
||||
# Instantiate a store expression that builds the substitute program
|
||||
# (the program that fetches URLs and unpacks them into the store).
|
||||
my $nixExpr =
|
||||
"(import @datadir@/nix/corepkgs/nix-pull) " .
|
||||
"{system = \"@system@\";}";
|
||||
|
||||
print STDERR "instantiating store expression...\n";
|
||||
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
||||
or die "cannot instantiate Nix expression";
|
||||
chomp $storeExpr;
|
||||
|
||||
|
||||
# Register all substitutes.
|
||||
print STDERR "registering substitutes...\n";
|
||||
|
||||
@@ -65,13 +64,13 @@ my $pid = open2(\*READ, \*WRITE, "@bindir@/nix-store --substitute")
|
||||
|
||||
close READ;
|
||||
|
||||
foreach my $storePath (keys %storePaths2urls) {
|
||||
print WRITE "$storePath\n";
|
||||
print WRITE "$storeExpr\n";
|
||||
print WRITE "/fetch\n";
|
||||
print WRITE "2\n";
|
||||
print WRITE "$storePaths2urls{$storePath}\n";
|
||||
print WRITE "$urls2hashes{$storePaths2urls{$storePath}}\n";
|
||||
foreach my $storePath (keys %narFiles) {
|
||||
my $narFileList = $narFiles{$storePath};
|
||||
foreach my $narFile (@{$narFileList}) {
|
||||
print WRITE "$storePath\n";
|
||||
print WRITE "@libexecdir@/nix/download-using-manifests.pl\n";
|
||||
print WRITE "0\n";
|
||||
}
|
||||
}
|
||||
|
||||
close WRITE;
|
||||
|
||||
+40
-27
@@ -2,6 +2,7 @@
|
||||
|
||||
use strict;
|
||||
use POSIX qw(tmpnam);
|
||||
use readmanifest;
|
||||
|
||||
my $tmpdir;
|
||||
do { $tmpdir = tmpnam(); }
|
||||
@@ -25,7 +26,7 @@ my $manifest_put_url = shift @ARGV;
|
||||
|
||||
# From the given store expressions, determine the requisite store
|
||||
# paths.
|
||||
my %storepaths;
|
||||
my %storePaths;
|
||||
|
||||
foreach my $storeexpr (@ARGV) {
|
||||
die unless $storeexpr =~ /^\//;
|
||||
@@ -39,12 +40,12 @@ foreach my $storeexpr (@ARGV) {
|
||||
while (<PATHS>) {
|
||||
chomp;
|
||||
die "bad: $_" unless /^\//;
|
||||
$storepaths{$_} = "";
|
||||
$storePaths{$_} = "";
|
||||
}
|
||||
close PATHS;
|
||||
}
|
||||
|
||||
my @storepaths = keys %storepaths;
|
||||
my @storePaths = keys %storePaths;
|
||||
|
||||
|
||||
# For each path, create a Nix expression that turns the path into
|
||||
@@ -52,14 +53,14 @@ my @storepaths = keys %storepaths;
|
||||
open NIX, ">$nixfile";
|
||||
print NIX "[";
|
||||
|
||||
foreach my $storepath (@storepaths) {
|
||||
die unless ($storepath =~ /\/[0-9a-z]{32}.*$/);
|
||||
foreach my $storePath (@storePaths) {
|
||||
die unless ($storePath =~ /\/[0-9a-z]{32}.*$/);
|
||||
|
||||
# Construct a Nix expression that creates a Nix archive.
|
||||
my $nixexpr =
|
||||
"((import @datadir@/nix/corepkgs/nar/nar.nix) " .
|
||||
# !!! $storepath should be represented as a closure
|
||||
"{path = \"$storepath\"; system = \"@system@\";}) ";
|
||||
# !!! $storePath should be represented as a closure
|
||||
"{path = \"$storePath\"; system = \"@system@\";}) ";
|
||||
|
||||
print NIX $nixexpr;
|
||||
}
|
||||
@@ -92,7 +93,7 @@ while (scalar @tmp > 0) {
|
||||
my @tmp2 = @tmp[0..$n - 1];
|
||||
@tmp = @tmp[$n..scalar @tmp - 1];
|
||||
|
||||
system "@bindir@/nix-store --realise -B @tmp2 > /dev/null";
|
||||
system "@bindir@/nix-store --realise @tmp2 > /dev/null";
|
||||
if ($?) { die "`nix-store --realise' failed"; }
|
||||
|
||||
open NARPATHS, "@bindir@/nix-store --query --list @tmp2 |" or die "cannot run nix";
|
||||
@@ -108,53 +109,65 @@ while (scalar @tmp > 0) {
|
||||
# Create the manifest.
|
||||
print STDERR "creating manifest...\n";
|
||||
|
||||
open MANIFEST, ">$manifest";
|
||||
my %narFiles;
|
||||
my %patches;
|
||||
my %successors;
|
||||
|
||||
my @nararchives;
|
||||
for (my $n = 0; $n < scalar @storepaths; $n++) {
|
||||
my $storepath = $storepaths[$n];
|
||||
for (my $n = 0; $n < scalar @storePaths; $n++) {
|
||||
my $storePath = $storePaths[$n];
|
||||
my $nardir = $narpaths[$n];
|
||||
|
||||
$storepath =~ /\/([^\/]*)$/;
|
||||
$storePath =~ /\/([^\/]*)$/;
|
||||
my $basename = $1;
|
||||
defined $basename or die;
|
||||
|
||||
my $narname = "$basename.nar.bz2";
|
||||
|
||||
my $narfile = "$nardir/$narname";
|
||||
(-f $narfile) or die "narfile for $storepath not found";
|
||||
(-f $narfile) or die "narfile for $storePath not found";
|
||||
push @nararchives, $narfile;
|
||||
|
||||
open MD5, "$nardir/md5" or die "cannot open hash";
|
||||
my $hash = <MD5>;
|
||||
chomp $hash;
|
||||
$hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
||||
open MD5, "$nardir/narbz2-hash" or die "cannot open narbz2-hash";
|
||||
my $narbz2Hash = <MD5>;
|
||||
chomp $narbz2Hash;
|
||||
$narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
||||
close MD5;
|
||||
|
||||
print MANIFEST "{\n";
|
||||
print MANIFEST " StorePath: $storepath\n";
|
||||
print MANIFEST " NarURL: $archives_get_url/$narname\n";
|
||||
print MANIFEST " MD5: $hash\n";
|
||||
open MD5, "$nardir/nar-hash" or die "cannot open nar-hash";
|
||||
my $narHash = <MD5>;
|
||||
chomp $narHash;
|
||||
$narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
||||
close MD5;
|
||||
|
||||
my $narbz2Size = (stat $narfile)[7];
|
||||
|
||||
if ($storepath =~ /\.store$/) {
|
||||
open PREDS, "@bindir@/nix-store --query --predecessors $storepath |" or die "cannot run nix";
|
||||
$narFiles{$storePath} = [
|
||||
{ url => $archives_get_url/$narname
|
||||
, hash => $narbz2Hash
|
||||
, size => $narbz2Size
|
||||
, narHash => $narHash
|
||||
}
|
||||
];
|
||||
|
||||
if ($storePath =~ /\.store$/) {
|
||||
open PREDS, "@bindir@/nix-store --query --predecessors $storePath |" or die "cannot run nix";
|
||||
while (<PREDS>) {
|
||||
chomp;
|
||||
die unless (/^\//);
|
||||
my $pred = $_;
|
||||
# Only include predecessors that are themselves being
|
||||
# pushed.
|
||||
if (defined $storepaths{$pred}) {
|
||||
print MANIFEST " SuccOf: $pred\n";
|
||||
if (defined $storePaths{$pred}) {
|
||||
$successors{$pred} = $storePath;
|
||||
}
|
||||
}
|
||||
close PREDS;
|
||||
}
|
||||
|
||||
print MANIFEST "}\n";
|
||||
}
|
||||
|
||||
close MANIFEST;
|
||||
writeManifest $manifest, \%narFiles, \%patches, \%successors;
|
||||
|
||||
|
||||
# Upload the archives.
|
||||
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
|
||||
{ my $ofh = select STDOUT;
|
||||
$| = 1;
|
||||
select $ofh;
|
||||
}
|
||||
|
||||
#my @paths = ("/nix/store/caef3a49150506d233f474322a824e50-glibc-2.3.3", "/nix/store/a8a9d585d1ad4b1bc911be7743b3b996-glibc-2.3.3");
|
||||
my @paths = ("/nix/store");
|
||||
|
||||
my $tmpfile = "/tmp/nix-optimise-hash-list";
|
||||
#my $tmpfile = "/data/nix-optimise-hash-list";
|
||||
|
||||
system("find @paths -type f -print0 | xargs -0 md5sum -- > $tmpfile") == 0
|
||||
or die "cannot hash store files";
|
||||
|
||||
system("sort $tmpfile > $tmpfile.sorted") == 0
|
||||
or die "cannot sort list";
|
||||
|
||||
open LIST, "<$tmpfile.sorted" or die;
|
||||
|
||||
my $prevFile;
|
||||
my $prevHash;
|
||||
|
||||
my $totalSpace = 0;
|
||||
my $savedSpace = 0;
|
||||
|
||||
my $files = 0;
|
||||
|
||||
while (<LIST>) {
|
||||
# print "D";
|
||||
/^([0-9a-f]*)\s+(.*)$/ or die;
|
||||
my $curFile = $2;
|
||||
my $curHash = $1;
|
||||
|
||||
# print "A";
|
||||
my $fileSize = (stat $curFile)[7];
|
||||
# print "B";
|
||||
# my $fileSize = 1;
|
||||
$totalSpace += $fileSize;
|
||||
|
||||
if (defined $prevHash && $curHash eq $prevHash) {
|
||||
|
||||
# print "$curFile = $prevFile\n";
|
||||
|
||||
$savedSpace += $fileSize;
|
||||
|
||||
} else {
|
||||
$prevFile = $curFile;
|
||||
$prevHash = $curHash;
|
||||
}
|
||||
|
||||
print "." if ($files++ % 100 == 0);
|
||||
#print ".";
|
||||
|
||||
# print "C";
|
||||
}
|
||||
|
||||
print "\n";
|
||||
|
||||
print "total space = $totalSpace\n";
|
||||
print "saved space = $savedSpace\n";
|
||||
my $savings = ($savedSpace / $totalSpace) * 100.0;
|
||||
print "savings = $savings %\n";
|
||||
|
||||
|
||||
close LIST;
|
||||
+153
-32
@@ -1,27 +1,54 @@
|
||||
use strict;
|
||||
|
||||
sub processURL {
|
||||
|
||||
sub addPatch {
|
||||
my $patches = shift;
|
||||
my $storePath = shift;
|
||||
my $patch = shift;
|
||||
|
||||
$$patches{$storePath} = []
|
||||
unless defined $$patches{$storePath};
|
||||
|
||||
my $patchList = $$patches{$storePath};
|
||||
|
||||
my $found = 0;
|
||||
foreach my $patch2 (@{$patchList}) {
|
||||
if ($patch2->{url} eq $patch->{url}) {
|
||||
if ($patch2->{hash} eq $patch->{hash}) {
|
||||
$found = 1 if ($patch2->{basePath} eq $patch->{basePath});
|
||||
} else {
|
||||
die "conflicting hashes for URL $patch->{url}, " .
|
||||
"namely $patch2->{hash} and $patch->{hash}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
push @{$patchList}, $patch if !$found;
|
||||
|
||||
return !$found;
|
||||
}
|
||||
|
||||
|
||||
sub readManifest {
|
||||
my $manifest = shift;
|
||||
my $url = shift;
|
||||
my $storePaths2urls = shift;
|
||||
my $urls2hashes = shift;
|
||||
my $narFiles = shift;
|
||||
my $patches = shift;
|
||||
my $successors = shift;
|
||||
|
||||
$url =~ s/\/$//;
|
||||
print "obtaining list of Nix archives at $url...\n";
|
||||
|
||||
system("@curl@ --fail --silent --show-error --location --max-redirs 20 " .
|
||||
"'$url' > '$manifest' 2> /dev/null") == 0
|
||||
or die "curl failed: $?";
|
||||
|
||||
open MANIFEST, "<$manifest";
|
||||
|
||||
my $inside = 0;
|
||||
my $type;
|
||||
|
||||
my $storePath;
|
||||
my $narurl;
|
||||
my $url;
|
||||
my $hash;
|
||||
my $size;
|
||||
my @preds;
|
||||
my $basePath;
|
||||
my $baseHash;
|
||||
my $patchType;
|
||||
my $narHash;
|
||||
|
||||
while (<MANIFEST>) {
|
||||
chomp;
|
||||
@@ -29,39 +56,82 @@ sub processURL {
|
||||
next if (/^$/);
|
||||
|
||||
if (!$inside) {
|
||||
if (/^\{$/) {
|
||||
|
||||
if (/^\s*(\w*)\s*\{$/) {
|
||||
$type = $1;
|
||||
$type = "narfile" if $type eq "";
|
||||
$inside = 1;
|
||||
undef $storePath;
|
||||
undef $narurl;
|
||||
undef $url;
|
||||
undef $hash;
|
||||
undef $size;
|
||||
@preds = ();
|
||||
undef $narHash;
|
||||
undef $basePath;
|
||||
undef $baseHash;
|
||||
undef $patchType;
|
||||
}
|
||||
else { die "bad line: $_"; }
|
||||
|
||||
} else {
|
||||
|
||||
if (/^\}$/) {
|
||||
$inside = 0;
|
||||
|
||||
$$storePaths2urls{$storePath} = $narurl;
|
||||
$$urls2hashes{$narurl} = $hash;
|
||||
if ($type eq "narfile") {
|
||||
|
||||
foreach my $p (@preds) {
|
||||
$$successors{$p} = $storePath;
|
||||
$$narFiles{$storePath} = []
|
||||
unless defined $$narFiles{$storePath};
|
||||
|
||||
my $narFileList = $$narFiles{$storePath};
|
||||
|
||||
my $found = 0;
|
||||
foreach my $narFile (@{$narFileList}) {
|
||||
if ($narFile->{url} eq $url) {
|
||||
if ($narFile->{hash} eq $hash) {
|
||||
$found = 1;
|
||||
} else {
|
||||
die "conflicting hashes for URL $url, " .
|
||||
"namely $narFile->{hash} and $hash";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
push @{$narFileList},
|
||||
{ url => $url, hash => $hash, size => $size
|
||||
, narHash => $narHash
|
||||
};
|
||||
}
|
||||
|
||||
foreach my $p (@preds) {
|
||||
$$successors{$p} = $storePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
elsif ($type eq "patch") {
|
||||
addPatch $patches, $storePath,
|
||||
{ url => $url, hash => $hash, size => $size
|
||||
, basePath => $basePath, baseHash => $baseHash
|
||||
, narHash => $narHash, patchType => $patchType
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) {
|
||||
$storePath = $1;
|
||||
}
|
||||
elsif (/^\s*NarURL:\s*(\S+)\s*$/) {
|
||||
$narurl = $1;
|
||||
}
|
||||
elsif (/^\s*MD5:\s*(\S+)\s*$/) {
|
||||
$hash = $1;
|
||||
}
|
||||
elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) {
|
||||
push @preds, $1;
|
||||
}
|
||||
else { die "bad line: $_"; }
|
||||
|
||||
elsif (/^\s*StorePath:\s*(\/\S+)\s*$/) { $storePath = $1; }
|
||||
elsif (/^\s*Hash:\s*(\S+)\s*$/) { $hash = $1; }
|
||||
elsif (/^\s*URL:\s*(\S+)\s*$/) { $url = $1; }
|
||||
elsif (/^\s*Size:\s*(\d+)\s*$/) { $size = $1; }
|
||||
elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) { push @preds, $1; }
|
||||
elsif (/^\s*BasePath:\s*(\/\S+)\s*$/) { $basePath = $1; }
|
||||
elsif (/^\s*BaseHash:\s*(\S+)\s*$/) { $baseHash = $1; }
|
||||
elsif (/^\s*Type:\s*(\S+)\s*$/) { $patchType = $1; }
|
||||
elsif (/^\s*NarHash:\s*(\S+)\s*$/) { $narHash = $1; }
|
||||
|
||||
# Compatibility;
|
||||
elsif (/^\s*NarURL:\s*(\S+)\s*$/) { $url = $1; }
|
||||
elsif (/^\s*MD5:\s*(\S+)\s*$/) { $hash = $1; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +139,55 @@ sub processURL {
|
||||
}
|
||||
|
||||
|
||||
sub writeManifest
|
||||
{
|
||||
my $manifest = shift;
|
||||
my $narFiles = shift;
|
||||
my $patches = shift;
|
||||
my $successors = shift;
|
||||
|
||||
open MANIFEST, ">$manifest.tmp"; # !!! check exclusive
|
||||
|
||||
foreach my $storePath (keys %{$narFiles}) {
|
||||
my $narFileList = $$narFiles{$storePath};
|
||||
foreach my $narFile (@{$narFileList}) {
|
||||
print MANIFEST "{\n";
|
||||
print MANIFEST " StorePath: $storePath\n";
|
||||
print MANIFEST " NarURL: $narFile->{url}\n";
|
||||
print MANIFEST " MD5: $narFile->{hash}\n";
|
||||
print MANIFEST " NarHash: $narFile->{narHash}\n";
|
||||
print MANIFEST " Size: $narFile->{size}\n";
|
||||
foreach my $p (keys %{$successors}) { # !!! quadratic
|
||||
if ($$successors{$p} eq $storePath) {
|
||||
print MANIFEST " SuccOf: $p\n";
|
||||
}
|
||||
}
|
||||
print MANIFEST "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $storePath (keys %{$patches}) {
|
||||
my $patchList = $$patches{$storePath};
|
||||
foreach my $patch (@{$patchList}) {
|
||||
print MANIFEST "patch {\n";
|
||||
print MANIFEST " StorePath: $storePath\n";
|
||||
print MANIFEST " NarURL: $patch->{url}\n";
|
||||
print MANIFEST " MD5: $patch->{hash}\n";
|
||||
print MANIFEST " NarHash: $patch->{narHash}\n";
|
||||
print MANIFEST " Size: $patch->{size}\n";
|
||||
print MANIFEST " BasePath: $patch->{basePath}\n";
|
||||
print MANIFEST " BaseHash: $patch->{baseHash}\n";
|
||||
print MANIFEST " Type: $patch->{patchType}\n";
|
||||
print MANIFEST "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
close MANIFEST;
|
||||
|
||||
rename("$manifest.tmp", $manifest)
|
||||
or die "cannot rename $manifest.tmp: $!";
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#! /usr/bin/perl -w -I/home/eelco/nix/scripts
|
||||
|
||||
use strict;
|
||||
use readmanifest;
|
||||
|
||||
for my $p (@ARGV) {
|
||||
|
||||
my %narFiles;
|
||||
my %patches;
|
||||
my %successors;
|
||||
|
||||
readManifest $p,
|
||||
\%narFiles, \%patches, \%successors;
|
||||
|
||||
%patches = ();
|
||||
|
||||
writeManifest $p,
|
||||
\%narFiles, \%patches, \%successors;
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#! /usr/bin/perl -w -I.
|
||||
|
||||
use strict;
|
||||
use readmanifest;
|
||||
|
||||
die unless scalar @ARGV == 2;
|
||||
|
||||
my $cache = $ARGV[0];
|
||||
my $manifest = $ARGV[1];
|
||||
my %narFiles;
|
||||
my %patches;
|
||||
my %successors;
|
||||
|
||||
readManifest $manifest, \%narFiles, \%patches, \%successors;
|
||||
|
||||
foreach my $storePath (keys %narFiles) {
|
||||
my $narFileList = $narFiles{$storePath};
|
||||
|
||||
foreach my $narFile (@{$narFileList}) {
|
||||
if (!defined $narFile->{size} or
|
||||
!defined $narFile->{narHash})
|
||||
{
|
||||
$narFile->{url} =~ /\/([^\/]+)$/;
|
||||
die unless defined $1;
|
||||
my $fn = "$cache/$1";
|
||||
|
||||
my @info = stat $fn or die;
|
||||
$narFile->{size} = $info[7];
|
||||
|
||||
my $narHash;
|
||||
my $hashFile = "$fn.NARHASH";
|
||||
if (-e $hashFile) {
|
||||
open HASH, "<$hashFile" or die;
|
||||
$narHash = <HASH>;
|
||||
close HASH;
|
||||
} else {
|
||||
print "$fn\n";
|
||||
$narHash = `bunzip2 < '$fn' | nix-hash --flat /dev/stdin` or die;
|
||||
open HASH, ">$hashFile" or die;
|
||||
print HASH $narHash;
|
||||
close HASH;
|
||||
}
|
||||
chomp $narHash;
|
||||
$narFile->{narHash} = $narHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! -e "$manifest.backup") {
|
||||
system "mv --reply=no '$manifest' '$manifest.backup'";
|
||||
}
|
||||
|
||||
writeManifest $manifest, \%narFiles, \%patches, \%successors;
|
||||
+14
-1
@@ -1,2 +1,15 @@
|
||||
SUBDIRS = bin2c boost libutil libstore libmain nix-store nix-hash \
|
||||
libexpr nix-instantiate nix-env log2xml
|
||||
libexpr nix-instantiate nix-env log2xml bsdiff-4.2
|
||||
|
||||
EXTRA_DIST = aterm-helper.pl
|
||||
|
||||
SETUID_PROGS = nix-store nix-instantiate nix-env
|
||||
install-exec-hook:
|
||||
if SETUID_HACK
|
||||
if HAVE_SETRESUID
|
||||
cd $(DESTDIR)$(bindir) && chown @NIX_USER@ $(SETUID_PROGS) \
|
||||
&& chgrp @NIX_GROUP@ $(SETUID_PROGS) && chmod ug+s $(SETUID_PROGS)
|
||||
else
|
||||
cd $(DESTDIR)$(bindir) && chown root $(SETUID_PROGS) && chmod u+s $(SETUID_PROGS)
|
||||
endif
|
||||
endif
|
||||
Executable
+143
@@ -0,0 +1,143 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
# This program generates C/C++ code for efficiently manipulating
|
||||
# ATerms. It generates functions to build and match ATerms according
|
||||
# to a set of constructor definitions defined in a file read from
|
||||
# standard input. A constructor is defined by a line with the
|
||||
# following format:
|
||||
#
|
||||
# SYM | ARGS | TYPE | FUN?
|
||||
#
|
||||
# where SYM is the name of the constructor, ARGS is a
|
||||
# whitespace-separated list of argument types, TYPE is the type of the
|
||||
# resulting ATerm (which should be `ATerm' or a type synonym for
|
||||
# `ATerm'), and the optional FUN is used to construct the names of the
|
||||
# build and match functions (it defaults to SYM; overriding it is
|
||||
# useful if there are overloaded constructors, e.g., with different
|
||||
# arities). Note that SYM may be empty.
|
||||
#
|
||||
# A line of the form
|
||||
#
|
||||
# VAR = EXPR
|
||||
#
|
||||
# causes a ATerm variable to be generated that is initialised to the
|
||||
# value EXPR.
|
||||
#
|
||||
# Finally, a line of the form
|
||||
#
|
||||
# init NAME
|
||||
#
|
||||
# causes the initialisation function to be called `NAME'. This
|
||||
# function must be called before any of the build/match functions or
|
||||
# the generated variables are used.
|
||||
|
||||
die if scalar @ARGV != 2;
|
||||
|
||||
my $syms = "";
|
||||
my $init = "";
|
||||
my $initFun = "init";
|
||||
|
||||
open HEADER, ">$ARGV[0]";
|
||||
open IMPL, ">$ARGV[1]";
|
||||
|
||||
while (<STDIN>) {
|
||||
next if (/^\s*$/);
|
||||
|
||||
if (/^\s*(\w*)\s*\|([^\|]*)\|\s*(\w+)\s*\|\s*(\w+)?/) {
|
||||
my $const = $1;
|
||||
my @types = split ' ', $2;
|
||||
my $result = $3;
|
||||
my $funname = $4;
|
||||
$funname = $const unless defined $funname;
|
||||
|
||||
my $formals = "";
|
||||
my $formals2 = "";
|
||||
my $args = "";
|
||||
my $unpack = "";
|
||||
my $n = 1;
|
||||
foreach my $type (@types) {
|
||||
$args .= ", ";
|
||||
if ($type eq "string") {
|
||||
# $args .= "(ATerm) ATmakeAppl0(ATmakeAFun((char *) e$n, 0, ATtrue))";
|
||||
# $type = "const char *";
|
||||
$type = "ATerm";
|
||||
$args .= "e$n";
|
||||
# !!! in the matcher, we should check that the
|
||||
# argument is a string (i.e., a nullary application).
|
||||
} elsif ($type eq "int") {
|
||||
$args .= "(ATerm) ATmakeInt(e$n)";
|
||||
} elsif ($type eq "ATermList" || $type eq "ATermBlob") {
|
||||
$args .= "(ATerm) e$n";
|
||||
} else {
|
||||
$args .= "e$n";
|
||||
}
|
||||
$formals .= ", " if $formals ne "";
|
||||
$formals .= "$type e$n";
|
||||
$formals2 .= ", ";
|
||||
$formals2 .= "$type & e$n";
|
||||
my $m = $n - 1;
|
||||
# !!! more checks here
|
||||
if ($type eq "int") {
|
||||
$unpack .= " e$n = ATgetInt((ATermInt) ATgetArgument(e, $m));\n";
|
||||
} elsif ($type eq "ATermList") {
|
||||
$unpack .= " e$n = (ATermList) ATgetArgument(e, $m);\n";
|
||||
} elsif ($type eq "ATermBlob") {
|
||||
$unpack .= " e$n = (ATermBlob) ATgetArgument(e, $m);\n";
|
||||
} else {
|
||||
$unpack .= " e$n = ATgetArgument(e, $m);\n";
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
|
||||
my $arity = scalar @types;
|
||||
|
||||
print HEADER "extern AFun sym$funname;\n\n";
|
||||
|
||||
print IMPL "AFun sym$funname = 0;\n";
|
||||
|
||||
print HEADER "static inline $result make$funname($formals) {\n";
|
||||
print HEADER " return (ATerm) ATmakeAppl$arity(sym$funname$args);\n";
|
||||
print HEADER "}\n\n";
|
||||
|
||||
print HEADER "#ifdef __cplusplus\n";
|
||||
print HEADER "static inline bool match$funname(ATerm e$formals2) {\n";
|
||||
print HEADER " if (ATgetType(e) != AT_APPL || ATgetAFun(e) != sym$funname) return false;\n";
|
||||
print HEADER "$unpack";
|
||||
print HEADER " return true;\n";
|
||||
print HEADER "}\n";
|
||||
print HEADER "#endif\n\n\n";
|
||||
|
||||
$init .= " sym$funname = ATmakeAFun(\"$const\", $arity, ATfalse);\n";
|
||||
$init .= " ATprotectAFun(sym$funname);\n";
|
||||
}
|
||||
|
||||
elsif (/^\s*(\w+)\s*=\s*(.*)$/) {
|
||||
my $name = $1;
|
||||
my $value = $2;
|
||||
print HEADER "extern ATerm $name;\n";
|
||||
print IMPL "ATerm $name = 0;\n";
|
||||
$init .= " $name = $value;\n";
|
||||
}
|
||||
|
||||
elsif (/^\s*init\s+(\w+)\s*$/) {
|
||||
$initFun = $1;
|
||||
}
|
||||
|
||||
else {
|
||||
die "bad line: `$_'";
|
||||
}
|
||||
}
|
||||
|
||||
print HEADER "void $initFun();\n\n";
|
||||
|
||||
print HEADER "static inline const char * aterm2String(ATerm t) {\n";
|
||||
print HEADER " return (const char *) ATgetName(ATgetAFun(t));\n";
|
||||
print HEADER "}\n\n";
|
||||
|
||||
print IMPL "\n";
|
||||
print IMPL "void $initFun() {\n";
|
||||
print IMPL "$init";
|
||||
print IMPL "}\n";
|
||||
|
||||
close HEADER;
|
||||
close IMPL;
|
||||
@@ -0,0 +1,121 @@
|
||||
BSD Protection License
|
||||
February 2002
|
||||
|
||||
Preamble
|
||||
--------
|
||||
|
||||
The Berkeley Software Distribution ("BSD") license has proven very effective
|
||||
over the years at allowing for a wide spread of work throughout both
|
||||
commercial and non-commercial products. For programmers whose primary
|
||||
intention is to improve the general quality of available software, it is
|
||||
arguable that there is no better license than the BSD license, as it
|
||||
permits improvements to be used wherever they will help, without idealogical
|
||||
or metallic constraint.
|
||||
|
||||
This is of particular value to those who produce reference implementations
|
||||
of proposed standards: The case of TCP/IP clearly illustrates that freely
|
||||
and universally available implementations leads the rapid acceptance of
|
||||
standards -- often even being used instead of a de jure standard (eg, OSI
|
||||
network models).
|
||||
|
||||
With the rapid proliferation of software licensed under the GNU General
|
||||
Public License, however, the continued success of this role is called into
|
||||
question. Given that the inclusion of a few lines of "GPL-tainted" work
|
||||
into a larger body of work will result in restricted distribution -- and
|
||||
given that further work will likely build upon the "tainted" portions,
|
||||
making them difficult to remove at a future date -- there are inevitable
|
||||
circumstances where authors would, in order to protect their goal of
|
||||
providing for the widespread usage of their work, wish to guard against
|
||||
such "GPL-taint".
|
||||
|
||||
In addition, one can imagine that companies which operate by producing and
|
||||
selling (possibly closed-source) code would wish to protect themselves
|
||||
against the rise of a GPL-licensed competitor. While under existing
|
||||
licenses this would mean not releasing their code under any form of open
|
||||
license, if a license existed under which they could incorporate any
|
||||
improvements back into their own (commercial) products then they might be
|
||||
far more willing to provide for non-closed distribution.
|
||||
|
||||
For the above reasons, we put forth this "BSD Protection License": A
|
||||
license designed to retain the freedom granted by the BSD license to use
|
||||
licensed works in a wide variety of settings, both non-commercial and
|
||||
commercial, while protecting the work from having future contributors
|
||||
restrict that freedom.
|
||||
|
||||
The precise terms and conditions for copying, distribution, and
|
||||
modification follow.
|
||||
|
||||
BSD PROTECTION LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
|
||||
----------------------------------------------------------------
|
||||
|
||||
0. Definitions.
|
||||
a) "Program", below, refers to any program or work distributed under
|
||||
the terms of this license.
|
||||
b) A "work based on the Program", below, refers to either the Program
|
||||
or any derivative work under copyright law.
|
||||
c) "Modification", below, refers to the act of creating derivative works.
|
||||
d) "You", below, refers to each licensee.
|
||||
|
||||
1. Scope.
|
||||
This license governs the copying, distribution, and modification of the
|
||||
Program. Other activities are outside the scope of this license; The
|
||||
act of running the Program is not restricted, and the output from the
|
||||
Program is covered only if its contents constitute a work based on the
|
||||
Program.
|
||||
|
||||
2. Verbatim copies.
|
||||
You may copy and distribute verbatim copies of the Program as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice; keep
|
||||
intact all the notices that refer to this License and to the absence of
|
||||
any warranty; and give any other recipients of the Program a copy of this
|
||||
License along with the Program.
|
||||
|
||||
3. Modification and redistribution under closed license.
|
||||
You may modify your copy or copies of the Program, and distribute
|
||||
the resulting derivative works, provided that you meet the
|
||||
following conditions:
|
||||
a) The copyright notice and disclaimer on the Program must be reproduced
|
||||
and included in the source code, documentation, and/or other materials
|
||||
provided in a manner in which such notices are normally distributed.
|
||||
b) The derivative work must be clearly identified as such, in order that
|
||||
it may not be confused with the original work.
|
||||
c) The license under which the derivative work is distributed must
|
||||
expressly prohibit the distribution of further derivative works.
|
||||
|
||||
4. Modification and redistribution under open license.
|
||||
You may modify your copy or copies of the Program, and distribute
|
||||
the resulting derivative works, provided that you meet the
|
||||
following conditions:
|
||||
a) The copyright notice and disclaimer on the Program must be reproduced
|
||||
and included in the source code, documentation, and/or other materials
|
||||
provided in a manner in which such notices are normally distributed.
|
||||
b) You must clearly indicate the nature and date of any changes made
|
||||
to the Program. The full details need not necessarily be included in
|
||||
the individual modified files, provided that each modified file is
|
||||
clearly marked as such and instructions are included on where the
|
||||
full details of the modifications may be found.
|
||||
c) You must cause any work that you distribute or publish, that in whole
|
||||
or in part contains or is derived from the Program or any part
|
||||
thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
5. Implied acceptance.
|
||||
You may not copy or distribute the Program or any derivative works except
|
||||
as expressly provided under this license. Consequently, any such action
|
||||
will be taken as implied acceptance of the terms of this license.
|
||||
|
||||
6. NO WARRANTY.
|
||||
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT, EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
@@ -0,0 +1,7 @@
|
||||
libexec_PROGRAMS = bsdiff bspatch
|
||||
|
||||
bsdiff_SOURCES = bsdiff.c
|
||||
|
||||
bspatch_SOURCES = bspatch.c
|
||||
|
||||
AM_CFLAGS = -O3 -DBZIP2=\"$(bzip2)\"
|
||||
@@ -0,0 +1,18 @@
|
||||
CFLAGS += -O3
|
||||
.ifdef BZIP2
|
||||
CFLAGS += -DBZIP2=\"${BZIP2}\"
|
||||
.endif
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
INSTALL_PROGRAM ?= ${INSTALL} -c -s -m 555
|
||||
INSTALL_MAN ?= ${INSTALL} -c -m 444
|
||||
|
||||
all: bsdiff bspatch
|
||||
bsdiff: bsdiff.c
|
||||
bspatch: bspatch.c
|
||||
|
||||
install:
|
||||
${INSTALL_PROGRAM} bsdiff bspatch ${PREFIX}/bin
|
||||
.ifndef WITHOUT_MAN
|
||||
${INSTALL_MAN} bsdiff.1 bspatch.1 ${PREFIX}/man/man1
|
||||
.endif
|
||||
@@ -0,0 +1,36 @@
|
||||
.Dd May 18, 2003
|
||||
.Dt BSDIFF 1
|
||||
.Os FreeBSD
|
||||
.Sh NAME
|
||||
.Nm bsdiff
|
||||
.Nd generate a patch between two binary files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ao Ar oldfile Ac Ao Ar newfile Ac Ao Ar patchfile Ac
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
compares
|
||||
.Ao Ar oldfile Ac
|
||||
to
|
||||
.Ao Ar newfile Ac
|
||||
and writes to
|
||||
.Ao Ar patchfile Ac
|
||||
a binary patch suitable for use by bspatch(1).
|
||||
When
|
||||
.Ao Ar oldfile Ac
|
||||
and
|
||||
.Ao Ar newfile Ac
|
||||
are two versions of an executable program, the
|
||||
patches produced are on average a factor of five smaller
|
||||
than those produced by any other binary patch tool known
|
||||
to the author.
|
||||
.Pp
|
||||
.Nm
|
||||
uses memory equal to 17 times the size of
|
||||
.Ao Ar oldfile Ac ,
|
||||
and requires
|
||||
an absolute minimum working set size of 8 times the size of oldfile.
|
||||
.Sh SEE ALSO
|
||||
.Xr bspatch 1
|
||||
.Sh AUTHORS
|
||||
.An Colin Percival Aq cperciva@daemonology.net
|
||||
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
bsdiff.c -- Binary patch generator.
|
||||
|
||||
Copyright 2003 Colin Percival
|
||||
|
||||
For the terms under which this work may be distributed, please see
|
||||
the adjoining file "LICENSE".
|
||||
*/
|
||||
|
||||
#ifndef BZIP2
|
||||
#define BZIP2 "/usr/bin/bzip2"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#define MIN(x,y) (((x)<(y)) ? (x) : (y))
|
||||
|
||||
void split(off_t *I,off_t *V,off_t start,off_t len,off_t h)
|
||||
{
|
||||
off_t i,j,k,x,tmp,jj,kk;
|
||||
|
||||
if(len<16) {
|
||||
for(k=start;k<start+len;k+=j) {
|
||||
j=1;x=V[I[k]+h];
|
||||
for(i=1;k+i<start+len;i++) {
|
||||
if(V[I[k+i]+h]<x) {
|
||||
x=V[I[k+i]+h];
|
||||
j=0;
|
||||
};
|
||||
if(V[I[k+i]+h]==x) {
|
||||
tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
|
||||
j++;
|
||||
};
|
||||
};
|
||||
for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
|
||||
if(j==1) I[k]=-1;
|
||||
};
|
||||
return;
|
||||
};
|
||||
|
||||
x=V[I[start+len/2]+h];
|
||||
jj=0;kk=0;
|
||||
for(i=start;i<start+len;i++) {
|
||||
if(V[I[i]+h]<x) jj++;
|
||||
if(V[I[i]+h]==x) kk++;
|
||||
};
|
||||
jj+=start;kk+=jj;
|
||||
|
||||
i=start;j=0;k=0;
|
||||
while(i<jj) {
|
||||
if(V[I[i]+h]<x) {
|
||||
i++;
|
||||
} else if(V[I[i]+h]==x) {
|
||||
tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
|
||||
j++;
|
||||
} else {
|
||||
tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
|
||||
k++;
|
||||
};
|
||||
};
|
||||
|
||||
while(jj+j<kk) {
|
||||
if(V[I[jj+j]+h]==x) {
|
||||
j++;
|
||||
} else {
|
||||
tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
|
||||
k++;
|
||||
};
|
||||
};
|
||||
|
||||
if(jj>start) split(I,V,start,jj-start,h);
|
||||
|
||||
for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
|
||||
if(jj==kk-1) I[jj]=-1;
|
||||
|
||||
if(start+len>kk) split(I,V,kk,start+len-kk,h);
|
||||
}
|
||||
|
||||
void qsufsort(off_t *I,off_t *V,u_char *old,off_t oldsize)
|
||||
{
|
||||
off_t buckets[256];
|
||||
off_t i,h,len;
|
||||
|
||||
for(i=0;i<256;i++) buckets[i]=0;
|
||||
for(i=0;i<oldsize;i++) buckets[old[i]]++;
|
||||
for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
|
||||
for(i=255;i>0;i--) buckets[i]=buckets[i-1];
|
||||
buckets[0]=0;
|
||||
|
||||
for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
|
||||
I[0]=oldsize;
|
||||
for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
|
||||
V[oldsize]=0;
|
||||
for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
|
||||
I[0]=-1;
|
||||
|
||||
for(h=1;I[0]!=-(oldsize+1);h+=h) {
|
||||
len=0;
|
||||
for(i=0;i<oldsize+1;) {
|
||||
if(I[i]<0) {
|
||||
len-=I[i];
|
||||
i-=I[i];
|
||||
} else {
|
||||
if(len) I[i-len]=-len;
|
||||
len=V[I[i]]+1-i;
|
||||
split(I,V,i,len,h);
|
||||
i+=len;
|
||||
len=0;
|
||||
};
|
||||
};
|
||||
if(len) I[i-len]=-len;
|
||||
};
|
||||
|
||||
for(i=0;i<oldsize+1;i++) I[V[i]]=i;
|
||||
}
|
||||
|
||||
off_t matchlen(u_char *old,off_t oldsize,u_char *new,off_t newsize)
|
||||
{
|
||||
off_t i;
|
||||
|
||||
for(i=0;(i<oldsize)&&(i<newsize);i++)
|
||||
if(old[i]!=new[i]) break;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
off_t search(off_t *I,u_char *old,off_t oldsize,
|
||||
u_char *new,off_t newsize,off_t st,off_t en,off_t *pos)
|
||||
{
|
||||
off_t x,y;
|
||||
|
||||
if(en-st<2) {
|
||||
x=matchlen(old+I[st],oldsize-I[st],new,newsize);
|
||||
y=matchlen(old+I[en],oldsize-I[en],new,newsize);
|
||||
|
||||
if(x>y) {
|
||||
*pos=I[st];
|
||||
return x;
|
||||
} else {
|
||||
*pos=I[en];
|
||||
return y;
|
||||
}
|
||||
};
|
||||
|
||||
x=st+(en-st)/2;
|
||||
if(memcmp(old+I[x],new,MIN(oldsize-I[x],newsize))<0) {
|
||||
return search(I,old,oldsize,new,newsize,x,en,pos);
|
||||
} else {
|
||||
return search(I,old,oldsize,new,newsize,st,x,pos);
|
||||
};
|
||||
}
|
||||
|
||||
void offtout(off_t x,u_char *buf)
|
||||
{
|
||||
off_t y;
|
||||
|
||||
if(x<0) y=-x; else y=x;
|
||||
|
||||
buf[0]=y%256;y-=buf[0];
|
||||
y=y/256;buf[1]=y%256;y-=buf[1];
|
||||
y=y/256;buf[2]=y%256;y-=buf[2];
|
||||
y=y/256;buf[3]=y%256;y-=buf[3];
|
||||
y=y/256;buf[4]=y%256;y-=buf[4];
|
||||
y=y/256;buf[5]=y%256;y-=buf[5];
|
||||
y=y/256;buf[6]=y%256;y-=buf[6];
|
||||
y=y/256;buf[7]=y%256;
|
||||
|
||||
if(x<0) buf[7]|=0x80;
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
int fd,p[2];
|
||||
pid_t pid;
|
||||
u_char *old,*new;
|
||||
off_t oldsize,newsize;
|
||||
off_t *I,*V;
|
||||
|
||||
off_t scan,pos,len;
|
||||
off_t lastscan,lastpos,lastoffset;
|
||||
off_t oldscore,scsc;
|
||||
|
||||
off_t s,Sf,lenf,Sb,lenb;
|
||||
off_t overlap,Ss,lens;
|
||||
off_t i;
|
||||
|
||||
off_t dblen,eblen;
|
||||
u_char *db,*eb;
|
||||
|
||||
u_char buf[8];
|
||||
u_char header[32];
|
||||
|
||||
if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
|
||||
|
||||
/* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
|
||||
that we never try to malloc(0) and get a NULL pointer */
|
||||
if(((fd=open(argv[1],O_RDONLY,0))<0) ||
|
||||
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
|
||||
((old=malloc(oldsize+1))==NULL) ||
|
||||
(lseek(fd,0,SEEK_SET)!=0) ||
|
||||
(read(fd,old,oldsize)!=oldsize) ||
|
||||
(close(fd)==-1)) err(1,"%s",argv[1]);
|
||||
|
||||
if(((I=malloc((oldsize+1)*sizeof(off_t)))==NULL) ||
|
||||
((V=malloc((oldsize+1)*sizeof(off_t)))==NULL)) err(1,NULL);
|
||||
|
||||
qsufsort(I,V,old,oldsize);
|
||||
|
||||
free(V);
|
||||
|
||||
/* Allocate newsize+1 bytes instead of newsize bytes to ensure
|
||||
that we never try to malloc(0) and get a NULL pointer */
|
||||
if(((fd=open(argv[2],O_RDONLY,0))<0) ||
|
||||
((newsize=lseek(fd,0,SEEK_END))==-1) ||
|
||||
((new=malloc(newsize+1))==NULL) ||
|
||||
(lseek(fd,0,SEEK_SET)!=0) ||
|
||||
(read(fd,new,newsize)!=newsize) ||
|
||||
(close(fd)==-1)) err(1,"%s",argv[2]);
|
||||
|
||||
if(((db=malloc(newsize+1))==NULL) ||
|
||||
((eb=malloc(newsize+1))==NULL)) err(1,NULL);
|
||||
dblen=0;
|
||||
eblen=0;
|
||||
|
||||
if((fd=open(argv[3],O_CREAT|O_TRUNC|O_WRONLY,0666))<0)
|
||||
err(1,"%s",argv[3]);
|
||||
|
||||
/* Header is
|
||||
0 8 "BSDIFF40"
|
||||
8 8 length of bzip2ed ctrl block
|
||||
16 8 length of bzip2ed diff block
|
||||
24 8 length of new file */
|
||||
/* File is
|
||||
0 32 Header
|
||||
32 ?? Bzip2ed ctrl block
|
||||
?? ?? Bzip2ed diff block
|
||||
?? ?? Bzip2ed extra block */
|
||||
memcpy(header,"BSDIFF40",8);
|
||||
memset(header+8,0,24);
|
||||
if(write(fd,header,32)!=32) err(1,"%s",argv[3]);
|
||||
|
||||
if((pipe(p)==-1) || ((pid=fork())==-1)) err(1,NULL);
|
||||
if(pid==0) {
|
||||
if((close(0)==-1) || (close(1)==-1) || (dup2(fd,1)==-1) ||
|
||||
(dup2(p[0],0)==-1) || (close(fd)==-1) ||
|
||||
(close(p[0])==-1) || (close(p[1])==-1))
|
||||
err(1,NULL);
|
||||
execl(BZIP2,BZIP2,"-zc",NULL);
|
||||
err(1,"%s",BZIP2);
|
||||
};
|
||||
if(close(p[0])==-1) err(1,NULL);
|
||||
|
||||
scan=0;len=0;
|
||||
lastscan=0;lastpos=0;lastoffset=0;
|
||||
while(scan<newsize) {
|
||||
oldscore=0;
|
||||
|
||||
for(scsc=scan+=len;scan<newsize;scan++) {
|
||||
len=search(I,old,oldsize,new+scan,newsize-scan,
|
||||
0,oldsize,&pos);
|
||||
|
||||
for(;scsc<scan+len;scsc++)
|
||||
if((scsc+lastoffset<oldsize) &&
|
||||
(old[scsc+lastoffset] == new[scsc]))
|
||||
oldscore++;
|
||||
|
||||
if(((len==oldscore) && (len!=0)) ||
|
||||
(len>oldscore+8)) break;
|
||||
|
||||
if((scan+lastoffset<oldsize) &&
|
||||
(old[scan+lastoffset] == new[scan]))
|
||||
oldscore--;
|
||||
};
|
||||
|
||||
if((len!=oldscore) || (scan==newsize)) {
|
||||
s=0;Sf=0;lenf=0;
|
||||
for(i=0;(lastscan+i<scan)&&(lastpos+i<oldsize);) {
|
||||
if(old[lastpos+i]==new[lastscan+i]) s++;
|
||||
i++;
|
||||
if(s*2-i>Sf*2-lenf) { Sf=s; lenf=i; };
|
||||
};
|
||||
|
||||
lenb=0;
|
||||
if(scan<newsize) {
|
||||
s=0;Sb=0;
|
||||
for(i=1;(scan>=lastscan+i)&&(pos>=i);i++) {
|
||||
if(old[pos-i]==new[scan-i]) s++;
|
||||
if(s*2-i>Sb*2-lenb) { Sb=s; lenb=i; };
|
||||
};
|
||||
};
|
||||
|
||||
if(lastscan+lenf>scan-lenb) {
|
||||
overlap=(lastscan+lenf)-(scan-lenb);
|
||||
s=0;Ss=0;lens=0;
|
||||
for(i=0;i<overlap;i++) {
|
||||
if(new[lastscan+lenf-overlap+i]==
|
||||
old[lastpos+lenf-overlap+i]) s++;
|
||||
if(new[scan-lenb+i]==
|
||||
old[pos-lenb+i]) s--;
|
||||
if(s>Ss) { Ss=s; lens=i+1; };
|
||||
};
|
||||
|
||||
lenf+=lens-overlap;
|
||||
lenb-=lens;
|
||||
};
|
||||
|
||||
for(i=0;i<lenf;i++)
|
||||
db[dblen+i]=new[lastscan+i]-old[lastpos+i];
|
||||
for(i=0;i<(scan-lenb)-(lastscan+lenf);i++)
|
||||
eb[eblen+i]=new[lastscan+lenf+i];
|
||||
|
||||
dblen+=lenf;
|
||||
eblen+=(scan-lenb)-(lastscan+lenf);
|
||||
|
||||
offtout(lenf,buf);
|
||||
if(write(p[1],buf,8)!=8) err(1,NULL);
|
||||
offtout((scan-lenb)-(lastscan+lenf),buf);
|
||||
if(write(p[1],buf,8)!=8) err(1,NULL);
|
||||
offtout((pos-lenb)-(lastpos+lenf),buf);
|
||||
if(write(p[1],buf,8)!=8) err(1,NULL);
|
||||
|
||||
lastscan=scan-lenb;
|
||||
lastpos=pos-lenb;
|
||||
lastoffset=pos-scan;
|
||||
};
|
||||
};
|
||||
|
||||
if((close(p[1])==-1) || (waitpid(pid,NULL,0)!=pid)) err(1,NULL);
|
||||
|
||||
if((len=lseek(fd,0,SEEK_END))==-1) err(1,"%s",argv[3]);
|
||||
offtout(len-32,buf);
|
||||
if((lseek(fd,8,SEEK_SET)!=8) || (write(fd,buf,8)!=8))
|
||||
err(1,"%s",argv[3]);
|
||||
offtout(newsize,buf);
|
||||
if((lseek(fd,24,SEEK_SET)!=24) || (write(fd,buf,8)!=8))
|
||||
err(1,"%s",argv[3]);
|
||||
|
||||
if(lseek(fd,0,SEEK_END)==-1) err(1,"%s",argv[3]);
|
||||
if((pipe(p)==-1) || ((pid=fork())==-1)) err(1,NULL);
|
||||
if(pid==0) {
|
||||
if((close(0)==-1) || (close(1)==-1) || (dup2(fd,1)==-1) ||
|
||||
(dup2(p[0],0)==-1) || (close(fd)==-1) ||
|
||||
(close(p[0])==-1) || (close(p[1])==-1))
|
||||
err(1,NULL);
|
||||
execl(BZIP2,BZIP2,"-zc",NULL);
|
||||
err(1,"%s",BZIP2);
|
||||
};
|
||||
if(close(p[0])==-1) err(1,NULL);
|
||||
if(write(p[1],db,dblen)!=dblen) err(1,NULL);
|
||||
if((close(p[1])==-1) || (waitpid(pid,NULL,0)!=pid)) err(1,NULL);
|
||||
|
||||
if((newsize=lseek(fd,0,SEEK_END))==-1) err(1,"%s",argv[3]);
|
||||
offtout(newsize-len,buf);
|
||||
if((lseek(fd,16,SEEK_SET)!=16) || (write(fd,buf,8)!=8))
|
||||
err(1,"%s",argv[3]);
|
||||
|
||||
if(lseek(fd,0,SEEK_END)==-1) err(1,"%s",argv[3]);
|
||||
if((pipe(p)==-1) || ((pid=fork())==-1)) err(1,NULL);
|
||||
if(pid==0) {
|
||||
if((close(0)==-1) || (close(1)==-1) || (dup2(fd,1)==-1) ||
|
||||
(dup2(p[0],0)==-1) || (close(fd)==-1) ||
|
||||
(close(p[0])==-1) || (close(p[1])==-1))
|
||||
err(1,NULL);
|
||||
execl(BZIP2,BZIP2,"-zc",NULL);
|
||||
err(1,"%s",BZIP2);
|
||||
};
|
||||
if(close(p[0])==-1) err(1,NULL);
|
||||
if(write(p[1],eb,eblen)!=eblen) err(1,NULL);
|
||||
if((close(p[1])==-1) || (waitpid(pid,NULL,0)!=pid)) err(1,NULL);
|
||||
if(close(fd)==-1) err(1,"%s",argv[3]);
|
||||
|
||||
free(db);
|
||||
free(eb);
|
||||
free(I);
|
||||
free(old);
|
||||
free(new);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
.Dd May 18, 2003
|
||||
.Dt BSPATCH 1
|
||||
.Os FreeBSD
|
||||
.Sh NAME
|
||||
.Nm bspatch
|
||||
.Nd apply a patch built with bsdiff(1)
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ao Ar oldfile Ac Ao Ar newfile Ac Ao Ar patchfile Ac
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
generates
|
||||
.Ao Ar newfile Ac
|
||||
from
|
||||
.Ao Ar oldfile Ac
|
||||
and
|
||||
.Ao Ar patchfile Ac
|
||||
where
|
||||
.Ao Ar patchfile Ac
|
||||
is a binary patch built by bsdiff(1).
|
||||
.Pp
|
||||
.Nm
|
||||
uses memory equal to the size of
|
||||
.Ao Ar oldfile Ac
|
||||
plus the size of
|
||||
.Ao Ar newfile Ac ,
|
||||
but can tolerate a very small working set without a dramatic loss
|
||||
of performance.
|
||||
.Sh SEE ALSO
|
||||
.Xr bsdiff 1
|
||||
.Sh AUTHORS
|
||||
.An Colin Percival Aq cperciva@daemonology.net
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
.c -- Binary patcher
|
||||
|
||||
Copyright 2003,2004 Colin Percival
|
||||
|
||||
For the terms under which this work may be distributed, please see
|
||||
the adjoining file "LICENSE".
|
||||
*/
|
||||
|
||||
#ifndef BZIP2
|
||||
#define BZIP2 "/usr/bin/bzip2"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
ssize_t loopread(int d,void *buf,size_t nbytes)
|
||||
{
|
||||
ssize_t ptr,lenread;
|
||||
|
||||
for(ptr=0;ptr<nbytes;ptr+=lenread) {
|
||||
lenread=read(d,buf+ptr,nbytes-ptr);
|
||||
if(lenread==0) return ptr;
|
||||
if(lenread==-1) return -1;
|
||||
};
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int bz2read(int fd,off_t offset,off_t len,char * fname,pid_t * pids)
|
||||
{
|
||||
int p0[2],p1[2];
|
||||
u_char * data;
|
||||
|
||||
if((pipe(p0)==-1) || (pipe(p1)==-1)) err(1,NULL);
|
||||
|
||||
if((pids[0]=fork())==-1) err(1,NULL);
|
||||
if(pids[0]==0) {
|
||||
if(close(0) || close(1) || close(p0[0]) ||
|
||||
close(p1[0]) || close(p1[1])) err(1,NULL);
|
||||
if((data=malloc(len+1))==NULL) err(1,NULL);
|
||||
if((pread(fd,data,len,offset)!=len) || close(fd))
|
||||
err(1,"%s",fname);
|
||||
if((write(p0[1],data,len)!=len) || close(p0[1]))
|
||||
err(1,NULL);
|
||||
free(data);
|
||||
_exit(0);
|
||||
};
|
||||
|
||||
if((pids[1]=fork())==-1) err(1,NULL);
|
||||
if(pids[1]==0) {
|
||||
if(close(0) || close(1) || close(p0[1]) ||
|
||||
close(p1[0])) err(1,NULL);
|
||||
if((dup2(p0[0],0)==-1) || close(p0[0])) err(1,NULL);
|
||||
if((dup2(p1[1],1)==-1) || close(p1[1])) err(1,NULL);
|
||||
if(close(fd)==-1) err(1,"%s",fname);
|
||||
|
||||
execl(BZIP2,BZIP2,"-dc",NULL);
|
||||
err(1,"%s",BZIP2);
|
||||
};
|
||||
|
||||
if(close(p0[0]) || close(p0[1]) || close(p1[1])) err(1,NULL);
|
||||
|
||||
return p1[0];
|
||||
}
|
||||
|
||||
off_t offtin(u_char *buf)
|
||||
{
|
||||
off_t y;
|
||||
|
||||
y=buf[7]&0x7F;
|
||||
y=y*256;y+=buf[6];
|
||||
y=y*256;y+=buf[5];
|
||||
y=y*256;y+=buf[4];
|
||||
y=y*256;y+=buf[3];
|
||||
y=y*256;y+=buf[2];
|
||||
y=y*256;y+=buf[1];
|
||||
y=y*256;y+=buf[0];
|
||||
|
||||
if(buf[7]&0x80) y=-y;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int main(int argc,char * argv[])
|
||||
{
|
||||
int fd,ctrlpipe,diffpipe,extrapipe;
|
||||
pid_t pids[6];
|
||||
ssize_t patchsize,oldsize,newsize;
|
||||
ssize_t bzctrllen,bzdatalen;
|
||||
u_char header[32],buf[8];
|
||||
int version=0;
|
||||
u_char *old, *new;
|
||||
off_t oldpos,newpos;
|
||||
off_t ctrl[3];
|
||||
off_t lenread;
|
||||
off_t i;
|
||||
|
||||
if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
|
||||
|
||||
if(((fd=open(argv[3],O_RDONLY,0))<0) ||
|
||||
((patchsize=lseek(fd,0,SEEK_END))==-1) ||
|
||||
(lseek(fd,0,SEEK_SET)!=0)) err(1,"%s",argv[3]);
|
||||
if(patchsize<32) errx(1,"Corrupt patch\n");
|
||||
|
||||
/*
|
||||
Ok, this is going to be messy. There are two different patch
|
||||
formats which we need to support.
|
||||
|
||||
The old format (pre-4.0) is:
|
||||
0 8 "QSUFDIFF" or "BSDIFF30"
|
||||
8 8 X
|
||||
16 8 Y
|
||||
24 8 sizeof(newfile)
|
||||
32 X bzip2(control block)
|
||||
32+X Y bzip2(data block)
|
||||
with control block a set of pairs (x,y) meaning "seek forward
|
||||
in oldfile by y bytes, and add the next x bytes to x bytes from
|
||||
the data block".
|
||||
|
||||
The new format (4.0) is:
|
||||
0 8 "BSDIFF40"
|
||||
8 8 X
|
||||
16 8 Y
|
||||
24 8 sizeof(newfile)
|
||||
32 X bzip2(control block)
|
||||
32+X Y bzip2(diff block)
|
||||
32+X+Y ??? bzip2(extra block)
|
||||
with control block a set of triples (x,y,z) meaning "add x bytes
|
||||
from oldfile to x bytes from the diff block; copy y bytes from the
|
||||
extra block; seek forwards in oldfile by z bytes".
|
||||
*/
|
||||
|
||||
if(read(fd,header,32)!=32) err(1,"%s",argv[3]);
|
||||
if(memcmp(header,"QSUFDIFF",8)==0) version=1;
|
||||
if(memcmp(header,"BSDIFF30",8)==0) version=1;
|
||||
if(memcmp(header,"BSDIFF40",8)==0) version=2;
|
||||
|
||||
if(!version) errx(1,"Corrupt patch\n");
|
||||
|
||||
bzctrllen=offtin(header+8);
|
||||
bzdatalen=offtin(header+16);
|
||||
newsize=offtin(header+24);
|
||||
if((bzctrllen<0) || (bzdatalen<0) || (newsize<0) ||
|
||||
((version==1) && (32+bzctrllen+bzdatalen!=patchsize)))
|
||||
errx(1,"Corrupt patch\n");
|
||||
|
||||
ctrlpipe=bz2read(fd,32,bzctrllen,argv[3],pids);
|
||||
diffpipe=bz2read(fd,32+bzctrllen,bzdatalen,argv[3],pids+2);
|
||||
if(version==2) {
|
||||
extrapipe=bz2read(fd,32+bzctrllen+bzdatalen,
|
||||
patchsize-(32+bzctrllen+bzdatalen),argv[3],pids+4);
|
||||
};
|
||||
|
||||
if(close(fd)==-1) err(1,"%s",argv[3]);
|
||||
if(((fd=open(argv[1],O_RDONLY,0))<0) ||
|
||||
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
|
||||
((old=malloc(oldsize+1))==NULL) ||
|
||||
(lseek(fd,0,SEEK_SET)!=0) ||
|
||||
(read(fd,old,oldsize)!=oldsize) ||
|
||||
(close(fd)==-1)) err(1,"%s",argv[1]);
|
||||
if((new=malloc(newsize+1))==NULL) err(1,NULL);
|
||||
|
||||
oldpos=0;newpos=0;
|
||||
while(newpos<newsize) {
|
||||
for(i=0;i<=version;i++) {
|
||||
if((lenread=loopread(ctrlpipe,buf,8))<0) err(1,NULL);
|
||||
if(lenread<8) errx(1,"Corrupt patch\n");
|
||||
ctrl[i]=offtin(buf);
|
||||
};
|
||||
|
||||
if(version==1) oldpos+=ctrl[1];
|
||||
|
||||
if(newpos+ctrl[0]>newsize) errx(1,"Corrupt patch\n");
|
||||
if((lenread=loopread(diffpipe,new+newpos,ctrl[0]))<0)
|
||||
err(1,NULL);
|
||||
if(lenread!=ctrl[0]) errx(1,"Corrupt patch\n");
|
||||
for(i=0;i<ctrl[0];i++)
|
||||
if((oldpos+i>=0) && (oldpos+i<oldsize))
|
||||
new[newpos+i]+=old[oldpos+i];
|
||||
newpos+=ctrl[0];
|
||||
oldpos+=ctrl[0];
|
||||
|
||||
if(version==2) {
|
||||
if(newpos+ctrl[1]>newsize) errx(1,"Corrupt patch\n");
|
||||
if((lenread=loopread(extrapipe,new+newpos,ctrl[1]))<0)
|
||||
err(1,NULL);
|
||||
if(lenread!=ctrl[1]) errx(1,"Corrupt patch\n");
|
||||
|
||||
newpos+=ctrl[1];
|
||||
oldpos+=ctrl[2];
|
||||
};
|
||||
};
|
||||
|
||||
if(loopread(ctrlpipe,buf,1)!=0) errx(1,"Corrupt patch\n");
|
||||
if(loopread(diffpipe,buf,1)!=0) errx(1,"Corrupt patch\n");
|
||||
if(version==2)
|
||||
if(loopread(extrapipe,buf,1)!=0) errx(1,"Corrupt patch\n");
|
||||
|
||||
if(close(ctrlpipe) || close(diffpipe) ||
|
||||
((version==2) && close(extrapipe)))
|
||||
err(1,NULL);
|
||||
for(i=0;i<(version+1)*2;i++) waitpid(pids[i],NULL,0);
|
||||
|
||||
if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) ||
|
||||
(write(fd,new,newsize)!=newsize) || (close(fd)==-1))
|
||||
err(1,"%s",argv[2]);
|
||||
|
||||
free(new);
|
||||
free(old);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+12
-3
@@ -1,10 +1,11 @@
|
||||
noinst_LIBRARIES = libexpr.a
|
||||
|
||||
libexpr_a_SOURCES = nixexpr.cc nixexpr.hh parser.cc parser.hh \
|
||||
eval.cc eval.hh primops.cc primops.hh \
|
||||
lexer-tab.c lexer-tab.h parser-tab.c parser-tab.h
|
||||
eval.cc eval.hh primops.cc \
|
||||
lexer-tab.c lexer-tab.h parser-tab.c parser-tab.h \
|
||||
nixexpr-ast.hh
|
||||
|
||||
EXTRA_DIST = lexer.l parser.y
|
||||
EXTRA_DIST = lexer.l parser.y nixexpr-ast.def nixexpr-ast.cc
|
||||
|
||||
AM_CXXFLAGS = \
|
||||
-I.. ${bdb_include} ${aterm_include} -I../libutil -I../libstore
|
||||
@@ -23,4 +24,12 @@ lexer-tab.c lexer-tab.h: lexer.l
|
||||
$(flex) --outfile lexer-tab.c --header-file=lexer-tab.h lexer.l
|
||||
|
||||
|
||||
# ATerm helper function generation.
|
||||
|
||||
nixexpr-ast.cc nixexpr-ast.hh: ../aterm-helper.pl nixexpr-ast.def
|
||||
$(perl) ../aterm-helper.pl nixexpr-ast.hh nixexpr-ast.cc < nixexpr-ast.def
|
||||
|
||||
nixexpr.hh: nixexpr-ast.hh
|
||||
|
||||
|
||||
CLEANFILES =
|
||||
+123
-112
@@ -1,70 +1,40 @@
|
||||
#include "eval.hh"
|
||||
#include "parser.hh"
|
||||
#include "primops.hh"
|
||||
|
||||
|
||||
static void addPrimOp(ATermMap & map, const string & name, void * f)
|
||||
{
|
||||
map.set(name, (ATerm) ATmakeBlob(0, f));
|
||||
}
|
||||
|
||||
|
||||
static void * lookupPrimOp(ATermMap & map, ATerm name)
|
||||
{
|
||||
ATermBlob b = (ATermBlob) map.get(name);
|
||||
if (!b) return 0;
|
||||
return ATgetBlobData(b);
|
||||
}
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
|
||||
EvalState::EvalState()
|
||||
: normalForms(32768, 50)
|
||||
{
|
||||
blackHole = ATmake("BlackHole()");
|
||||
if (!blackHole) throw Error("cannot build black hole");
|
||||
blackHole = makeBlackHole();
|
||||
|
||||
nrEvaluated = nrCached = 0;
|
||||
|
||||
addPrimOp0("true", primTrue);
|
||||
addPrimOp0("false", primFalse);
|
||||
addPrimOp0("null", primNull);
|
||||
initNixExprHelpers();
|
||||
|
||||
addPrimOp1("import", primImport);
|
||||
addPrimOp1("derivation", primDerivation);
|
||||
addPrimOp1("baseNameOf", primBaseNameOf);
|
||||
addPrimOp1("toString", primToString);
|
||||
addPrimOp1("isNull", primIsNull);
|
||||
|
||||
primOpsAll.add(primOps0);
|
||||
primOpsAll.add(primOps1);
|
||||
addPrimOps();
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addPrimOp0(const string & name, PrimOp0 primOp)
|
||||
void EvalState::addPrimOp(const string & name,
|
||||
unsigned int arity, PrimOp primOp)
|
||||
{
|
||||
addPrimOp(primOps0, name, (void *) primOp);
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addPrimOp1(const string & name, PrimOp1 primOp)
|
||||
{
|
||||
addPrimOp(primOps1, name, (void *) primOp);
|
||||
primOps.set(name, makePrimOpDef(arity, ATmakeBlob(0, (void *) primOp)));
|
||||
}
|
||||
|
||||
|
||||
/* Substitute an argument set into the body of a function. */
|
||||
static Expr substArgs(Expr body, ATermList formals, Expr arg)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermMap subs;
|
||||
Expr undefined = ATmake("Undefined");
|
||||
Expr undefined = makeUndefined();
|
||||
|
||||
/* Get the formal arguments. */
|
||||
for (ATermIterator i(formals); i; ++i) {
|
||||
Expr name, def;
|
||||
if (atMatch(m, *i) >> "NoDefFormal" >> name)
|
||||
if (matchNoDefFormal(*i, name))
|
||||
subs.set(name, undefined);
|
||||
else if (atMatch(m, *i) >> "DefFormal" >> name >> def)
|
||||
else if (matchDefFormal(*i, name, def))
|
||||
subs.set(name, def);
|
||||
else abort(); /* can't happen */
|
||||
}
|
||||
@@ -99,38 +69,32 @@ static Expr substArgs(Expr body, ATermList formals, Expr arg)
|
||||
(e.x) (e.y); y = e.x;}'. */
|
||||
ATerm expandRec(ATerm e, ATermList rbnds, ATermList nrbnds)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATerm name;
|
||||
Expr e2;
|
||||
Pos pos;
|
||||
|
||||
/* Create the substitution list. */
|
||||
ATermMap subs;
|
||||
for (ATermIterator i(rbnds); i; ++i) {
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2))
|
||||
abort(); /* can't happen */
|
||||
subs.set(name, ATmake("Select(<term>, <term>)", e, name));
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
subs.set(name, makeSelect(e, name));
|
||||
}
|
||||
for (ATermIterator i(nrbnds); i; ++i) {
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2))
|
||||
abort(); /* can't happen */
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
subs.set(name, e2);
|
||||
}
|
||||
|
||||
/* Create the non-recursive set. */
|
||||
ATermMap as;
|
||||
for (ATermIterator i(rbnds); i; ++i) {
|
||||
ATerm pos;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2 >> pos))
|
||||
abort(); /* can't happen */
|
||||
as.set(name, ATmake("(<term>, <term>)", substitute(subs, e2), pos));
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
as.set(name, makeAttrRHS(substitute(subs, e2), pos));
|
||||
}
|
||||
|
||||
/* Copy the non-recursive bindings. !!! inefficient */
|
||||
for (ATermIterator i(nrbnds); i; ++i) {
|
||||
ATerm pos;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2 >> pos))
|
||||
abort(); /* can't happen */
|
||||
as.set(name, ATmake("(<term>, <term>)", e2, pos));
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
as.set(name, makeAttrRHS(e2, pos));
|
||||
}
|
||||
|
||||
return makeAttrs(as);
|
||||
@@ -152,73 +116,73 @@ static Expr updateAttrs(Expr e1, Expr e2)
|
||||
string evalString(EvalState & state, Expr e)
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
ATMatcher m;
|
||||
string s;
|
||||
if (!(atMatch(m, e) >> "Str" >> s))
|
||||
throw Error("string expected");
|
||||
return s;
|
||||
ATerm s;
|
||||
if (!matchStr(e, s)) throw Error("string expected");
|
||||
return aterm2String(s);
|
||||
}
|
||||
|
||||
|
||||
Path evalPath(EvalState & state, Expr e)
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
ATMatcher m;
|
||||
string s;
|
||||
if (!(atMatch(m, e) >> "Path" >> s))
|
||||
throw Error("path expected");
|
||||
return s;
|
||||
ATerm s;
|
||||
if (!matchPath(e, s)) throw Error("path expected");
|
||||
return aterm2String(s);
|
||||
}
|
||||
|
||||
|
||||
bool evalBool(EvalState & state, Expr e)
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
ATMatcher m;
|
||||
if (atMatch(m, e) >> "Bool" >> "True") return true;
|
||||
else if (atMatch(m, e) >> "Bool" >> "False") return false;
|
||||
if (e == eTrue) return true;
|
||||
else if (e == eFalse) return false;
|
||||
else throw Error("boolean expected");
|
||||
}
|
||||
|
||||
|
||||
Expr evalExpr2(EvalState & state, Expr e)
|
||||
{
|
||||
ATMatcher m;
|
||||
Expr e1, e2, e3, e4;
|
||||
ATerm name, pos;
|
||||
AFun sym = ATgetAFun(e);
|
||||
|
||||
/* Normal forms. */
|
||||
string cons;
|
||||
if (atMatch(m, e) >> cons &&
|
||||
(cons == "Str" ||
|
||||
cons == "Path" ||
|
||||
cons == "SubPath" ||
|
||||
cons == "Uri" ||
|
||||
cons == "Null" ||
|
||||
cons == "Int" ||
|
||||
cons == "Bool" ||
|
||||
cons == "Function" ||
|
||||
cons == "Function1" ||
|
||||
cons == "Attrs" ||
|
||||
cons == "List"))
|
||||
if (sym == symStr ||
|
||||
sym == symPath ||
|
||||
sym == symSubPath ||
|
||||
sym == symUri ||
|
||||
sym == symNull ||
|
||||
sym == symInt ||
|
||||
sym == symBool ||
|
||||
sym == symFunction ||
|
||||
sym == symFunction1 ||
|
||||
sym == symAttrs ||
|
||||
sym == symList ||
|
||||
sym == symPrimOp)
|
||||
return e;
|
||||
|
||||
|
||||
/* The `Closed' constructor is just a way to prevent substitutions
|
||||
into expressions not containing free variables. */
|
||||
if (atMatch(m, e) >> "Closed" >> e1)
|
||||
if (matchClosed(e, e1))
|
||||
return evalExpr(state, e1);
|
||||
|
||||
/* Any encountered variables must be undeclared or primops. */
|
||||
if (atMatch(m, e) >> "Var" >> name) {
|
||||
PrimOp0 primOp = (PrimOp0) lookupPrimOp(state.primOps0, name);
|
||||
if (primOp)
|
||||
return primOp(state);
|
||||
/* Any encountered variables must be primops (since undefined
|
||||
variables are detected after parsing). */
|
||||
if (matchVar(e, name)) {
|
||||
ATerm primOp = state.primOps.get(name);
|
||||
if (!primOp)
|
||||
throw Error(format("impossible: undefined variable `%1%'") % name);
|
||||
int arity;
|
||||
ATermBlob fun;
|
||||
if (!matchPrimOpDef(primOp, arity, fun)) abort();
|
||||
if (arity == 0)
|
||||
return ((PrimOp) ATgetBlobData(fun)) (state, ATermVector());
|
||||
else
|
||||
return e;
|
||||
return makePrimOp(arity, fun, ATempty);
|
||||
}
|
||||
|
||||
/* Function application. */
|
||||
if (atMatch(m, e) >> "Call" >> e1 >> e2) {
|
||||
if (matchCall(e, e1, e2)) {
|
||||
|
||||
ATermList formals;
|
||||
ATerm pos;
|
||||
@@ -227,28 +191,41 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||
e1 = evalExpr(state, e1);
|
||||
|
||||
/* Is it a primop or a function? */
|
||||
if (atMatch(m, e1) >> "Var" >> name) {
|
||||
PrimOp1 primOp = (PrimOp1) lookupPrimOp(state.primOps1, name);
|
||||
if (primOp) return primOp(state, e2); else abort();
|
||||
int arity;
|
||||
ATermBlob fun;
|
||||
ATermList args;
|
||||
if (matchPrimOp(e1, arity, fun, args)) {
|
||||
args = ATinsert(args, e2);
|
||||
if (ATgetLength(args) == arity) {
|
||||
/* Put the arguments in a vector in reverse (i.e.,
|
||||
actual) order. */
|
||||
ATermVector args2(arity);
|
||||
for (ATermIterator i(args); i; ++i)
|
||||
args2[--arity] = *i;
|
||||
return ((PrimOp) ATgetBlobData((ATermBlob) fun))
|
||||
(state, args2);
|
||||
} else
|
||||
/* Need more arguments, so propagate the primop. */
|
||||
return makePrimOp(arity, fun, args);
|
||||
}
|
||||
|
||||
else if (atMatch(m, e1) >> "Function" >> formals >> e4 >> pos) {
|
||||
else if (matchFunction(e1, formals, e4, pos)) {
|
||||
e2 = evalExpr(state, e2);
|
||||
try {
|
||||
return evalExpr(state, substArgs(e4, formals, e2));
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating function at %1%:\n%2%")
|
||||
throw Error(format("while evaluating the function at %1%:\n%2%")
|
||||
% showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
else if (atMatch(m, e1) >> "Function1" >> name >> e4 >> pos) {
|
||||
else if (matchFunction1(e1, name, e4, pos)) {
|
||||
try {
|
||||
ATermMap subs;
|
||||
subs.set(name, e2);
|
||||
return evalExpr(state, substitute(subs, e4));
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating function at %1%:\n%2%")
|
||||
throw Error(format("while evaluating the function at %1%:\n%2%")
|
||||
% showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
@@ -257,26 +234,26 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||
}
|
||||
|
||||
/* Attribute selection. */
|
||||
string s1;
|
||||
if (atMatch(m, e) >> "Select" >> e1 >> s1) {
|
||||
if (matchSelect(e, e1, name)) {
|
||||
ATerm pos;
|
||||
string s1 = aterm2String(name);
|
||||
Expr a = queryAttr(evalExpr(state, e1), s1, pos);
|
||||
if (!a) throw Error(format("attribute `%1%' missing") % s1);
|
||||
try {
|
||||
return evalExpr(state, a);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating attribute `%1%' at %2%:\n%3%")
|
||||
throw Error(format("while evaluating the attribute `%1%' at %2%:\n%3%")
|
||||
% s1 % showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
/* Mutually recursive sets. */
|
||||
ATermList rbnds, nrbnds;
|
||||
if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds)
|
||||
if (matchRec(e, rbnds, nrbnds))
|
||||
return expandRec(e, rbnds, nrbnds);
|
||||
|
||||
/* Conditionals. */
|
||||
if (atMatch(m, e) >> "If" >> e1 >> e2 >> e3) {
|
||||
if (matchIf(e, e1, e2, e3)) {
|
||||
if (evalBool(state, e1))
|
||||
return evalExpr(state, e2);
|
||||
else
|
||||
@@ -284,47 +261,81 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||
}
|
||||
|
||||
/* Assertions. */
|
||||
if (atMatch(m, e) >> "Assert" >> e1 >> e2 >> pos) {
|
||||
if (matchAssert(e, e1, e2, pos)) {
|
||||
if (!evalBool(state, e1))
|
||||
throw Error(format("assertion failed at %1%") % showPos(pos));
|
||||
return evalExpr(state, e2);
|
||||
}
|
||||
|
||||
/* Withs. */
|
||||
if (matchWith(e, e1, e2, pos)) {
|
||||
ATermMap attrs;
|
||||
try {
|
||||
e1 = evalExpr(state, e1);
|
||||
queryAllAttrs(e1, attrs);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating the `with' definitions at %1%:\n%2%")
|
||||
% showPos(pos) % e.msg());
|
||||
}
|
||||
try {
|
||||
e2 = substitute(attrs, e2);
|
||||
checkVarDefs(state.primOps, e2);
|
||||
return evalExpr(state, e2);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating the `with' body at %1%:\n%2%")
|
||||
% showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
/* Generic equality. */
|
||||
if (atMatch(m, e) >> "OpEq" >> e1 >> e2)
|
||||
if (matchOpEq(e, e1, e2))
|
||||
return makeBool(evalExpr(state, e1) == evalExpr(state, e2));
|
||||
|
||||
/* Generic inequality. */
|
||||
if (atMatch(m, e) >> "OpNEq" >> e1 >> e2)
|
||||
if (matchOpNEq(e, e1, e2))
|
||||
return makeBool(evalExpr(state, e1) != evalExpr(state, e2));
|
||||
|
||||
/* Negation. */
|
||||
if (atMatch(m, e) >> "OpNot" >> e1)
|
||||
if (matchOpNot(e, e1))
|
||||
return makeBool(!evalBool(state, e1));
|
||||
|
||||
/* Implication. */
|
||||
if (atMatch(m, e) >> "OpImpl" >> e1 >> e2)
|
||||
if (matchOpImpl(e, e1, e2))
|
||||
return makeBool(!evalBool(state, e1) || evalBool(state, e2));
|
||||
|
||||
/* Conjunction (logical AND). */
|
||||
if (atMatch(m, e) >> "OpAnd" >> e1 >> e2)
|
||||
if (matchOpAnd(e, e1, e2))
|
||||
return makeBool(evalBool(state, e1) && evalBool(state, e2));
|
||||
|
||||
/* Disjunction (logical OR). */
|
||||
if (atMatch(m, e) >> "OpOr" >> e1 >> e2)
|
||||
if (matchOpOr(e, e1, e2))
|
||||
return makeBool(evalBool(state, e1) || evalBool(state, e2));
|
||||
|
||||
/* Attribute set update (//). */
|
||||
if (atMatch(m, e) >> "OpUpdate" >> e1 >> e2)
|
||||
if (matchOpUpdate(e, e1, e2))
|
||||
return updateAttrs(evalExpr(state, e1), evalExpr(state, e2));
|
||||
|
||||
/* Attribute existence test (?). */
|
||||
if (atMatch(m, e) >> "OpHasAttr" >> e1 >> name) {
|
||||
if (matchOpHasAttr(e, e1, name)) {
|
||||
ATermMap attrs;
|
||||
queryAllAttrs(evalExpr(state, e1), attrs);
|
||||
return makeBool(attrs.get(name) != 0);
|
||||
}
|
||||
|
||||
/* String or path concatenation. */
|
||||
if (matchOpPlus(e, e1, e2)) {
|
||||
e1 = evalExpr(state, e1);
|
||||
e2 = evalExpr(state, e2);
|
||||
ATerm s1, s2;
|
||||
if (matchStr(e1, s1) && matchStr(e2, s2))
|
||||
return makeStr(toATerm(
|
||||
(string) aterm2String(s1) + (string) aterm2String(s2)));
|
||||
else if (matchPath(e1, s1) && matchPath(e2, s2))
|
||||
return makePath(toATerm(canonPath(
|
||||
(string) aterm2String(s1) + "/" + (string) aterm2String(s2))));
|
||||
else throw Error("wrong argument types in `+' operator");
|
||||
}
|
||||
|
||||
/* Barf. */
|
||||
throw badTerm("invalid expression", e);
|
||||
}
|
||||
@@ -364,7 +375,7 @@ Expr evalFile(EvalState & state, const Path & path)
|
||||
try {
|
||||
return evalExpr(state, e);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating file `%1%':\n%2%")
|
||||
throw Error(format("while evaluating the file `%1%':\n%2%")
|
||||
% path % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
+10
-9
@@ -8,21 +8,21 @@
|
||||
#include "nixexpr.hh"
|
||||
|
||||
|
||||
typedef map<Path, PathSet> DrvPaths;
|
||||
typedef map<Path, PathSet> DrvRoots;
|
||||
typedef map<Path, Hash> DrvHashes;
|
||||
|
||||
struct EvalState;
|
||||
typedef Expr (* PrimOp0) (EvalState &);
|
||||
typedef Expr (* PrimOp1) (EvalState &, Expr arg);
|
||||
|
||||
/* Note: using a ATermVector is safe here, since when we call a primop
|
||||
we also have an ATermList on the stack. */
|
||||
typedef Expr (* PrimOp) (EvalState &, const ATermVector & args);
|
||||
|
||||
|
||||
struct EvalState
|
||||
{
|
||||
ATermMap normalForms;
|
||||
ATermMap primOps0; /* nullary primops */
|
||||
ATermMap primOps1; /* unary primops */
|
||||
ATermMap primOpsAll;
|
||||
DrvPaths drvPaths;
|
||||
ATermMap primOps;
|
||||
DrvRoots drvRoots;
|
||||
DrvHashes drvHashes; /* normalised derivation hashes */
|
||||
Expr blackHole;
|
||||
|
||||
@@ -31,8 +31,9 @@ struct EvalState
|
||||
|
||||
EvalState();
|
||||
|
||||
void addPrimOp0(const string & name, PrimOp0 primOp);
|
||||
void addPrimOp1(const string & name, PrimOp1 primOp);
|
||||
void addPrimOps();
|
||||
void addPrimOp(const string & name,
|
||||
unsigned int arity, PrimOp primOp);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -48,6 +48,7 @@ if { return IF; }
|
||||
then { return THEN; }
|
||||
else { return ELSE; }
|
||||
assert { return ASSERT; }
|
||||
with { return WITH; }
|
||||
let { return LET; }
|
||||
rec { return REC; }
|
||||
inherit { return INHERIT; }
|
||||
@@ -75,7 +76,7 @@ inherit { return INHERIT; }
|
||||
|
||||
[ \t\n]+ /* eat up whitespace */
|
||||
\#[^\n]* /* single-line comments */
|
||||
\/\*(.|\n)*\*\/ /* long comments */
|
||||
\/\*([^*]|\*[^\/])*\*\/ /* long comments */
|
||||
|
||||
. return yytext[0];
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
init initNixExprHelpers
|
||||
|
||||
Pos | string int int | Pos |
|
||||
NoPos | | Pos |
|
||||
|
||||
Function | ATermList Expr Pos | Expr |
|
||||
Function1 | string Expr Pos | Expr |
|
||||
Assert | Expr Expr Pos | Expr |
|
||||
With | Expr Expr Pos | Expr |
|
||||
If | Expr Expr Expr | Expr |
|
||||
OpNot | Expr | Expr |
|
||||
OpEq | Expr Expr | Expr |
|
||||
OpNEq | Expr Expr | Expr |
|
||||
OpAnd | Expr Expr | Expr |
|
||||
OpOr | Expr Expr | Expr |
|
||||
OpImpl | Expr Expr | Expr |
|
||||
OpUpdate | Expr Expr | Expr |
|
||||
SubPath | Expr Expr | Expr |
|
||||
OpHasAttr | Expr string | Expr |
|
||||
OpPlus | Expr Expr | Expr |
|
||||
Call | Expr Expr | Expr |
|
||||
Select | Expr string | Expr |
|
||||
Var | string | Expr |
|
||||
Int | int | Expr |
|
||||
Str | string | Expr |
|
||||
Path | string | Expr |
|
||||
Uri | string | Expr |
|
||||
List | ATermList | Expr |
|
||||
BlackHole | | Expr |
|
||||
Undefined | | Expr |
|
||||
PrimOp | int ATermBlob ATermList | Expr |
|
||||
Attrs | ATermList | Expr |
|
||||
Closed | Expr | Expr |
|
||||
Rec | ATermList ATermList | Expr |
|
||||
Bool | ATerm | Expr |
|
||||
Null | | Expr |
|
||||
|
||||
Bind | string Expr Pos | ATerm |
|
||||
Bind | string Expr | ATerm | Bind2
|
||||
Inherit | Expr ATermList Pos | ATerm |
|
||||
|
||||
Scope | | Expr |
|
||||
|
||||
NoDefFormal | string | ATerm |
|
||||
DefFormal | string Expr | ATerm |
|
||||
|
||||
True | | ATerm |
|
||||
False | | ATerm |
|
||||
|
||||
PrimOpDef | int ATermBlob | ATerm |
|
||||
|
||||
AttrRHS | Expr Pos | ATerm |
|
||||
|
||||
eTrue = makeBool(makeTrue())
|
||||
eFalse = makeBool(makeFalse())
|
||||
+58
-74
@@ -2,6 +2,10 @@
|
||||
#include "storeexpr.hh"
|
||||
|
||||
|
||||
#include "nixexpr-ast.hh"
|
||||
#include "nixexpr-ast.cc"
|
||||
|
||||
|
||||
ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct)
|
||||
{
|
||||
this->maxLoadPct = maxLoadPct;
|
||||
@@ -38,7 +42,7 @@ void ATermMap::set(ATerm key, ATerm value)
|
||||
|
||||
void ATermMap::set(const string & key, ATerm value)
|
||||
{
|
||||
set(string2ATerm(key), value);
|
||||
set(toATerm(key), value);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +54,7 @@ ATerm ATermMap::get(ATerm key) const
|
||||
|
||||
ATerm ATermMap::get(const string & key) const
|
||||
{
|
||||
return get(string2ATerm(key));
|
||||
return get(toATerm(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +66,7 @@ void ATermMap::remove(ATerm key)
|
||||
|
||||
void ATermMap::remove(const string & key)
|
||||
{
|
||||
remove(string2ATerm(key));
|
||||
remove(toATerm(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -94,28 +98,14 @@ void ATermMap::reset()
|
||||
}
|
||||
|
||||
|
||||
ATerm string2ATerm(const string & s)
|
||||
{
|
||||
return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s.c_str(), 0, ATtrue));
|
||||
}
|
||||
|
||||
|
||||
string aterm2String(ATerm t)
|
||||
{
|
||||
return ATgetName(ATgetAFun(t));
|
||||
}
|
||||
|
||||
|
||||
string showPos(ATerm pos)
|
||||
{
|
||||
ATMatcher m;
|
||||
Path path;
|
||||
ATerm path;
|
||||
int line, column;
|
||||
if (atMatch(m, pos) >> "NoPos")
|
||||
return "undefined position";
|
||||
if (!(atMatch(m, pos) >> "Pos" >> path >> line >> column))
|
||||
if (matchNoPos(pos)) return "undefined position";
|
||||
if (!matchPos(pos, path, line, column))
|
||||
throw badTerm("position expected", pos);
|
||||
return (format("`%1%', line %2%") % path % line).str();
|
||||
return (format("`%1%', line %2%") % aterm2String(path) % line).str();
|
||||
}
|
||||
|
||||
|
||||
@@ -150,18 +140,16 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
|
||||
|
||||
void queryAllAttrs(Expr e, ATermMap & attrs, bool withPos)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList bnds;
|
||||
if (!(atMatch(m, e) >> "Attrs" >> bnds))
|
||||
if (!matchAttrs(e, bnds))
|
||||
throw Error("attribute set expected");
|
||||
|
||||
for (ATermIterator i(bnds); i; ++i) {
|
||||
string s;
|
||||
ATerm name;
|
||||
Expr e;
|
||||
ATerm pos;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> s >> e >> pos))
|
||||
abort(); /* can't happen */
|
||||
attrs.set(s, withPos ? ATmake("(<term>, <term>)", e, pos) : e);
|
||||
if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */
|
||||
attrs.set(name, withPos ? makeAttrRHS(e, pos) : e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,18 +163,16 @@ Expr queryAttr(Expr e, const string & name)
|
||||
|
||||
Expr queryAttr(Expr e, const string & name, ATerm & pos)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList bnds;
|
||||
if (!(atMatch(m, e) >> "Attrs" >> bnds))
|
||||
if (!matchAttrs(e, bnds))
|
||||
throw Error("attribute set expected");
|
||||
|
||||
for (ATermIterator i(bnds); i; ++i) {
|
||||
string s;
|
||||
ATerm name2, pos2;
|
||||
Expr e;
|
||||
ATerm pos2;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> s >> e >> pos2))
|
||||
if (!matchBind(*i, name2, e, pos2))
|
||||
abort(); /* can't happen */
|
||||
if (s == name) {
|
||||
if (aterm2String(name2) == name) {
|
||||
pos = pos2;
|
||||
return e;
|
||||
}
|
||||
@@ -198,17 +184,15 @@ Expr queryAttr(Expr e, const string & name, ATerm & pos)
|
||||
|
||||
Expr makeAttrs(const ATermMap & attrs)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList bnds = ATempty;
|
||||
for (ATermIterator i(attrs.keys()); i; ++i) {
|
||||
Expr e;
|
||||
ATerm pos;
|
||||
if (!(atMatch(m, attrs.get(*i)) >> "" >> e >> pos))
|
||||
if (!matchAttrRHS(attrs.get(*i), e, pos))
|
||||
abort(); /* can't happen */
|
||||
bnds = ATinsert(bnds,
|
||||
ATmake("Bind(<term>, <term>, <term>)", *i, e, pos));
|
||||
bnds = ATinsert(bnds, makeBind(*i, e, pos));
|
||||
}
|
||||
return ATmake("Attrs(<term>)", ATreverse(bnds));
|
||||
return makeAttrs(ATreverse(bnds));
|
||||
}
|
||||
|
||||
|
||||
@@ -216,57 +200,53 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||
{
|
||||
checkInterrupt();
|
||||
|
||||
ATMatcher m;
|
||||
ATerm name, pos;
|
||||
ATerm name, pos, e2;
|
||||
|
||||
/* As an optimisation, don't substitute in subterms known to be
|
||||
closed. */
|
||||
if (atMatch(m, e) >> "Closed") return e;
|
||||
if (matchClosed(e, e2)) return e;
|
||||
|
||||
if (atMatch(m, e) >> "Var" >> name) {
|
||||
if (matchVar(e, name)) {
|
||||
Expr sub = subs.get(name);
|
||||
return sub ? ATmake("Closed(<term>)", sub) : e;
|
||||
return sub ? makeClosed(sub) : e;
|
||||
}
|
||||
|
||||
/* In case of a function, filter out all variables bound by this
|
||||
function. */
|
||||
ATermList formals;
|
||||
ATerm body;
|
||||
if (atMatch(m, e) >> "Function" >> formals >> body >> pos) {
|
||||
ATerm body, def;
|
||||
if (matchFunction(e, formals, body, pos)) {
|
||||
ATermMap subs2(subs);
|
||||
for (ATermIterator i(formals); i; ++i) {
|
||||
if (!(atMatch(m, *i) >> "NoDefFormal" >> name) &&
|
||||
!(atMatch(m, *i) >> "DefFormal" >> name))
|
||||
if (!matchNoDefFormal(*i, name) &&
|
||||
!matchDefFormal(*i, name, def))
|
||||
abort();
|
||||
subs2.remove(name);
|
||||
}
|
||||
return ATmake("Function(<term>, <term>, <term>)",
|
||||
substitute(subs, (ATerm) formals),
|
||||
return makeFunction(
|
||||
(ATermList) substitute(subs, (ATerm) formals),
|
||||
substitute(subs2, body), pos);
|
||||
}
|
||||
|
||||
if (atMatch(m, e) >> "Function1" >> name >> body >> pos) {
|
||||
if (matchFunction1(e, name, body, pos)) {
|
||||
ATermMap subs2(subs);
|
||||
subs2.remove(name);
|
||||
return ATmake("Function1(<term>, <term>, <term>)", name,
|
||||
substitute(subs2, body), pos);
|
||||
return makeFunction1(name, substitute(subs2, body), pos);
|
||||
}
|
||||
|
||||
/* Idem for a mutually recursive attribute set. */
|
||||
ATermList rbnds, nrbnds;
|
||||
if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds) {
|
||||
if (matchRec(e, rbnds, nrbnds)) {
|
||||
ATermMap subs2(subs);
|
||||
for (ATermIterator i(rbnds); i; ++i)
|
||||
if (atMatch(m, *i) >> "Bind" >> name)
|
||||
subs2.remove(name);
|
||||
if (matchBind(*i, name, e2, pos)) subs2.remove(name);
|
||||
else abort(); /* can't happen */
|
||||
for (ATermIterator i(nrbnds); i; ++i)
|
||||
if (atMatch(m, *i) >> "Bind" >> name)
|
||||
subs2.remove(name);
|
||||
if (matchBind(*i, name, e2, pos)) subs2.remove(name);
|
||||
else abort(); /* can't happen */
|
||||
return ATmake("Rec(<term>, <term>)",
|
||||
substitute(subs2, (ATerm) rbnds),
|
||||
substitute(subs, (ATerm) nrbnds));
|
||||
return makeRec(
|
||||
(ATermList) substitute(subs2, (ATerm) rbnds),
|
||||
(ATermList) substitute(subs, (ATerm) nrbnds));
|
||||
}
|
||||
|
||||
if (ATgetType(e) == AT_APPL) {
|
||||
@@ -293,24 +273,23 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||
|
||||
void checkVarDefs(const ATermMap & defs, Expr e)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATerm name;
|
||||
ATerm name, pos, value;
|
||||
ATermList formals;
|
||||
ATerm body;
|
||||
ATerm with, body;
|
||||
ATermList rbnds, nrbnds;
|
||||
|
||||
if (atMatch(m, e) >> "Var" >> name) {
|
||||
if (matchVar(e, name)) {
|
||||
if (!defs.get(name))
|
||||
throw Error(format("undefined variable `%1%'")
|
||||
% aterm2String(name));
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "Function" >> formals >> body) {
|
||||
else if (matchFunction(e, formals, body, pos)) {
|
||||
ATermMap defs2(defs);
|
||||
for (ATermIterator i(formals); i; ++i) {
|
||||
Expr deflt;
|
||||
if (!(atMatch(m, *i) >> "NoDefFormal" >> name))
|
||||
if (atMatch(m, *i) >> "DefFormal" >> name >> deflt)
|
||||
if (!matchNoDefFormal(*i, name))
|
||||
if (matchDefFormal(*i, name, deflt))
|
||||
checkVarDefs(defs, deflt);
|
||||
else
|
||||
abort();
|
||||
@@ -319,27 +298,32 @@ void checkVarDefs(const ATermMap & defs, Expr e)
|
||||
checkVarDefs(defs2, body);
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "Function1" >> name >> body) {
|
||||
else if (matchFunction1(e, name, body, pos)) {
|
||||
ATermMap defs2(defs);
|
||||
defs2.set(name, (ATerm) ATempty);
|
||||
checkVarDefs(defs2, body);
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds) {
|
||||
else if (matchRec(e, rbnds, nrbnds)) {
|
||||
checkVarDefs(defs, (ATerm) nrbnds);
|
||||
ATermMap defs2(defs);
|
||||
for (ATermIterator i(rbnds); i; ++i) {
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name))
|
||||
abort(); /* can't happen */
|
||||
if (!matchBind(*i, name, value, pos)) abort(); /* can't happen */
|
||||
defs2.set(name, (ATerm) ATempty);
|
||||
}
|
||||
for (ATermIterator i(nrbnds); i; ++i) {
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name))
|
||||
abort(); /* can't happen */
|
||||
if (!matchBind(*i, name, value, pos)) abort(); /* can't happen */
|
||||
defs2.set(name, (ATerm) ATempty);
|
||||
}
|
||||
checkVarDefs(defs2, (ATerm) rbnds);
|
||||
}
|
||||
|
||||
else if (matchWith(e, with, body, pos)) {
|
||||
/* We can't check the body without evaluating the definitions
|
||||
(which is an arbitrary expression), so we don't do that
|
||||
here but only when actually evaluating the `with'. */
|
||||
checkVarDefs(defs, with);
|
||||
}
|
||||
|
||||
else if (ATgetType(e) == AT_APPL) {
|
||||
int arity = ATgetArity(ATgetAFun(e));
|
||||
@@ -355,5 +339,5 @@ void checkVarDefs(const ATermMap & defs, Expr e)
|
||||
|
||||
Expr makeBool(bool b)
|
||||
{
|
||||
return b ? ATmake("Bool(True)") : ATmake("Bool(False)");
|
||||
return b ? eTrue : eFalse;
|
||||
}
|
||||
+13
-4
@@ -13,6 +13,8 @@
|
||||
normals forms efficiently. */
|
||||
typedef ATerm Expr;
|
||||
|
||||
typedef ATerm Pos;
|
||||
|
||||
|
||||
/* Mappings from ATerms to ATerms. This is just a wrapper around
|
||||
ATerm tables. */
|
||||
@@ -47,10 +49,11 @@ private:
|
||||
};
|
||||
|
||||
|
||||
/* Convert a string to an ATerm (i.e., a quoted nullary function
|
||||
applicaton). */
|
||||
ATerm string2ATerm(const string & s);
|
||||
string aterm2String(ATerm t);
|
||||
/* A STL vector of ATerms. Should be used with great care since it's
|
||||
stored on the heap, and the elements are therefore not roots to the
|
||||
ATerm garbage collector. */
|
||||
typedef vector<ATerm> ATermVector;
|
||||
|
||||
|
||||
/* Show a position. */
|
||||
string showPos(ATerm pos);
|
||||
@@ -86,5 +89,11 @@ void checkVarDefs(const ATermMap & def, Expr e);
|
||||
/* Create an expression representing a boolean. */
|
||||
Expr makeBool(bool b);
|
||||
|
||||
/* Create an expression representing a string. */
|
||||
Expr makeString(const string & s);
|
||||
|
||||
/* Create an expression representing a path. */
|
||||
Expr makePath(const Path & path);
|
||||
|
||||
|
||||
#endif /* !__NIXEXPR_H */
|
||||
+11
-12
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "aterm.hh"
|
||||
#include "parser.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
|
||||
struct ParseData
|
||||
@@ -34,7 +35,7 @@ void setParseResult(ParseData * data, ATerm t)
|
||||
|
||||
ATerm absParsedPath(ParseData * data, ATerm t)
|
||||
{
|
||||
return string2ATerm(absPath(aterm2String(t), data->basePath).c_str());
|
||||
return toATerm(absPath(aterm2String(t), data->basePath));
|
||||
}
|
||||
|
||||
void parseError(ParseData * data, char * error, int line, int column)
|
||||
@@ -45,28 +46,24 @@ void parseError(ParseData * data, char * error, int line, int column)
|
||||
|
||||
ATerm fixAttrs(int recursive, ATermList as)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList bs = ATempty, cs = ATempty;
|
||||
ATermList * is = recursive ? &cs : &bs;
|
||||
for (ATermIterator i(as); i; ++i) {
|
||||
ATermList names;
|
||||
Expr src;
|
||||
ATerm pos;
|
||||
if (atMatch(m, *i) >> "Inherit" >> src >> names >> pos) {
|
||||
bool fromScope = atMatch(m, src) >> "Scope";
|
||||
if (matchInherit(*i, src, names, pos)) {
|
||||
bool fromScope = matchScope(src);
|
||||
for (ATermIterator j(names); j; ++j) {
|
||||
Expr rhs = fromScope
|
||||
? ATmake("Var(<term>)", *j)
|
||||
: ATmake("Select(<term>, <term>)", src, *j);
|
||||
*is = ATinsert(*is, ATmake("Bind(<term>, <term>, <term>)",
|
||||
*j, rhs, pos));
|
||||
Expr rhs = fromScope ? makeVar(*j) : makeSelect(src, *j);
|
||||
*is = ATinsert(*is, makeBind(*j, rhs, pos));
|
||||
}
|
||||
} else bs = ATinsert(bs, *i);
|
||||
}
|
||||
if (recursive)
|
||||
return ATmake("Rec(<term>, <term>)", bs, cs);
|
||||
return makeRec(bs, cs);
|
||||
else
|
||||
return ATmake("Attrs(<term>)", bs);
|
||||
return makeAttrs(bs);
|
||||
}
|
||||
|
||||
const char * getPath(ParseData * data)
|
||||
@@ -95,7 +92,7 @@ static Expr parse(EvalState & state,
|
||||
if (res) throw Error(data.error);
|
||||
|
||||
try {
|
||||
checkVarDefs(state.primOpsAll, data.result);
|
||||
checkVarDefs(state.primOps, data.result);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("%1%, in `%2%'") % e.msg() % path);
|
||||
}
|
||||
@@ -106,6 +103,8 @@ static Expr parse(EvalState & state,
|
||||
|
||||
Expr parseExprFromFile(EvalState & state, Path path)
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
|
||||
assert(path[0] == '/');
|
||||
|
||||
#if 0
|
||||
|
||||
+48
-38
@@ -15,6 +15,11 @@
|
||||
#include "parser-tab.h"
|
||||
#include "lexer-tab.h"
|
||||
|
||||
typedef ATerm Expr;
|
||||
typedef ATerm Pos;
|
||||
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
void setParseResult(void * data, ATerm t);
|
||||
void parseError(void * data, char * error, int line, int column);
|
||||
ATerm absParsedPath(void * data, ATerm t);
|
||||
@@ -26,13 +31,18 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
|
||||
parseError(data, s, loc->first_line, loc->first_column);
|
||||
}
|
||||
|
||||
ATerm makePos(YYLTYPE * loc, void * data)
|
||||
ATerm toATerm(const char * s)
|
||||
{
|
||||
return ATmake("Pos(<str>, <int>, <int>)",
|
||||
getPath(data), loc->first_line, loc->first_column);
|
||||
return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
|
||||
}
|
||||
|
||||
#define CUR_POS makePos(yylocp, data)
|
||||
static Pos makeCurPos(YYLTYPE * loc, void * data)
|
||||
{
|
||||
return makePos(toATerm(getPath(data)),
|
||||
loc->first_line, loc->first_column);
|
||||
}
|
||||
|
||||
#define CUR_POS makeCurPos(yylocp, data)
|
||||
|
||||
%}
|
||||
|
||||
@@ -41,11 +51,11 @@ ATerm makePos(YYLTYPE * loc, void * data)
|
||||
ATermList ts;
|
||||
}
|
||||
|
||||
%type <t> start expr expr_function expr_assert 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 <ts> binds ids expr_list formals
|
||||
%token <t> ID INT STR PATH URI
|
||||
%token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL
|
||||
%token IF THEN ELSE ASSERT WITH LET REC INHERIT EQ NEQ AND OR IMPL
|
||||
|
||||
%nonassoc IMPL
|
||||
%left OR
|
||||
@@ -53,6 +63,7 @@ ATerm makePos(YYLTYPE * loc, void * data)
|
||||
%nonassoc EQ NEQ
|
||||
%right UPDATE
|
||||
%left NEG
|
||||
%left '+'
|
||||
%nonassoc '?'
|
||||
%nonassoc '~'
|
||||
|
||||
@@ -64,65 +75,64 @@ expr: expr_function;
|
||||
|
||||
expr_function
|
||||
: '{' formals '}' ':' expr_function
|
||||
{ $$ = ATmake("Function(<term>, <term>, <term>)", $2, $5, CUR_POS); }
|
||||
{ $$ = makeFunction($2, $5, CUR_POS); }
|
||||
| ID ':' expr_function
|
||||
{ $$ = ATmake("Function1(<term>, <term>, <term>)", $1, $3, CUR_POS); }
|
||||
| expr_assert
|
||||
;
|
||||
|
||||
expr_assert
|
||||
: ASSERT expr ';' expr_assert
|
||||
{ $$ = ATmake("Assert(<term>, <term>, <term>)", $2, $4, CUR_POS); }
|
||||
{ $$ = makeFunction1($1, $3, CUR_POS); }
|
||||
| ASSERT expr ';' expr_function
|
||||
{ $$ = makeAssert($2, $4, CUR_POS); }
|
||||
| WITH expr ';' expr_function
|
||||
{ $$ = makeWith($2, $4, CUR_POS); }
|
||||
| expr_if
|
||||
;
|
||||
|
||||
expr_if
|
||||
: IF expr THEN expr ELSE expr
|
||||
{ $$ = ATmake("If(<term>, <term>, <term>)", $2, $4, $6); }
|
||||
{ $$ = makeIf($2, $4, $6); }
|
||||
| expr_op
|
||||
;
|
||||
|
||||
expr_op
|
||||
: '!' expr_op %prec NEG { $$ = ATmake("OpNot(<term>)", $2); }
|
||||
| expr_op EQ expr_op { $$ = ATmake("OpEq(<term>, <term>)", $1, $3); }
|
||||
| expr_op NEQ expr_op { $$ = ATmake("OpNEq(<term>, <term>)", $1, $3); }
|
||||
| expr_op AND expr_op { $$ = ATmake("OpAnd(<term>, <term>)", $1, $3); }
|
||||
| expr_op OR expr_op { $$ = ATmake("OpOr(<term>, <term>)", $1, $3); }
|
||||
| expr_op IMPL expr_op { $$ = ATmake("OpImpl(<term>, <term>)", $1, $3); }
|
||||
| expr_op UPDATE expr_op { $$ = ATmake("OpUpdate(<term>, <term>)", $1, $3); }
|
||||
| expr_op '~' expr_op { $$ = ATmake("SubPath(<term>, <term>)", $1, $3); }
|
||||
| expr_op '?' ID { $$ = ATmake("OpHasAttr(<term>, <term>)", $1, $3); }
|
||||
: '!' expr_op %prec NEG { $$ = makeOpNot($2); }
|
||||
| expr_op EQ expr_op { $$ = makeOpEq($1, $3); }
|
||||
| expr_op NEQ expr_op { $$ = makeOpNEq($1, $3); }
|
||||
| expr_op AND expr_op { $$ = makeOpAnd($1, $3); }
|
||||
| expr_op OR expr_op { $$ = makeOpOr($1, $3); }
|
||||
| expr_op IMPL expr_op { $$ = makeOpImpl($1, $3); }
|
||||
| expr_op UPDATE expr_op { $$ = makeOpUpdate($1, $3); }
|
||||
| expr_op '~' expr_op { $$ = makeSubPath($1, $3); }
|
||||
| expr_op '?' ID { $$ = makeOpHasAttr($1, $3); }
|
||||
| expr_op '+' expr_op { $$ = makeOpPlus($1, $3); }
|
||||
| expr_app
|
||||
;
|
||||
|
||||
expr_app
|
||||
: expr_app expr_select
|
||||
{ $$ = ATmake("Call(<term>, <term>)", $1, $2); }
|
||||
{ $$ = makeCall($1, $2); }
|
||||
| expr_select { $$ = $1; }
|
||||
;
|
||||
|
||||
expr_select
|
||||
: expr_select '.' ID
|
||||
{ $$ = ATmake("Select(<term>, <term>)", $1, $3); }
|
||||
{ $$ = makeSelect($1, $3); }
|
||||
| expr_simple { $$ = $1; }
|
||||
;
|
||||
|
||||
expr_simple
|
||||
: ID { $$ = ATmake("Var(<term>)", $1); }
|
||||
| INT { $$ = ATmake("Int(<term>)", $1); }
|
||||
| STR { $$ = ATmake("Str(<term>)", $1); }
|
||||
| PATH { $$ = ATmake("Path(<term>)", absParsedPath(data, $1)); }
|
||||
| URI { $$ = ATmake("Uri(<term>)", $1); }
|
||||
: ID { $$ = makeVar($1); }
|
||||
| INT { $$ = makeInt(ATgetInt((ATermInt) $1)); }
|
||||
| STR { $$ = makeStr($1); }
|
||||
| PATH { $$ = makePath(absParsedPath(data, $1)); }
|
||||
| URI { $$ = makeUri($1); }
|
||||
| '(' expr ')' { $$ = $2; }
|
||||
/* Let expressions `let {..., body = ...}' are just desugared
|
||||
into `(rec {..., body = ...}).body'. */
|
||||
| LET '{' binds '}'
|
||||
{ $$ = ATmake("Select(<term>, \"body\")", fixAttrs(1, $3)); }
|
||||
{ $$ = makeSelect(fixAttrs(1, $3), toATerm("body")); }
|
||||
| REC '{' binds '}'
|
||||
{ $$ = fixAttrs(1, $3); }
|
||||
| '{' binds '}'
|
||||
{ $$ = fixAttrs(0, $2); }
|
||||
| '[' expr_list ']' { $$ = ATmake("List(<term>)", $2); }
|
||||
| '[' expr_list ']' { $$ = makeList($2); }
|
||||
;
|
||||
|
||||
binds
|
||||
@@ -132,14 +142,14 @@ binds
|
||||
|
||||
bind
|
||||
: ID '=' expr ';'
|
||||
{ $$ = ATmake("Bind(<term>, <term>, <term>)", $1, $3, CUR_POS); }
|
||||
{ $$ = makeBind($1, $3, CUR_POS); }
|
||||
| INHERIT inheritsrc ids ';'
|
||||
{ $$ = ATmake("Inherit(<term>, <term>, <term>)", $2, $3, CUR_POS); }
|
||||
{ $$ = makeInherit($2, $3, CUR_POS); }
|
||||
;
|
||||
|
||||
inheritsrc
|
||||
: '(' expr ')' { $$ = $2; }
|
||||
| { $$ = ATmake("Scope"); }
|
||||
| { $$ = makeScope(); }
|
||||
;
|
||||
|
||||
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };
|
||||
@@ -158,8 +168,8 @@ formals
|
||||
;
|
||||
|
||||
formal
|
||||
: ID { $$ = ATmake("NoDefFormal(<term>)", $1); }
|
||||
| ID '?' expr { $$ = ATmake("DefFormal(<term>, <term>)", $1, $3); }
|
||||
: ID { $$ = makeNoDefFormal($1); }
|
||||
| ID '?' expr { $$ = makeDefFormal($1, $3); }
|
||||
;
|
||||
|
||||
%%
|
||||
+125
-63
@@ -1,26 +1,29 @@
|
||||
#include "primops.hh"
|
||||
#include "normalise.hh"
|
||||
#include "eval.hh"
|
||||
#include "globals.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
|
||||
Expr primImport(EvalState & state, Expr arg)
|
||||
/* Load and evaluate an expression from path specified by the
|
||||
argument. */
|
||||
static Expr primImport(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
ATMatcher m;
|
||||
string path;
|
||||
if (!(atMatch(m, arg) >> "Path" >> path))
|
||||
ATerm path;
|
||||
Expr fn = evalExpr(state, args[0]);
|
||||
if (!matchPath(fn, path))
|
||||
throw Error("path expected");
|
||||
return evalFile(state, path);
|
||||
return evalFile(state, aterm2String(path));
|
||||
}
|
||||
|
||||
|
||||
static PathSet storeExprRootsCached(EvalState & state, const Path & nePath)
|
||||
{
|
||||
DrvPaths::iterator i = state.drvPaths.find(nePath);
|
||||
if (i != state.drvPaths.end())
|
||||
DrvRoots::iterator i = state.drvRoots.find(nePath);
|
||||
if (i != state.drvRoots.end())
|
||||
return i->second;
|
||||
else {
|
||||
PathSet paths = storeExprRoots(nePath);
|
||||
state.drvPaths[nePath] = paths;
|
||||
state.drvRoots[nePath] = paths;
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +62,8 @@ static Path copyAtom(EvalState & state, const Path & srcPath)
|
||||
Path drvPath = writeTerm(unparseStoreExpr(ne), "");
|
||||
state.drvHashes[drvPath] = drvHash;
|
||||
|
||||
state.drvRoots[drvPath] = ne.closure.roots;
|
||||
|
||||
printMsg(lvlChatty, format("copied `%1%' -> closure `%2%'")
|
||||
% srcPath % drvPath);
|
||||
return drvPath;
|
||||
@@ -81,24 +86,23 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne,
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
|
||||
ATMatcher m;
|
||||
string s;
|
||||
ATerm s;
|
||||
ATermList es;
|
||||
int n;
|
||||
Expr e1, e2;
|
||||
|
||||
if (atMatch(m, e) >> "Str" >> s) ss.push_back(s);
|
||||
else if (atMatch(m, e) >> "Uri" >> s) ss.push_back(s);
|
||||
else if (atMatch(m, e) >> "Bool" >> "True") ss.push_back("1");
|
||||
else if (atMatch(m, e) >> "Bool" >> "False") ss.push_back("");
|
||||
if (matchStr(e, s)) ss.push_back(aterm2String(s));
|
||||
else if (matchUri(e, s)) ss.push_back(aterm2String(s));
|
||||
else if (e == eTrue) ss.push_back("1");
|
||||
else if (e == eFalse) ss.push_back("");
|
||||
|
||||
else if (atMatch(m, e) >> "Int" >> n) {
|
||||
else if (matchInt(e, n)) {
|
||||
ostringstream st;
|
||||
st << n;
|
||||
ss.push_back(st.str());
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "Attrs") {
|
||||
else if (matchAttrs(e, es)) {
|
||||
Expr a = queryAttr(e, "type");
|
||||
if (a && evalString(state, a) == "derivation") {
|
||||
a = queryAttr(e, "drvPath");
|
||||
@@ -109,37 +113,42 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne,
|
||||
if (!a) throw Error("derivation hash missing");
|
||||
Hash drvHash = parseHash(evalString(state, a));
|
||||
|
||||
state.drvHashes[drvPath] = drvHash;
|
||||
a = queryAttr(e, "outPath");
|
||||
if (!a) throw Error("output path missing");
|
||||
PathSet drvRoots;
|
||||
drvRoots.insert(evalPath(state, a));
|
||||
|
||||
state.drvHashes[drvPath] = drvHash;
|
||||
state.drvRoots[drvPath] = drvRoots;
|
||||
|
||||
ss.push_back(addInput(state, drvPath, ne));
|
||||
} else
|
||||
throw Error("invalid derivation attribute");
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "Path" >> s) {
|
||||
Path drvPath = copyAtom(state, s);
|
||||
else if (matchPath(e, s)) {
|
||||
Path drvPath = copyAtom(state, aterm2String(s));
|
||||
ss.push_back(addInput(state, drvPath, ne));
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "List" >> es) {
|
||||
else if (matchList(e, es)) {
|
||||
for (ATermIterator i(es); i; ++i) {
|
||||
startNest(nest, lvlVomit, format("processing list element"));
|
||||
processBinding(state, evalExpr(state, *i), ne, ss);
|
||||
}
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "Null") ss.push_back("");
|
||||
else if (matchNull(e)) ss.push_back("");
|
||||
|
||||
else if (atMatch(m, e) >> "SubPath" >> e1 >> e2) {
|
||||
else if (matchSubPath(e, e1, e2)) {
|
||||
Strings ss2;
|
||||
processBinding(state, evalExpr(state, e1), ne, ss2);
|
||||
if (ss2.size() != 1)
|
||||
throw Error("left-hand side of `~' operator cannot be a list");
|
||||
e2 = evalExpr(state, e2);
|
||||
if (!(atMatch(m, e2) >> "Str" >> s ||
|
||||
(atMatch(m, e2) >> "Path" >> s)))
|
||||
if (!(matchStr(e2, s) || matchPath(e2, s)))
|
||||
throw Error("right-hand side of `~' operator must be a path or string");
|
||||
ss.push_back(canonPath(ss2.front() + "/" + s));
|
||||
ss.push_back(canonPath(ss2.front() + "/" + aterm2String(s)));
|
||||
}
|
||||
|
||||
else throw Error("invalid derivation attribute");
|
||||
@@ -158,11 +167,19 @@ static string concatStrings(const Strings & ss)
|
||||
}
|
||||
|
||||
|
||||
Expr primDerivation(EvalState & state, Expr args)
|
||||
/* Construct (as a unobservable side effect) a Nix derivation
|
||||
expression that performs the derivation described by the argument
|
||||
set. Returns the original set extended with the following
|
||||
attributes: `outPath' containing the primary output path of the
|
||||
derivation; `drvPath' containing the path of the Nix expression;
|
||||
and `type' set to `derivation' to indicate that this is a
|
||||
derivation. */
|
||||
static Expr primDerivation(EvalState & state, const ATermVector & _args)
|
||||
{
|
||||
startNest(nest, lvlVomit, "evaluating derivation");
|
||||
|
||||
ATermMap attrs;
|
||||
Expr args = _args[0];
|
||||
args = evalExpr(state, args);
|
||||
queryAllAttrs(args, attrs, true);
|
||||
|
||||
@@ -171,7 +188,6 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||
ne.type = StoreExpr::neDerivation;
|
||||
|
||||
string drvName;
|
||||
Path outPath;
|
||||
Hash outHash;
|
||||
bool outHashGiven = false;
|
||||
|
||||
@@ -180,15 +196,14 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||
ATerm value;
|
||||
Expr pos;
|
||||
ATerm rhs = attrs.get(key);
|
||||
ATMatcher m;
|
||||
if (!(atMatch(m, rhs) >> "" >> value >> pos)) abort();
|
||||
if (!matchAttrRHS(rhs, value, pos)) abort();
|
||||
startNest(nest, lvlVomit, format("processing attribute `%1%'") % key);
|
||||
|
||||
Strings ss;
|
||||
try {
|
||||
processBinding(state, value, ne, ss);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while processing derivation attribute `%1%' at %2%:\n%3%")
|
||||
throw Error(format("while processing the derivation attribute `%1%' at %2%:\n%3%")
|
||||
% key % showPos(pos) % e.msg());
|
||||
}
|
||||
|
||||
@@ -207,7 +222,6 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||
if (key == "builder") ne.derivation.builder = s;
|
||||
else if (key == "system") ne.derivation.platform = s;
|
||||
else if (key == "name") drvName = s;
|
||||
else if (key == "outPath") outPath = s;
|
||||
else if (key == "id") {
|
||||
outHash = parseHash(s);
|
||||
outHashGiven = true;
|
||||
@@ -222,14 +236,27 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||
throw Error("required attribute `system' missing");
|
||||
if (drvName == "")
|
||||
throw Error("required attribute `name' missing");
|
||||
|
||||
/* Check the derivation name. It shouldn't contain whitespace,
|
||||
but we are conservative here: we check whether only
|
||||
alphanumerics and some other characters appear. */
|
||||
string validChars = "+-._?=";
|
||||
for (string::iterator i = drvName.begin(); i != drvName.end(); ++i)
|
||||
if (!((*i >= 'A' && *i <= 'Z') ||
|
||||
(*i >= 'a' && *i <= 'z') ||
|
||||
(*i >= '0' && *i <= '9') ||
|
||||
validChars.find(*i) != string::npos))
|
||||
{
|
||||
throw Error(format("invalid character `%1%' in derivation name `%2%'")
|
||||
% *i % drvName);
|
||||
}
|
||||
|
||||
/* Determine the output path. */
|
||||
/* Determine the output path by hashing the Nix expression with no
|
||||
outputs to produce a unique but deterministic path name for
|
||||
this derivation. */
|
||||
if (!outHashGiven) outHash = hashDerivation(state, ne);
|
||||
if (outPath == "")
|
||||
/* Hash the Nix expression with no outputs to produce a
|
||||
unique but deterministic path name for this derivation. */
|
||||
outPath = canonPath(nixStore + "/" +
|
||||
((string) outHash).c_str() + "-" + drvName);
|
||||
Path outPath = canonPath(nixStore + "/" +
|
||||
((string) outHash).c_str() + "-" + drvName);
|
||||
ne.derivation.env["out"] = outPath;
|
||||
ne.derivation.outputs.insert(outPath);
|
||||
|
||||
@@ -242,56 +269,91 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||
printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'")
|
||||
% drvName % drvPath);
|
||||
|
||||
attrs.set("outPath", ATmake("(Path(<str>), NoPos)", outPath.c_str()));
|
||||
attrs.set("drvPath", ATmake("(Path(<str>), NoPos)", drvPath.c_str()));
|
||||
attrs.set("drvHash", ATmake("(Str(<str>), NoPos)", ((string) drvHash).c_str()));
|
||||
attrs.set("type", ATmake("(Str(\"derivation\"), NoPos)"));
|
||||
attrs.set("outPath", makeAttrRHS(makePath(toATerm(outPath)), makeNoPos()));
|
||||
attrs.set("drvPath", makeAttrRHS(makePath(toATerm(drvPath)), makeNoPos()));
|
||||
attrs.set("drvHash",
|
||||
makeAttrRHS(makeStr(toATerm((string) drvHash)), makeNoPos()));
|
||||
attrs.set("type", makeAttrRHS(makeStr(toATerm("derivation")), makeNoPos()));
|
||||
|
||||
return makeAttrs(attrs);
|
||||
}
|
||||
|
||||
|
||||
Expr primBaseNameOf(EvalState & state, Expr arg)
|
||||
/* Return the base name of the given string, i.e., everything
|
||||
following the last slash. */
|
||||
static Expr primBaseNameOf(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
string s = evalString(state, arg);
|
||||
return ATmake("Str(<str>)", baseNameOf(s).c_str());
|
||||
return makeStr(toATerm(baseNameOf(evalString(state, args[0]))));
|
||||
}
|
||||
|
||||
|
||||
Expr primToString(EvalState & state, Expr arg)
|
||||
/* Convert the argument (which can be a path or a uri) to a string. */
|
||||
static Expr primToString(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
arg = evalExpr(state, arg);
|
||||
ATMatcher m;
|
||||
string s;
|
||||
if (atMatch(m, arg) >> "Str" >> s ||
|
||||
atMatch(m, arg) >> "Path" >> s ||
|
||||
atMatch(m, arg) >> "Uri" >> s)
|
||||
return ATmake("Str(<str>)", s.c_str());
|
||||
Expr arg = evalExpr(state, args[0]);
|
||||
ATerm s;
|
||||
if (matchStr(arg, s) || matchPath(arg, s) || matchUri(arg, s))
|
||||
return makeStr(s);
|
||||
else throw Error("cannot coerce value to string");
|
||||
}
|
||||
|
||||
|
||||
Expr primTrue(EvalState & state)
|
||||
/* Boolean constructors. */
|
||||
static Expr primTrue(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
return ATmake("Bool(True)");
|
||||
return eTrue;
|
||||
}
|
||||
|
||||
|
||||
Expr primFalse(EvalState & state)
|
||||
static Expr primFalse(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
return ATmake("Bool(False)");
|
||||
return eFalse;
|
||||
}
|
||||
|
||||
|
||||
Expr primNull(EvalState & state)
|
||||
/* Return the null value. */
|
||||
Expr primNull(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
return ATmake("Null");
|
||||
return makeNull();
|
||||
}
|
||||
|
||||
|
||||
Expr primIsNull(EvalState & state, Expr arg)
|
||||
/* Determine whether the argument is the null value. */
|
||||
Expr primIsNull(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
arg = evalExpr(state, arg);
|
||||
ATMatcher m;
|
||||
return makeBool(atMatch(m, arg) >> "Null");
|
||||
return makeBool(matchNull(evalExpr(state, args[0])));
|
||||
}
|
||||
|
||||
|
||||
/* Apply a function to every element of a list. */
|
||||
Expr primMap(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
Expr fun = evalExpr(state, args[0]);
|
||||
Expr list = evalExpr(state, args[1]);
|
||||
|
||||
ATermList list2;
|
||||
if (!matchList(list, list2))
|
||||
throw Error("`map' expects a list as its second argument");
|
||||
|
||||
ATermList list3 = ATempty;
|
||||
for (ATermIterator i(list2); i; ++i)
|
||||
list3 = ATinsert(list3, makeCall(fun, *i));
|
||||
|
||||
return makeList(ATreverse(list3));
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addPrimOps()
|
||||
{
|
||||
addPrimOp("true", 0, primTrue);
|
||||
addPrimOp("false", 0, primFalse);
|
||||
addPrimOp("null", 0, primNull);
|
||||
|
||||
addPrimOp("import", 1, primImport);
|
||||
addPrimOp("derivation", 1, primDerivation);
|
||||
addPrimOp("baseNameOf", 1, primBaseNameOf);
|
||||
addPrimOp("toString", 1, primToString);
|
||||
addPrimOp("isNull", 1, primIsNull);
|
||||
|
||||
addPrimOp("map", 2, primMap);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef __PRIMOPS_H
|
||||
#define __PRIMOPS_H
|
||||
|
||||
#include "eval.hh"
|
||||
|
||||
|
||||
/* Load and evaluate an expression from path specified by the
|
||||
argument. */
|
||||
Expr primImport(EvalState & state, Expr arg);
|
||||
|
||||
/* Construct (as a unobservable side effect) a Nix derivation
|
||||
expression that performs the derivation described by the argument
|
||||
set. Returns the original set extended with the following
|
||||
attributes: `outPath' containing the primary output path of the
|
||||
derivation; `drvPath' containing the path of the Nix expression;
|
||||
and `type' set to `derivation' to indicate that this is a
|
||||
derivation. */
|
||||
Expr primDerivation(EvalState & state, Expr args);
|
||||
|
||||
/* Return the base name of the given string, i.e., everything
|
||||
following the last slash. */
|
||||
Expr primBaseNameOf(EvalState & state, Expr arg);
|
||||
|
||||
/* Convert the argument (which can be a path or a uri) to a string. */
|
||||
Expr primToString(EvalState & state, Expr arg);
|
||||
|
||||
/* Boolean constructors. */
|
||||
Expr primTrue(EvalState & state);
|
||||
Expr primFalse(EvalState & state);
|
||||
|
||||
/* Return the null value. */
|
||||
Expr primNull(EvalState & state);
|
||||
|
||||
/* Determine whether the argument is the null value. */
|
||||
Expr primIsNull(EvalState & state, Expr arg);
|
||||
|
||||
|
||||
#endif /* !__PRIMOPS_H */
|
||||
+153
-4
@@ -5,6 +5,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
extern "C" {
|
||||
#include <aterm2.h>
|
||||
}
|
||||
@@ -52,6 +55,9 @@ void checkStoreNotSymlink(Path path)
|
||||
}
|
||||
|
||||
|
||||
void initStoreExprHelpers();
|
||||
|
||||
|
||||
/* Initialize and reorder arguments, then call the actual argument
|
||||
processor. */
|
||||
static void initAndRun(int argc, char * * argv)
|
||||
@@ -88,10 +94,19 @@ static void initAndRun(int argc, char * * argv)
|
||||
if (sigaction(SIGPIPE, &act, &oact))
|
||||
throw SysError("ignoring SIGPIPE");
|
||||
|
||||
/* There is no privacy in the Nix system ;-) At least not for
|
||||
now. In particular, store objects should be readable by
|
||||
everybody. This prevents nasty surprises when using a shared
|
||||
store (with the setuid() hack). */
|
||||
umask(0022);
|
||||
|
||||
/* Process the NIX_LOG_TYPE environment variable. */
|
||||
string lt = getEnv("NIX_LOG_TYPE");
|
||||
if (lt != "") setLogType(lt);
|
||||
|
||||
/* ATerm stuff. !!! find a better place to put this */
|
||||
initStoreExprHelpers();
|
||||
|
||||
/* Put the arguments in a vector. */
|
||||
Strings args, remaining;
|
||||
while (argc--) args.push_back(*argv++);
|
||||
@@ -126,7 +141,9 @@ static void initAndRun(int argc, char * * argv)
|
||||
setLogType(*i);
|
||||
}
|
||||
else if (arg == "--build-output" || arg == "-B")
|
||||
buildVerbosity = lvlError; /* lowest */
|
||||
; /* !!! obsolete - remove eventually */
|
||||
else if (arg == "--no-build-output" || arg == "-Q")
|
||||
buildVerbosity = lvlVomit;
|
||||
else if (arg == "--help") {
|
||||
printHelp();
|
||||
return;
|
||||
@@ -144,13 +161,13 @@ static void initAndRun(int argc, char * * argv)
|
||||
else if (arg == "--max-jobs" || arg == "-j") {
|
||||
++i;
|
||||
if (i == args.end()) throw UsageError("`--max-jobs' requires an argument");
|
||||
istringstream str(*i);
|
||||
int n;
|
||||
str >> n;
|
||||
if (!str || !str.eof() || n < 0)
|
||||
if (!string2Int(*i, n) || n < 0)
|
||||
throw UsageError(format("`--max-jobs' requires a non-negative integer"));
|
||||
maxBuildJobs = n;
|
||||
}
|
||||
else if (arg == "--readonly-mode")
|
||||
readOnlyMode = true;
|
||||
else remaining.push_back(arg);
|
||||
}
|
||||
|
||||
@@ -158,10 +175,142 @@ static void initAndRun(int argc, char * * argv)
|
||||
}
|
||||
|
||||
|
||||
static bool haveSwitched;
|
||||
static uid_t savedUid, nixUid;
|
||||
static gid_t savedGid, nixGid;
|
||||
|
||||
|
||||
#if HAVE_SETRESUID
|
||||
#define _setuid(uid) setresuid(uid, uid, savedUid)
|
||||
#define _setgid(gid) setresgid(gid, gid, savedGid)
|
||||
#else
|
||||
/* Only works properly when run by root. */
|
||||
#define _setuid(uid) setuid(uid)
|
||||
#define _setgid(gid) setgid(gid)
|
||||
#endif
|
||||
|
||||
|
||||
SwitchToOriginalUser::SwitchToOriginalUser()
|
||||
{
|
||||
#if SETUID_HACK && HAVE_SETRESUID
|
||||
/* Temporarily switch the effective uid/gid back to the saved
|
||||
uid/gid (which is the uid/gid of the user that executed the Nix
|
||||
program; it's *not* the real uid/gid, since we changed that to
|
||||
the Nix user in switchToNixUser()). */
|
||||
if (haveSwitched) {
|
||||
if (setuid(savedUid) == -1)
|
||||
throw SysError(format("temporarily restoring uid to `%1%'") % savedUid);
|
||||
if (setgid(savedGid) == -1)
|
||||
throw SysError(format("temporarily restoring gid to `%1%'") % savedGid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
SwitchToOriginalUser::~SwitchToOriginalUser()
|
||||
{
|
||||
#if SETUID_HACK && HAVE_SETRESUID
|
||||
/* Switch the effective uid/gid back to the Nix user. */
|
||||
if (haveSwitched) {
|
||||
if (setuid(nixUid) == -1)
|
||||
throw SysError(format("restoring uid to `%1%'") % nixUid);
|
||||
if (setgid(nixGid) == -1)
|
||||
throw SysError(format("restoring gid to `%1%'") % nixGid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void switchToNixUser()
|
||||
{
|
||||
#if SETUID_HACK
|
||||
|
||||
/* Don't do anything if this is not a setuid binary. */
|
||||
if (getuid() == geteuid() && getgid() == getegid()) return;
|
||||
|
||||
/* Here we set the uid and gid to the Nix user and group,
|
||||
respectively, IF the current (real) user is a member of the Nix
|
||||
group. Otherwise we just drop all privileges. */
|
||||
|
||||
/* Lookup the Nix gid. */
|
||||
struct group * gr = getgrnam(NIX_GROUP);
|
||||
if (!gr) {
|
||||
cerr << format("missing group `%1%'\n") % NIX_GROUP;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Get the supplementary group IDs for the current user. */
|
||||
int maxGids = 512, nrGids;
|
||||
gid_t gids[maxGids];
|
||||
if ((nrGids = getgroups(maxGids, gids)) == -1) {
|
||||
cerr << format("unable to query gids\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* !!! Apparently it is unspecified whether getgroups() includes
|
||||
the effective gid. In that case the following test is always
|
||||
true *if* the program is installed setgid (which we do when we
|
||||
have setresuid()). On Linux this doesn't appear to be the
|
||||
case, but we should switch to the real gid before doing this
|
||||
test, and then switch back to the saved gid. */
|
||||
|
||||
/* Check that the current user is a member of the Nix group. */
|
||||
bool found = false;
|
||||
for (int i = 0; i < nrGids; ++i)
|
||||
if (gids[i] == gr->gr_gid) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
/* Not in the Nix group - drop all root/Nix privileges. */
|
||||
_setgid(getgid());
|
||||
_setuid(getuid());
|
||||
return;
|
||||
}
|
||||
|
||||
savedUid = getuid();
|
||||
savedGid = getgid();
|
||||
|
||||
/* Set the real, effective and saved gids to gr->gr_gid. Also
|
||||
make very sure that this succeeded. We switch the gid first
|
||||
because we cannot do it after we have dropped root uid. */
|
||||
nixGid = gr->gr_gid;
|
||||
if (_setgid(nixGid) != 0 || getgid() != nixGid || getegid() != nixGid) {
|
||||
cerr << format("unable to set gid to `%1%'\n") % NIX_GROUP;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Lookup the Nix uid. */
|
||||
struct passwd * pw = getpwnam(NIX_USER);
|
||||
if (!pw) {
|
||||
cerr << format("missing user `%1%'\n") % NIX_USER;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* This will drop all root privileges, setting the real, effective
|
||||
and saved uids to pw->pw_uid. Also make very sure that this
|
||||
succeeded.*/
|
||||
nixUid = pw->pw_uid;
|
||||
if (_setuid(nixUid) != 0 || getuid() != nixUid || geteuid() != nixUid) {
|
||||
cerr << format("unable to set uid to `%1%'\n") % NIX_USER;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
haveSwitched = true;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static char buf[1024];
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
/* If we are setuid root, we have to get rid of the excess
|
||||
privileges ASAP. */
|
||||
switchToNixUser();
|
||||
|
||||
/* ATerm setup. */
|
||||
ATerm bottomOfStack;
|
||||
ATinit(argc, argv, &bottomOfStack);
|
||||
|
||||
@@ -4,7 +4,15 @@ libstore_a_SOURCES = \
|
||||
store.cc store.hh storeexpr.cc storeexpr.hh \
|
||||
normalise.cc misc.cc normalise.hh \
|
||||
globals.cc globals.hh db.cc db.hh \
|
||||
references.cc references.hh pathlocks.cc pathlocks.hh
|
||||
references.cc references.hh pathlocks.cc pathlocks.hh \
|
||||
gc.cc gc.hh storeexpr-ast.hh
|
||||
|
||||
EXTRA_DIST = storeexpr-ast.def storeexpr-ast.cc
|
||||
|
||||
AM_CXXFLAGS = -Wall \
|
||||
-I.. ${bdb_include} ${aterm_include} -I../libutil
|
||||
|
||||
storeexpr-ast.cc storeexpr-ast.hh: ../aterm-helper.pl storeexpr-ast.def
|
||||
$(perl) ../aterm-helper.pl storeexpr-ast.hh storeexpr-ast.cc < storeexpr-ast.def
|
||||
|
||||
storeexpr.cc: storeexpr-ast.hh
|
||||
+32
-4
@@ -1,6 +1,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -81,12 +82,16 @@ void Transaction::moveTo(Transaction & t)
|
||||
void Database::requireEnv()
|
||||
{
|
||||
checkInterrupt();
|
||||
if (!env) throw Error("database environment not open");
|
||||
if (!env)throw Error("database environment is not open "
|
||||
"(maybe you don't have sufficient permission?)");
|
||||
}
|
||||
|
||||
|
||||
Db * Database::getDb(TableId table)
|
||||
{
|
||||
if (table == 0)
|
||||
throw Error("database table is not open "
|
||||
"(maybe you don't have sufficient permission?)");
|
||||
map<TableId, Db *>::iterator i = tables.find(table);
|
||||
if (i == tables.end())
|
||||
throw Error("unknown table id");
|
||||
@@ -165,11 +170,30 @@ void Database::open(const string & path)
|
||||
DbEnv * env = 0; /* !!! close on error */
|
||||
env = new DbEnv(0);
|
||||
|
||||
/* Smaller log files. */
|
||||
env->set_lg_bsize(32 * 1024); /* default */
|
||||
env->set_lg_max(256 * 1024); /* must be > 4 * lg_bsize */
|
||||
env->set_lk_detect(DB_LOCK_DEFAULT);
|
||||
|
||||
/* Write the log, but don't sync. This protects transactions
|
||||
against application crashes, but if the system crashes,
|
||||
some transactions may be undone. An acceptable risk, I
|
||||
think. */
|
||||
env->set_flags(DB_TXN_WRITE_NOSYNC | DB_LOG_AUTOREMOVE, 1);
|
||||
|
||||
|
||||
/* Increase the locking limits. If you ever get `Dbc::get:
|
||||
Cannot allocate memory' or similar, especially while
|
||||
running `nix-store --verify', just increase the following
|
||||
number, then run db_recover on the database to remove the
|
||||
existing DB environment (since changes only take effect on
|
||||
new environments). */
|
||||
env->set_lk_max_locks(4000);
|
||||
env->set_lk_max_lockers(4000);
|
||||
env->set_lk_max_objects(4000);
|
||||
env->set_lk_detect(DB_LOCK_DEFAULT);
|
||||
|
||||
/* Dangerous, probably, but from the docs it *seems* that BDB
|
||||
shouldn't sync when DB_TXN_WRITE_NOSYNC is used, but it
|
||||
still fsync()s sometimes. */
|
||||
db_env_set_func_fsync(my_fsync);
|
||||
|
||||
|
||||
@@ -191,7 +215,11 @@ void Database::open(const string & path)
|
||||
string accessorsPath = path + "/accessor_count";
|
||||
fdAccessors = ::open(accessorsPath.c_str(), O_RDWR | O_CREAT, 0666);
|
||||
if (fdAccessors == -1)
|
||||
throw SysError(format("opening file `%1%'") % accessorsPath);
|
||||
if (errno == EACCES)
|
||||
throw DbNoPermission(
|
||||
format("permission denied to database in `%1%'") % accessorsPath);
|
||||
else
|
||||
throw SysError(format("opening file `%1%'") % accessorsPath);
|
||||
|
||||
/* Open the lock file. */
|
||||
string lockPath = path + "/access_lock";
|
||||
|
||||
@@ -87,4 +87,11 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class DbNoPermission : public Error
|
||||
{
|
||||
public:
|
||||
DbNoPermission(const format & f) : Error(f) { };
|
||||
};
|
||||
|
||||
|
||||
#endif /* !__DB_H */
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "normalise.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void followLivePaths(Path nePath, PathSet & live)
|
||||
{
|
||||
/* Just to be sure, canonicalise the path. It is important to do
|
||||
this here and in findDeadPath() to ensure that a live path is
|
||||
not mistaken for a dead path due to some non-canonical
|
||||
representation. */
|
||||
nePath = canonPath(nePath);
|
||||
|
||||
if (live.find(nePath) != live.end()) return;
|
||||
live.insert(nePath);
|
||||
|
||||
startNest(nest, lvlDebug, format("following `%1%'") % nePath);
|
||||
assertStorePath(nePath);
|
||||
|
||||
if (isValidPath(nePath)) {
|
||||
|
||||
/* !!! should make sure that no substitutes are used */
|
||||
StoreExpr ne = storeExprFromPath(nePath);
|
||||
|
||||
/* !!! painfully similar to requisitesWorker() */
|
||||
if (ne.type == StoreExpr::neClosure)
|
||||
for (ClosureElems::iterator i = ne.closure.elems.begin();
|
||||
i != ne.closure.elems.end(); ++i)
|
||||
{
|
||||
Path p = canonPath(i->first);
|
||||
if (live.find(p) == live.end()) {
|
||||
debug(format("found live `%1%'") % p);
|
||||
assertStorePath(p);
|
||||
live.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
else if (ne.type == StoreExpr::neDerivation)
|
||||
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
||||
i != ne.derivation.inputs.end(); ++i)
|
||||
followLivePaths(*i, live);
|
||||
|
||||
else abort();
|
||||
|
||||
}
|
||||
|
||||
Path nfPath;
|
||||
if (querySuccessor(nePath, nfPath))
|
||||
followLivePaths(nfPath, live);
|
||||
}
|
||||
|
||||
|
||||
PathSet findLivePaths(const Paths & roots)
|
||||
{
|
||||
PathSet live;
|
||||
|
||||
startNest(nest, lvlDebug, "finding live paths");
|
||||
|
||||
for (Paths::const_iterator i = roots.begin(); i != roots.end(); ++i)
|
||||
followLivePaths(*i, live);
|
||||
|
||||
return live;
|
||||
}
|
||||
|
||||
|
||||
PathSet findDeadPaths(const PathSet & live, time_t minAge)
|
||||
{
|
||||
PathSet dead;
|
||||
|
||||
startNest(nest, lvlDebug, "finding dead paths");
|
||||
|
||||
time_t now = time(0);
|
||||
|
||||
Strings storeNames = readDirectory(nixStore);
|
||||
|
||||
for (Strings::iterator i = storeNames.begin(); i != storeNames.end(); ++i) {
|
||||
Path p = canonPath(nixStore + "/" + *i);
|
||||
|
||||
if (minAge > 0) {
|
||||
struct stat st;
|
||||
if (lstat(p.c_str(), &st) != 0)
|
||||
throw SysError(format("obtaining information about `%1%'") % p);
|
||||
if (st.st_atime + minAge >= now) continue;
|
||||
}
|
||||
|
||||
if (live.find(p) == live.end()) {
|
||||
debug(format("dead path `%1%'") % p);
|
||||
dead.insert(p);
|
||||
} else
|
||||
debug(format("live path `%1%'") % p);
|
||||
}
|
||||
|
||||
return dead;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef __GC_H
|
||||
#define __GC_H
|
||||
|
||||
#include "storeexpr.hh"
|
||||
|
||||
|
||||
/* Determine the set of "live" store paths, given a set of root store
|
||||
expressions. The live store paths are those that are reachable
|
||||
from the roots. The roots are reachable by definition. Any path
|
||||
mentioned in a reachable store expression is also reachable. If a
|
||||
derivation store expression is reachable, then its successor (if it
|
||||
exists) if also reachable. It is not an error for store
|
||||
expressions not to exist (since this can happen on derivation store
|
||||
expressions, for instance, due to the substitute mechanism), but
|
||||
successor links are followed even for non-existant derivations. */
|
||||
PathSet findLivePaths(const Paths & roots);
|
||||
|
||||
/* Given a set of "live" store paths, determine the set of "dead"
|
||||
store paths (which are simply all store paths that are not in the
|
||||
live set). The value `minAge' specifies the minimum age in seconds
|
||||
for an unreachable file to be considered dead (0 meaning that any
|
||||
unreachable file is dead). */
|
||||
PathSet findDeadPaths(const PathSet & live, time_t minAge);
|
||||
|
||||
|
||||
#endif /* !__GC_H */
|
||||
@@ -12,6 +12,8 @@ bool keepGoing = false;
|
||||
|
||||
bool tryFallback = false;
|
||||
|
||||
Verbosity buildVerbosity = lvlDebug;
|
||||
Verbosity buildVerbosity = lvlInfo;
|
||||
|
||||
unsigned int maxBuildJobs = 1;
|
||||
|
||||
bool readOnlyMode = false;
|
||||
@@ -43,5 +43,9 @@ extern Verbosity buildVerbosity;
|
||||
/* Maximum number of parallel build jobs. 0 means unlimited. */
|
||||
extern unsigned int maxBuildJobs;
|
||||
|
||||
/* Read-only mode. Don't copy stuff to the store, don't change the
|
||||
database. */
|
||||
extern bool readOnlyMode;
|
||||
|
||||
|
||||
#endif /* !__GLOBALS_H */
|
||||
+84
-107
@@ -5,9 +5,11 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include "normalise.hh"
|
||||
#include "references.hh"
|
||||
@@ -53,10 +55,7 @@ protected:
|
||||
here to prevent cycles. */
|
||||
WeakGoals waiters;
|
||||
|
||||
/* Number of goals we are waiting for. */
|
||||
unsigned int nrWaitees;
|
||||
|
||||
/* Number of goals we were waiting for that have failed. */
|
||||
/* Number of goals we are/were waiting for that have failed. */
|
||||
unsigned int nrFailed;
|
||||
|
||||
/* Whether amDone() has been called. */
|
||||
@@ -66,6 +65,7 @@ protected:
|
||||
Goal(Worker & _worker) : worker(_worker)
|
||||
{
|
||||
done = false;
|
||||
nrFailed = 0;
|
||||
}
|
||||
|
||||
virtual ~Goal()
|
||||
@@ -73,12 +73,6 @@ protected:
|
||||
printMsg(lvlVomit, "goal destroyed");
|
||||
}
|
||||
|
||||
void resetWaitees(int nrWaitees)
|
||||
{
|
||||
this->nrWaitees = nrWaitees;
|
||||
nrFailed = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void work() = 0;
|
||||
|
||||
@@ -210,8 +204,7 @@ void Goal::waiteeDone(GoalPtr waitee, bool success)
|
||||
|
||||
if (!success) ++nrFailed;
|
||||
|
||||
assert(nrWaitees > 0);
|
||||
if (!--nrWaitees || (!success && !keepGoing)) {
|
||||
if (waitees.empty() || (!success && !keepGoing)) {
|
||||
|
||||
/* If we failed and keepGoing is not set, we remove all
|
||||
remaining waitees. */
|
||||
@@ -297,11 +290,67 @@ const char * * strings2CharPtrs(const Strings & ss)
|
||||
/* Should only be called after an expression has been normalised. */
|
||||
Path queryNormalForm(const Path & nePath)
|
||||
{
|
||||
StoreExpr ne = storeExprFromPath(nePath);
|
||||
if (ne.type == StoreExpr::neClosure) return nePath;
|
||||
Path nfPath;
|
||||
if (!querySuccessor(nePath, nfPath)) abort();
|
||||
return nfPath;
|
||||
if (querySuccessor(nePath, nfPath)) return nfPath;
|
||||
/* If there is no successor, than nePath must be a normal form
|
||||
itself. */
|
||||
StoreExpr ne = storeExprFromPath(nePath);
|
||||
if (ne.type != StoreExpr::neClosure) abort();
|
||||
return nePath;
|
||||
}
|
||||
|
||||
|
||||
/* "Fix", or canonicalise, the meta-data of the files in a store path
|
||||
after it has been built. In particular:
|
||||
- the last modification date on each file is set to 0 (i.e.,
|
||||
00:00:00 1/1/1970 UTC)
|
||||
- the permissions are set of 444 or 555 (i.e., read-only with or
|
||||
without execute permission; setuid bits etc. are cleared)
|
||||
- the owner and group are set to the Nix user and group, if we're
|
||||
in a setuid Nix installation
|
||||
*/
|
||||
void canonicalisePathMetaData(const Path & path)
|
||||
{
|
||||
checkInterrupt();
|
||||
|
||||
struct stat st;
|
||||
if (lstat(path.c_str(), &st))
|
||||
throw SysError(format("getting attributes of path `%1%'") % path);
|
||||
|
||||
if (!S_ISLNK(st.st_mode)) {
|
||||
|
||||
/* Mask out all type related bits. */
|
||||
mode_t mode = st.st_mode & ~S_IFMT;
|
||||
|
||||
if (mode != 0444 && mode != 0555) {
|
||||
mode = (st.st_mode & S_IFMT)
|
||||
| 0444
|
||||
| (st.st_mode & S_IXUSR ? 0111 : 0);
|
||||
if (chmod(path.c_str(), mode) == -1)
|
||||
throw SysError(format("changing mode of `%1%' to %2$o") % path % mode);
|
||||
}
|
||||
|
||||
if (st.st_uid != getuid() || st.st_gid != getgid()) {
|
||||
if (chown(path.c_str(), getuid(), getgid()) == -1)
|
||||
throw SysError(format("changing owner/group of `%1%' to %2%/%3%")
|
||||
% path % getuid() % getgid());
|
||||
}
|
||||
|
||||
if (st.st_mtime != 0) {
|
||||
struct utimbuf utimbuf;
|
||||
utimbuf.actime = st.st_atime;
|
||||
utimbuf.modtime = 0;
|
||||
if (utime(path.c_str(), &utimbuf) == -1)
|
||||
throw SysError(format("changing modification time of `%1%'") % path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
Strings names = readDirectory(path);
|
||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
||||
canonicalisePathMetaData(path + "/" + *i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -364,7 +413,6 @@ private:
|
||||
/* The states. */
|
||||
void init();
|
||||
void haveStoreExpr();
|
||||
void inputNormalised();
|
||||
void inputRealised();
|
||||
void tryToBuild();
|
||||
void buildDone();
|
||||
@@ -451,7 +499,6 @@ void NormalisationGoal::init()
|
||||
/* The first thing to do is to make sure that the store expression
|
||||
exists. If it doesn't, it may be created through a
|
||||
substitute. */
|
||||
resetWaitees(1);
|
||||
addWaitee(worker.makeSubstitutionGoal(nePath));
|
||||
|
||||
state = &NormalisationGoal::haveStoreExpr;
|
||||
@@ -482,36 +529,10 @@ void NormalisationGoal::haveStoreExpr()
|
||||
}
|
||||
assert(expr.type == StoreExpr::neDerivation);
|
||||
|
||||
/* Inputs must be normalised before we can build this goal. */
|
||||
/* Inputs must be realised before we can build this goal. */
|
||||
for (PathSet::iterator i = expr.derivation.inputs.begin();
|
||||
i != expr.derivation.inputs.end(); ++i)
|
||||
addWaitee(worker.makeNormalisationGoal(*i));
|
||||
|
||||
resetWaitees(expr.derivation.inputs.size());
|
||||
|
||||
state = &NormalisationGoal::inputNormalised;
|
||||
}
|
||||
|
||||
|
||||
void NormalisationGoal::inputNormalised()
|
||||
{
|
||||
trace("all inputs normalised");
|
||||
|
||||
if (nrFailed != 0) {
|
||||
printMsg(lvlError,
|
||||
format("cannot normalise derivation `%1%': "
|
||||
"%2% closure element(s) could not be normalised")
|
||||
% nePath % nrFailed);
|
||||
amDone(false);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Inputs must also be realised before we can build this goal. */
|
||||
for (PathSet::iterator i = expr.derivation.inputs.begin();
|
||||
i != expr.derivation.inputs.end(); ++i)
|
||||
addWaitee(worker.makeRealisationGoal(queryNormalForm(*i)));
|
||||
|
||||
resetWaitees(expr.derivation.inputs.size());
|
||||
addWaitee(worker.makeRealisationGoal(*i));
|
||||
|
||||
state = &NormalisationGoal::inputRealised;
|
||||
}
|
||||
@@ -818,6 +839,7 @@ void NormalisationGoal::terminateBuildHook()
|
||||
toHook.writeSide.close();
|
||||
fdLogFile.close();
|
||||
logPipe.readSide.close();
|
||||
deleteTmpDir(true); /* get rid of the hook's temporary directory */
|
||||
}
|
||||
|
||||
|
||||
@@ -1038,19 +1060,22 @@ void NormalisationGoal::createClosure()
|
||||
Path path = *i;
|
||||
if (!pathExists(path)) {
|
||||
throw BuildError(
|
||||
format("builder for `%1%' failed to produce output path `%1%'")
|
||||
format("builder for `%1%' failed to produce output path `%2%'")
|
||||
% nePath % path);
|
||||
}
|
||||
nf.closure.roots.insert(path);
|
||||
|
||||
makePathReadOnly(path);
|
||||
canonicalisePathMetaData(path);
|
||||
|
||||
/* For this output path, find the references to other paths contained
|
||||
in it. */
|
||||
startNest(nest2, lvlChatty,
|
||||
format("scanning for store references in `%1%'") % path);
|
||||
Strings refPaths = filterReferences(path,
|
||||
Strings(allPaths.begin(), allPaths.end()));
|
||||
Strings refPaths;
|
||||
if (!pathExists(path + "/nix-support/no-scan")) {
|
||||
refPaths = filterReferences(path,
|
||||
Strings(allPaths.begin(), allPaths.end()));
|
||||
}
|
||||
nest2.close();
|
||||
|
||||
/* Construct a closure element for this output path. */
|
||||
@@ -1278,7 +1303,6 @@ void RealisationGoal::init()
|
||||
|
||||
/* First normalise the expression (which is a no-op if the
|
||||
expression is already a closure). */
|
||||
resetWaitees(1);
|
||||
addWaitee(worker.makeNormalisationGoal(nePath));
|
||||
|
||||
/* Since there is no successor right now, the normalisation goal
|
||||
@@ -1304,7 +1328,6 @@ void RealisationGoal::isNormalised()
|
||||
|
||||
/* Now make sure that the store expression exists. If it doesn't,
|
||||
it may be created through a substitute. */
|
||||
resetWaitees(1);
|
||||
addWaitee(worker.makeSubstitutionGoal(nfPath));
|
||||
|
||||
state = &RealisationGoal::haveStoreExpr;
|
||||
@@ -1335,8 +1358,6 @@ void RealisationGoal::haveStoreExpr()
|
||||
i != expr.closure.elems.end(); ++i)
|
||||
addWaitee(worker.makeSubstitutionGoal(i->first));
|
||||
|
||||
resetWaitees(expr.closure.elems.size());
|
||||
|
||||
state = &RealisationGoal::elemFinished;
|
||||
}
|
||||
|
||||
@@ -1365,6 +1386,7 @@ void RealisationGoal::fallBack(const format & error)
|
||||
% error);
|
||||
tryFallback = false;
|
||||
unregisterSuccessor(nePath);
|
||||
nrFailed = 0;
|
||||
init();
|
||||
} else {
|
||||
printMsg(lvlError, format("%1%; maybe `--fallback' will help") % error);
|
||||
@@ -1395,9 +1417,6 @@ private:
|
||||
/* The current substitute. */
|
||||
Substitute sub;
|
||||
|
||||
/* The normal form of the substitute store expression. */
|
||||
Path nfSub;
|
||||
|
||||
/* Pipe for the substitute's standard output/error. */
|
||||
Pipe logPipe;
|
||||
|
||||
@@ -1419,8 +1438,6 @@ public:
|
||||
/* The states. */
|
||||
void init();
|
||||
void tryNext();
|
||||
void exprNormalised();
|
||||
void exprRealised();
|
||||
void tryToRun();
|
||||
void finished();
|
||||
|
||||
@@ -1485,42 +1502,7 @@ void SubstitutionGoal::tryNext()
|
||||
sub = subs.front();
|
||||
subs.pop_front();
|
||||
|
||||
/* Normalise the substitute store expression. */
|
||||
addWaitee(worker.makeNormalisationGoal(sub.storeExpr));
|
||||
resetWaitees(1);
|
||||
|
||||
state = &SubstitutionGoal::exprNormalised;
|
||||
}
|
||||
|
||||
|
||||
void SubstitutionGoal::exprNormalised()
|
||||
{
|
||||
trace("substitute store expression normalised");
|
||||
|
||||
if (nrFailed != 0) {
|
||||
tryNext();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Realise the substitute store expression. */
|
||||
nfSub = queryNormalForm(sub.storeExpr);
|
||||
addWaitee(worker.makeRealisationGoal(nfSub));
|
||||
|
||||
resetWaitees(1);
|
||||
|
||||
state = &SubstitutionGoal::exprRealised;
|
||||
}
|
||||
|
||||
|
||||
void SubstitutionGoal::exprRealised()
|
||||
{
|
||||
trace("substitute store expression realised");
|
||||
|
||||
if (nrFailed != 0) {
|
||||
tryNext();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Wait until we can run the substitute program. */
|
||||
state = &SubstitutionGoal::tryToRun;
|
||||
worker.waitForBuildSlot(shared_from_this());
|
||||
}
|
||||
@@ -1552,15 +1534,8 @@ void SubstitutionGoal::tryToRun()
|
||||
|
||||
printMsg(lvlInfo,
|
||||
format("substituting path `%1%' using substituter `%2%'")
|
||||
% storePath % sub.storeExpr);
|
||||
% storePath % sub.program);
|
||||
|
||||
/* What's the substitute program? */
|
||||
StoreExpr expr = storeExprFromPath(nfSub);
|
||||
assert(expr.type == StoreExpr::neClosure);
|
||||
assert(!expr.closure.roots.empty());
|
||||
Path program =
|
||||
canonPath(*expr.closure.roots.begin() + "/" + sub.program);
|
||||
|
||||
logPipe.create();
|
||||
|
||||
/* Remove the (stale) output path if it exists. */
|
||||
@@ -1586,12 +1561,12 @@ void SubstitutionGoal::tryToRun()
|
||||
/* Fill in the arguments. */
|
||||
Strings args(sub.args);
|
||||
args.push_front(storePath);
|
||||
args.push_front(baseNameOf(program));
|
||||
args.push_front(baseNameOf(sub.program));
|
||||
const char * * argArr = strings2CharPtrs(args);
|
||||
|
||||
execv(program.c_str(), (char * *) argArr);
|
||||
execv(sub.program.c_str(), (char * *) argArr);
|
||||
|
||||
throw SysError(format("executing `%1%'") % program);
|
||||
throw SysError(format("executing `%1%'") % sub.program);
|
||||
|
||||
} catch (exception & e) {
|
||||
cerr << format("substitute error: %1%\n") % e.what();
|
||||
@@ -1643,7 +1618,7 @@ void SubstitutionGoal::finished()
|
||||
|
||||
printMsg(lvlInfo,
|
||||
format("substitution of path `%1%' using substituter `%2%' failed: %3%")
|
||||
% storePath % sub.storeExpr % e.msg());
|
||||
% storePath % sub.program % e.msg());
|
||||
|
||||
/* Try the next substitute. */
|
||||
state = &SubstitutionGoal::tryNext;
|
||||
@@ -1651,6 +1626,8 @@ void SubstitutionGoal::finished()
|
||||
return;
|
||||
}
|
||||
|
||||
canonicalisePathMetaData(storePath);
|
||||
|
||||
Transaction txn;
|
||||
createStoreTransaction(txn);
|
||||
registerValidPath(txn, storePath);
|
||||
|
||||
@@ -40,9 +40,5 @@ PathSet storeExprRoots(const Path & nePath);
|
||||
PathSet storeExprRequisites(const Path & nePath,
|
||||
bool includeExprs, bool includeSuccessors);
|
||||
|
||||
/* Return the list of the paths of all known store expressions whose
|
||||
output paths are completely contained in the set `outputs'. */
|
||||
PathSet findGenerators(const PathSet & outputs);
|
||||
|
||||
|
||||
#endif /* !__NORMALISE_H */
|
||||
+100
-98
@@ -21,7 +21,7 @@ static Database nixDB;
|
||||
|
||||
The existence of a key $p$ indicates that path $p$ is valid (that
|
||||
is, produced by a succesful build). */
|
||||
static TableId dbValidPaths;
|
||||
static TableId dbValidPaths = 0;
|
||||
|
||||
/* dbSuccessors :: Path -> Path
|
||||
|
||||
@@ -32,21 +32,22 @@ static TableId dbValidPaths;
|
||||
Note that a term $y$ is a successor of $x$ iff there exists a
|
||||
sequence of rewrite steps that rewrites $x$ into $y$.
|
||||
*/
|
||||
static TableId dbSuccessors;
|
||||
static TableId dbSuccessors = 0;
|
||||
|
||||
/* dbSuccessorsRev :: Path -> [Path]
|
||||
|
||||
The reverse mapping of dbSuccessors (i.e., it stores the
|
||||
predecessors of a Nix expression).
|
||||
*/
|
||||
static TableId dbSuccessorsRev;
|
||||
static TableId dbSuccessorsRev = 0;
|
||||
|
||||
/* dbSubstitutes :: Path -> [(Path, Path, [string])]
|
||||
/* dbSubstitutes :: Path -> [[Path]]
|
||||
|
||||
Each pair $(p, subs)$ tells Nix that it can use any of the
|
||||
substitutes in $subs$ to build path $p$. Each substitute is a
|
||||
tuple $(storeExpr, program, args)$ (see the type `Substitute' in
|
||||
`store.hh').
|
||||
substitutes in $subs$ to build path $p$. Each substitute defines a
|
||||
command-line invocation of a program (i.e., the first list element
|
||||
is the full path to the program, the remaining elements are
|
||||
arguments).
|
||||
|
||||
The main purpose of this is for distributed caching of derivates.
|
||||
One system can compute a derivate and put it on a website (as a Nix
|
||||
@@ -54,32 +55,30 @@ static TableId dbSuccessorsRev;
|
||||
substitute for that derivate. The substitute in this case might be
|
||||
a Nix expression that fetches the Nix archive.
|
||||
*/
|
||||
static TableId dbSubstitutes;
|
||||
|
||||
/* dbSubstitutesRev :: Path -> [Path]
|
||||
|
||||
The reverse mapping of dbSubstitutes; it maps store expressions
|
||||
back to the paths for which they are substitutes.
|
||||
*/
|
||||
static TableId dbSubstitutesRev;
|
||||
static TableId dbSubstitutes = 0;
|
||||
|
||||
|
||||
bool Substitute::operator == (const Substitute & sub)
|
||||
{
|
||||
return storeExpr == sub.storeExpr
|
||||
&& program == sub.program
|
||||
return program == sub.program
|
||||
&& args == sub.args;
|
||||
}
|
||||
|
||||
|
||||
void openDB()
|
||||
{
|
||||
nixDB.open(nixDBPath);
|
||||
if (readOnlyMode) return;
|
||||
try {
|
||||
nixDB.open(nixDBPath);
|
||||
} catch (DbNoPermission & e) {
|
||||
printMsg(lvlTalkative, "cannot access Nix database; continuing anyway");
|
||||
readOnlyMode = true;
|
||||
return;
|
||||
}
|
||||
dbValidPaths = nixDB.openTable("validpaths");
|
||||
dbSuccessors = nixDB.openTable("successors");
|
||||
dbSuccessorsRev = nixDB.openTable("successors-rev");
|
||||
dbSubstitutes = nixDB.openTable("substitutes");
|
||||
dbSubstitutesRev = nixDB.openTable("substitutes-rev");
|
||||
}
|
||||
|
||||
|
||||
@@ -157,7 +156,10 @@ void copyPath(const Path & src, const Path & dst)
|
||||
|
||||
CopySink sink;
|
||||
sink.fd = pipe.writeSide;
|
||||
dumpPath(src, sink);
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
dumpPath(src, sink);
|
||||
}
|
||||
|
||||
/* Wait for the child to finish. */
|
||||
int status = pid.wait(true);
|
||||
@@ -290,10 +292,13 @@ static Substitutes readSubstitutes(const Transaction & txn,
|
||||
break;
|
||||
}
|
||||
Strings ss2 = unpackStrings(*i);
|
||||
if (ss2.size() != 3) throw Error("malformed substitute");
|
||||
if (ss2.size() == 3) {
|
||||
/* Another old-style substitute. */
|
||||
continue;
|
||||
}
|
||||
if (ss2.size() != 2) throw Error("malformed substitute");
|
||||
Strings::iterator j = ss2.begin();
|
||||
Substitute sub;
|
||||
sub.storeExpr = *j++;
|
||||
sub.program = *j++;
|
||||
sub.args = unpackStrings(*j++);
|
||||
subs.push_back(sub);
|
||||
@@ -312,7 +317,6 @@ static void writeSubstitutes(const Transaction & txn,
|
||||
i != subs.end(); ++i)
|
||||
{
|
||||
Strings ss2;
|
||||
ss2.push_back(i->storeExpr);
|
||||
ss2.push_back(i->program);
|
||||
ss2.push_back(packStrings(i->args));
|
||||
ss.push_back(packStrings(ss2));
|
||||
@@ -322,29 +326,26 @@ static void writeSubstitutes(const Transaction & txn,
|
||||
}
|
||||
|
||||
|
||||
void registerSubstitute(const Transaction & txn,
|
||||
const Path & srcPath, const Substitute & sub)
|
||||
void registerSubstitutes(const Transaction & txn,
|
||||
const SubstitutePairs & subPairs)
|
||||
{
|
||||
assertStorePath(srcPath);
|
||||
assertStorePath(sub.storeExpr);
|
||||
|
||||
Substitutes subs = readSubstitutes(txn, srcPath);
|
||||
for (SubstitutePairs::const_iterator i = subPairs.begin();
|
||||
i != subPairs.end(); ++i)
|
||||
{
|
||||
const Path & srcPath(i->first);
|
||||
const Substitute & sub(i->second);
|
||||
|
||||
if (find(subs.begin(), subs.end(), sub) != subs.end()) {
|
||||
/* Nothing to do if the substitute is already known. */
|
||||
return;
|
||||
assertStorePath(srcPath);
|
||||
|
||||
Substitutes subs = readSubstitutes(txn, srcPath);
|
||||
|
||||
/* New substitutes take precedence over old ones. If the
|
||||
substitute is already present, it's moved to the front. */
|
||||
remove(subs.begin(), subs.end(), sub);
|
||||
subs.push_front(sub);
|
||||
|
||||
writeSubstitutes(txn, srcPath, subs);
|
||||
}
|
||||
subs.push_front(sub); /* new substitutes take precedence */
|
||||
|
||||
writeSubstitutes(txn, srcPath, subs);
|
||||
|
||||
Paths revs;
|
||||
nixDB.queryStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
|
||||
if (find(revs.begin(), revs.end(), srcPath) == revs.end())
|
||||
revs.push_back(srcPath);
|
||||
|
||||
// !!! O(n^2) complexity in building this
|
||||
// nixDB.setStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
|
||||
}
|
||||
|
||||
|
||||
@@ -354,6 +355,44 @@ Substitutes querySubstitutes(const Path & srcPath)
|
||||
}
|
||||
|
||||
|
||||
static void unregisterPredecessors(const Path & path, Transaction & txn)
|
||||
{
|
||||
/* Remove any successor mappings to this path (but not *from*
|
||||
it). */
|
||||
Paths revs;
|
||||
nixDB.queryStrings(txn, dbSuccessorsRev, path, revs);
|
||||
for (Paths::iterator i = revs.begin(); i != revs.end(); ++i)
|
||||
nixDB.delPair(txn, dbSuccessors, *i);
|
||||
nixDB.delPair(txn, dbSuccessorsRev, path);
|
||||
}
|
||||
|
||||
|
||||
void clearSubstitutes()
|
||||
{
|
||||
Transaction txn(nixDB);
|
||||
|
||||
/* Iterate over all paths for which there are substitutes. */
|
||||
Paths subKeys;
|
||||
nixDB.enumTable(txn, dbSubstitutes, subKeys);
|
||||
for (Paths::iterator i = subKeys.begin(); i != subKeys.end(); ++i) {
|
||||
|
||||
/* If this path has not become valid in the mean-while, delete
|
||||
any successor mappings *to* it. This is to preserve the
|
||||
invariant the all successors are `usable' as opposed to
|
||||
`valid' (i.e., the successor must be valid *or* have at
|
||||
least one substitute). */
|
||||
if (!isValidPath(*i)) {
|
||||
unregisterPredecessors(*i, txn);
|
||||
}
|
||||
|
||||
/* Delete all substitutes for path *i. */
|
||||
nixDB.delPair(txn, dbSubstitutes, *i);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
void registerValidPath(const Transaction & txn, const Path & _path)
|
||||
{
|
||||
Path path(canonPath(_path));
|
||||
@@ -368,36 +407,7 @@ static void invalidatePath(const Path & path, Transaction & txn)
|
||||
debug(format("unregistering path `%1%'") % path);
|
||||
|
||||
nixDB.delPair(txn, dbValidPaths, path);
|
||||
|
||||
/* Remove any successor mappings to this path (but not *from*
|
||||
it). */
|
||||
Paths revs;
|
||||
nixDB.queryStrings(txn, dbSuccessorsRev, path, revs);
|
||||
for (Paths::iterator i = revs.begin(); i != revs.end(); ++i)
|
||||
nixDB.delPair(txn, dbSuccessors, *i);
|
||||
nixDB.delPair(txn, dbSuccessorsRev, path);
|
||||
|
||||
/* Remove any substitute mappings to this path. */
|
||||
revs.clear();
|
||||
nixDB.queryStrings(txn, dbSubstitutesRev, path, revs);
|
||||
for (Paths::iterator i = revs.begin(); i != revs.end(); ++i) {
|
||||
Substitutes subs = readSubstitutes(txn, *i), subs2;
|
||||
bool found = false;
|
||||
for (Substitutes::iterator j = subs.begin(); j != subs.end(); ++j)
|
||||
if (j->storeExpr != path)
|
||||
subs2.push_back(*j);
|
||||
else
|
||||
found = true;
|
||||
if (!found) throw Error("integrity error in substitutes mapping");
|
||||
writeSubstitutes(txn, *i, subs);
|
||||
|
||||
/* If path *i now has no substitutes left, and is not valid,
|
||||
then it too should be invalidated. This is because it may
|
||||
be a substitute or successor. */
|
||||
if (subs.size() == 0 && !isValidPathTxn(*i, txn))
|
||||
invalidatePath(*i, txn);
|
||||
}
|
||||
nixDB.delPair(txn, dbSubstitutesRev, path);
|
||||
unregisterPredecessors(path, txn);
|
||||
}
|
||||
|
||||
|
||||
@@ -406,12 +416,16 @@ Path addToStore(const Path & _srcPath)
|
||||
Path srcPath(absPath(_srcPath));
|
||||
debug(format("adding `%1%' to the store") % srcPath);
|
||||
|
||||
Hash h = hashPath(srcPath);
|
||||
Hash h;
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
h = hashPath(srcPath);
|
||||
}
|
||||
|
||||
string baseName = baseNameOf(srcPath);
|
||||
Path dstPath = canonPath(nixStore + "/" + (string) h + "-" + baseName);
|
||||
|
||||
if (!isValidPath(dstPath)) {
|
||||
if (!readOnlyMode && !isValidPath(dstPath)) {
|
||||
|
||||
/* The first check above is an optimisation to prevent
|
||||
unnecessary lock acquisition. */
|
||||
@@ -423,9 +437,14 @@ Path addToStore(const Path & _srcPath)
|
||||
if (!isValidPath(dstPath)) {
|
||||
|
||||
if (pathExists(dstPath)) deletePath(dstPath);
|
||||
|
||||
/* !!! race: srcPath might change between hashPath() and
|
||||
here! */
|
||||
|
||||
copyPath(srcPath, dstPath);
|
||||
|
||||
makePathReadOnly(dstPath);
|
||||
|
||||
Transaction txn(nixDB);
|
||||
registerValidPath(txn, dstPath);
|
||||
txn.commit();
|
||||
@@ -454,6 +473,8 @@ void addTextToStore(const Path & dstPath, const string & s)
|
||||
|
||||
writeStringToFile(dstPath, s);
|
||||
|
||||
makePathReadOnly(dstPath);
|
||||
|
||||
Transaction txn(nixDB);
|
||||
registerValidPath(txn, dstPath);
|
||||
txn.commit();
|
||||
@@ -512,30 +533,11 @@ void verifyStore()
|
||||
Paths subKeys;
|
||||
nixDB.enumTable(txn, dbSubstitutes, subKeys);
|
||||
for (Paths::iterator i = subKeys.begin(); i != subKeys.end(); ++i) {
|
||||
Substitutes subs = readSubstitutes(txn, *i), subs2;
|
||||
for (Substitutes::iterator j = subs.begin(); j != subs.end(); ++j)
|
||||
if (validPaths.find(j->storeExpr) == validPaths.end())
|
||||
printMsg(lvlError,
|
||||
format("found substitute mapping to non-existent path `%1%'")
|
||||
% j->storeExpr);
|
||||
else
|
||||
subs2.push_back(*j);
|
||||
if (subs.size() != subs2.size())
|
||||
writeSubstitutes(txn, *i, subs2);
|
||||
if (subs2.size() > 0)
|
||||
Substitutes subs = readSubstitutes(txn, *i);
|
||||
if (subs.size() > 0)
|
||||
usablePaths.insert(*i);
|
||||
}
|
||||
|
||||
/* Check that the keys of the reverse substitute mappings are
|
||||
valid paths. */
|
||||
Paths rsubKeys;
|
||||
nixDB.enumTable(txn, dbSubstitutesRev, rsubKeys);
|
||||
for (Paths::iterator i = rsubKeys.begin(); i != rsubKeys.end(); ++i) {
|
||||
if (validPaths.find(*i) == validPaths.end()) {
|
||||
printMsg(lvlError,
|
||||
format("found reverse substitute mapping for non-existent path `%1%'") % *i);
|
||||
nixDB.delPair(txn, dbSubstitutesRev, *i);
|
||||
}
|
||||
else
|
||||
nixDB.delPair(txn, dbSubstitutes, *i);
|
||||
}
|
||||
|
||||
/* Check that the values of the successor mappings are usable
|
||||
|
||||
@@ -14,10 +14,6 @@ using namespace std;
|
||||
network). */
|
||||
struct Substitute
|
||||
{
|
||||
/* Store expression to be normalised and realised in order to
|
||||
obtain `program'. */
|
||||
Path storeExpr;
|
||||
|
||||
/* Program to be executed to create the store path. Must be in
|
||||
the output path of `storeExpr'. */
|
||||
Path program;
|
||||
@@ -66,12 +62,16 @@ bool querySuccessor(const Path & srcPath, Path & sucPath);
|
||||
Paths queryPredecessors(const Path & sucPath);
|
||||
|
||||
/* Register a substitute. */
|
||||
void registerSubstitute(const Transaction & txn,
|
||||
const Path & srcPath, const Substitute & sub);
|
||||
typedef list<pair<Path, Substitute> > SubstitutePairs;
|
||||
void registerSubstitutes(const Transaction & txn,
|
||||
const SubstitutePairs & subPairs);
|
||||
|
||||
/* Return the substitutes expression for the given path. */
|
||||
Substitutes querySubstitutes(const Path & srcPath);
|
||||
|
||||
/* Deregister all substitutes. */
|
||||
void clearSubstitutes();
|
||||
|
||||
/* Register the validity of a path. */
|
||||
void registerValidPath(const Transaction & txn, const Path & path);
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
init initStoreExprHelpers
|
||||
|
||||
Closure | ATermList ATermList | ATerm |
|
||||
Derive | ATermList ATermList string string ATermList ATermList | ATerm |
|
||||
|
||||
| string string | ATerm | EnvBinding |
|
||||
| string ATermList | ATerm | ClosureElem |
|
||||
+32
-31
@@ -2,6 +2,9 @@
|
||||
#include "globals.hh"
|
||||
#include "store.hh"
|
||||
|
||||
#include "storeexpr-ast.hh"
|
||||
#include "storeexpr-ast.cc"
|
||||
|
||||
|
||||
Hash hashTerm(ATerm t)
|
||||
{
|
||||
@@ -17,7 +20,7 @@ Path writeTerm(ATerm t, const string & suffix)
|
||||
Path path = canonPath(nixStore + "/" +
|
||||
(string) h + suffix + ".store");
|
||||
|
||||
if (!isValidPath(path)) {
|
||||
if (!readOnlyMode && !isValidPath(path)) {
|
||||
char * s = ATwriteToString(t);
|
||||
if (!s) throw Error(format("cannot write aterm to `%1%'") % path);
|
||||
addTextToStore(path, string(s));
|
||||
@@ -29,10 +32,11 @@ Path writeTerm(ATerm t, const string & suffix)
|
||||
|
||||
static void parsePaths(ATermList paths, PathSet & out)
|
||||
{
|
||||
ATMatcher m;
|
||||
for (ATermIterator i(paths); i; ++i) {
|
||||
string s;
|
||||
if (!(atMatch(m, *i) >> s))
|
||||
if (ATgetType(*i) != AT_APPL)
|
||||
throw badTerm("not a path", *i);
|
||||
string s = aterm2String(*i);
|
||||
if (s.size() == 0 || s[0] != '/')
|
||||
throw badTerm("not a path", *i);
|
||||
out.insert(s);
|
||||
}
|
||||
@@ -69,21 +73,20 @@ static void checkClosure(const Closure & closure)
|
||||
static bool parseClosure(ATerm t, Closure & closure)
|
||||
{
|
||||
ATermList roots, elems;
|
||||
ATMatcher m;
|
||||
|
||||
if (!(atMatch(m, t) >> "Closure" >> roots >> elems))
|
||||
if (!matchClosure(t, roots, elems))
|
||||
return false;
|
||||
|
||||
parsePaths(roots, closure.roots);
|
||||
|
||||
for (ATermIterator i(elems); i; ++i) {
|
||||
string path;
|
||||
ATerm path;
|
||||
ATermList refs;
|
||||
if (!(atMatch(m, *i) >> "" >> path >> refs))
|
||||
if (!matchClosureElem(*i, path, refs))
|
||||
throw badTerm("not a closure element", *i);
|
||||
ClosureElem elem;
|
||||
parsePaths(refs, elem.refs);
|
||||
closure.elems[path] = elem;
|
||||
closure.elems[aterm2String(path)] = elem;
|
||||
}
|
||||
|
||||
checkClosure(closure);
|
||||
@@ -93,32 +96,29 @@ static bool parseClosure(ATerm t, Closure & closure)
|
||||
|
||||
static bool parseDerivation(ATerm t, Derivation & derivation)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList outs, ins, args, bnds;
|
||||
string builder, platform;
|
||||
ATerm builder, platform;
|
||||
|
||||
if (!(atMatch(m, t) >> "Derive" >> outs >> ins >> platform
|
||||
>> builder >> args >> bnds))
|
||||
if (!matchDerive(t, outs, ins, platform, builder, args, bnds))
|
||||
return false;
|
||||
|
||||
parsePaths(outs, derivation.outputs);
|
||||
parsePaths(ins, derivation.inputs);
|
||||
|
||||
derivation.builder = builder;
|
||||
derivation.platform = platform;
|
||||
derivation.builder = aterm2String(builder);
|
||||
derivation.platform = aterm2String(platform);
|
||||
|
||||
for (ATermIterator i(args); i; ++i) {
|
||||
string s;
|
||||
if (!(atMatch(m, *i) >> s))
|
||||
if (ATgetType(*i) != AT_APPL)
|
||||
throw badTerm("string expected", *i);
|
||||
derivation.args.push_back(s);
|
||||
derivation.args.push_back(aterm2String(*i));
|
||||
}
|
||||
|
||||
for (ATermIterator i(bnds); i; ++i) {
|
||||
string s1, s2;
|
||||
if (!(atMatch(m, *i) >> "" >> s1 >> s2))
|
||||
ATerm s1, s2;
|
||||
if (!matchEnvBinding(*i, s1, s2))
|
||||
throw badTerm("tuple of strings expected", *i);
|
||||
derivation.env[s1] = s2;
|
||||
derivation.env[aterm2String(s1)] = aterm2String(s2);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -142,7 +142,7 @@ static ATermList unparsePaths(const PathSet & paths)
|
||||
ATermList l = ATempty;
|
||||
for (PathSet::const_iterator i = paths.begin();
|
||||
i != paths.end(); i++)
|
||||
l = ATinsert(l, ATmake("<str>", i->c_str()));
|
||||
l = ATinsert(l, toATerm(*i));
|
||||
return ATreverse(l);
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ static ATerm unparseClosure(const Closure & closure)
|
||||
for (ClosureElems::const_iterator i = closure.elems.begin();
|
||||
i != closure.elems.end(); i++)
|
||||
elems = ATinsert(elems,
|
||||
ATmake("(<str>, <term>)",
|
||||
i->first.c_str(),
|
||||
makeClosureElem(
|
||||
toATerm(i->first),
|
||||
unparsePaths(i->second.refs)));
|
||||
|
||||
return ATmake("Closure(<term>, <term>)", roots, elems);
|
||||
return makeClosure(roots, elems);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,20 +168,21 @@ static ATerm unparseDerivation(const Derivation & derivation)
|
||||
ATermList args = ATempty;
|
||||
for (Strings::const_iterator i = derivation.args.begin();
|
||||
i != derivation.args.end(); i++)
|
||||
args = ATinsert(args, ATmake("<str>", i->c_str()));
|
||||
args = ATinsert(args, toATerm(*i));
|
||||
|
||||
ATermList env = ATempty;
|
||||
for (StringPairs::const_iterator i = derivation.env.begin();
|
||||
i != derivation.env.end(); i++)
|
||||
env = ATinsert(env,
|
||||
ATmake("(<str>, <str>)",
|
||||
i->first.c_str(), i->second.c_str()));
|
||||
makeEnvBinding(
|
||||
toATerm(i->first),
|
||||
toATerm(i->second)));
|
||||
|
||||
return ATmake("Derive(<term>, <term>, <str>, <str>, <term>, <term>)",
|
||||
return makeDerive(
|
||||
unparsePaths(derivation.outputs),
|
||||
unparsePaths(derivation.inputs),
|
||||
derivation.platform.c_str(),
|
||||
derivation.builder.c_str(),
|
||||
toATerm(derivation.platform),
|
||||
toATerm(derivation.builder),
|
||||
ATreverse(args),
|
||||
ATreverse(env));
|
||||
}
|
||||
|
||||
@@ -4,10 +4,3 @@ libutil_a_SOURCES = util.cc util.hh hash.cc hash.hh \
|
||||
archive.cc archive.hh md5.c md5.h aterm.cc aterm.hh
|
||||
|
||||
AM_CXXFLAGS = -Wall -I.. ${aterm_include}
|
||||
|
||||
check_PROGRAMS = test-aterm
|
||||
|
||||
test_aterm_SOURCES = test-aterm.cc
|
||||
test_aterm_LDADD = ./libutil.a ../boost/format/libformat.a \
|
||||
${aterm_lib}
|
||||
|
||||
+12
-89
@@ -16,95 +16,6 @@ ostream & operator << (ostream & stream, ATerm e)
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & atMatch(ATMatcher & pos, ATerm t)
|
||||
{
|
||||
pos.t = t;
|
||||
pos.pos = ATMatcher::funPos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
static inline bool failed(const ATMatcher & pos)
|
||||
{
|
||||
return pos.pos == ATMatcher::failPos;
|
||||
}
|
||||
|
||||
|
||||
static inline ATMatcher & fail(ATMatcher & pos)
|
||||
{
|
||||
pos.pos = ATMatcher::failPos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, ATerm & out)
|
||||
{
|
||||
out = 0;
|
||||
if (failed(pos)) return pos;
|
||||
if (pos.pos == ATMatcher::funPos ||
|
||||
ATgetType(pos.t) != AT_APPL ||
|
||||
pos.pos >= (int) ATgetArity(ATgetAFun(pos.t)))
|
||||
return fail(pos);
|
||||
out = ATgetArgument(pos.t, pos.pos);
|
||||
pos.pos++;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, string & out)
|
||||
{
|
||||
out = "";
|
||||
if (pos.pos == ATMatcher::funPos) {
|
||||
if (ATgetType(pos.t) != AT_APPL) return fail(pos);
|
||||
out = ATgetName(ATgetAFun(pos.t));
|
||||
pos.pos = 0;
|
||||
} else {
|
||||
ATerm t;
|
||||
pos = pos >> t;
|
||||
if (failed(pos)) return pos;
|
||||
if (ATgetType(t) != AT_APPL ||
|
||||
ATgetArity(ATgetAFun(t)) != 0)
|
||||
return fail(pos);
|
||||
out = ATgetName(ATgetAFun(t));
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, const string & s)
|
||||
{
|
||||
string s2;
|
||||
pos = pos >> s2;
|
||||
if (failed(pos)) return pos;
|
||||
if (s != s2) return fail(pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, int & n)
|
||||
{
|
||||
n = 0;
|
||||
ATerm t;
|
||||
pos = pos >> t;
|
||||
if (failed(pos)) return pos;
|
||||
if (ATgetType(t) != AT_INT) return fail(pos);
|
||||
n = ATgetInt((ATermInt) t);
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
ATMatcher & operator >> (ATMatcher & pos, ATermList & out)
|
||||
{
|
||||
out = 0;
|
||||
ATerm t;
|
||||
pos = pos >> t;
|
||||
if (failed(pos)) return pos;
|
||||
if (ATgetType(t) != AT_LIST) return fail(pos);
|
||||
out = (ATermList) t;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
Error badTerm(const format & f, ATerm t)
|
||||
{
|
||||
char * s = ATwriteToString(t);
|
||||
@@ -116,3 +27,15 @@ Error badTerm(const format & f, ATerm t)
|
||||
}
|
||||
return Error(format("%1%, in `%2%'") % f.str() % (string) s);
|
||||
}
|
||||
|
||||
|
||||
ATerm toATerm(const char * s)
|
||||
{
|
||||
return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
|
||||
}
|
||||
|
||||
|
||||
ATerm toATerm(const string & s)
|
||||
{
|
||||
return toATerm(s.c_str());
|
||||
}
|
||||
+5
-42
@@ -36,51 +36,14 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/* Type-safe matching. */
|
||||
|
||||
struct ATMatcher
|
||||
{
|
||||
ATerm t;
|
||||
int pos;
|
||||
const static int failPos = -2;
|
||||
const static int funPos = -1;
|
||||
|
||||
ATMatcher() : t(0), pos(failPos)
|
||||
{
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return pos != failPos;
|
||||
}
|
||||
};
|
||||
|
||||
/* Initiate matching of a term. */
|
||||
ATMatcher & atMatch(ATMatcher & pos, ATerm t);
|
||||
|
||||
/* Get the next argument of an application. */
|
||||
ATMatcher & operator >> (ATMatcher & pos, ATerm & out);
|
||||
|
||||
/* Get the name of the function symbol of an application, or the next
|
||||
argument of an application as a string. */
|
||||
ATMatcher & operator >> (ATMatcher & pos, string & out);
|
||||
|
||||
/* Like the previous, but check that the string is equal to the given
|
||||
string. */
|
||||
ATMatcher & operator >> (ATMatcher & pos, const string & s);
|
||||
|
||||
/* Get the next argument of an application, and verify that it is a
|
||||
integer. */
|
||||
ATMatcher & operator >> (ATMatcher & pos, int & n);
|
||||
|
||||
/* Get the next argument of an application, and verify that it is a
|
||||
list. */
|
||||
ATMatcher & operator >> (ATMatcher & pos, ATermList & out);
|
||||
|
||||
|
||||
/* Throw an exception with an error message containing the given
|
||||
aterm. */
|
||||
Error badTerm(const format & f, ATerm t);
|
||||
|
||||
|
||||
/* Convert strings to ATerms. */
|
||||
ATerm toATerm(const char * s);
|
||||
ATerm toATerm(const string & s);
|
||||
|
||||
|
||||
#endif /* !__ATERM_H */
|
||||
@@ -1,66 +0,0 @@
|
||||
#include "aterm.hh"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void runTests()
|
||||
{
|
||||
verbosity = lvlDebug;
|
||||
|
||||
ATMatcher pos;
|
||||
|
||||
ATerm t = ATmake("Call(Foo, Bar, \"xyz\")");
|
||||
|
||||
debug(format("term: %1%") % t);
|
||||
|
||||
string fun, arg3;
|
||||
ATerm lhs, rhs;
|
||||
|
||||
if (!(atMatch(pos, t) >> "Call" >> lhs >> rhs >> arg3))
|
||||
throw Error("should succeed");
|
||||
if (arg3 != "xyz") throw Error("bad 1");
|
||||
|
||||
if (!(atMatch(pos, t) >> fun >> lhs >> rhs >> arg3))
|
||||
throw Error("should succeed");
|
||||
if (fun != "Call") throw Error("bad 2");
|
||||
if (arg3 != "xyz") throw Error("bad 3");
|
||||
|
||||
if (!(atMatch(pos, t) >> fun >> lhs >> rhs >> "xyz"))
|
||||
throw Error("should succeed");
|
||||
|
||||
if (atMatch(pos, t) >> fun >> lhs >> rhs >> "abc")
|
||||
throw Error("should fail");
|
||||
|
||||
if (atMatch(pos, t) >> "Call" >> lhs >> rhs >> "abc")
|
||||
throw Error("should fail");
|
||||
|
||||
t = ATmake("X([A, B, C], \"abc\")");
|
||||
|
||||
ATerm t1, t2, t3;
|
||||
if (atMatch(pos, t) >> "X" >> t1 >> t2 >> t3)
|
||||
throw Error("should fail");
|
||||
if (!(atMatch(pos, t) >> "X" >> t1 >> t2))
|
||||
throw Error("should succeed");
|
||||
ATermList ts;
|
||||
if (!(atMatch(pos, t) >> "X" >> ts >> t2))
|
||||
throw Error("should succeed");
|
||||
if (ATgetLength(ts) != 3)
|
||||
throw Error("bad");
|
||||
if (atMatch(pos, t) >> "X" >> t1 >> ts)
|
||||
throw Error("should fail");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
ATerm bottomOfStack;
|
||||
ATinit(argc, argv, &bottomOfStack);
|
||||
|
||||
try {
|
||||
runTests();
|
||||
} catch (Error & e) {
|
||||
printMsg(lvlError, format("error: %1%") % e.msg());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+11
-3
@@ -115,7 +115,7 @@ bool pathExists(const Path & path)
|
||||
struct stat st;
|
||||
res = lstat(path.c_str(), &st);
|
||||
if (!res) return true;
|
||||
if (errno != ENOENT)
|
||||
if (errno != ENOENT && errno != ENOTDIR)
|
||||
throw SysError(format("getting status of %1%") % path);
|
||||
return false;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ static void _deletePath(const Path & path)
|
||||
/* Make the directory writable. */
|
||||
if (!(st.st_mode & S_IWUSR)) {
|
||||
if (chmod(path.c_str(), st.st_mode | S_IWUSR) == -1)
|
||||
throw SysError(format("making `%1%' writable"));
|
||||
throw SysError(format("making `%1%' writable") % path);
|
||||
}
|
||||
|
||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
||||
@@ -243,7 +243,7 @@ void writeStringToFile(const Path & path, const string & s)
|
||||
|
||||
|
||||
LogType logType = ltPretty;
|
||||
Verbosity verbosity = lvlError;
|
||||
Verbosity verbosity = lvlInfo;
|
||||
|
||||
static int nestingLevel = 0;
|
||||
|
||||
@@ -616,3 +616,11 @@ bool statusOk(int status)
|
||||
{
|
||||
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool string2Int(const string & s, int & n)
|
||||
{
|
||||
istringstream str(s);
|
||||
str >> n;
|
||||
return str && str.eof();
|
||||
}
|
||||
@@ -246,4 +246,18 @@ string statusToString(int status);
|
||||
bool statusOk(int status);
|
||||
|
||||
|
||||
/* Parse a string into an integer. */
|
||||
bool string2Int(const string & s, int & n);
|
||||
|
||||
|
||||
/* !!! HACK HACK HACK - this should be in shared.hh, but it's to
|
||||
facilitate a quick hack - will remove this eventually (famous last
|
||||
words). */
|
||||
struct SwitchToOriginalUser
|
||||
{
|
||||
SwitchToOriginalUser();
|
||||
~SwitchToOriginalUser();
|
||||
};
|
||||
|
||||
|
||||
#endif /* !__UTIL_H */
|
||||
@@ -16,6 +16,8 @@ name `*' may be used to indicate all derivations.
|
||||
--switch-generation / -G NUMBER: switch to specified generation of profile
|
||||
--rollback: switch to the previous generation
|
||||
--list-generations: list available generations of a profile
|
||||
--delete-generations GENERATIONS...: deleted listed generations,
|
||||
`old' for all non-current generations
|
||||
|
||||
--import / -I FILE: set default Nix expression
|
||||
|
||||
@@ -49,3 +51,5 @@ Options:
|
||||
--file / -f FILE: use Nix expression FILE for installation, etc.
|
||||
--verbose / -v: verbose operation (may be repeated)
|
||||
--keep-failed / -K: keep temporary directories of failed builds
|
||||
--preserve-installed: do not replace currently installed versions in `-i'
|
||||
--system-filter SYSTEM: only use derivations for specified platform
|
||||
+96
-44
@@ -6,6 +6,7 @@
|
||||
#include "parser.hh"
|
||||
#include "eval.hh"
|
||||
#include "help.txt.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
#include <cerrno>
|
||||
#include <ctime>
|
||||
@@ -47,10 +48,9 @@ void printHelp()
|
||||
|
||||
bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
|
||||
{
|
||||
ATMatcher m;
|
||||
|
||||
ATermList es;
|
||||
e = evalExpr(state, e);
|
||||
if (!(atMatch(m, e) >> "Attrs")) return false;
|
||||
if (!matchAttrs(e, es)) return false;
|
||||
Expr a = queryAttr(e, "type");
|
||||
if (!a || evalString(state, a) != "derivation") return false;
|
||||
|
||||
@@ -82,7 +82,6 @@ bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
|
||||
|
||||
bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList es;
|
||||
DrvInfo drv;
|
||||
|
||||
@@ -91,7 +90,7 @@ bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||
if (parseDerivation(state, e, drv))
|
||||
drvs[drv.drvPath] = drv;
|
||||
|
||||
else if (atMatch(m, e) >> "Attrs") {
|
||||
else if (matchAttrs(e, es)) {
|
||||
ATermMap drvMap;
|
||||
queryAllAttrs(e, drvMap);
|
||||
for (ATermIterator i(drvMap.keys()); i; ++i) {
|
||||
@@ -103,7 +102,7 @@ bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||
}
|
||||
}
|
||||
|
||||
else if (atMatch(m, e) >> "List" >> es) {
|
||||
else if (matchList(e, es)) {
|
||||
for (ATermIterator i(es); i; ++i) {
|
||||
debug(format("evaluating list element"));
|
||||
if (parseDerivation(state, *i, drv))
|
||||
@@ -152,12 +151,10 @@ struct AddPos : TermFun
|
||||
{
|
||||
ATerm operator () (ATerm e)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATerm x, y, z;
|
||||
if (atMatch(m, e) >> "Bind" >> x >> y >> z)
|
||||
return e;
|
||||
if (atMatch(m, e) >> "Bind" >> x >> y)
|
||||
return ATmake("Bind(<term>, <term>, NoPos)", x, y);
|
||||
if (matchBind(e, x, y, z)) return e;
|
||||
if (matchBind2(e, x, y))
|
||||
return makeBind(x, y, makeNoPos());
|
||||
return e;
|
||||
}
|
||||
};
|
||||
@@ -194,36 +191,36 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
|
||||
for (DrvInfos::const_iterator i = drvs.begin();
|
||||
i != drvs.end(); ++i)
|
||||
{
|
||||
ATerm t = ATmake(
|
||||
"Attrs(["
|
||||
"Bind(\"type\", Str(\"derivation\"), NoPos), "
|
||||
"Bind(\"name\", Str(<str>), NoPos), "
|
||||
"Bind(\"system\", Str(<str>), NoPos), "
|
||||
"Bind(\"drvPath\", Path(<str>), NoPos), "
|
||||
"Bind(\"drvHash\", Str(<str>), NoPos), "
|
||||
"Bind(\"outPath\", Path(<str>), NoPos)"
|
||||
"])",
|
||||
i->second.name.c_str(),
|
||||
i->second.system.c_str(),
|
||||
i->second.drvPath.c_str(),
|
||||
((string) i->second.drvHash).c_str(),
|
||||
i->second.outPath.c_str());
|
||||
ATerm t = makeAttrs(ATmakeList6(
|
||||
makeBind(toATerm("type"),
|
||||
makeStr(toATerm("derivation")), makeNoPos()),
|
||||
makeBind(toATerm("name"),
|
||||
makeStr(toATerm(i->second.name)), makeNoPos()),
|
||||
makeBind(toATerm("system"),
|
||||
makeStr(toATerm(i->second.system)), makeNoPos()),
|
||||
makeBind(toATerm("drvPath"),
|
||||
makePath(toATerm(i->second.drvPath)), makeNoPos()),
|
||||
makeBind(toATerm("drvHash"),
|
||||
makeStr(toATerm((string) i->second.drvHash)), makeNoPos()),
|
||||
makeBind(toATerm("outPath"),
|
||||
makePath(toATerm(i->second.outPath)), makeNoPos())
|
||||
));
|
||||
inputs = ATinsert(inputs, t);
|
||||
}
|
||||
|
||||
ATerm inputs2 = ATmake("List(<term>)", ATreverse(inputs));
|
||||
ATerm inputs2 = makeList(ATreverse(inputs));
|
||||
|
||||
/* Also write a copy of the list of inputs to the store; we need
|
||||
it for future modifications of the environment. */
|
||||
Path inputsFile = writeTerm(inputs2, "-env-inputs");
|
||||
|
||||
Expr topLevel = ATmake(
|
||||
"Call(<term>, Attrs(["
|
||||
"Bind(\"system\", Str(<str>), NoPos), "
|
||||
"Bind(\"derivations\", <term>, NoPos), " // !!! redundant
|
||||
"Bind(\"manifest\", Path(<str>), NoPos)"
|
||||
"]))",
|
||||
envBuilder, thisSystem.c_str(), inputs2, inputsFile.c_str());
|
||||
Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3(
|
||||
makeBind(toATerm("system"),
|
||||
makeStr(toATerm(thisSystem)), makeNoPos()),
|
||||
makeBind(toATerm("derivations"), inputs2, makeNoPos()),
|
||||
makeBind(toATerm("manifest"),
|
||||
makePath(toATerm(inputsFile)), makeNoPos())
|
||||
)));
|
||||
|
||||
/* Instantiate it. */
|
||||
debug(format("evaluating builder expression `%1%'") % topLevel);
|
||||
@@ -465,9 +462,17 @@ static void opUninstall(Globals & globals,
|
||||
}
|
||||
|
||||
|
||||
static bool cmpChars(char a, char b)
|
||||
{
|
||||
return toupper(a) < toupper(b);
|
||||
}
|
||||
|
||||
|
||||
static bool cmpDrvByName(const DrvInfo & a, const DrvInfo & b)
|
||||
{
|
||||
return a.name < b.name;
|
||||
return lexicographical_compare(
|
||||
a.name.begin(), a.name.end(),
|
||||
b.name.begin(), b.name.end(), cmpChars);
|
||||
}
|
||||
|
||||
|
||||
@@ -476,20 +481,22 @@ typedef list<Strings> Table;
|
||||
|
||||
void printTable(Table & table)
|
||||
{
|
||||
int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
||||
unsigned int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
||||
|
||||
vector<int> widths;
|
||||
vector<unsigned int> widths;
|
||||
widths.resize(nrColumns);
|
||||
|
||||
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
||||
assert(i->size() == nrColumns);
|
||||
Strings::iterator j; int column;
|
||||
Strings::iterator j;
|
||||
unsigned int column;
|
||||
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
||||
if (j->size() > widths[column]) widths[column] = j->size();
|
||||
}
|
||||
|
||||
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
||||
Strings::iterator j; int column;
|
||||
Strings::iterator j;
|
||||
unsigned int column;
|
||||
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
||||
{
|
||||
cout << *j;
|
||||
@@ -511,6 +518,8 @@ static void opQuery(Globals & globals,
|
||||
|
||||
enum { sInstalled, sAvailable } source = sInstalled;
|
||||
|
||||
readOnlyMode = true; /* makes evaluation a bit faster */
|
||||
|
||||
for (Strings::iterator i = opFlags.begin();
|
||||
i != opFlags.end(); ++i)
|
||||
if (*i == "--status" || *i == "-s") printStatus = true;
|
||||
@@ -600,6 +609,7 @@ static void opSwitchProfile(Globals & globals,
|
||||
Path profile = opArgs.front();
|
||||
Path profileLink = getHomeDir() + "/.nix-profile";
|
||||
|
||||
SwitchToOriginalUser sw;
|
||||
switchLink(profileLink, profile);
|
||||
}
|
||||
|
||||
@@ -642,10 +652,8 @@ static void opSwitchGeneration(Globals & globals,
|
||||
if (opArgs.size() != 1)
|
||||
throw UsageError(format("exactly one argument expected"));
|
||||
|
||||
istringstream str(opArgs.front());
|
||||
int dstGen;
|
||||
str >> dstGen;
|
||||
if (!str || !str.eof())
|
||||
if (!string2Int(opArgs.front(), dstGen))
|
||||
throw UsageError(format("expected a generation number"));
|
||||
|
||||
switchGeneration(globals, dstGen);
|
||||
@@ -687,6 +695,49 @@ static void opListGenerations(Globals & globals,
|
||||
}
|
||||
|
||||
|
||||
static void deleteGeneration2(const Path & profile, unsigned int gen)
|
||||
{
|
||||
printMsg(lvlInfo, format("removing generation %1%") % gen);
|
||||
deleteGeneration(profile, gen);
|
||||
}
|
||||
|
||||
|
||||
static void opDeleteGenerations(Globals & globals,
|
||||
Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||
|
||||
int curGen;
|
||||
Generations gens = findGenerations(globals.profile, curGen);
|
||||
|
||||
for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) {
|
||||
|
||||
if (*i == "old") {
|
||||
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j)
|
||||
if (j->number != curGen)
|
||||
deleteGeneration2(globals.profile, j->number);
|
||||
}
|
||||
|
||||
else {
|
||||
int n;
|
||||
if (!string2Int(*i, n) || n < 0)
|
||||
throw UsageError(format("invalid generation specifier `%1%'") % *i);
|
||||
bool found = false;
|
||||
for (Generations::iterator j = gens.begin(); j != gens.end(); ++j) {
|
||||
if (j->number == n) {
|
||||
deleteGeneration2(globals.profile, j->number);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
printMsg(lvlError, format("generation %1% does not exist") % n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void opDefaultExpr(Globals & globals,
|
||||
Strings opFlags, Strings opArgs)
|
||||
{
|
||||
@@ -698,15 +749,13 @@ static void opDefaultExpr(Globals & globals,
|
||||
Path defNixExpr = absPath(opArgs.front());
|
||||
Path defNixExprLink = getDefNixExprPath();
|
||||
|
||||
SwitchToOriginalUser sw;
|
||||
switchLink(defNixExprLink, defNixExpr);
|
||||
}
|
||||
|
||||
|
||||
void run(Strings args)
|
||||
{
|
||||
/* Use a higher default verbosity (lvlInfo). */
|
||||
verbosity = (Verbosity) ((int) verbosity + 1);
|
||||
|
||||
Strings opFlags, opArgs;
|
||||
Operation op = 0;
|
||||
|
||||
@@ -751,6 +800,8 @@ void run(Strings args)
|
||||
op = opRollback;
|
||||
else if (arg == "--list-generations")
|
||||
op = opListGenerations;
|
||||
else if (arg == "--delete-generations")
|
||||
op = opDeleteGenerations;
|
||||
else if (arg == "--dry-run") {
|
||||
printMsg(lvlInfo, "(dry run; not doing anything)");
|
||||
globals.dryRun = true;
|
||||
@@ -775,6 +826,7 @@ void run(Strings args)
|
||||
if (!op) throw UsageError("no operation specified");
|
||||
|
||||
if (globals.profile == "") {
|
||||
SwitchToOriginalUser sw;
|
||||
Path profileLink = getHomeDir() + "/.nix-profile";
|
||||
globals.profile = pathExists(profileLink)
|
||||
? absPath(readLink(profileLink), dirOf(profileLink))
|
||||
|
||||
+1
-11
@@ -56,20 +56,10 @@ static string nextComponent(string::const_iterator & p,
|
||||
}
|
||||
|
||||
|
||||
#include <fstream>
|
||||
|
||||
static bool parseInt(const string & s, int & n)
|
||||
{
|
||||
istringstream st(s);
|
||||
st >> n;
|
||||
return !st.fail();
|
||||
}
|
||||
|
||||
|
||||
static bool componentsLT(const string & c1, const string & c2)
|
||||
{
|
||||
int n1, n2;
|
||||
bool c1Num = parseInt(c1, n1), c2Num = parseInt(c2, n2);
|
||||
bool c1Num = string2Int(c1, n1), c2Num = string2Int(c2, n2);
|
||||
|
||||
if (c1Num && c2Num) return n1 < n2;
|
||||
else if (c1 == "" && c2Num) return true;
|
||||
|
||||
+33
-7
@@ -20,9 +20,11 @@ static int parseName(const string & profileName, const string & name)
|
||||
string s = string(name, profileName.size() + 1);
|
||||
int p = s.find("-link");
|
||||
if (p == string::npos) return -1;
|
||||
istringstream str(string(s, 0, p));
|
||||
unsigned int n;
|
||||
if (str >> n && str.eof()) return n; else return -1;
|
||||
int n;
|
||||
if (string2Int(string(s, 0, p), n) && n >= 0)
|
||||
return n;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +61,16 @@ Generations findGenerations(Path profile, int & curGen)
|
||||
}
|
||||
|
||||
|
||||
static void makeNames(const Path & profile, unsigned int num,
|
||||
Path & generation, Path & gcrootDrv, Path & gcrootClr)
|
||||
{
|
||||
Path prefix = (format("%1%-%2%") % profile % num).str();
|
||||
generation = prefix + "-link";
|
||||
gcrootDrv = prefix + "-drv.gcroot";
|
||||
gcrootClr = prefix + "-clr.gcroot";
|
||||
}
|
||||
|
||||
|
||||
Path createGeneration(Path profile, Path outPath,
|
||||
Path drvPath, Path clrPath)
|
||||
{
|
||||
@@ -72,10 +84,7 @@ Path createGeneration(Path profile, Path outPath,
|
||||
Path generation, gcrootDrv, gcrootClr;
|
||||
|
||||
while (1) {
|
||||
Path prefix = (format("%1%-%2%") % profile % num).str();
|
||||
generation = prefix + "-link";
|
||||
gcrootDrv = prefix + "-drv.gcroot";
|
||||
gcrootClr = prefix + "-clr.gcroot";
|
||||
makeNames(profile, num, generation, gcrootDrv, gcrootClr);
|
||||
if (symlink(outPath.c_str(), generation.c_str()) == 0) break;
|
||||
if (errno != EEXIST)
|
||||
throw SysError(format("creating symlink `%1%'") % generation);
|
||||
@@ -90,6 +99,23 @@ Path createGeneration(Path profile, Path outPath,
|
||||
}
|
||||
|
||||
|
||||
static void removeFile(const Path & path)
|
||||
{
|
||||
if (remove(path.c_str()) == -1)
|
||||
throw SysError(format("cannot unlink `%1%'") % path);
|
||||
}
|
||||
|
||||
|
||||
void deleteGeneration(const Path & profile, unsigned int gen)
|
||||
{
|
||||
Path generation, gcrootDrv, gcrootClr;
|
||||
makeNames(profile, gen, generation, gcrootDrv, gcrootClr);
|
||||
removeFile(generation);
|
||||
if (pathExists(gcrootClr)) removeFile(gcrootClr);
|
||||
if (pathExists(gcrootDrv)) removeFile(gcrootDrv);
|
||||
}
|
||||
|
||||
|
||||
void switchLink(Path link, Path target)
|
||||
{
|
||||
/* Hacky. */
|
||||
|
||||
@@ -31,6 +31,8 @@ Generations findGenerations(Path profile, int & curGen);
|
||||
Path createGeneration(Path profile, Path outPath,
|
||||
Path drvPath, Path clrPath);
|
||||
|
||||
void deleteGeneration(const Path & profile, unsigned int gen);
|
||||
|
||||
void switchLink(Path link, Path target);
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ Options:
|
||||
--version: output version information
|
||||
--help: display help
|
||||
|
||||
Options:
|
||||
|
||||
--verbose / -v: verbose operation (may be repeated)
|
||||
|
||||
--eval-only: evaluate and print resulting term; do not instantiate
|
||||
--parse-only: parse and print abstract syntax tree
|
||||
+31
-11
@@ -6,6 +6,7 @@
|
||||
#include "shared.hh"
|
||||
#include "eval.hh"
|
||||
#include "parser.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
#include "help.txt.hh"
|
||||
|
||||
|
||||
@@ -15,24 +16,23 @@ void printHelp()
|
||||
}
|
||||
|
||||
|
||||
static Expr evalStdin(EvalState & state)
|
||||
static Expr evalStdin(EvalState & state, bool parseOnly)
|
||||
{
|
||||
startNest(nest, lvlTalkative, format("evaluating standard input"));
|
||||
string s, s2;
|
||||
while (getline(cin, s2)) s += s2 + "\n";
|
||||
Expr e = parseExprFromString(state, s, absPath("."));
|
||||
return evalExpr(state, e);
|
||||
return parseOnly ? e : evalExpr(state, e);
|
||||
}
|
||||
|
||||
|
||||
static void printNixExpr(EvalState & state, Expr e)
|
||||
static void printDrvPaths(EvalState & state, Expr e)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList es;
|
||||
|
||||
/* !!! duplication w.r.t. parseDerivations in nix-env */
|
||||
|
||||
if (atMatch(m, e) >> "Attrs" >> es) {
|
||||
if (matchAttrs(e, es)) {
|
||||
Expr a = queryAttr(e, "type");
|
||||
if (a && evalString(state, a) == "derivation") {
|
||||
a = queryAttr(e, "drvPath");
|
||||
@@ -45,14 +45,14 @@ static void printNixExpr(EvalState & state, Expr e)
|
||||
ATermMap drvMap;
|
||||
queryAllAttrs(e, drvMap);
|
||||
for (ATermIterator i(drvMap.keys()); i; ++i)
|
||||
printNixExpr(state, evalExpr(state, drvMap.get(*i)));
|
||||
printDrvPaths(state, evalExpr(state, drvMap.get(*i)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (atMatch(m, e) >> "List" >> es) {
|
||||
if (matchList(e, es)) {
|
||||
for (ATermIterator i(es); i; ++i)
|
||||
printNixExpr(state, evalExpr(state, *i));
|
||||
printDrvPaths(state, evalExpr(state, *i));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,11 +60,22 @@ static void printNixExpr(EvalState & state, Expr e)
|
||||
}
|
||||
|
||||
|
||||
static void printResult(EvalState & state, Expr e, bool evalOnly)
|
||||
{
|
||||
if (evalOnly)
|
||||
cout << format("%1%\n") % e;
|
||||
else
|
||||
printDrvPaths(state, e);
|
||||
}
|
||||
|
||||
|
||||
void run(Strings args)
|
||||
{
|
||||
EvalState state;
|
||||
Strings files;
|
||||
bool readStdin = false;
|
||||
bool evalOnly = false;
|
||||
bool parseOnly = false;
|
||||
|
||||
for (Strings::iterator it = args.begin();
|
||||
it != args.end(); )
|
||||
@@ -73,6 +84,14 @@ void run(Strings args)
|
||||
|
||||
if (arg == "-")
|
||||
readStdin = true;
|
||||
else if (arg == "--eval-only") {
|
||||
readOnlyMode = true;
|
||||
evalOnly = true;
|
||||
}
|
||||
else if (arg == "--parse-only") {
|
||||
readOnlyMode = true;
|
||||
parseOnly = evalOnly = true;
|
||||
}
|
||||
else if (arg[0] == '-')
|
||||
throw UsageError(format("unknown flag `%1%`") % arg);
|
||||
else
|
||||
@@ -82,15 +101,16 @@ void run(Strings args)
|
||||
openDB();
|
||||
|
||||
if (readStdin) {
|
||||
Expr e = evalStdin(state);
|
||||
printNixExpr(state, e);
|
||||
Expr e = evalStdin(state, parseOnly);
|
||||
printResult(state, e, evalOnly);
|
||||
}
|
||||
|
||||
for (Strings::iterator it = files.begin();
|
||||
it != files.end(); it++)
|
||||
{
|
||||
Expr e = evalFile(state, absPath(*it));
|
||||
printNixExpr(state, e);
|
||||
/* !!! parseOnly ignored */
|
||||
printResult(state, e, evalOnly);
|
||||
}
|
||||
|
||||
printEvalStats(state);
|
||||
|
||||
@@ -11,6 +11,7 @@ Operations:
|
||||
|
||||
--successor: register a successor expression (dangerous!)
|
||||
--substitute: register a substitute expression (dangerous!)
|
||||
--clear-substitute: clear all substitutes
|
||||
--validpath: register path validity (dangerous!)
|
||||
--isvalid: check path validity
|
||||
|
||||
|
||||
+79
-19
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "normalise.hh"
|
||||
#include "gc.hh"
|
||||
#include "archive.hh"
|
||||
#include "shared.hh"
|
||||
#include "dotgraph.hh"
|
||||
@@ -32,17 +32,6 @@ static void opRealise(Strings opFlags, Strings opArgs)
|
||||
}
|
||||
|
||||
|
||||
/* Delete a path in the Nix store directory. */
|
||||
static void opDelete(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||
|
||||
for (Strings::iterator it = opArgs.begin();
|
||||
it != opArgs.end(); it++)
|
||||
deleteFromStore(*it);
|
||||
}
|
||||
|
||||
|
||||
/* Add paths to the Nix values directory and print the hashes of those
|
||||
paths. */
|
||||
static void opAdd(Strings opFlags, Strings opArgs)
|
||||
@@ -168,6 +157,7 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
|
||||
if (!opArgs.empty())
|
||||
throw UsageError("no arguments expected");
|
||||
|
||||
SubstitutePairs subPairs;
|
||||
Transaction txn;
|
||||
createStoreTransaction(txn);
|
||||
|
||||
@@ -176,26 +166,36 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
|
||||
Substitute sub;
|
||||
getline(cin, srcPath);
|
||||
if (cin.eof()) break;
|
||||
getline(cin, sub.storeExpr);
|
||||
getline(cin, sub.program);
|
||||
string s;
|
||||
getline(cin, s);
|
||||
istringstream st(s);
|
||||
int n;
|
||||
st >> n;
|
||||
if (!st) throw Error("number expected");
|
||||
if (!string2Int(s, n)) throw Error("number expected");
|
||||
while (n--) {
|
||||
getline(cin, s);
|
||||
sub.args.push_back(s);
|
||||
}
|
||||
if (!cin || cin.eof()) throw Error("missing input");
|
||||
registerSubstitute(txn, srcPath, sub);
|
||||
subPairs.push_back(pair<Path, Substitute>(srcPath, sub));
|
||||
}
|
||||
|
||||
registerSubstitutes(txn, subPairs);
|
||||
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
static void opClearSubstitutes(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||
if (!opArgs.empty())
|
||||
throw UsageError("no arguments expected");
|
||||
|
||||
clearSubstitutes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void opValidPath(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||
@@ -220,6 +220,64 @@ static void opIsValid(Strings opFlags, Strings opArgs)
|
||||
}
|
||||
|
||||
|
||||
static void opGC(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
/* Do what? */
|
||||
enum { soPrintLive, soPrintDead, soDelete } subOp;
|
||||
time_t minAge = 0;
|
||||
for (Strings::iterator i = opFlags.begin();
|
||||
i != opFlags.end(); ++i)
|
||||
if (*i == "--print-live") subOp = soPrintLive;
|
||||
else if (*i == "--print-dead") subOp = soPrintDead;
|
||||
else if (*i == "--delete") subOp = soDelete;
|
||||
else if (*i == "--min-age") {
|
||||
int n;
|
||||
if (opArgs.size() == 0 || !string2Int(opArgs.front(), n))
|
||||
throw UsageError("`--min-age' requires an integer argument");
|
||||
minAge = n;
|
||||
}
|
||||
else throw UsageError(format("bad sub-operation `%1%' in GC") % *i);
|
||||
|
||||
Paths roots;
|
||||
while (1) {
|
||||
Path root;
|
||||
getline(cin, root);
|
||||
if (cin.eof()) break;
|
||||
roots.push_back(root);
|
||||
}
|
||||
|
||||
PathSet live = findLivePaths(roots);
|
||||
|
||||
if (subOp == soPrintLive) {
|
||||
for (PathSet::iterator i = live.begin(); i != live.end(); ++i)
|
||||
cout << *i << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
PathSet dead = findDeadPaths(live, minAge * 3600);
|
||||
|
||||
if (subOp == soPrintDead) {
|
||||
for (PathSet::iterator i = dead.begin(); i != dead.end(); ++i)
|
||||
cout << *i << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (subOp == soDelete) {
|
||||
|
||||
/* !!! What happens if the garbage collector run is aborted
|
||||
halfway through? In particular, dead paths can always
|
||||
become live again (through re-instantiation), and might
|
||||
then refer to deleted paths. => check instantiation
|
||||
invariants */
|
||||
|
||||
for (PathSet::iterator i = dead.begin(); i != dead.end(); ++i) {
|
||||
printMsg(lvlInfo, format("deleting `%1%'") % *i);
|
||||
deleteFromStore(*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* A sink that writes dump output to stdout. */
|
||||
struct StdoutSink : DumpSink
|
||||
{
|
||||
@@ -298,8 +356,6 @@ void run(Strings args)
|
||||
|
||||
if (arg == "--realise" || arg == "-r")
|
||||
op = opRealise;
|
||||
else if (arg == "--delete" || arg == "-d")
|
||||
op = opDelete;
|
||||
else if (arg == "--add" || arg == "-A")
|
||||
op = opAdd;
|
||||
else if (arg == "--query" || arg == "-q")
|
||||
@@ -308,10 +364,14 @@ void run(Strings args)
|
||||
op = opSuccessor;
|
||||
else if (arg == "--substitute")
|
||||
op = opSubstitute;
|
||||
else if (arg == "--clear-substitutes")
|
||||
op = opClearSubstitutes;
|
||||
else if (arg == "--validpath")
|
||||
op = opValidPath;
|
||||
else if (arg == "--isvalid")
|
||||
op = opIsValid;
|
||||
else if (arg == "--gc")
|
||||
op = opGC;
|
||||
else if (arg == "--dump")
|
||||
op = opDump;
|
||||
else if (arg == "--restore")
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#! /bin/sh
|
||||
|
||||
IFS=
|
||||
|
||||
echo "printing list of args"
|
||||
|
||||
for i in $@; do
|
||||
echo "arg: $i"
|
||||
done
|
||||
|
||||
touch $out
|
||||
@@ -1,7 +0,0 @@
|
||||
Package(
|
||||
[ ("name", "args")
|
||||
, ("build", Relative("args/args-build.sh"))
|
||||
|
||||
, ("args", ["1", "2", "3", IncludeFix("slow2/slow.fix")])
|
||||
]
|
||||
)
|
||||
@@ -1,9 +0,0 @@
|
||||
Call(
|
||||
Function(["x"],
|
||||
Call(
|
||||
Function(["x"], Var("x")),
|
||||
[ ("x", Var("x")) ]
|
||||
)
|
||||
),
|
||||
[ ("x", True) ]
|
||||
)
|
||||
@@ -1,9 +0,0 @@
|
||||
Call(
|
||||
Function(["x"],
|
||||
Call(
|
||||
Function(["y", "z"], Var("y")),
|
||||
[ ("y", Var("x")) ]
|
||||
)
|
||||
),
|
||||
[ ("x", True) ]
|
||||
)
|
||||
@@ -1,9 +0,0 @@
|
||||
Call(
|
||||
Function(["x"],
|
||||
Call(
|
||||
Function(["x"], Var("x")),
|
||||
[ ("x", False) ]
|
||||
)
|
||||
),
|
||||
[ ("x", True) ]
|
||||
)
|
||||
Loaded 100 of 134 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user