Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1ed34081e | ||
|
|
17e20716c0 | ||
|
|
5d48dd6912 | ||
|
|
af54a60204 | ||
|
|
7d386d5c29 | ||
|
|
fa50c0849e | ||
|
|
321be4649d | ||
|
|
0920fe3038 | ||
|
|
08de98f8b6 | ||
|
|
15646244ba | ||
|
|
a2e33d200e |
No files matched your search
@@ -1,8 +0,0 @@
|
||||
The following people contributed to Nix, in alphabetical order:
|
||||
|
||||
Martin Bravenboer
|
||||
Eelco Dolstra
|
||||
Niels Janssen
|
||||
Armijn Hemel
|
||||
Rob Vermaas
|
||||
Eelco Visser
|
||||
+8
-16
@@ -1,5 +1,5 @@
|
||||
SUBDIRS = externals src scripts corepkgs doc misc tests
|
||||
EXTRA_DIST = substitute.mk nix.spec nix.spec.in bootstrap.sh svn-revision
|
||||
EXTRA_DIST = substitute.mk nix.spec nix.spec.in
|
||||
|
||||
include ./substitute.mk
|
||||
|
||||
@@ -14,25 +14,17 @@ 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) $(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
|
||||
$(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
|
||||
rm -f $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||
ln -s $(localstatedir)/nix/profiles $(DESTDIR)$(localstatedir)/nix/gcroots/profiles
|
||||
$(INSTALL) $(INIT_FLAGS) -d $(DESTDIR)$(prefix)/store
|
||||
$(INSTALL) -d $(DESTDIR)$(prefix)/store
|
||||
# $(bindir)/nix-store --init
|
||||
else
|
||||
init-state:
|
||||
endif
|
||||
|
||||
svn-revision:
|
||||
svnversion . > svn-revision
|
||||
@@ -1,69 +0,0 @@
|
||||
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.
|
||||
@@ -1,5 +0,0 @@
|
||||
#! /bin/sh -e
|
||||
aclocal
|
||||
autoheader
|
||||
automake --add-missing --copy
|
||||
autoconf
|
||||
+7
-50
@@ -1,11 +1,11 @@
|
||||
AC_INIT(nix, "0.6.1")
|
||||
AC_INIT(nix, "0.6")
|
||||
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=1
|
||||
STABLE=0
|
||||
|
||||
# Put the revision number in the version.
|
||||
if test "$STABLE" != "1"; then
|
||||
@@ -22,24 +22,12 @@ AC_CANONICAL_HOST
|
||||
|
||||
# Construct a Nix system name (like "i686-linux").
|
||||
AC_MSG_CHECKING([for the canonical Nix system name])
|
||||
cpu_name=$(uname -p | tr 'A-Z ' 'a-z_')
|
||||
machine_name=$(uname -m | tr 'A-Z ' 'a-z_')
|
||||
|
||||
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_')
|
||||
#machine_name=`uname -m`
|
||||
#sys_name=`uname -s | tr [A-Z] [a-z]`
|
||||
#system="${machine_name}-${sys_name}"
|
||||
AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM],
|
||||
[platform identifier (e.g., `i686-linux')]),
|
||||
system=$withval, system="${machine_name}-${sys_name}")
|
||||
system=$withval, system="$host_cpu-$host_os")
|
||||
AC_MSG_RESULT($system)
|
||||
AC_SUBST(system)
|
||||
AC_DEFINE_UNQUOTED(SYSTEM, ["$system"], [platform identifier (`cpu-os')])
|
||||
@@ -68,7 +56,7 @@ AC_DEFUN([NEED_PROG],
|
||||
[
|
||||
AC_PATH_PROG($1, $2)
|
||||
if test -z "$$1"; then
|
||||
AC_MSG_ERROR([$2 is required])
|
||||
AC_MSG_ERROR([$1 is required])
|
||||
fi
|
||||
])
|
||||
|
||||
@@ -128,15 +116,12 @@ 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)
|
||||
|
||||
@@ -145,34 +130,6 @@ 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
|
||||
|
||||
@@ -24,10 +24,9 @@ sub createLinks {
|
||||
my $dstFile = "$dstDir/$baseName";
|
||||
|
||||
if ($srcFile =~ /\/propagated-build-inputs$/ ||
|
||||
$srcFile =~ /\/nix-support$/ ||
|
||||
$srcFile =~ /\/log$/)
|
||||
$srcFile =~ /\/nix-support$/)
|
||||
{
|
||||
# Do nothing.
|
||||
# Do noting.
|
||||
}
|
||||
|
||||
elsif (-d $srcFile) {
|
||||
|
||||
@@ -8,8 +8,6 @@ mkdir $out
|
||||
dst=$out/$(basename $path).nar.bz2
|
||||
@bindir@/nix-store --dump "$path" | @bzip2@ > $dst
|
||||
|
||||
if test "${PIPESTATUS[0]}" != "0"; then exit 1; fi
|
||||
|
||||
md5=$(md5sum -b $dst | cut -c1-32)
|
||||
if test $? != 0; then exit 1; fi
|
||||
echo $md5 > $out/md5
|
||||
+3
-10
@@ -4,18 +4,13 @@ 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 xref.with.number.and.title 0
|
||||
--param html.stylesheet \'style.css\'
|
||||
|
||||
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
|
||||
|
||||
FIGURES = figures/user-environments.png
|
||||
|
||||
SOURCES = manual.xml introduction.xml installation.xml \
|
||||
package-management.xml writing-nix-expressions.xml \
|
||||
build-farm.xml \
|
||||
SOURCES = manual.xml introduction.xml installation.xml overview.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
|
||||
@@ -40,8 +35,6 @@ 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
|
||||
@@ -52,6 +45,6 @@ images:
|
||||
|
||||
KEEP = manual.html manual.is-valid version.xml $(MANS)
|
||||
|
||||
EXTRA_DIST = $(SOURCES) $(FIGURES) $(KEEP)
|
||||
EXTRA_DIST = $(SOURCES) $(KEEP)
|
||||
|
||||
DISTCLEANFILES = $(KEEP)
|
||||
+25
-18
@@ -1,6 +1,7 @@
|
||||
<appendix><title>Bugs / To-Do</title>
|
||||
<appendix>
|
||||
<title>Bugs / To-Do</title>
|
||||
|
||||
<itemizedlist>
|
||||
<itemizedlist>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
@@ -52,6 +53,17 @@
|
||||
</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
|
||||
@@ -87,22 +99,17 @@ $ 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>
|
||||
|
||||
<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>
|
||||
</itemizedlist>
|
||||
|
||||
</appendix>
|
||||
@@ -1,129 +0,0 @@
|
||||
<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.
|
Before Width: | Height: | Size: 16 KiB |
+179
-180
@@ -1,212 +1,211 @@
|
||||
<chapter id='chap-installation'><title>Installation</title>
|
||||
<chapter id='chap-installation'>
|
||||
<title>Installation</title>
|
||||
|
||||
<sect1>
|
||||
<title>Obtaining Nix</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 Red Hat 9 are also available. These
|
||||
distributions are generated automatically.</para>
|
||||
|
||||
<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>
|
||||
|
||||
</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>
|
||||
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>
|
||||
|
||||
<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>
|
||||
|
||||
</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>
|
||||
$ ./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>
|
||||
|
||||
<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>
|
||||
|
||||
<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>
|
||||
|
||||
<sect2><title>Setuid installation</title>
|
||||
<sect1>
|
||||
<title>Using Nix</title>
|
||||
|
||||
<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.,
|
||||
<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>
|
||||
$ ./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>
|
||||
<screen>
|
||||
. <replaceable>prefix</replaceable>/etc/profile.d/nix.sh</screen>
|
||||
|
||||
</sect1>
|
||||
|
||||
</chapter>
|
||||
+78
-128
@@ -1,143 +1,93 @@
|
||||
<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 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 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>
|
||||
|
||||
<itemizedlist>
|
||||
<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>
|
||||
|
||||
<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>
|
||||
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 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>
|
||||
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>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>
|
||||
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>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>
|
||||
Other features:
|
||||
</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>Transparent source/binary deployment.</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>Unambiguous identification of configuration.</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>Automatic storage management.</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>Atomic upgrades and rollbacks.</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 succesfully 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>Support for many simultaneous configurations.</emphasis>
|
||||
</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>
|
||||
|
||||
</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>
|
||||
<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>
|
||||
|
||||
</chapter>
|
||||
+10
-11
@@ -1,14 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE book
|
||||
PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
||||
"http://www.docbook.org/xml/4.3/docbook-xml-4.3.zip"
|
||||
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" -->
|
||||
<!ENTITY introduction SYSTEM "introduction.xml">
|
||||
<!ENTITY quick-start SYSTEM "quick-start.xml">
|
||||
<!ENTITY installation SYSTEM "installation.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 overview SYSTEM "overview.xml">
|
||||
<!ENTITY opt-common SYSTEM "opt-common.xml">
|
||||
<!ENTITY opt-common-syn SYSTEM "opt-common-syn.xml">
|
||||
<!ENTITY nix-env SYSTEM "nix-env.xml">
|
||||
@@ -18,14 +19,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 User's Guide</title>
|
||||
<title>Nix: A System for Software Deployment</title>
|
||||
|
||||
<subtitle>Draft (Version &version;)</subtitle>
|
||||
|
||||
@@ -43,9 +44,7 @@
|
||||
&introduction;
|
||||
&quick-start;
|
||||
&installation;
|
||||
&package-management;
|
||||
&writing-nix-expressions;
|
||||
&build-farm;
|
||||
&overview;
|
||||
|
||||
<appendix>
|
||||
<title>Command Reference</title>
|
||||
@@ -79,7 +78,7 @@
|
||||
</sect1>
|
||||
</appendix>
|
||||
|
||||
<!-- &nix-lang-ref; -->
|
||||
&nix-lang-ref;
|
||||
|
||||
&troubleshooting;
|
||||
&bugs;
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
<refentry>
|
||||
<refnamediv>
|
||||
<refname>nix-collect-garbage</refname>
|
||||
<refpurpose>remove unreachable store paths</refpurpose>
|
||||
<refpurpose>determine the set of unreachable store paths</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>nix-collect-garbage</command>
|
||||
<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>
|
||||
<arg><option>--invert</option></arg>
|
||||
<arg><option>--no-successors</option></arg>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
@@ -19,22 +16,10 @@
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
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).
|
||||
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.
|
||||
</para>
|
||||
|
||||
</refsection>
|
||||
@@ -45,24 +30,27 @@
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--print-live</option> / <option>--print-dead</option></term>
|
||||
<term><option>--invert</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
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>.
|
||||
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.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--min-age</option> <replaceable>age</replaceable></term>
|
||||
<term><option>--no-successors</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This option corresponds to the <option>--min-age</option>
|
||||
option in <command>nix-store <option>--gc</option></command>.
|
||||
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.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -75,10 +63,10 @@
|
||||
<title>Examples</title>
|
||||
|
||||
<para>
|
||||
To delete all unreachable paths, just do:
|
||||
To delete all unreachable paths, do the following:
|
||||
|
||||
<screen>
|
||||
$ nix-collect-garbage</screen>
|
||||
$ nix-collect-garbage | xargs nix-store --delete</screen>
|
||||
|
||||
</para>
|
||||
|
||||
|
||||
@@ -22,11 +22,6 @@
|
||||
</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>
|
||||
@@ -126,38 +121,6 @@
|
||||
</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>
|
||||
@@ -756,47 +719,6 @@ $ 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,10 +8,6 @@
|
||||
<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>
|
||||
@@ -43,27 +39,6 @@
|
||||
|
||||
&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 @@
|
||||
<appendix>
|
||||
<chapter>
|
||||
<title>Nix Language Reference</title>
|
||||
|
||||
<sect1>
|
||||
@@ -274,4 +274,4 @@
|
||||
</sect1>
|
||||
|
||||
|
||||
</appendix>
|
||||
</chapter>
|
||||
+12
-70
@@ -135,19 +135,17 @@
|
||||
<!--######################################################################-->
|
||||
|
||||
<refsection>
|
||||
<title>Operation <option>--gc</option></title>
|
||||
<title>Operation <option>--delete</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><option>--min-age</option> <replaceable>age</replaceable></arg>
|
||||
<arg choice='plain' rep='repeat'><replaceable>paths</replaceable></arg>
|
||||
</cmdsynopsis>
|
||||
</refsection>
|
||||
|
||||
@@ -155,75 +153,19 @@
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
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.
|
||||
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.
|
||||
</para>
|
||||
|
||||
<warning>
|
||||
<para>
|
||||
You generally will want to use the command
|
||||
<command>nix-collect-garbage</command>, which figures out
|
||||
the roots and then calls this command automatically.
|
||||
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).
|
||||
</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>--no-build-output</option></arg>
|
||||
<arg><option>-Q</option></arg>
|
||||
<arg><option>--build-output</option></arg>
|
||||
<arg><option>-B</option></arg>
|
||||
<arg>
|
||||
<group choice='req'>
|
||||
<arg choice='plain'><option>--max-jobs</option></arg>
|
||||
@@ -16,4 +16,3 @@
|
||||
<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. This is the default.
|
||||
doing.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -94,13 +94,14 @@
|
||||
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--no-build-output</option> / <option>-Q</option></term>
|
||||
<term><option>--build-output</option> / <option>-B</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
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
|
||||
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
|
||||
<filename><replaceable>prefix</replaceable>/nix/var/log/nix</filename>.
|
||||
</para>
|
||||
</listitem>
|
||||
@@ -171,14 +172,3 @@
|
||||
</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>
|
||||
@@ -0,0 +1,450 @@
|
||||
<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>
|
||||
@@ -1,455 +0,0 @@
|
||||
<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>
|
||||
+98
-75
@@ -1,118 +1,141 @@
|
||||
<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 the following chapters.</para>
|
||||
<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>
|
||||
|
||||
<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 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>
|
||||
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>
|
||||
|
||||
<listitem><para>Subscribe to the Nix Packages channel.
|
||||
<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.
|
||||
|
||||
<screen>
|
||||
$ nix-channel --add http://catamaran.labs.cs.uu.nl/dist/nix/channels/nixpkgs-unstable</screen>
|
||||
<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>
|
||||
|
||||
</para></listitem>
|
||||
This will unpack the distribution into a directory
|
||||
<filename>nixpkgs-<replaceable>version</replaceable>/</filename>.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem><para>Download the latest Nix expressions available in the channel.
|
||||
<screen>
|
||||
$ nix-channel --update</screen>
|
||||
<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.
|
||||
|
||||
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>
|
||||
<screen>
|
||||
$ nix-pull http://<replaceable>...</replaceable>/nix/nixpkgs-<replaceable>version</replaceable>/MANIFEST</screen>
|
||||
|
||||
<listitem><para>See what installable components are currently
|
||||
available in the channel:
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
$ nix-env -qa
|
||||
docbook-xml-4.2
|
||||
firefox-1.0pre-PR-0.10.1
|
||||
<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
|
||||
docbook-xml-4.2
|
||||
libxslt-1.1.0
|
||||
<replaceable>...</replaceable></screen>
|
||||
|
||||
</para></listitem>
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem><para>Install some components from the channel:
|
||||
<listitem>
|
||||
<para>
|
||||
Install some packages:
|
||||
|
||||
<screen>
|
||||
$ nix-env -i hello firefox <replaceable>...</replaceable> </screen>
|
||||
<screen>
|
||||
$ nix-env -iBf nixpkgs-<replaceable>version</replaceable>/ hello MozillaFirebird <replaceable>...</replaceable> </screen>
|
||||
|
||||
This should download the pre-built components; it should not build
|
||||
them locally (if it does, something went wrong).</para></listitem>
|
||||
</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!
|
||||
$ firefox
|
||||
$ MozillaFirebird
|
||||
<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>To keep up-to-date with the channel, do:
|
||||
<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:
|
||||
|
||||
<screen>
|
||||
$ nix-channel --update
|
||||
$ nix-env -u '*'</screen>
|
||||
<screen>
|
||||
$ nix-env -uBf nixpkgs-<replaceable>version</replaceable>/ '*'</screen>
|
||||
|
||||
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>
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<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:
|
||||
<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:
|
||||
|
||||
<screen>
|
||||
$ nix-env --rollback</screen>
|
||||
<screen>
|
||||
$ nix-collect-garbage | xargs nix-store --delete</screen>
|
||||
|
||||
</para></listitem>
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<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:
|
||||
</orderedlist>
|
||||
|
||||
<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>
|
||||
</chapter>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
|
||||
<uri pattern="*.xml" typeId="DocBook"/>
|
||||
<uri pathSuffix=".xml" typeId="DocBook"/>
|
||||
</locatingRules>
|
||||
@@ -112,16 +112,10 @@ div.note,div.warning
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
div.warning h3
|
||||
div.note h3,div.warning h3
|
||||
{
|
||||
color: red;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
div.note h3
|
||||
{
|
||||
color: blue;
|
||||
font-size: 100%;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
div.navfooter *
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,30 @@
|
||||
rec {
|
||||
|
||||
inherit (import ../../../lib) compileC makeLibrary;
|
||||
|
||||
sources = [
|
||||
./afun.c
|
||||
./aterm.c
|
||||
./bafio.c
|
||||
./byteio.c
|
||||
./gc.c
|
||||
./hash.c
|
||||
./list.c
|
||||
./make.c
|
||||
./md5c.c
|
||||
./memory.c
|
||||
./tafio.c
|
||||
./version.c
|
||||
];
|
||||
|
||||
compile = fn: compileC {
|
||||
main = fn;
|
||||
localIncludes = "auto";
|
||||
};
|
||||
|
||||
libATerm = makeLibrary {
|
||||
libraryName = "ATerm";
|
||||
objects = map {function = compile; list = sources;};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
import test/default.nix
|
||||
@@ -0,0 +1,16 @@
|
||||
let {
|
||||
|
||||
inherit (import ../../../lib) compileC link;
|
||||
|
||||
inherit (import ../aterm) libATerm;
|
||||
|
||||
compile = fn: compileC {
|
||||
main = fn;
|
||||
localIncludes = "auto";
|
||||
cFlags = "-I../aterm";
|
||||
};
|
||||
|
||||
fib = link {objects = compile ./fib.c; libraries = libATerm;};
|
||||
|
||||
body = [fib];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
[ (import ./trivial)
|
||||
(import ./simple-header)
|
||||
(import ./not-so-simple-header)
|
||||
(import ./not-so-simple-header-auto)
|
||||
(import ./aterm)
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
#define WHAT "World"
|
||||
@@ -0,0 +1,11 @@
|
||||
let {
|
||||
|
||||
inherit (import ../../lib) compileC findIncludes link;
|
||||
|
||||
hello = link {programName = "hello"; objects = compileC {
|
||||
main = ./foo/hello.c;
|
||||
localIncludes = "auto";
|
||||
};};
|
||||
|
||||
body = [hello];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#define HELLO "Hello"
|
||||
|
||||
#include "../../bar/hello.h"
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fnord/indirect.h"
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
printf(HELLO " " WHAT "\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#define WHAT "World"
|
||||
@@ -0,0 +1,14 @@
|
||||
let {
|
||||
|
||||
inherit (import ../../lib) compileC link;
|
||||
|
||||
hello = link {programName = "hello"; objects = compileC {
|
||||
main = ./foo/hello.c;
|
||||
localIncludes = [
|
||||
[./foo/fnord/indirect.h "fnord/indirect.h"]
|
||||
[./bar/hello.h "fnord/../../bar/hello.h"]
|
||||
];
|
||||
};};
|
||||
|
||||
body = [hello];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#define HELLO "Hello"
|
||||
|
||||
#include "../../bar/hello.h"
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fnord/indirect.h"
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
printf(HELLO " " WHAT "\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
let {
|
||||
|
||||
inherit (import ../../lib) compileC link;
|
||||
|
||||
hello = link {objects = compileC {
|
||||
main = ./hello.c;
|
||||
localIncludes = [ [./hello.h "hello.h"] ];
|
||||
};};
|
||||
|
||||
body = [hello];
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "hello.h"
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
printf("Hello " WHAT "\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#define WHAT "World"
|
||||
@@ -0,0 +1,8 @@
|
||||
let {
|
||||
|
||||
inherit (import ../../lib) compileC link;
|
||||
|
||||
hello = link {objects = compileC {main = ./hello.c;};};
|
||||
|
||||
body = [hello];
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
printf("Hello World\n");
|
||||
return 0;
|
||||
}
|
||||
Vendored
+5
-4
@@ -34,12 +34,12 @@ endif
|
||||
|
||||
# CWI ATerm
|
||||
|
||||
ATERM = aterm-2.2
|
||||
ATERM = aterm-2.1
|
||||
|
||||
$(ATERM).tar.gz:
|
||||
@echo "Nix requires the CWI ATerm library to build."
|
||||
@echo "Please download version 2.2 from"
|
||||
@echo " http://www.cwi.nl/projects/MetaEnv/aterm/aterm-2.2.tar.gz"
|
||||
@echo "Please download version 2.1 from"
|
||||
@echo " http://www.cwi.nl/projects/MetaEnv/aterm/aterm-2.1.tar.gz"
|
||||
@echo "and place it in the externals/ directory."
|
||||
false
|
||||
|
||||
@@ -56,7 +56,8 @@ else
|
||||
build-aterm: have-aterm
|
||||
(pfx=`pwd` && \
|
||||
cd $(ATERM) && \
|
||||
CC="$(CC)" ./configure --prefix=$$pfx/inst-aterm && \
|
||||
CC="$(CC)" ./configure --prefix=$$pfx/inst-aterm \
|
||||
--with-cflags="-DNDEBUG -DXGC_VERBOSE -DXHASHPEM -DWITH_STATS $(CFLAGS)" && \
|
||||
make && \
|
||||
make install)
|
||||
touch build-aterm
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
. $stdenv/setup
|
||||
|
||||
mainName=$(basename $main | cut -c34-)
|
||||
|
||||
echo "compiling \`$mainName'..."
|
||||
|
||||
# Turn $localIncludes into an array.
|
||||
localIncludes=($localIncludes)
|
||||
|
||||
# Determine how many `..' levels appear in the header file references.
|
||||
# E.g., if there is some reference `../../foo.h', then we have to
|
||||
# insert two extra levels in the directory structure, so that `a.c' is
|
||||
# stored at `dotdot/dotdot/a.c', and a reference from it to
|
||||
# `../../foo.h' resolves to `dotdot/dotdot/../../foo.h' == `foo.h'.
|
||||
n=0
|
||||
maxDepth=0
|
||||
for ((n = 0; n < ${#localIncludes[*]}; n += 2)); do
|
||||
target=${localIncludes[$((n + 1))]}
|
||||
|
||||
# Split the target name into path components using some IFS magic.
|
||||
savedIFS="$IFS"
|
||||
IFS=/
|
||||
components=($target)
|
||||
depth=0
|
||||
for ((m = 0; m < ${#components[*]}; m++)); do
|
||||
c=${components[m]}
|
||||
if test "$c" = ".."; then
|
||||
depth=$((depth + 1))
|
||||
fi
|
||||
done
|
||||
IFS="$savedIFS"
|
||||
|
||||
if test $depth -gt $maxDepth; then
|
||||
maxDepth=$depth;
|
||||
fi
|
||||
done
|
||||
|
||||
# Create the extra levels in the directory hierarchy.
|
||||
prefix=
|
||||
for ((n = 0; n < maxDepth; n++)); do
|
||||
prefix="dotdot/$prefix"
|
||||
done
|
||||
|
||||
# Create symlinks to the header files.
|
||||
for ((n = 0; n < ${#localIncludes[*]}; n += 2)); do
|
||||
source=${localIncludes[n]}
|
||||
target=${localIncludes[$((n + 1))]}
|
||||
|
||||
# Create missing directories. We use IFS magic to split the path
|
||||
# into path components.
|
||||
savedIFS="$IFS"
|
||||
IFS=/
|
||||
components=($prefix$target)
|
||||
fullPath=(.)
|
||||
for ((m = 0; m < ${#components[*]} - 1; m++)); do
|
||||
fullPath=("${fullPath[@]}" ${components[m]})
|
||||
if ! test -d "${fullPath[*]}"; then
|
||||
mkdir "${fullPath[*]}"
|
||||
fi
|
||||
done
|
||||
IFS="$savedIFS"
|
||||
|
||||
ln -s $source $prefix$target
|
||||
done
|
||||
|
||||
# Create a symlink to the main file.
|
||||
if ! test "$(readlink $prefix$mainName)" = $main; then
|
||||
ln -s $main $prefix$mainName
|
||||
fi
|
||||
|
||||
mkdir $out
|
||||
test "$prefix" && cd $prefix
|
||||
gcc -Wall $cFlags -c $mainName -o $out/$mainName.o
|
||||
@@ -0,0 +1,46 @@
|
||||
rec {
|
||||
|
||||
inherit (import /home/eelco/nixpkgs/pkgs/system/i686-linux.nix) stdenv;
|
||||
|
||||
compileC = {main, localIncludes ? [], cFlags ? ""}: stdenv.mkDerivation {
|
||||
name = "compile-c";
|
||||
builder = ./compile-c.sh;
|
||||
localIncludes =
|
||||
if localIncludes == "auto" then
|
||||
import (findIncludes {
|
||||
main = toString main;
|
||||
hack = curTime;
|
||||
inherit cFlags;
|
||||
})
|
||||
else
|
||||
localIncludes;
|
||||
inherit main cFlags;
|
||||
};
|
||||
|
||||
/*
|
||||
runCommand = {command}: {
|
||||
name = "run-command";
|
||||
builder = ./run-command.sh;
|
||||
inherit command;
|
||||
};
|
||||
*/
|
||||
|
||||
findIncludes = {main, hack, cFlags ? ""}: stdenv.mkDerivation {
|
||||
name = "find-includes";
|
||||
builder = ./find-includes.sh;
|
||||
inherit main hack cFlags;
|
||||
};
|
||||
|
||||
link = {objects, programName ? "program", libraries ? []}: stdenv.mkDerivation {
|
||||
name = "link";
|
||||
builder = ./link.sh;
|
||||
inherit objects programName libraries;
|
||||
};
|
||||
|
||||
makeLibrary = {objects, libraryName ? []}: stdenv.mkDerivation {
|
||||
name = "library";
|
||||
builder = ./make-library.sh;
|
||||
inherit objects libraryName;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
. $stdenv/setup
|
||||
|
||||
echo "finding includes of \`$(basename $main)'..."
|
||||
|
||||
makefile=$NIX_BUILD_TOP/makefile
|
||||
|
||||
mainDir=$(dirname $main)
|
||||
(cd $mainDir && gcc $cFlags -MM $(basename $main) -MF $makefile) || false
|
||||
|
||||
echo "[" >$out
|
||||
|
||||
while read line; do
|
||||
line=$(echo "$line" | sed 's/.*://')
|
||||
for i in $line; do
|
||||
fullPath=$(readlink -f $mainDir/$i)
|
||||
echo " [ $fullPath \"$i\" ]" >>$out
|
||||
done
|
||||
done < $makefile
|
||||
|
||||
echo "]" >>$out
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
. $stdenv/setup
|
||||
|
||||
objs=
|
||||
for i in $objects; do
|
||||
obj=$(echo $i/*.o)
|
||||
objs="$objs $obj"
|
||||
done
|
||||
|
||||
libs=
|
||||
for i in $libraries; do
|
||||
lib=$(echo $i/*.a)
|
||||
name=$(echo $(basename $lib) | sed -e 's/^lib//' -e 's/.a$//')
|
||||
libs="$libs -L$(dirname $lib) -l$name"
|
||||
done
|
||||
|
||||
echo "linking object files into \`$programName'..."
|
||||
|
||||
mkdir $out
|
||||
gcc -o $out/$programName $objs $libs
|
||||
@@ -0,0 +1,15 @@
|
||||
. $stdenv/setup
|
||||
|
||||
objs=
|
||||
for i in $objects; do
|
||||
obj=$(echo $i/*.o)
|
||||
objs="$objs $obj"
|
||||
done
|
||||
|
||||
echo "archiving object files into library \`$libraryName'..."
|
||||
|
||||
outPath=$out/lib${libraryName}.a
|
||||
|
||||
mkdir $out
|
||||
ar crs $outPath $objs
|
||||
ranlib $outPath
|
||||
+5
-37
@@ -1,47 +1,25 @@
|
||||
%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: Software Deployment
|
||||
URL: http://www.cs.uu.nl/groups/ST/Trace/Nix
|
||||
Group: WeetNiet
|
||||
URL: http://www.cs.uu.nl/groups/ST/twiki/bin/view/Trace/NixDeploymentSystem
|
||||
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 system for software deployment.
|
||||
Nix is a software deployment system.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
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
|
||||
./configure --prefix=%{_prefix}
|
||||
make
|
||||
make check
|
||||
|
||||
@@ -53,18 +31,8 @@ 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
|
||||
|
||||
+3
-19
@@ -8,34 +8,18 @@ if test -z "$nixExpr"; then
|
||||
fi
|
||||
|
||||
extraArgs=
|
||||
noLink=
|
||||
|
||||
for i in "$@"; do
|
||||
case "$i" in
|
||||
--no-link)
|
||||
noLink=1
|
||||
;;
|
||||
-*)
|
||||
extraArgs="$extraArgs $i"
|
||||
;;
|
||||
*)
|
||||
storeExprs=$(nix-instantiate "$i")
|
||||
for j in $storeExprs; do
|
||||
storeExpr=$(nix-instantiate "$i")
|
||||
for j in $storeExpr; do
|
||||
echo "store expression is $j" >&2
|
||||
done
|
||||
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
|
||||
nix-store -qnfv $extraArgs $storeExpr
|
||||
;;
|
||||
esac
|
||||
done
|
||||
+4
-21
@@ -2,8 +2,6 @@
|
||||
|
||||
use strict;
|
||||
|
||||
my $rootsDir = "@localstatedir@/nix/gcroots/channels";
|
||||
|
||||
|
||||
# Figure out the name of the `.nix-channels' file to use.
|
||||
my $home = $ENV{"HOME"};
|
||||
@@ -17,7 +15,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, $_;
|
||||
@@ -28,7 +26,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";
|
||||
}
|
||||
@@ -81,33 +79,18 @@ sub update {
|
||||
"(import @datadir@/nix/corepkgs/channels/unpack.nix) " .
|
||||
"{inputs = $nixExpr; system = \"@system@\";}";
|
||||
|
||||
# Instantiate the Nix expression.
|
||||
# Instantiate and realise it.
|
||||
my $storeExpr = `echo '$nixExpr' | @bindir@/nix-instantiate -`
|
||||
or die "cannot instantiate Nix expression";
|
||||
chomp $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'`
|
||||
my $outPath = `nix-store -qnfB '$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': $!";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,24 +8,16 @@ my $storeDir = "@storedir@";
|
||||
|
||||
my %alive;
|
||||
|
||||
my $gcOper = "--delete";
|
||||
my $minAge = 0;
|
||||
my $keepSuccessors = 1;
|
||||
my $invert = 0;
|
||||
|
||||
my @roots = ();
|
||||
|
||||
|
||||
# Parse the command line.
|
||||
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*$/;
|
||||
}
|
||||
foreach my $arg (@ARGV) {
|
||||
if ($arg eq "--no-successors") { $keepSuccessors = 0; }
|
||||
elsif ($arg eq "--invert") { $invert = 1; }
|
||||
else { die "unknown argument `$arg'" };
|
||||
}
|
||||
|
||||
@@ -76,15 +68,33 @@ sub findRoots {
|
||||
findRoots 1, $rootsDir;
|
||||
|
||||
|
||||
# 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";
|
||||
}
|
||||
|
||||
# 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"; };
|
||||
}
|
||||
close READ;
|
||||
|
||||
waitpid $pid, 0;
|
||||
$? == 0 or die "`nix-store --gc' failed";
|
||||
$? == 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;
|
||||
@@ -7,18 +7,9 @@ if test -z "$url"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# !!! race
|
||||
# !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
|
||||
tmpPath1=@storedir@/nix-prefetch-url-$$
|
||||
|
||||
# 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
|
||||
|
||||
# Perform the checkout.
|
||||
@curl@ --fail --location --max-redirs 20 "$url" > $tmpPath1
|
||||
|
||||
@@ -26,24 +17,22 @@ fi
|
||||
hash=$(@bindir@/nix-hash --flat $tmpPath1)
|
||||
echo "hash is $hash" >&2
|
||||
|
||||
# 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
|
||||
# Rename it so that the fetchsvn builder can find it.
|
||||
tmpPath2=@storedir@/nix-prefetch-url-$hash
|
||||
test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
||||
|
||||
# Create a Nix expression that does a fetchurl.
|
||||
# Create a Nix expression that does a fetchsvn.
|
||||
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)
|
||||
|
||||
|
||||
echo "path is $finalPath" >&2
|
||||
|
||||
rm -rf $tmpPath1 $tmpPath2 || true
|
||||
rm -rf $tmpPath2 || true
|
||||
|
||||
echo $hash
|
||||
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ while (scalar @tmp > 0) {
|
||||
my @tmp2 = @tmp[0..$n - 1];
|
||||
@tmp = @tmp[$n..scalar @tmp - 1];
|
||||
|
||||
system "@bindir@/nix-store --realise @tmp2 > /dev/null";
|
||||
system "@bindir@/nix-store --realise -B @tmp2 > /dev/null";
|
||||
if ($?) { die "`nix-store --realise' failed"; }
|
||||
|
||||
open NARPATHS, "@bindir@/nix-store --query --list @tmp2 |" or die "cannot run nix";
|
||||
|
||||
@@ -11,13 +11,12 @@ sub processURL {
|
||||
print "obtaining list of Nix archives at $url...\n";
|
||||
|
||||
system("@curl@ --fail --silent --show-error --location --max-redirs 20 " .
|
||||
"'$url' > '$manifest'") == 0
|
||||
"'$url' > '$manifest' 2> /dev/null") == 0
|
||||
or die "curl failed: $?";
|
||||
|
||||
open MANIFEST, "<$manifest";
|
||||
|
||||
my $inside = 0;
|
||||
my $type;
|
||||
|
||||
my $storePath;
|
||||
my $narurl;
|
||||
@@ -30,27 +29,23 @@ sub processURL {
|
||||
next if (/^$/);
|
||||
|
||||
if (!$inside) {
|
||||
if (/^\s*(\w*)\s*\{$/) {
|
||||
if (/^\{$/) {
|
||||
$inside = 1;
|
||||
$type = $1;
|
||||
$type = "narfile" if $type eq "";
|
||||
undef $storePath;
|
||||
undef $narurl;
|
||||
undef $hash;
|
||||
@preds = ();
|
||||
}
|
||||
else { die "bad line: $_"; }
|
||||
} else {
|
||||
if (/^\}$/) {
|
||||
$inside = 0;
|
||||
|
||||
if ($type eq "narfile") {
|
||||
$$storePaths2urls{$storePath} = $narurl;
|
||||
$$urls2hashes{$narurl} = $hash;
|
||||
|
||||
$$storePaths2urls{$storePath} = $narurl;
|
||||
$$urls2hashes{$narurl} = $hash;
|
||||
|
||||
foreach my $p (@preds) {
|
||||
$$successors{$p} = $storePath;
|
||||
}
|
||||
foreach my $p (@preds) {
|
||||
$$successors{$p} = $storePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,7 +61,7 @@ sub processURL {
|
||||
elsif (/^\s*SuccOf:\s*(\/\S+)\s*$/) {
|
||||
push @preds, $1;
|
||||
}
|
||||
|
||||
else { die "bad line: $_"; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,2 @@
|
||||
SUBDIRS = bin2c boost libutil libstore libmain nix-store nix-hash \
|
||||
libexpr nix-instantiate nix-env log2xml
|
||||
|
||||
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
|
||||
@@ -1,143 +0,0 @@
|
||||
#! /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;
|
||||
+3
-14
@@ -1,11 +1,10 @@
|
||||
noinst_LIBRARIES = libexpr.a
|
||||
|
||||
libexpr_a_SOURCES = nixexpr.cc nixexpr.hh parser.cc parser.hh \
|
||||
eval.cc eval.hh primops.cc \
|
||||
lexer-tab.c lexer-tab.h parser-tab.c parser-tab.h \
|
||||
nixexpr-ast.hh
|
||||
eval.cc eval.hh primops.cc primops.hh \
|
||||
lexer-tab.c lexer-tab.h parser-tab.c parser-tab.h
|
||||
|
||||
EXTRA_DIST = lexer.l parser.y nixexpr-ast.def nixexpr-ast.cc
|
||||
EXTRA_DIST = lexer.l parser.y
|
||||
|
||||
AM_CXXFLAGS = \
|
||||
-I.. ${bdb_include} ${aterm_include} -I../libutil -I../libstore
|
||||
@@ -24,14 +23,4 @@ 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.cc eval.cc parser.cc primops.cc: nixexpr-ast.hh
|
||||
|
||||
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 =
|
||||
+114
-123
@@ -1,40 +1,72 @@
|
||||
#include "eval.hh"
|
||||
#include "parser.hh"
|
||||
#include "nixexpr-ast.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);
|
||||
}
|
||||
|
||||
|
||||
EvalState::EvalState()
|
||||
: normalForms(32768, 50)
|
||||
{
|
||||
blackHole = makeBlackHole();
|
||||
blackHole = ATmake("BlackHole()");
|
||||
if (!blackHole) throw Error("cannot build black hole");
|
||||
|
||||
nrEvaluated = nrCached = 0;
|
||||
|
||||
initNixExprHelpers();
|
||||
addPrimOp0("true", primTrue);
|
||||
addPrimOp0("false", primFalse);
|
||||
addPrimOp0("null", primNull);
|
||||
addPrimOp0("curTime", primCurTime);
|
||||
|
||||
addPrimOps();
|
||||
addPrimOp1("import", primImport);
|
||||
addPrimOp1("derivation", primDerivation);
|
||||
addPrimOp1("baseNameOf", primBaseNameOf);
|
||||
addPrimOp1("toString", primToString);
|
||||
addPrimOp1("isNull", primIsNull);
|
||||
addPrimOp1("map", primMap);
|
||||
|
||||
primOpsAll.add(primOps0);
|
||||
primOpsAll.add(primOps1);
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addPrimOp(const string & name,
|
||||
unsigned int arity, PrimOp primOp)
|
||||
void EvalState::addPrimOp0(const string & name, PrimOp0 primOp)
|
||||
{
|
||||
primOps.set(name, makePrimOpDef(arity, ATmakeBlob(0, (void *) primOp)));
|
||||
addPrimOp(primOps0, name, (void *) primOp);
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addPrimOp1(const string & name, PrimOp1 primOp)
|
||||
{
|
||||
addPrimOp(primOps1, name, (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 = makeUndefined();
|
||||
Expr undefined = ATmake("Undefined");
|
||||
|
||||
/* Get the formal arguments. */
|
||||
for (ATermIterator i(formals); i; ++i) {
|
||||
Expr name, def;
|
||||
if (matchNoDefFormal(*i, name))
|
||||
if (atMatch(m, *i) >> "NoDefFormal" >> name)
|
||||
subs.set(name, undefined);
|
||||
else if (matchDefFormal(*i, name, def))
|
||||
else if (atMatch(m, *i) >> "DefFormal" >> name >> def)
|
||||
subs.set(name, def);
|
||||
else abort(); /* can't happen */
|
||||
}
|
||||
@@ -69,32 +101,38 @@ 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 (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
subs.set(name, makeSelect(e, name));
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2))
|
||||
abort(); /* can't happen */
|
||||
subs.set(name, ATmake("Select(<term>, <term>)", e, name));
|
||||
}
|
||||
for (ATermIterator i(nrbnds); i; ++i) {
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2))
|
||||
abort(); /* can't happen */
|
||||
subs.set(name, e2);
|
||||
}
|
||||
|
||||
/* Create the non-recursive set. */
|
||||
ATermMap as;
|
||||
for (ATermIterator i(rbnds); i; ++i) {
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
as.set(name, makeAttrRHS(substitute(subs, e2), pos));
|
||||
ATerm pos;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2 >> pos))
|
||||
abort(); /* can't happen */
|
||||
as.set(name, ATmake("(<term>, <term>)", substitute(subs, e2), pos));
|
||||
}
|
||||
|
||||
/* Copy the non-recursive bindings. !!! inefficient */
|
||||
for (ATermIterator i(nrbnds); i; ++i) {
|
||||
if (!matchBind(*i, name, e2, pos)) abort(); /* can't happen */
|
||||
as.set(name, makeAttrRHS(e2, pos));
|
||||
ATerm pos;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name >> e2 >> pos))
|
||||
abort(); /* can't happen */
|
||||
as.set(name, ATmake("(<term>, <term>)", e2, pos));
|
||||
}
|
||||
|
||||
return makeAttrs(as);
|
||||
@@ -116,73 +154,73 @@ static Expr updateAttrs(Expr e1, Expr e2)
|
||||
string evalString(EvalState & state, Expr e)
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
ATerm s;
|
||||
if (!matchStr(e, s)) throw Error("string expected");
|
||||
return aterm2String(s);
|
||||
ATMatcher m;
|
||||
string s;
|
||||
if (!(atMatch(m, e) >> "Str" >> s))
|
||||
throw Error("string expected");
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Path evalPath(EvalState & state, Expr e)
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
ATerm s;
|
||||
if (!matchPath(e, s)) throw Error("path expected");
|
||||
return aterm2String(s);
|
||||
ATMatcher m;
|
||||
string s;
|
||||
if (!(atMatch(m, e) >> "Path" >> s))
|
||||
throw Error("path expected");
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
bool evalBool(EvalState & state, Expr e)
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
if (e == eTrue) return true;
|
||||
else if (e == eFalse) return false;
|
||||
ATMatcher m;
|
||||
if (atMatch(m, e) >> "Bool" >> "True") return true;
|
||||
else if (atMatch(m, e) >> "Bool" >> "False") 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. */
|
||||
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)
|
||||
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"))
|
||||
return e;
|
||||
|
||||
|
||||
/* The `Closed' constructor is just a way to prevent substitutions
|
||||
into expressions not containing free variables. */
|
||||
if (matchClosed(e, e1))
|
||||
if (atMatch(m, e) >> "Closed" >> e1)
|
||||
return evalExpr(state, e1);
|
||||
|
||||
/* 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());
|
||||
/* 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);
|
||||
else
|
||||
return makePrimOp(arity, fun, ATempty);
|
||||
return e;
|
||||
}
|
||||
|
||||
/* Function application. */
|
||||
if (matchCall(e, e1, e2)) {
|
||||
if (atMatch(m, e) >> "Call" >> e1 >> e2) {
|
||||
|
||||
ATermList formals;
|
||||
ATerm pos;
|
||||
@@ -191,41 +229,28 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||
e1 = evalExpr(state, e1);
|
||||
|
||||
/* Is it a primop or a function? */
|
||||
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);
|
||||
if (atMatch(m, e1) >> "Var" >> name) {
|
||||
PrimOp1 primOp = (PrimOp1) lookupPrimOp(state.primOps1, name);
|
||||
if (primOp) return primOp(state, e2); else abort();
|
||||
}
|
||||
|
||||
else if (matchFunction(e1, formals, e4, pos)) {
|
||||
else if (atMatch(m, e1) >> "Function" >> formals >> e4 >> pos) {
|
||||
e2 = evalExpr(state, e2);
|
||||
try {
|
||||
return evalExpr(state, substArgs(e4, formals, e2));
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating the function at %1%:\n%2%")
|
||||
throw Error(format("while evaluating function at %1%:\n%2%")
|
||||
% showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
else if (matchFunction1(e1, name, e4, pos)) {
|
||||
else if (atMatch(m, e1) >> "Function1" >> name >> e4 >> pos) {
|
||||
try {
|
||||
ATermMap subs;
|
||||
subs.set(name, e2);
|
||||
return evalExpr(state, substitute(subs, e4));
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating the function at %1%:\n%2%")
|
||||
throw Error(format("while evaluating function at %1%:\n%2%")
|
||||
% showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
@@ -234,26 +259,26 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||
}
|
||||
|
||||
/* Attribute selection. */
|
||||
if (matchSelect(e, e1, name)) {
|
||||
string s1;
|
||||
if (atMatch(m, e) >> "Select" >> e1 >> s1) {
|
||||
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 the attribute `%1%' at %2%:\n%3%")
|
||||
throw Error(format("while evaluating attribute `%1%' at %2%:\n%3%")
|
||||
% s1 % showPos(pos) % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
/* Mutually recursive sets. */
|
||||
ATermList rbnds, nrbnds;
|
||||
if (matchRec(e, rbnds, nrbnds))
|
||||
if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds)
|
||||
return expandRec(e, rbnds, nrbnds);
|
||||
|
||||
/* Conditionals. */
|
||||
if (matchIf(e, e1, e2, e3)) {
|
||||
if (atMatch(m, e) >> "If" >> e1 >> e2 >> e3) {
|
||||
if (evalBool(state, e1))
|
||||
return evalExpr(state, e2);
|
||||
else
|
||||
@@ -261,81 +286,47 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||
}
|
||||
|
||||
/* Assertions. */
|
||||
if (matchAssert(e, e1, e2, pos)) {
|
||||
if (atMatch(m, e) >> "Assert" >> 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 (matchOpEq(e, e1, e2))
|
||||
if (atMatch(m, e) >> "OpEq" >> e1 >> e2)
|
||||
return makeBool(evalExpr(state, e1) == evalExpr(state, e2));
|
||||
|
||||
/* Generic inequality. */
|
||||
if (matchOpNEq(e, e1, e2))
|
||||
if (atMatch(m, e) >> "OpNEq" >> e1 >> e2)
|
||||
return makeBool(evalExpr(state, e1) != evalExpr(state, e2));
|
||||
|
||||
/* Negation. */
|
||||
if (matchOpNot(e, e1))
|
||||
if (atMatch(m, e) >> "OpNot" >> e1)
|
||||
return makeBool(!evalBool(state, e1));
|
||||
|
||||
/* Implication. */
|
||||
if (matchOpImpl(e, e1, e2))
|
||||
if (atMatch(m, e) >> "OpImpl" >> e1 >> e2)
|
||||
return makeBool(!evalBool(state, e1) || evalBool(state, e2));
|
||||
|
||||
/* Conjunction (logical AND). */
|
||||
if (matchOpAnd(e, e1, e2))
|
||||
if (atMatch(m, e) >> "OpAnd" >> e1 >> e2)
|
||||
return makeBool(evalBool(state, e1) && evalBool(state, e2));
|
||||
|
||||
/* Disjunction (logical OR). */
|
||||
if (matchOpOr(e, e1, e2))
|
||||
if (atMatch(m, e) >> "OpOr" >> e1 >> e2)
|
||||
return makeBool(evalBool(state, e1) || evalBool(state, e2));
|
||||
|
||||
/* Attribute set update (//). */
|
||||
if (matchOpUpdate(e, e1, e2))
|
||||
if (atMatch(m, e) >> "OpUpdate" >> e1 >> e2)
|
||||
return updateAttrs(evalExpr(state, e1), evalExpr(state, e2));
|
||||
|
||||
/* Attribute existence test (?). */
|
||||
if (matchOpHasAttr(e, e1, name)) {
|
||||
if (atMatch(m, e) >> "OpHasAttr" >> 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);
|
||||
}
|
||||
@@ -375,7 +366,7 @@ Expr evalFile(EvalState & state, const Path & path)
|
||||
try {
|
||||
return evalExpr(state, e);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("while evaluating the file `%1%':\n%2%")
|
||||
throw Error(format("while evaluating file `%1%':\n%2%")
|
||||
% path % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
+9
-10
@@ -8,21 +8,21 @@
|
||||
#include "nixexpr.hh"
|
||||
|
||||
|
||||
typedef map<Path, PathSet> DrvRoots;
|
||||
typedef map<Path, PathSet> DrvPaths;
|
||||
typedef map<Path, Hash> DrvHashes;
|
||||
|
||||
struct EvalState;
|
||||
|
||||
/* 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);
|
||||
typedef Expr (* PrimOp0) (EvalState &);
|
||||
typedef Expr (* PrimOp1) (EvalState &, Expr arg);
|
||||
|
||||
|
||||
struct EvalState
|
||||
{
|
||||
ATermMap normalForms;
|
||||
ATermMap primOps;
|
||||
DrvRoots drvRoots;
|
||||
ATermMap primOps0; /* nullary primops */
|
||||
ATermMap primOps1; /* unary primops */
|
||||
ATermMap primOpsAll;
|
||||
DrvPaths drvPaths;
|
||||
DrvHashes drvHashes; /* normalised derivation hashes */
|
||||
Expr blackHole;
|
||||
|
||||
@@ -31,9 +31,8 @@ struct EvalState
|
||||
|
||||
EvalState();
|
||||
|
||||
void addPrimOps();
|
||||
void addPrimOp(const string & name,
|
||||
unsigned int arity, PrimOp primOp);
|
||||
void addPrimOp0(const string & name, PrimOp0 primOp);
|
||||
void addPrimOp1(const string & name, PrimOp1 primOp);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -48,7 +48,6 @@ if { return IF; }
|
||||
then { return THEN; }
|
||||
else { return ELSE; }
|
||||
assert { return ASSERT; }
|
||||
with { return WITH; }
|
||||
let { return LET; }
|
||||
rec { return REC; }
|
||||
inherit { return INHERIT; }
|
||||
@@ -76,7 +75,7 @@ inherit { return INHERIT; }
|
||||
|
||||
[ \t\n]+ /* eat up whitespace */
|
||||
\#[^\n]* /* single-line comments */
|
||||
\/\*([^*]|\*[^\/])*\*\/ /* long comments */
|
||||
\/\*(.|\n)*\*\/ /* long comments */
|
||||
|
||||
. return yytext[0];
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
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())
|
||||
+74
-58
@@ -2,10 +2,6 @@
|
||||
#include "storeexpr.hh"
|
||||
|
||||
|
||||
#include "nixexpr-ast.hh"
|
||||
#include "nixexpr-ast.cc"
|
||||
|
||||
|
||||
ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct)
|
||||
{
|
||||
this->maxLoadPct = maxLoadPct;
|
||||
@@ -42,7 +38,7 @@ void ATermMap::set(ATerm key, ATerm value)
|
||||
|
||||
void ATermMap::set(const string & key, ATerm value)
|
||||
{
|
||||
set(toATerm(key), value);
|
||||
set(string2ATerm(key), value);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +50,7 @@ ATerm ATermMap::get(ATerm key) const
|
||||
|
||||
ATerm ATermMap::get(const string & key) const
|
||||
{
|
||||
return get(toATerm(key));
|
||||
return get(string2ATerm(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +62,7 @@ void ATermMap::remove(ATerm key)
|
||||
|
||||
void ATermMap::remove(const string & key)
|
||||
{
|
||||
remove(toATerm(key));
|
||||
remove(string2ATerm(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,14 +94,28 @@ 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)
|
||||
{
|
||||
ATerm path;
|
||||
ATMatcher m;
|
||||
Path path;
|
||||
int line, column;
|
||||
if (matchNoPos(pos)) return "undefined position";
|
||||
if (!matchPos(pos, path, line, column))
|
||||
if (atMatch(m, pos) >> "NoPos")
|
||||
return "undefined position";
|
||||
if (!(atMatch(m, pos) >> "Pos" >> path >> line >> column))
|
||||
throw badTerm("position expected", pos);
|
||||
return (format("`%1%', line %2%") % aterm2String(path) % line).str();
|
||||
return (format("`%1%', line %2%") % path % line).str();
|
||||
}
|
||||
|
||||
|
||||
@@ -140,16 +150,18 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
|
||||
|
||||
void queryAllAttrs(Expr e, ATermMap & attrs, bool withPos)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList bnds;
|
||||
if (!matchAttrs(e, bnds))
|
||||
if (!(atMatch(m, e) >> "Attrs" >> bnds))
|
||||
throw Error("attribute set expected");
|
||||
|
||||
for (ATermIterator i(bnds); i; ++i) {
|
||||
ATerm name;
|
||||
string s;
|
||||
Expr e;
|
||||
ATerm pos;
|
||||
if (!matchBind(*i, name, e, pos)) abort(); /* can't happen */
|
||||
attrs.set(name, withPos ? makeAttrRHS(e, pos) : e);
|
||||
if (!(atMatch(m, *i) >> "Bind" >> s >> e >> pos))
|
||||
abort(); /* can't happen */
|
||||
attrs.set(s, withPos ? ATmake("(<term>, <term>)", e, pos) : e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,16 +175,18 @@ Expr queryAttr(Expr e, const string & name)
|
||||
|
||||
Expr queryAttr(Expr e, const string & name, ATerm & pos)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList bnds;
|
||||
if (!matchAttrs(e, bnds))
|
||||
if (!(atMatch(m, e) >> "Attrs" >> bnds))
|
||||
throw Error("attribute set expected");
|
||||
|
||||
for (ATermIterator i(bnds); i; ++i) {
|
||||
ATerm name2, pos2;
|
||||
string s;
|
||||
Expr e;
|
||||
if (!matchBind(*i, name2, e, pos2))
|
||||
ATerm pos2;
|
||||
if (!(atMatch(m, *i) >> "Bind" >> s >> e >> pos2))
|
||||
abort(); /* can't happen */
|
||||
if (aterm2String(name2) == name) {
|
||||
if (s == name) {
|
||||
pos = pos2;
|
||||
return e;
|
||||
}
|
||||
@@ -184,15 +198,17 @@ 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 (!matchAttrRHS(attrs.get(*i), e, pos))
|
||||
if (!(atMatch(m, attrs.get(*i)) >> "" >> e >> pos))
|
||||
abort(); /* can't happen */
|
||||
bnds = ATinsert(bnds, makeBind(*i, e, pos));
|
||||
bnds = ATinsert(bnds,
|
||||
ATmake("Bind(<term>, <term>, <term>)", *i, e, pos));
|
||||
}
|
||||
return makeAttrs(ATreverse(bnds));
|
||||
return ATmake("Attrs(<term>)", ATreverse(bnds));
|
||||
}
|
||||
|
||||
|
||||
@@ -200,53 +216,57 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||
{
|
||||
checkInterrupt();
|
||||
|
||||
ATerm name, pos, e2;
|
||||
ATMatcher m;
|
||||
ATerm name, pos;
|
||||
|
||||
/* As an optimisation, don't substitute in subterms known to be
|
||||
closed. */
|
||||
if (matchClosed(e, e2)) return e;
|
||||
if (atMatch(m, e) >> "Closed") return e;
|
||||
|
||||
if (matchVar(e, name)) {
|
||||
if (atMatch(m, e) >> "Var" >> name) {
|
||||
Expr sub = subs.get(name);
|
||||
return sub ? makeClosed(sub) : e;
|
||||
return sub ? ATmake("Closed(<term>)", sub) : e;
|
||||
}
|
||||
|
||||
/* In case of a function, filter out all variables bound by this
|
||||
function. */
|
||||
ATermList formals;
|
||||
ATerm body, def;
|
||||
if (matchFunction(e, formals, body, pos)) {
|
||||
ATerm body;
|
||||
if (atMatch(m, e) >> "Function" >> formals >> body >> pos) {
|
||||
ATermMap subs2(subs);
|
||||
for (ATermIterator i(formals); i; ++i) {
|
||||
if (!matchNoDefFormal(*i, name) &&
|
||||
!matchDefFormal(*i, name, def))
|
||||
if (!(atMatch(m, *i) >> "NoDefFormal" >> name) &&
|
||||
!(atMatch(m, *i) >> "DefFormal" >> name))
|
||||
abort();
|
||||
subs2.remove(name);
|
||||
}
|
||||
return makeFunction(
|
||||
(ATermList) substitute(subs, (ATerm) formals),
|
||||
return ATmake("Function(<term>, <term>, <term>)",
|
||||
substitute(subs, (ATerm) formals),
|
||||
substitute(subs2, body), pos);
|
||||
}
|
||||
|
||||
if (matchFunction1(e, name, body, pos)) {
|
||||
if (atMatch(m, e) >> "Function1" >> name >> body >> pos) {
|
||||
ATermMap subs2(subs);
|
||||
subs2.remove(name);
|
||||
return makeFunction1(name, substitute(subs2, body), pos);
|
||||
return ATmake("Function1(<term>, <term>, <term>)", name,
|
||||
substitute(subs2, body), pos);
|
||||
}
|
||||
|
||||
/* Idem for a mutually recursive attribute set. */
|
||||
ATermList rbnds, nrbnds;
|
||||
if (matchRec(e, rbnds, nrbnds)) {
|
||||
if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds) {
|
||||
ATermMap subs2(subs);
|
||||
for (ATermIterator i(rbnds); i; ++i)
|
||||
if (matchBind(*i, name, e2, pos)) subs2.remove(name);
|
||||
if (atMatch(m, *i) >> "Bind" >> name)
|
||||
subs2.remove(name);
|
||||
else abort(); /* can't happen */
|
||||
for (ATermIterator i(nrbnds); i; ++i)
|
||||
if (matchBind(*i, name, e2, pos)) subs2.remove(name);
|
||||
if (atMatch(m, *i) >> "Bind" >> name)
|
||||
subs2.remove(name);
|
||||
else abort(); /* can't happen */
|
||||
return makeRec(
|
||||
(ATermList) substitute(subs2, (ATerm) rbnds),
|
||||
(ATermList) substitute(subs, (ATerm) nrbnds));
|
||||
return ATmake("Rec(<term>, <term>)",
|
||||
substitute(subs2, (ATerm) rbnds),
|
||||
substitute(subs, (ATerm) nrbnds));
|
||||
}
|
||||
|
||||
if (ATgetType(e) == AT_APPL) {
|
||||
@@ -273,23 +293,24 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||
|
||||
void checkVarDefs(const ATermMap & defs, Expr e)
|
||||
{
|
||||
ATerm name, pos, value;
|
||||
ATMatcher m;
|
||||
ATerm name;
|
||||
ATermList formals;
|
||||
ATerm with, body;
|
||||
ATerm body;
|
||||
ATermList rbnds, nrbnds;
|
||||
|
||||
if (matchVar(e, name)) {
|
||||
if (atMatch(m, e) >> "Var" >> name) {
|
||||
if (!defs.get(name))
|
||||
throw Error(format("undefined variable `%1%'")
|
||||
% aterm2String(name));
|
||||
}
|
||||
|
||||
else if (matchFunction(e, formals, body, pos)) {
|
||||
else if (atMatch(m, e) >> "Function" >> formals >> body) {
|
||||
ATermMap defs2(defs);
|
||||
for (ATermIterator i(formals); i; ++i) {
|
||||
Expr deflt;
|
||||
if (!matchNoDefFormal(*i, name))
|
||||
if (matchDefFormal(*i, name, deflt))
|
||||
if (!(atMatch(m, *i) >> "NoDefFormal" >> name))
|
||||
if (atMatch(m, *i) >> "DefFormal" >> name >> deflt)
|
||||
checkVarDefs(defs, deflt);
|
||||
else
|
||||
abort();
|
||||
@@ -298,32 +319,27 @@ void checkVarDefs(const ATermMap & defs, Expr e)
|
||||
checkVarDefs(defs2, body);
|
||||
}
|
||||
|
||||
else if (matchFunction1(e, name, body, pos)) {
|
||||
else if (atMatch(m, e) >> "Function1" >> name >> body) {
|
||||
ATermMap defs2(defs);
|
||||
defs2.set(name, (ATerm) ATempty);
|
||||
checkVarDefs(defs2, body);
|
||||
}
|
||||
|
||||
else if (matchRec(e, rbnds, nrbnds)) {
|
||||
else if (atMatch(m, e) >> "Rec" >> rbnds >> nrbnds) {
|
||||
checkVarDefs(defs, (ATerm) nrbnds);
|
||||
ATermMap defs2(defs);
|
||||
for (ATermIterator i(rbnds); i; ++i) {
|
||||
if (!matchBind(*i, name, value, pos)) abort(); /* can't happen */
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name))
|
||||
abort(); /* can't happen */
|
||||
defs2.set(name, (ATerm) ATempty);
|
||||
}
|
||||
for (ATermIterator i(nrbnds); i; ++i) {
|
||||
if (!matchBind(*i, name, value, pos)) abort(); /* can't happen */
|
||||
if (!(atMatch(m, *i) >> "Bind" >> name))
|
||||
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));
|
||||
@@ -339,5 +355,5 @@ void checkVarDefs(const ATermMap & defs, Expr e)
|
||||
|
||||
Expr makeBool(bool b)
|
||||
{
|
||||
return b ? eTrue : eFalse;
|
||||
return b ? ATmake("Bool(True)") : ATmake("Bool(False)");
|
||||
}
|
||||
+4
-13
@@ -13,8 +13,6 @@
|
||||
normals forms efficiently. */
|
||||
typedef ATerm Expr;
|
||||
|
||||
typedef ATerm Pos;
|
||||
|
||||
|
||||
/* Mappings from ATerms to ATerms. This is just a wrapper around
|
||||
ATerm tables. */
|
||||
@@ -49,11 +47,10 @@ private:
|
||||
};
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Convert a string to an ATerm (i.e., a quoted nullary function
|
||||
applicaton). */
|
||||
ATerm string2ATerm(const string & s);
|
||||
string aterm2String(ATerm t);
|
||||
|
||||
/* Show a position. */
|
||||
string showPos(ATerm pos);
|
||||
@@ -89,11 +86,5 @@ 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 */
|
||||
+12
-11
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "aterm.hh"
|
||||
#include "parser.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
|
||||
struct ParseData
|
||||
@@ -35,7 +34,7 @@ void setParseResult(ParseData * data, ATerm t)
|
||||
|
||||
ATerm absParsedPath(ParseData * data, ATerm t)
|
||||
{
|
||||
return toATerm(absPath(aterm2String(t), data->basePath));
|
||||
return string2ATerm(absPath(aterm2String(t), data->basePath).c_str());
|
||||
}
|
||||
|
||||
void parseError(ParseData * data, char * error, int line, int column)
|
||||
@@ -46,24 +45,28 @@ 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 (matchInherit(*i, src, names, pos)) {
|
||||
bool fromScope = matchScope(src);
|
||||
if (atMatch(m, *i) >> "Inherit" >> src >> names >> pos) {
|
||||
bool fromScope = atMatch(m, src) >> "Scope";
|
||||
for (ATermIterator j(names); j; ++j) {
|
||||
Expr rhs = fromScope ? makeVar(*j) : makeSelect(src, *j);
|
||||
*is = ATinsert(*is, makeBind(*j, rhs, pos));
|
||||
Expr rhs = fromScope
|
||||
? ATmake("Var(<term>)", *j)
|
||||
: ATmake("Select(<term>, <term>)", src, *j);
|
||||
*is = ATinsert(*is, ATmake("Bind(<term>, <term>, <term>)",
|
||||
*j, rhs, pos));
|
||||
}
|
||||
} else bs = ATinsert(bs, *i);
|
||||
}
|
||||
if (recursive)
|
||||
return makeRec(bs, cs);
|
||||
return ATmake("Rec(<term>, <term>)", bs, cs);
|
||||
else
|
||||
return makeAttrs(bs);
|
||||
return ATmake("Attrs(<term>)", bs);
|
||||
}
|
||||
|
||||
const char * getPath(ParseData * data)
|
||||
@@ -92,7 +95,7 @@ static Expr parse(EvalState & state,
|
||||
if (res) throw Error(data.error);
|
||||
|
||||
try {
|
||||
checkVarDefs(state.primOps, data.result);
|
||||
checkVarDefs(state.primOpsAll, data.result);
|
||||
} catch (Error & e) {
|
||||
throw Error(format("%1%, in `%2%'") % e.msg() % path);
|
||||
}
|
||||
@@ -103,8 +106,6 @@ static Expr parse(EvalState & state,
|
||||
|
||||
Expr parseExprFromFile(EvalState & state, Path path)
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
|
||||
assert(path[0] == '/');
|
||||
|
||||
#if 0
|
||||
|
||||
+38
-48
@@ -15,11 +15,6 @@
|
||||
#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);
|
||||
@@ -31,18 +26,13 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
|
||||
parseError(data, s, loc->first_line, loc->first_column);
|
||||
}
|
||||
|
||||
ATerm toATerm(const char * s)
|
||||
ATerm makePos(YYLTYPE * loc, void * data)
|
||||
{
|
||||
return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
|
||||
return ATmake("Pos(<str>, <int>, <int>)",
|
||||
getPath(data), loc->first_line, loc->first_column);
|
||||
}
|
||||
|
||||
static Pos makeCurPos(YYLTYPE * loc, void * data)
|
||||
{
|
||||
return makePos(toATerm(getPath(data)),
|
||||
loc->first_line, loc->first_column);
|
||||
}
|
||||
|
||||
#define CUR_POS makeCurPos(yylocp, data)
|
||||
#define CUR_POS makePos(yylocp, data)
|
||||
|
||||
%}
|
||||
|
||||
@@ -51,11 +41,11 @@ static Pos makeCurPos(YYLTYPE * loc, void * data)
|
||||
ATermList ts;
|
||||
}
|
||||
|
||||
%type <t> start expr expr_function expr_if expr_op
|
||||
%type <t> start expr expr_function expr_assert 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 WITH LET REC INHERIT EQ NEQ AND OR IMPL
|
||||
%token IF THEN ELSE ASSERT LET REC INHERIT EQ NEQ AND OR IMPL
|
||||
|
||||
%nonassoc IMPL
|
||||
%left OR
|
||||
@@ -63,7 +53,6 @@ static Pos makeCurPos(YYLTYPE * loc, void * data)
|
||||
%nonassoc EQ NEQ
|
||||
%right UPDATE
|
||||
%left NEG
|
||||
%left '+'
|
||||
%nonassoc '?'
|
||||
%nonassoc '~'
|
||||
|
||||
@@ -75,64 +64,65 @@ expr: expr_function;
|
||||
|
||||
expr_function
|
||||
: '{' formals '}' ':' expr_function
|
||||
{ $$ = makeFunction($2, $5, CUR_POS); }
|
||||
{ $$ = ATmake("Function(<term>, <term>, <term>)", $2, $5, CUR_POS); }
|
||||
| ID ':' expr_function
|
||||
{ $$ = makeFunction1($1, $3, CUR_POS); }
|
||||
| ASSERT expr ';' expr_function
|
||||
{ $$ = makeAssert($2, $4, CUR_POS); }
|
||||
| WITH expr ';' expr_function
|
||||
{ $$ = makeWith($2, $4, CUR_POS); }
|
||||
{ $$ = 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); }
|
||||
| expr_if
|
||||
;
|
||||
|
||||
expr_if
|
||||
: IF expr THEN expr ELSE expr
|
||||
{ $$ = makeIf($2, $4, $6); }
|
||||
{ $$ = ATmake("If(<term>, <term>, <term>)", $2, $4, $6); }
|
||||
| expr_op
|
||||
;
|
||||
|
||||
expr_op
|
||||
: '!' 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_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_app
|
||||
;
|
||||
|
||||
expr_app
|
||||
: expr_app expr_select
|
||||
{ $$ = makeCall($1, $2); }
|
||||
{ $$ = ATmake("Call(<term>, <term>)", $1, $2); }
|
||||
| expr_select { $$ = $1; }
|
||||
;
|
||||
|
||||
expr_select
|
||||
: expr_select '.' ID
|
||||
{ $$ = makeSelect($1, $3); }
|
||||
{ $$ = ATmake("Select(<term>, <term>)", $1, $3); }
|
||||
| expr_simple { $$ = $1; }
|
||||
;
|
||||
|
||||
expr_simple
|
||||
: ID { $$ = makeVar($1); }
|
||||
| INT { $$ = makeInt(ATgetInt((ATermInt) $1)); }
|
||||
| STR { $$ = makeStr($1); }
|
||||
| PATH { $$ = makePath(absParsedPath(data, $1)); }
|
||||
| URI { $$ = makeUri($1); }
|
||||
: 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); }
|
||||
| '(' expr ')' { $$ = $2; }
|
||||
/* Let expressions `let {..., body = ...}' are just desugared
|
||||
into `(rec {..., body = ...}).body'. */
|
||||
| LET '{' binds '}'
|
||||
{ $$ = makeSelect(fixAttrs(1, $3), toATerm("body")); }
|
||||
{ $$ = ATmake("Select(<term>, \"body\")", fixAttrs(1, $3)); }
|
||||
| REC '{' binds '}'
|
||||
{ $$ = fixAttrs(1, $3); }
|
||||
| '{' binds '}'
|
||||
{ $$ = fixAttrs(0, $2); }
|
||||
| '[' expr_list ']' { $$ = makeList($2); }
|
||||
| '[' expr_list ']' { $$ = ATmake("List(<term>)", $2); }
|
||||
;
|
||||
|
||||
binds
|
||||
@@ -142,14 +132,14 @@ binds
|
||||
|
||||
bind
|
||||
: ID '=' expr ';'
|
||||
{ $$ = makeBind($1, $3, CUR_POS); }
|
||||
{ $$ = ATmake("Bind(<term>, <term>, <term>)", $1, $3, CUR_POS); }
|
||||
| INHERIT inheritsrc ids ';'
|
||||
{ $$ = makeInherit($2, $3, CUR_POS); }
|
||||
{ $$ = ATmake("Inherit(<term>, <term>, <term>)", $2, $3, CUR_POS); }
|
||||
;
|
||||
|
||||
inheritsrc
|
||||
: '(' expr ')' { $$ = $2; }
|
||||
| { $$ = makeScope(); }
|
||||
| { $$ = ATmake("Scope"); }
|
||||
;
|
||||
|
||||
ids: ids ID { $$ = ATinsert($1, $2); } | { $$ = ATempty; };
|
||||
@@ -168,8 +158,8 @@ formals
|
||||
;
|
||||
|
||||
formal
|
||||
: ID { $$ = makeNoDefFormal($1); }
|
||||
| ID '?' expr { $$ = makeDefFormal($1, $3); }
|
||||
: ID { $$ = ATmake("NoDefFormal(<term>)", $1); }
|
||||
| ID '?' expr { $$ = ATmake("DefFormal(<term>, <term>)", $1, $3); }
|
||||
;
|
||||
|
||||
%%
|
||||
+121
-117
@@ -1,29 +1,54 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "primops.hh"
|
||||
#include "normalise.hh"
|
||||
#include "eval.hh"
|
||||
#include "globals.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
|
||||
/* Load and evaluate an expression from path specified by the
|
||||
argument. */
|
||||
static Expr primImport(EvalState & state, const ATermVector & args)
|
||||
Expr primImport(EvalState & state, Expr arg)
|
||||
{
|
||||
ATerm path;
|
||||
Expr fn = evalExpr(state, args[0]);
|
||||
if (!matchPath(fn, path))
|
||||
throw Error("path expected");
|
||||
return evalFile(state, aterm2String(path));
|
||||
ATMatcher m;
|
||||
ATermList es;
|
||||
Path path;
|
||||
|
||||
arg = evalExpr(state, arg);
|
||||
|
||||
if (atMatch(m, arg) >> "Path" >> path)
|
||||
;
|
||||
|
||||
else if (atMatch(m, arg) >> "Attrs" >> es) {
|
||||
Expr a = queryAttr(arg, "type");
|
||||
|
||||
/* If it is a derivation, we have to realise it and load the
|
||||
Nix expression created at the derivation's output path. */
|
||||
if (a && evalString(state, a) == "derivation") {
|
||||
a = queryAttr(arg, "drvPath");
|
||||
if (!a) throw Error("bad derivation in import");
|
||||
Path drvPath = evalPath(state, a);
|
||||
|
||||
realiseStoreExpr(drvPath);
|
||||
|
||||
a = queryAttr(arg, "outPath");
|
||||
if (!a) throw Error("bad derivation in import");
|
||||
path = evalPath(state, a);
|
||||
}
|
||||
}
|
||||
|
||||
if (path == "")
|
||||
throw Error("path or derivation expected in import");
|
||||
|
||||
return evalFile(state, path);
|
||||
}
|
||||
|
||||
|
||||
static PathSet storeExprRootsCached(EvalState & state, const Path & nePath)
|
||||
{
|
||||
DrvRoots::iterator i = state.drvRoots.find(nePath);
|
||||
if (i != state.drvRoots.end())
|
||||
DrvPaths::iterator i = state.drvPaths.find(nePath);
|
||||
if (i != state.drvPaths.end())
|
||||
return i->second;
|
||||
else {
|
||||
PathSet paths = storeExprRoots(nePath);
|
||||
state.drvRoots[nePath] = paths;
|
||||
state.drvPaths[nePath] = paths;
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
@@ -62,8 +87,6 @@ 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;
|
||||
@@ -86,23 +109,24 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne,
|
||||
{
|
||||
e = evalExpr(state, e);
|
||||
|
||||
ATerm s;
|
||||
ATMatcher m;
|
||||
string s;
|
||||
ATermList es;
|
||||
int n;
|
||||
Expr e1, e2;
|
||||
|
||||
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("");
|
||||
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("");
|
||||
|
||||
else if (matchInt(e, n)) {
|
||||
else if (atMatch(m, e) >> "Int" >> n) {
|
||||
ostringstream st;
|
||||
st << n;
|
||||
ss.push_back(st.str());
|
||||
}
|
||||
|
||||
else if (matchAttrs(e, es)) {
|
||||
else if (atMatch(m, e) >> "Attrs") {
|
||||
Expr a = queryAttr(e, "type");
|
||||
if (a && evalString(state, a) == "derivation") {
|
||||
a = queryAttr(e, "drvPath");
|
||||
@@ -113,42 +137,37 @@ static void processBinding(EvalState & state, Expr e, StoreExpr & ne,
|
||||
if (!a) throw Error("derivation hash missing");
|
||||
Hash drvHash = parseHash(evalString(state, a));
|
||||
|
||||
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 (matchPath(e, s)) {
|
||||
Path drvPath = copyAtom(state, aterm2String(s));
|
||||
else if (atMatch(m, e) >> "Path" >> s) {
|
||||
Path drvPath = copyAtom(state, s);
|
||||
ss.push_back(addInput(state, drvPath, ne));
|
||||
}
|
||||
|
||||
else if (matchList(e, es)) {
|
||||
else if (atMatch(m, e) >> "List" >> es) {
|
||||
for (ATermIterator i(es); i; ++i) {
|
||||
startNest(nest, lvlVomit, format("processing list element"));
|
||||
processBinding(state, evalExpr(state, *i), ne, ss);
|
||||
}
|
||||
}
|
||||
|
||||
else if (matchNull(e)) ss.push_back("");
|
||||
else if (atMatch(m, e) >> "Null") ss.push_back("");
|
||||
|
||||
else if (matchSubPath(e, e1, e2)) {
|
||||
else if (atMatch(m, e) >> "SubPath" >> 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 (!(matchStr(e2, s) || matchPath(e2, s)))
|
||||
if (!(atMatch(m, e2) >> "Str" >> s ||
|
||||
(atMatch(m, e2) >> "Path" >> s)))
|
||||
throw Error("right-hand side of `~' operator must be a path or string");
|
||||
ss.push_back(canonPath(ss2.front() + "/" + aterm2String(s)));
|
||||
ss.push_back(canonPath(ss2.front() + "/" + s));
|
||||
}
|
||||
|
||||
else throw Error("invalid derivation attribute");
|
||||
@@ -167,19 +186,11 @@ static string concatStrings(const Strings & ss)
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
Expr primDerivation(EvalState & state, Expr args)
|
||||
{
|
||||
startNest(nest, lvlVomit, "evaluating derivation");
|
||||
|
||||
ATermMap attrs;
|
||||
Expr args = _args[0];
|
||||
args = evalExpr(state, args);
|
||||
queryAllAttrs(args, attrs, true);
|
||||
|
||||
@@ -188,6 +199,7 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
|
||||
ne.type = StoreExpr::neDerivation;
|
||||
|
||||
string drvName;
|
||||
Path outPath;
|
||||
Hash outHash;
|
||||
bool outHashGiven = false;
|
||||
|
||||
@@ -196,14 +208,15 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
|
||||
ATerm value;
|
||||
Expr pos;
|
||||
ATerm rhs = attrs.get(key);
|
||||
if (!matchAttrRHS(rhs, value, pos)) abort();
|
||||
ATMatcher m;
|
||||
if (!(atMatch(m, 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 the derivation attribute `%1%' at %2%:\n%3%")
|
||||
throw Error(format("while processing derivation attribute `%1%' at %2%:\n%3%")
|
||||
% key % showPos(pos) % e.msg());
|
||||
}
|
||||
|
||||
@@ -222,6 +235,7 @@ static Expr primDerivation(EvalState & state, const ATermVector & _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;
|
||||
@@ -236,27 +250,14 @@ static Expr primDerivation(EvalState & state, const ATermVector & _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 by hashing the Nix expression with no
|
||||
outputs to produce a unique but deterministic path name for
|
||||
this derivation. */
|
||||
/* Determine the output path. */
|
||||
if (!outHashGiven) outHash = hashDerivation(state, ne);
|
||||
Path outPath = canonPath(nixStore + "/" +
|
||||
((string) outHash).c_str() + "-" + drvName);
|
||||
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);
|
||||
ne.derivation.env["out"] = outPath;
|
||||
ne.derivation.outputs.insert(outPath);
|
||||
|
||||
@@ -269,91 +270,94 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
|
||||
printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'")
|
||||
% drvName % drvPath);
|
||||
|
||||
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()));
|
||||
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)"));
|
||||
|
||||
return makeAttrs(attrs);
|
||||
}
|
||||
|
||||
|
||||
/* Return the base name of the given string, i.e., everything
|
||||
following the last slash. */
|
||||
static Expr primBaseNameOf(EvalState & state, const ATermVector & args)
|
||||
Expr primBaseNameOf(EvalState & state, Expr arg)
|
||||
{
|
||||
return makeStr(toATerm(baseNameOf(evalString(state, args[0]))));
|
||||
string s = evalString(state, arg);
|
||||
return ATmake("Str(<str>)", baseNameOf(s).c_str());
|
||||
}
|
||||
|
||||
|
||||
/* Convert the argument (which can be a path or a uri) to a string. */
|
||||
static Expr primToString(EvalState & state, const ATermVector & args)
|
||||
Expr primToString(EvalState & state, Expr arg)
|
||||
{
|
||||
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");
|
||||
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());
|
||||
throw Error("cannot coerce value to string");
|
||||
}
|
||||
|
||||
|
||||
/* Boolean constructors. */
|
||||
static Expr primTrue(EvalState & state, const ATermVector & args)
|
||||
Expr primTrue(EvalState & state)
|
||||
{
|
||||
return eTrue;
|
||||
return ATmake("Bool(True)");
|
||||
}
|
||||
|
||||
|
||||
static Expr primFalse(EvalState & state, const ATermVector & args)
|
||||
Expr primFalse(EvalState & state)
|
||||
{
|
||||
return eFalse;
|
||||
return ATmake("Bool(False)");
|
||||
}
|
||||
|
||||
|
||||
/* Return the null value. */
|
||||
Expr primNull(EvalState & state, const ATermVector & args)
|
||||
Expr primNull(EvalState & state)
|
||||
{
|
||||
return makeNull();
|
||||
return ATmake("Null");
|
||||
}
|
||||
|
||||
|
||||
/* Determine whether the argument is the null value. */
|
||||
Expr primIsNull(EvalState & state, const ATermVector & args)
|
||||
Expr primIsNull(EvalState & state, Expr arg)
|
||||
{
|
||||
return makeBool(matchNull(evalExpr(state, args[0])));
|
||||
arg = evalExpr(state, arg);
|
||||
ATMatcher m;
|
||||
return makeBool(atMatch(m, arg) >> "Null");
|
||||
}
|
||||
|
||||
|
||||
/* Apply a function to every element of a list. */
|
||||
Expr primMap(EvalState & state, const ATermVector & args)
|
||||
Expr primCurTime(EvalState & state)
|
||||
{
|
||||
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));
|
||||
return ATmake("Int(<int>)", time(0));
|
||||
}
|
||||
|
||||
|
||||
void EvalState::addPrimOps()
|
||||
Expr primMap(EvalState & state, Expr arg)
|
||||
{
|
||||
addPrimOp("true", 0, primTrue);
|
||||
addPrimOp("false", 0, primFalse);
|
||||
addPrimOp("null", 0, primNull);
|
||||
arg = evalExpr(state, arg);
|
||||
|
||||
addPrimOp("import", 1, primImport);
|
||||
addPrimOp("derivation", 1, primDerivation);
|
||||
addPrimOp("baseNameOf", 1, primBaseNameOf);
|
||||
addPrimOp("toString", 1, primToString);
|
||||
addPrimOp("isNull", 1, primIsNull);
|
||||
ATMatcher m;
|
||||
ATermList es;
|
||||
if (!(atMatch(m, arg) >> "Attrs" >> es))
|
||||
throw Error("function `map' expects an attribute set");
|
||||
|
||||
addPrimOp("map", 2, primMap);
|
||||
Expr function = queryAttr(arg, "function");
|
||||
if (!function)
|
||||
throw Error("function `map' expects an attribute `function'");
|
||||
|
||||
Expr list = queryAttr(arg, "list");
|
||||
if (!list)
|
||||
throw Error("function `map' expects an attribute `list'");
|
||||
|
||||
list = evalExpr(state, list);
|
||||
|
||||
ATermList es2;
|
||||
if (!(atMatch(m, list) >> "List" >> es2))
|
||||
throw Error("attribute `list' in call to `map' must be a list");
|
||||
|
||||
ATermList res = ATempty;
|
||||
for (ATermIterator i(es2); i; ++i)
|
||||
res = ATinsert(res,
|
||||
ATmake("Call(<term>, <term>)", function, *i));
|
||||
|
||||
return ATmake("List(<term>)", ATreverse(res));
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#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);
|
||||
|
||||
/* Return the current time. !!! hack, impure - although due to
|
||||
memoization of evaluation results this should always yield the same
|
||||
value for a particular run of the program. */
|
||||
Expr primCurTime(EvalState & state);
|
||||
|
||||
/* Apply a function to each element of a list. */
|
||||
Expr primMap(EvalState & state, Expr arg);
|
||||
|
||||
|
||||
#endif /* !__PRIMOPS_H */
|
||||
+4
-153
@@ -5,9 +5,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
extern "C" {
|
||||
#include <aterm2.h>
|
||||
}
|
||||
@@ -55,9 +52,6 @@ void checkStoreNotSymlink(Path path)
|
||||
}
|
||||
|
||||
|
||||
void initStoreExprHelpers();
|
||||
|
||||
|
||||
/* Initialize and reorder arguments, then call the actual argument
|
||||
processor. */
|
||||
static void initAndRun(int argc, char * * argv)
|
||||
@@ -94,19 +88,10 @@ 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++);
|
||||
@@ -141,9 +126,7 @@ static void initAndRun(int argc, char * * argv)
|
||||
setLogType(*i);
|
||||
}
|
||||
else if (arg == "--build-output" || arg == "-B")
|
||||
; /* !!! obsolete - remove eventually */
|
||||
else if (arg == "--no-build-output" || arg == "-Q")
|
||||
buildVerbosity = lvlVomit;
|
||||
buildVerbosity = lvlError; /* lowest */
|
||||
else if (arg == "--help") {
|
||||
printHelp();
|
||||
return;
|
||||
@@ -161,13 +144,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;
|
||||
if (!string2Int(*i, n) || n < 0)
|
||||
str >> n;
|
||||
if (!str || !str.eof() || 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);
|
||||
}
|
||||
|
||||
@@ -175,142 +158,10 @@ 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,15 +4,7 @@ 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 \
|
||||
gc.cc gc.hh storeexpr-ast.hh
|
||||
|
||||
EXTRA_DIST = storeexpr-ast.def storeexpr-ast.cc
|
||||
references.cc references.hh pathlocks.cc pathlocks.hh
|
||||
|
||||
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
|
||||
+4
-32
@@ -1,7 +1,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -82,16 +81,12 @@ void Transaction::moveTo(Transaction & t)
|
||||
void Database::requireEnv()
|
||||
{
|
||||
checkInterrupt();
|
||||
if (!env)throw Error("database environment is not open "
|
||||
"(maybe you don't have sufficient permission?)");
|
||||
if (!env) throw Error("database environment not open");
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
@@ -170,30 +165,11 @@ 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 */
|
||||
|
||||
/* 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. */
|
||||
env->set_flags(DB_TXN_WRITE_NOSYNC | DB_LOG_AUTOREMOVE, 1);
|
||||
|
||||
db_env_set_func_fsync(my_fsync);
|
||||
|
||||
|
||||
@@ -215,11 +191,7 @@ void Database::open(const string & path)
|
||||
string accessorsPath = path + "/accessor_count";
|
||||
fdAccessors = ::open(accessorsPath.c_str(), O_RDWR | O_CREAT, 0666);
|
||||
if (fdAccessors == -1)
|
||||
if (errno == EACCES)
|
||||
throw DbNoPermission(
|
||||
format("permission denied to database in `%1%'") % accessorsPath);
|
||||
else
|
||||
throw SysError(format("opening file `%1%'") % accessorsPath);
|
||||
throw SysError(format("opening file `%1%'") % accessorsPath);
|
||||
|
||||
/* Open the lock file. */
|
||||
string lockPath = path + "/access_lock";
|
||||
|
||||
@@ -87,11 +87,4 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class DbNoPermission : public Error
|
||||
{
|
||||
public:
|
||||
DbNoPermission(const format & f) : Error(f) { };
|
||||
};
|
||||
|
||||
|
||||
#endif /* !__DB_H */
|
||||
@@ -1,98 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#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,8 +12,6 @@ bool keepGoing = false;
|
||||
|
||||
bool tryFallback = false;
|
||||
|
||||
Verbosity buildVerbosity = lvlInfo;
|
||||
Verbosity buildVerbosity = lvlDebug;
|
||||
|
||||
unsigned int maxBuildJobs = 1;
|
||||
|
||||
bool readOnlyMode = false;
|
||||
@@ -43,9 +43,5 @@ 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 */
|
||||
+74
-26
@@ -53,7 +53,10 @@ protected:
|
||||
here to prevent cycles. */
|
||||
WeakGoals waiters;
|
||||
|
||||
/* Number of goals we are/were waiting for that have failed. */
|
||||
/* Number of goals we are waiting for. */
|
||||
unsigned int nrWaitees;
|
||||
|
||||
/* Number of goals we were waiting for that have failed. */
|
||||
unsigned int nrFailed;
|
||||
|
||||
/* Whether amDone() has been called. */
|
||||
@@ -63,7 +66,6 @@ protected:
|
||||
Goal(Worker & _worker) : worker(_worker)
|
||||
{
|
||||
done = false;
|
||||
nrFailed = 0;
|
||||
}
|
||||
|
||||
virtual ~Goal()
|
||||
@@ -71,6 +73,12 @@ protected:
|
||||
printMsg(lvlVomit, "goal destroyed");
|
||||
}
|
||||
|
||||
void resetWaitees(int nrWaitees)
|
||||
{
|
||||
this->nrWaitees = nrWaitees;
|
||||
nrFailed = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void work() = 0;
|
||||
|
||||
@@ -202,7 +210,8 @@ void Goal::waiteeDone(GoalPtr waitee, bool success)
|
||||
|
||||
if (!success) ++nrFailed;
|
||||
|
||||
if (waitees.empty() || (!success && !keepGoing)) {
|
||||
assert(nrWaitees > 0);
|
||||
if (!--nrWaitees || (!success && !keepGoing)) {
|
||||
|
||||
/* If we failed and keepGoing is not set, we remove all
|
||||
remaining waitees. */
|
||||
@@ -288,13 +297,11 @@ const char * * strings2CharPtrs(const Strings & ss)
|
||||
/* Should only be called after an expression has been normalised. */
|
||||
Path queryNormalForm(const Path & nePath)
|
||||
{
|
||||
Path 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;
|
||||
if (ne.type == StoreExpr::neClosure) return nePath;
|
||||
Path nfPath;
|
||||
if (!querySuccessor(nePath, nfPath)) abort();
|
||||
return nfPath;
|
||||
}
|
||||
|
||||
|
||||
@@ -357,6 +364,7 @@ private:
|
||||
/* The states. */
|
||||
void init();
|
||||
void haveStoreExpr();
|
||||
void inputNormalised();
|
||||
void inputRealised();
|
||||
void tryToBuild();
|
||||
void buildDone();
|
||||
@@ -443,6 +451,7 @@ 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;
|
||||
@@ -473,10 +482,36 @@ void NormalisationGoal::haveStoreExpr()
|
||||
}
|
||||
assert(expr.type == StoreExpr::neDerivation);
|
||||
|
||||
/* Inputs must be realised before we can build this goal. */
|
||||
/* Inputs must be normalised before we can build this goal. */
|
||||
for (PathSet::iterator i = expr.derivation.inputs.begin();
|
||||
i != expr.derivation.inputs.end(); ++i)
|
||||
addWaitee(worker.makeRealisationGoal(*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());
|
||||
|
||||
state = &NormalisationGoal::inputRealised;
|
||||
}
|
||||
@@ -783,7 +818,6 @@ void NormalisationGoal::terminateBuildHook()
|
||||
toHook.writeSide.close();
|
||||
fdLogFile.close();
|
||||
logPipe.readSide.close();
|
||||
deleteTmpDir(true); /* get rid of the hook's temporary directory */
|
||||
}
|
||||
|
||||
|
||||
@@ -1004,7 +1038,7 @@ void NormalisationGoal::createClosure()
|
||||
Path path = *i;
|
||||
if (!pathExists(path)) {
|
||||
throw BuildError(
|
||||
format("builder for `%1%' failed to produce output path `%2%'")
|
||||
format("builder for `%1%' failed to produce output path `%1%'")
|
||||
% nePath % path);
|
||||
}
|
||||
nf.closure.roots.insert(path);
|
||||
@@ -1015,11 +1049,8 @@ void NormalisationGoal::createClosure()
|
||||
in it. */
|
||||
startNest(nest2, lvlChatty,
|
||||
format("scanning for store references in `%1%'") % path);
|
||||
Strings refPaths;
|
||||
if (!pathExists(path + "/nix-support/no-scan")) {
|
||||
refPaths = filterReferences(path,
|
||||
Strings(allPaths.begin(), allPaths.end()));
|
||||
}
|
||||
Strings refPaths = filterReferences(path,
|
||||
Strings(allPaths.begin(), allPaths.end()));
|
||||
nest2.close();
|
||||
|
||||
/* Construct a closure element for this output path. */
|
||||
@@ -1247,6 +1278,7 @@ 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
|
||||
@@ -1272,6 +1304,7 @@ 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;
|
||||
@@ -1302,6 +1335,8 @@ void RealisationGoal::haveStoreExpr()
|
||||
i != expr.closure.elems.end(); ++i)
|
||||
addWaitee(worker.makeSubstitutionGoal(i->first));
|
||||
|
||||
resetWaitees(expr.closure.elems.size());
|
||||
|
||||
state = &RealisationGoal::elemFinished;
|
||||
}
|
||||
|
||||
@@ -1330,7 +1365,6 @@ void RealisationGoal::fallBack(const format & error)
|
||||
% error);
|
||||
tryFallback = false;
|
||||
unregisterSuccessor(nePath);
|
||||
nrFailed = 0;
|
||||
init();
|
||||
} else {
|
||||
printMsg(lvlError, format("%1%; maybe `--fallback' will help") % error);
|
||||
@@ -1451,9 +1485,28 @@ 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. */
|
||||
nrFailed = 0;
|
||||
addWaitee(worker.makeRealisationGoal(sub.storeExpr));
|
||||
nfSub = queryNormalForm(sub.storeExpr);
|
||||
addWaitee(worker.makeRealisationGoal(nfSub));
|
||||
|
||||
resetWaitees(1);
|
||||
|
||||
state = &SubstitutionGoal::exprRealised;
|
||||
}
|
||||
@@ -1468,9 +1521,6 @@ void SubstitutionGoal::exprRealised()
|
||||
return;
|
||||
}
|
||||
|
||||
/* !!! the storeExpr doesn't have to be a derivation, right? */
|
||||
nfSub = queryNormalForm(sub.storeExpr);
|
||||
|
||||
state = &SubstitutionGoal::tryToRun;
|
||||
worker.waitForBuildSlot(shared_from_this());
|
||||
}
|
||||
@@ -1601,8 +1651,6 @@ void SubstitutionGoal::finished()
|
||||
return;
|
||||
}
|
||||
|
||||
makePathReadOnly(storePath);
|
||||
|
||||
Transaction txn;
|
||||
createStoreTransaction(txn);
|
||||
registerValidPath(txn, storePath);
|
||||
|
||||
@@ -40,5 +40,9 @@ 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 */
|
||||
+28
-64
@@ -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 = 0;
|
||||
static TableId dbValidPaths;
|
||||
|
||||
/* dbSuccessors :: Path -> Path
|
||||
|
||||
@@ -32,14 +32,14 @@ static TableId dbValidPaths = 0;
|
||||
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 = 0;
|
||||
static TableId dbSuccessors;
|
||||
|
||||
/* dbSuccessorsRev :: Path -> [Path]
|
||||
|
||||
The reverse mapping of dbSuccessors (i.e., it stores the
|
||||
predecessors of a Nix expression).
|
||||
*/
|
||||
static TableId dbSuccessorsRev = 0;
|
||||
static TableId dbSuccessorsRev;
|
||||
|
||||
/* dbSubstitutes :: Path -> [(Path, Path, [string])]
|
||||
|
||||
@@ -54,14 +54,14 @@ static TableId dbSuccessorsRev = 0;
|
||||
substitute for that derivate. The substitute in this case might be
|
||||
a Nix expression that fetches the Nix archive.
|
||||
*/
|
||||
static TableId dbSubstitutes = 0;
|
||||
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 = 0;
|
||||
static TableId dbSubstitutesRev;
|
||||
|
||||
|
||||
bool Substitute::operator == (const Substitute & sub)
|
||||
@@ -74,14 +74,7 @@ bool Substitute::operator == (const Substitute & sub)
|
||||
|
||||
void openDB()
|
||||
{
|
||||
if (readOnlyMode) return;
|
||||
try {
|
||||
nixDB.open(nixDBPath);
|
||||
} catch (DbNoPermission & e) {
|
||||
printMsg(lvlTalkative, "cannot access Nix database; continuing anyway");
|
||||
readOnlyMode = true;
|
||||
return;
|
||||
}
|
||||
nixDB.open(nixDBPath);
|
||||
dbValidPaths = nixDB.openTable("validpaths");
|
||||
dbSuccessors = nixDB.openTable("successors");
|
||||
dbSuccessorsRev = nixDB.openTable("successors-rev");
|
||||
@@ -164,10 +157,7 @@ void copyPath(const Path & src, const Path & dst)
|
||||
|
||||
CopySink sink;
|
||||
sink.fd = pipe.writeSide;
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
dumpPath(src, sink);
|
||||
}
|
||||
dumpPath(src, sink);
|
||||
|
||||
/* Wait for the child to finish. */
|
||||
int status = pid.wait(true);
|
||||
@@ -332,44 +322,29 @@ static void writeSubstitutes(const Transaction & txn,
|
||||
}
|
||||
|
||||
|
||||
typedef map<Path, Paths> SubstitutesRev;
|
||||
|
||||
|
||||
void registerSubstitutes(const Transaction & txn,
|
||||
const SubstitutePairs & subPairs)
|
||||
void registerSubstitute(const Transaction & txn,
|
||||
const Path & srcPath, const Substitute & sub)
|
||||
{
|
||||
SubstitutesRev revMap;
|
||||
assertStorePath(srcPath);
|
||||
assertStorePath(sub.storeExpr);
|
||||
|
||||
for (SubstitutePairs::const_iterator i = subPairs.begin();
|
||||
i != subPairs.end(); ++i)
|
||||
{
|
||||
const Path & srcPath(i->first);
|
||||
const Substitute & sub(i->second);
|
||||
Substitutes subs = readSubstitutes(txn, srcPath);
|
||||
|
||||
assertStorePath(srcPath);
|
||||
assertStorePath(sub.storeExpr);
|
||||
|
||||
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);
|
||||
|
||||
Paths & revs = revMap[sub.storeExpr];
|
||||
if (revs.empty())
|
||||
nixDB.queryStrings(txn, dbSubstitutesRev, sub.storeExpr, revs);
|
||||
if (find(revs.begin(), revs.end(), srcPath) == revs.end())
|
||||
revs.push_back(srcPath);
|
||||
if (find(subs.begin(), subs.end(), sub) != subs.end()) {
|
||||
/* Nothing to do if the substitute is already known. */
|
||||
return;
|
||||
}
|
||||
subs.push_front(sub); /* new substitutes take precedence */
|
||||
|
||||
/* Re-write the reverse mapping in one go to prevent Theta(n^2)
|
||||
performance. (This would occur because the data fields of the
|
||||
`substitutes-rev' table are lists). */
|
||||
for (SubstitutesRev::iterator i = revMap.begin(); i != revMap.end(); ++i)
|
||||
nixDB.setStrings(txn, dbSubstitutesRev, i->first, i->second);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -413,7 +388,7 @@ static void invalidatePath(const Path & path, Transaction & txn)
|
||||
subs2.push_back(*j);
|
||||
else
|
||||
found = true;
|
||||
// !!! if (!found) throw Error("integrity error in substitutes mapping");
|
||||
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,
|
||||
@@ -431,16 +406,12 @@ Path addToStore(const Path & _srcPath)
|
||||
Path srcPath(absPath(_srcPath));
|
||||
debug(format("adding `%1%' to the store") % srcPath);
|
||||
|
||||
Hash h;
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
h = hashPath(srcPath);
|
||||
}
|
||||
Hash h = hashPath(srcPath);
|
||||
|
||||
string baseName = baseNameOf(srcPath);
|
||||
Path dstPath = canonPath(nixStore + "/" + (string) h + "-" + baseName);
|
||||
|
||||
if (!readOnlyMode && !isValidPath(dstPath)) {
|
||||
if (!isValidPath(dstPath)) {
|
||||
|
||||
/* The first check above is an optimisation to prevent
|
||||
unnecessary lock acquisition. */
|
||||
@@ -452,14 +423,9 @@ 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();
|
||||
@@ -488,8 +454,6 @@ void addTextToStore(const Path & dstPath, const string & s)
|
||||
|
||||
writeStringToFile(dstPath, s);
|
||||
|
||||
makePathReadOnly(dstPath);
|
||||
|
||||
Transaction txn(nixDB);
|
||||
registerValidPath(txn, dstPath);
|
||||
txn.commit();
|
||||
|
||||
@@ -66,9 +66,8 @@ bool querySuccessor(const Path & srcPath, Path & sucPath);
|
||||
Paths queryPredecessors(const Path & sucPath);
|
||||
|
||||
/* Register a substitute. */
|
||||
typedef list<pair<Path, Substitute> > SubstitutePairs;
|
||||
void registerSubstitutes(const Transaction & txn,
|
||||
const SubstitutePairs & subPairs);
|
||||
void registerSubstitute(const Transaction & txn,
|
||||
const Path & srcPath, const Substitute & sub);
|
||||
|
||||
/* Return the substitutes expression for the given path. */
|
||||
Substitutes querySubstitutes(const Path & srcPath);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
init initStoreExprHelpers
|
||||
|
||||
Closure | ATermList ATermList | ATerm |
|
||||
Derive | ATermList ATermList string string ATermList ATermList | ATerm |
|
||||
|
||||
| string string | ATerm | EnvBinding |
|
||||
| string ATermList | ATerm | ClosureElem |
|
||||
+31
-32
@@ -2,9 +2,6 @@
|
||||
#include "globals.hh"
|
||||
#include "store.hh"
|
||||
|
||||
#include "storeexpr-ast.hh"
|
||||
#include "storeexpr-ast.cc"
|
||||
|
||||
|
||||
Hash hashTerm(ATerm t)
|
||||
{
|
||||
@@ -20,7 +17,7 @@ Path writeTerm(ATerm t, const string & suffix)
|
||||
Path path = canonPath(nixStore + "/" +
|
||||
(string) h + suffix + ".store");
|
||||
|
||||
if (!readOnlyMode && !isValidPath(path)) {
|
||||
if (!isValidPath(path)) {
|
||||
char * s = ATwriteToString(t);
|
||||
if (!s) throw Error(format("cannot write aterm to `%1%'") % path);
|
||||
addTextToStore(path, string(s));
|
||||
@@ -32,11 +29,10 @@ Path writeTerm(ATerm t, const string & suffix)
|
||||
|
||||
static void parsePaths(ATermList paths, PathSet & out)
|
||||
{
|
||||
ATMatcher m;
|
||||
for (ATermIterator i(paths); i; ++i) {
|
||||
if (ATgetType(*i) != AT_APPL)
|
||||
throw badTerm("not a path", *i);
|
||||
string s = aterm2String(*i);
|
||||
if (s.size() == 0 || s[0] != '/')
|
||||
string s;
|
||||
if (!(atMatch(m, *i) >> s))
|
||||
throw badTerm("not a path", *i);
|
||||
out.insert(s);
|
||||
}
|
||||
@@ -73,20 +69,21 @@ static void checkClosure(const Closure & closure)
|
||||
static bool parseClosure(ATerm t, Closure & closure)
|
||||
{
|
||||
ATermList roots, elems;
|
||||
ATMatcher m;
|
||||
|
||||
if (!matchClosure(t, roots, elems))
|
||||
if (!(atMatch(m, t) >> "Closure" >> roots >> elems))
|
||||
return false;
|
||||
|
||||
parsePaths(roots, closure.roots);
|
||||
|
||||
for (ATermIterator i(elems); i; ++i) {
|
||||
ATerm path;
|
||||
string path;
|
||||
ATermList refs;
|
||||
if (!matchClosureElem(*i, path, refs))
|
||||
if (!(atMatch(m, *i) >> "" >> path >> refs))
|
||||
throw badTerm("not a closure element", *i);
|
||||
ClosureElem elem;
|
||||
parsePaths(refs, elem.refs);
|
||||
closure.elems[aterm2String(path)] = elem;
|
||||
closure.elems[path] = elem;
|
||||
}
|
||||
|
||||
checkClosure(closure);
|
||||
@@ -96,29 +93,32 @@ static bool parseClosure(ATerm t, Closure & closure)
|
||||
|
||||
static bool parseDerivation(ATerm t, Derivation & derivation)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList outs, ins, args, bnds;
|
||||
ATerm builder, platform;
|
||||
string builder, platform;
|
||||
|
||||
if (!matchDerive(t, outs, ins, platform, builder, args, bnds))
|
||||
if (!(atMatch(m, t) >> "Derive" >> outs >> ins >> platform
|
||||
>> builder >> args >> bnds))
|
||||
return false;
|
||||
|
||||
parsePaths(outs, derivation.outputs);
|
||||
parsePaths(ins, derivation.inputs);
|
||||
|
||||
derivation.builder = aterm2String(builder);
|
||||
derivation.platform = aterm2String(platform);
|
||||
derivation.builder = builder;
|
||||
derivation.platform = platform;
|
||||
|
||||
for (ATermIterator i(args); i; ++i) {
|
||||
if (ATgetType(*i) != AT_APPL)
|
||||
string s;
|
||||
if (!(atMatch(m, *i) >> s))
|
||||
throw badTerm("string expected", *i);
|
||||
derivation.args.push_back(aterm2String(*i));
|
||||
derivation.args.push_back(s);
|
||||
}
|
||||
|
||||
for (ATermIterator i(bnds); i; ++i) {
|
||||
ATerm s1, s2;
|
||||
if (!matchEnvBinding(*i, s1, s2))
|
||||
string s1, s2;
|
||||
if (!(atMatch(m, *i) >> "" >> s1 >> s2))
|
||||
throw badTerm("tuple of strings expected", *i);
|
||||
derivation.env[aterm2String(s1)] = aterm2String(s2);
|
||||
derivation.env[s1] = 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, toATerm(*i));
|
||||
l = ATinsert(l, ATmake("<str>", i->c_str()));
|
||||
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,
|
||||
makeClosureElem(
|
||||
toATerm(i->first),
|
||||
ATmake("(<str>, <term>)",
|
||||
i->first.c_str(),
|
||||
unparsePaths(i->second.refs)));
|
||||
|
||||
return makeClosure(roots, elems);
|
||||
return ATmake("Closure(<term>, <term>)", roots, elems);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,21 +168,20 @@ 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, toATerm(*i));
|
||||
args = ATinsert(args, ATmake("<str>", i->c_str()));
|
||||
|
||||
ATermList env = ATempty;
|
||||
for (StringPairs::const_iterator i = derivation.env.begin();
|
||||
i != derivation.env.end(); i++)
|
||||
env = ATinsert(env,
|
||||
makeEnvBinding(
|
||||
toATerm(i->first),
|
||||
toATerm(i->second)));
|
||||
ATmake("(<str>, <str>)",
|
||||
i->first.c_str(), i->second.c_str()));
|
||||
|
||||
return makeDerive(
|
||||
return ATmake("Derive(<term>, <term>, <str>, <str>, <term>, <term>)",
|
||||
unparsePaths(derivation.outputs),
|
||||
unparsePaths(derivation.inputs),
|
||||
toATerm(derivation.platform),
|
||||
toATerm(derivation.builder),
|
||||
derivation.platform.c_str(),
|
||||
derivation.builder.c_str(),
|
||||
ATreverse(args),
|
||||
ATreverse(env));
|
||||
}
|
||||
|
||||
@@ -4,3 +4,10 @@ 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}
|
||||
|
||||
+89
-12
@@ -16,6 +16,95 @@ 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);
|
||||
@@ -27,15 +116,3 @@ 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());
|
||||
}
|
||||
+42
-5
@@ -36,14 +36,51 @@ 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 */
|
||||
@@ -0,0 +1,66 @@
|
||||
#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;
|
||||
}
|
||||
+3
-11
@@ -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 && errno != ENOTDIR)
|
||||
if (errno != ENOENT)
|
||||
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") % path);
|
||||
throw SysError(format("making `%1%' writable"));
|
||||
}
|
||||
|
||||
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 = lvlInfo;
|
||||
Verbosity verbosity = lvlError;
|
||||
|
||||
static int nestingLevel = 0;
|
||||
|
||||
@@ -616,11 +616,3 @@ 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,18 +246,4 @@ 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,8 +16,6 @@ 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
|
||||
|
||||
@@ -51,5 +49,3 @@ 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
|
||||
+44
-96
@@ -6,7 +6,6 @@
|
||||
#include "parser.hh"
|
||||
#include "eval.hh"
|
||||
#include "help.txt.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
|
||||
#include <cerrno>
|
||||
#include <ctime>
|
||||
@@ -48,9 +47,10 @@ void printHelp()
|
||||
|
||||
bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
|
||||
{
|
||||
ATermList es;
|
||||
ATMatcher m;
|
||||
|
||||
e = evalExpr(state, e);
|
||||
if (!matchAttrs(e, es)) return false;
|
||||
if (!(atMatch(m, e) >> "Attrs")) return false;
|
||||
Expr a = queryAttr(e, "type");
|
||||
if (!a || evalString(state, a) != "derivation") return false;
|
||||
|
||||
@@ -82,6 +82,7 @@ bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
|
||||
|
||||
bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList es;
|
||||
DrvInfo drv;
|
||||
|
||||
@@ -90,7 +91,7 @@ bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||
if (parseDerivation(state, e, drv))
|
||||
drvs[drv.drvPath] = drv;
|
||||
|
||||
else if (matchAttrs(e, es)) {
|
||||
else if (atMatch(m, e) >> "Attrs") {
|
||||
ATermMap drvMap;
|
||||
queryAllAttrs(e, drvMap);
|
||||
for (ATermIterator i(drvMap.keys()); i; ++i) {
|
||||
@@ -102,7 +103,7 @@ bool parseDerivations(EvalState & state, Expr e, DrvInfos & drvs)
|
||||
}
|
||||
}
|
||||
|
||||
else if (matchList(e, es)) {
|
||||
else if (atMatch(m, e) >> "List" >> es) {
|
||||
for (ATermIterator i(es); i; ++i) {
|
||||
debug(format("evaluating list element"));
|
||||
if (parseDerivation(state, *i, drv))
|
||||
@@ -151,10 +152,12 @@ struct AddPos : TermFun
|
||||
{
|
||||
ATerm operator () (ATerm e)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATerm x, y, z;
|
||||
if (matchBind(e, x, y, z)) return e;
|
||||
if (matchBind2(e, x, y))
|
||||
return makeBind(x, y, makeNoPos());
|
||||
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);
|
||||
return e;
|
||||
}
|
||||
};
|
||||
@@ -191,36 +194,36 @@ void createUserEnv(EvalState & state, const DrvInfos & drvs,
|
||||
for (DrvInfos::const_iterator i = drvs.begin();
|
||||
i != drvs.end(); ++i)
|
||||
{
|
||||
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())
|
||||
));
|
||||
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());
|
||||
inputs = ATinsert(inputs, t);
|
||||
}
|
||||
|
||||
ATerm inputs2 = makeList(ATreverse(inputs));
|
||||
ATerm inputs2 = ATmake("List(<term>)", 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 = makeCall(envBuilder, makeAttrs(ATmakeList3(
|
||||
makeBind(toATerm("system"),
|
||||
makeStr(toATerm(thisSystem)), makeNoPos()),
|
||||
makeBind(toATerm("derivations"), inputs2, makeNoPos()),
|
||||
makeBind(toATerm("manifest"),
|
||||
makePath(toATerm(inputsFile)), makeNoPos())
|
||||
)));
|
||||
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());
|
||||
|
||||
/* Instantiate it. */
|
||||
debug(format("evaluating builder expression `%1%'") % topLevel);
|
||||
@@ -462,17 +465,9 @@ 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 lexicographical_compare(
|
||||
a.name.begin(), a.name.end(),
|
||||
b.name.begin(), b.name.end(), cmpChars);
|
||||
return a.name < b.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -481,22 +476,20 @@ typedef list<Strings> Table;
|
||||
|
||||
void printTable(Table & table)
|
||||
{
|
||||
unsigned int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
||||
int nrColumns = table.size() > 0 ? table.front().size() : 0;
|
||||
|
||||
vector<unsigned int> widths;
|
||||
vector<int> widths;
|
||||
widths.resize(nrColumns);
|
||||
|
||||
for (Table::iterator i = table.begin(); i != table.end(); ++i) {
|
||||
assert(i->size() == nrColumns);
|
||||
Strings::iterator j;
|
||||
unsigned int column;
|
||||
Strings::iterator j; 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;
|
||||
unsigned int column;
|
||||
Strings::iterator j; int column;
|
||||
for (j = i->begin(), column = 0; j != i->end(); ++j, ++column)
|
||||
{
|
||||
cout << *j;
|
||||
@@ -518,8 +511,6 @@ 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;
|
||||
@@ -609,7 +600,6 @@ static void opSwitchProfile(Globals & globals,
|
||||
Path profile = opArgs.front();
|
||||
Path profileLink = getHomeDir() + "/.nix-profile";
|
||||
|
||||
SwitchToOriginalUser sw;
|
||||
switchLink(profileLink, profile);
|
||||
}
|
||||
|
||||
@@ -652,8 +642,10 @@ static void opSwitchGeneration(Globals & globals,
|
||||
if (opArgs.size() != 1)
|
||||
throw UsageError(format("exactly one argument expected"));
|
||||
|
||||
istringstream str(opArgs.front());
|
||||
int dstGen;
|
||||
if (!string2Int(opArgs.front(), dstGen))
|
||||
str >> dstGen;
|
||||
if (!str || !str.eof())
|
||||
throw UsageError(format("expected a generation number"));
|
||||
|
||||
switchGeneration(globals, dstGen);
|
||||
@@ -695,49 +687,6 @@ 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)
|
||||
{
|
||||
@@ -749,13 +698,15 @@ 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;
|
||||
|
||||
@@ -800,8 +751,6 @@ 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;
|
||||
@@ -826,7 +775,6 @@ 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))
|
||||
|
||||
+11
-1
@@ -56,10 +56,20 @@ 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 = string2Int(c1, n1), c2Num = string2Int(c2, n2);
|
||||
bool c1Num = parseInt(c1, n1), c2Num = parseInt(c2, n2);
|
||||
|
||||
if (c1Num && c2Num) return n1 < n2;
|
||||
else if (c1 == "" && c2Num) return true;
|
||||
|
||||
+7
-33
@@ -20,11 +20,9 @@ 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;
|
||||
int n;
|
||||
if (string2Int(string(s, 0, p), n) && n >= 0)
|
||||
return n;
|
||||
else
|
||||
return -1;
|
||||
istringstream str(string(s, 0, p));
|
||||
unsigned int n;
|
||||
if (str >> n && str.eof()) return n; else return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,16 +59,6 @@ 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)
|
||||
{
|
||||
@@ -84,7 +72,10 @@ Path createGeneration(Path profile, Path outPath,
|
||||
Path generation, gcrootDrv, gcrootClr;
|
||||
|
||||
while (1) {
|
||||
makeNames(profile, num, generation, gcrootDrv, gcrootClr);
|
||||
Path prefix = (format("%1%-%2%") % profile % num).str();
|
||||
generation = prefix + "-link";
|
||||
gcrootDrv = prefix + "-drv.gcroot";
|
||||
gcrootClr = prefix + "-clr.gcroot";
|
||||
if (symlink(outPath.c_str(), generation.c_str()) == 0) break;
|
||||
if (errno != EEXIST)
|
||||
throw SysError(format("creating symlink `%1%'") % generation);
|
||||
@@ -99,23 +90,6 @@ 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,8 +31,6 @@ 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,7 +10,6 @@ Options:
|
||||
--version: output version information
|
||||
--help: display help
|
||||
|
||||
--verbose / -v: verbose operation (may be repeated)
|
||||
Options:
|
||||
|
||||
--eval-only: evaluate and print resulting term; do not instantiate
|
||||
--parse-only: parse and print abstract syntax tree
|
||||
--verbose / -v: verbose operation (may be repeated)
|
||||
+11
-31
@@ -6,7 +6,6 @@
|
||||
#include "shared.hh"
|
||||
#include "eval.hh"
|
||||
#include "parser.hh"
|
||||
#include "nixexpr-ast.hh"
|
||||
#include "help.txt.hh"
|
||||
|
||||
|
||||
@@ -16,23 +15,24 @@ void printHelp()
|
||||
}
|
||||
|
||||
|
||||
static Expr evalStdin(EvalState & state, bool parseOnly)
|
||||
static Expr evalStdin(EvalState & state)
|
||||
{
|
||||
startNest(nest, lvlTalkative, format("evaluating standard input"));
|
||||
string s, s2;
|
||||
while (getline(cin, s2)) s += s2 + "\n";
|
||||
Expr e = parseExprFromString(state, s, absPath("."));
|
||||
return parseOnly ? e : evalExpr(state, e);
|
||||
return evalExpr(state, e);
|
||||
}
|
||||
|
||||
|
||||
static void printDrvPaths(EvalState & state, Expr e)
|
||||
static void printNixExpr(EvalState & state, Expr e)
|
||||
{
|
||||
ATMatcher m;
|
||||
ATermList es;
|
||||
|
||||
/* !!! duplication w.r.t. parseDerivations in nix-env */
|
||||
|
||||
if (matchAttrs(e, es)) {
|
||||
if (atMatch(m, e) >> "Attrs" >> es) {
|
||||
Expr a = queryAttr(e, "type");
|
||||
if (a && evalString(state, a) == "derivation") {
|
||||
a = queryAttr(e, "drvPath");
|
||||
@@ -45,14 +45,14 @@ static void printDrvPaths(EvalState & state, Expr e)
|
||||
ATermMap drvMap;
|
||||
queryAllAttrs(e, drvMap);
|
||||
for (ATermIterator i(drvMap.keys()); i; ++i)
|
||||
printDrvPaths(state, evalExpr(state, drvMap.get(*i)));
|
||||
printNixExpr(state, evalExpr(state, drvMap.get(*i)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchList(e, es)) {
|
||||
if (atMatch(m, e) >> "List" >> es) {
|
||||
for (ATermIterator i(es); i; ++i)
|
||||
printDrvPaths(state, evalExpr(state, *i));
|
||||
printNixExpr(state, evalExpr(state, *i));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,22 +60,11 @@ static void printDrvPaths(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(); )
|
||||
@@ -84,14 +73,6 @@ 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
|
||||
@@ -101,16 +82,15 @@ void run(Strings args)
|
||||
openDB();
|
||||
|
||||
if (readStdin) {
|
||||
Expr e = evalStdin(state, parseOnly);
|
||||
printResult(state, e, evalOnly);
|
||||
Expr e = evalStdin(state);
|
||||
printNixExpr(state, e);
|
||||
}
|
||||
|
||||
for (Strings::iterator it = files.begin();
|
||||
it != files.end(); it++)
|
||||
{
|
||||
Expr e = evalFile(state, absPath(*it));
|
||||
/* !!! parseOnly ignored */
|
||||
printResult(state, e, evalOnly);
|
||||
printNixExpr(state, e);
|
||||
}
|
||||
|
||||
printEvalStats(state);
|
||||
|
||||
+18
-66
@@ -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,6 +32,17 @@ 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)
|
||||
@@ -157,7 +168,6 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
|
||||
if (!opArgs.empty())
|
||||
throw UsageError("no arguments expected");
|
||||
|
||||
SubstitutePairs subPairs;
|
||||
Transaction txn;
|
||||
createStoreTransaction(txn);
|
||||
|
||||
@@ -170,18 +180,18 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
|
||||
getline(cin, sub.program);
|
||||
string s;
|
||||
getline(cin, s);
|
||||
istringstream st(s);
|
||||
int n;
|
||||
if (!string2Int(s, n)) throw Error("number expected");
|
||||
st >> n;
|
||||
if (!st) throw Error("number expected");
|
||||
while (n--) {
|
||||
getline(cin, s);
|
||||
sub.args.push_back(s);
|
||||
}
|
||||
if (!cin || cin.eof()) throw Error("missing input");
|
||||
subPairs.push_back(pair<Path, Substitute>(srcPath, sub));
|
||||
registerSubstitute(txn, srcPath, sub);
|
||||
}
|
||||
|
||||
registerSubstitutes(txn, subPairs);
|
||||
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@@ -210,64 +220,6 @@ 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
|
||||
{
|
||||
@@ -346,6 +298,8 @@ 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")
|
||||
@@ -358,8 +312,6 @@ void run(Strings args)
|
||||
op = opValidPath;
|
||||
else if (arg == "--isvalid")
|
||||
op = opIsValid;
|
||||
else if (arg == "--gc")
|
||||
op = opGC;
|
||||
else if (arg == "--dump")
|
||||
op = opDump;
|
||||
else if (arg == "--restore")
|
||||
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#! /bin/sh
|
||||
|
||||
IFS=
|
||||
|
||||
echo "printing list of args"
|
||||
|
||||
for i in $@; do
|
||||
echo "arg: $i"
|
||||
done
|
||||
|
||||
touch $out
|
||||
@@ -0,0 +1,7 @@
|
||||
Package(
|
||||
[ ("name", "args")
|
||||
, ("build", Relative("args/args-build.sh"))
|
||||
|
||||
, ("args", ["1", "2", "3", IncludeFix("slow2/slow.fix")])
|
||||
]
|
||||
)
|
||||
Loaded 100 of 133 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user