diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2012-12-03 23:04:47 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2012-12-03 23:05:08 +0100 |
| commit | c2033df432af87d0176347858c7d11acfe2ed89f (patch) | |
| tree | 05a7befd50cead52a401165c03dee3ae72840619 | |
| parent | 7eba5e6361b637a4c8aecbb13644f573a845732b (diff) | |
build: Include a copy of Nix's libstore and daemon; build it.
* configure.ac: Call `AC_USE_SYSTEM_EXTENSIONS', and
`GUIX_SYSTEM_TYPE'. Add `--with-store-dir' option, and substitute
`storedir'. Include `config-daemon.ac'.
* config-daemon.ac: New file.
* Makefile.am [BUILD_DAEMON]: Include `daemon.am'.
* daemon.am: New file.
* m4/guix.m4 (GUIX_SYSTEM_TYPE): New macro.
* nix/libutil/gcrypt-hash.cc, nix/libutil/gcrypt-hash.hh,
nix/libutil/md5.h, nix/libutil/sha1.h, nix/libutil/sha256.h,
nix/nix-daemon/guix-daemon.cc, nix/nix-daemon/shared.hh: New files.
| -rw-r--r-- | .gitignore | 10 | ||||
| -rw-r--r-- | Makefile.am | 6 | ||||
| -rw-r--r-- | config-daemon.ac | 64 | ||||
| -rw-r--r-- | configure.ac | 15 | ||||
| -rw-r--r-- | daemon.am | 152 | ||||
| -rw-r--r-- | m4/guix.m4 | 29 | ||||
| -rw-r--r-- | nix/.gitignore | 4 | ||||
| -rw-r--r-- | nix/boost/.gitignore | 3 | ||||
| -rw-r--r-- | nix/libstore/.gitignore | 3 | ||||
| -rw-r--r-- | nix/libutil/.gitignore | 2 | ||||
| -rw-r--r-- | nix/libutil/gcrypt-hash.cc | 50 | ||||
| -rw-r--r-- | nix/libutil/gcrypt-hash.hh | 39 | ||||
| -rw-r--r-- | nix/libutil/md5.h | 35 | ||||
| -rw-r--r-- | nix/libutil/sha1.h | 35 | ||||
| -rw-r--r-- | nix/libutil/sha256.h | 35 | ||||
| -rw-r--r-- | nix/nix-daemon/guix-daemon.cc | 115 | ||||
| -rw-r--r-- | nix/nix-daemon/shared.hh | 37 |
17 files changed, 633 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index 1fe15621e2c..89f0ae797c5 100644 --- a/.gitignore +++ b/.gitignore | |||
| @@ -50,3 +50,13 @@ config.cache | |||
| 50 | /guix-package | 50 | /guix-package |
| 51 | /guix/config.scm | 51 | /guix/config.scm |
| 52 | /guix-import | 52 | /guix-import |
| 53 | /nix/nix-daemon/nix-daemon.cc | ||
| 54 | /nix/config.h | ||
| 55 | /nix/config.h.in | ||
| 56 | stamp-h[0-9] | ||
| 57 | /nix/AUTHORS | ||
| 58 | /nix/COPYING | ||
| 59 | /libformat.a | ||
| 60 | /libstore.a | ||
| 61 | /libutil.a | ||
| 62 | /guix-daemon | ||
diff --git a/Makefile.am b/Makefile.am index 8bb3b556348..7e5be0be2a2 100644 --- a/Makefile.am +++ b/Makefile.am | |||
| @@ -222,6 +222,12 @@ SUBDIRS = po | |||
| 222 | info_TEXINFOS = doc/guix.texi | 222 | info_TEXINFOS = doc/guix.texi |
| 223 | EXTRA_DIST += doc/fdl-1.3.texi | 223 | EXTRA_DIST += doc/fdl-1.3.texi |
| 224 | 224 | ||
| 225 | if BUILD_DAEMON | ||
| 226 | |||
| 227 | include daemon.am | ||
| 228 | |||
| 229 | endif BUILD_DAEMON | ||
| 230 | |||
| 225 | ACLOCAL_AMFLAGS = -I m4 | 231 | ACLOCAL_AMFLAGS = -I m4 |
| 226 | AM_DISTCHECK_CONFIGURE_FLAGS = \ | 232 | AM_DISTCHECK_CONFIGURE_FLAGS = \ |
| 227 | --with-libgcrypt-prefix="$(LIBGCRYPT_PREFIX)" \ | 233 | --with-libgcrypt-prefix="$(LIBGCRYPT_PREFIX)" \ |
diff --git a/config-daemon.ac b/config-daemon.ac new file mode 100644 index 00000000000..75708147055 --- /dev/null +++ b/config-daemon.ac | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | dnl -*- Autoconf -*- fragment for the C++ daemon. | ||
| 2 | |||
| 3 | AC_ARG_ENABLE([daemon], | ||
| 4 | [AS_HELP_STRING([--enable-daemon], [build the Nix daemon (C++)])], | ||
| 5 | [guix_build_daemon="$enableval"], | ||
| 6 | [guix_build_daemon="no"]) | ||
| 7 | |||
| 8 | AC_MSG_CHECKING([whether to build daemon]) | ||
| 9 | AC_MSG_RESULT([$guix_build_daemon]) | ||
| 10 | |||
| 11 | dnl C++ environment. This macro must be used unconditionnaly. | ||
| 12 | AC_PROG_CXX | ||
| 13 | |||
| 14 | if test "x$guix_build_daemon" = "xyes"; then | ||
| 15 | |||
| 16 | AC_PROG_RANLIB | ||
| 17 | AC_CONFIG_HEADER([nix/config.h]) | ||
| 18 | |||
| 19 | dnl Use 64-bit file system calls so that we can support files > 2 GiB. | ||
| 20 | AC_SYS_LARGEFILE | ||
| 21 | |||
| 22 | dnl Look for libbz2, a required dependency. | ||
| 23 | AC_CHECK_LIB([bz2], [BZ2_bzWriteOpen], [true], | ||
| 24 | [AC_MSG_ERROR([Guix requires libbz2, which is part of bzip2. See http://www.bzip.org/.])]) | ||
| 25 | AC_CHECK_HEADERS([bzlib.h], [true], | ||
| 26 | [AC_MSG_ERROR([Guix requires libbz2, which is part of bzip2. See http://www.bzip.org/.])]) | ||
| 27 | |||
| 28 | dnl Look for SQLite, a required dependency. | ||
| 29 | PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= 3.6.19]) | ||
| 30 | |||
| 31 | AC_DEFINE([NIX_VERSION], ["0.0.0"], [Fake Nix version number.]) | ||
| 32 | AC_DEFINE_UNQUOTED([SYSTEM], ["\"$guix_system\""], | ||
| 33 | [Guix host system type--i.e., platform and OS kernel tuple.]) | ||
| 34 | |||
| 35 | case "$LIBGCRYPT_PREFIX" in | ||
| 36 | no) | ||
| 37 | LIBGCRYPT_CFLAGS="" | ||
| 38 | LIBGCRYPT_LIBS="" | ||
| 39 | ;; | ||
| 40 | *) | ||
| 41 | LIBGCRYPT_CFLAGS="-I$LIBGCRYPT_PREFIX/include" | ||
| 42 | LIBGCRYPT_LIBS="-L$LIBGCRYPT_PREFIX/lib -lgcrypt" | ||
| 43 | ;; | ||
| 44 | esac | ||
| 45 | AC_SUBST([LIBGCRYPT_CFLAGS]) | ||
| 46 | AC_SUBST([LIBGCRYPT_LIBS]) | ||
| 47 | |||
| 48 | save_CFLAGS="$CFLAGS" | ||
| 49 | save_LDFLAGS="$LDFLAGS" | ||
| 50 | CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS" | ||
| 51 | LDFLAGS="$LDFLAGS $LIBGCRYPT_LDFLAGS" | ||
| 52 | |||
| 53 | have_gcrypt=yes | ||
| 54 | AC_CHECK_LIB([gcrypt], [gcry_md_open], [:], [have_gcrypt=no]) | ||
| 55 | AC_CHECK_HEADER([gcrypt.h], [:], [have_gcrypt=no]) | ||
| 56 | if test "x$have_gcrypt" != "xyes"; then | ||
| 57 | AC_MSG_ERROR([GNU libgcrypt not found; please install it.]) | ||
| 58 | fi | ||
| 59 | |||
| 60 | CFLAGS="$save_CFLAGS" | ||
| 61 | LDFLAGS="$save_LDFLAGS" | ||
| 62 | fi | ||
| 63 | |||
| 64 | AM_CONDITIONAL([BUILD_DAEMON], [test "x$guix_build_daemon" = "xyes"]) | ||
diff --git a/configure.ac b/configure.ac index 65fc01857f9..6c7be59895e 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -12,13 +12,23 @@ AM_INIT_AUTOMAKE([1.11 gnu silent-rules subdir-objects \ | |||
| 12 | AC_CONFIG_SRCDIR([guix.scm]) | 12 | AC_CONFIG_SRCDIR([guix.scm]) |
| 13 | AC_CONFIG_MACRO_DIR([m4]) | 13 | AC_CONFIG_MACRO_DIR([m4]) |
| 14 | 14 | ||
| 15 | dnl For the C++ code. This must be used early. | ||
| 16 | AC_USE_SYSTEM_EXTENSIONS | ||
| 17 | |||
| 15 | AM_GNU_GETTEXT([external]) | 18 | AM_GNU_GETTEXT([external]) |
| 16 | AM_GNU_GETTEXT_VERSION([0.18.1]) | 19 | AM_GNU_GETTEXT_VERSION([0.18.1]) |
| 17 | 20 | ||
| 18 | guilemoduledir="${datarootdir}/guile/site/2.0" | 21 | guilemoduledir="${datarootdir}/guile/site/2.0" |
| 19 | AC_SUBST([guilemoduledir]) | 22 | AC_SUBST([guilemoduledir]) |
| 20 | 23 | ||
| 21 | AC_CANONICAL_HOST | 24 | GUIX_SYSTEM_TYPE |
| 25 | |||
| 26 | AC_ARG_WITH(store-dir, | ||
| 27 | AC_HELP_STRING([--with-store-dir=PATH], | ||
| 28 | [path of the store (defaults to /nix/store)]), | ||
| 29 | [storedir="$withval"], | ||
| 30 | [storedir="/nix/store"]) | ||
| 31 | AC_SUBST(storedir) | ||
| 22 | 32 | ||
| 23 | PKG_CHECK_MODULES([GUILE], [guile-2.0]) | 33 | PKG_CHECK_MODULES([GUILE], [guile-2.0]) |
| 24 | AC_PATH_PROG([GUILE], [guile]) | 34 | AC_PATH_PROG([GUILE], [guile]) |
| @@ -83,6 +93,9 @@ AC_SUBST([LIBGCRYPT_PREFIX]) | |||
| 83 | 93 | ||
| 84 | GUIX_ASSERT_LIBGCRYPT_USABLE | 94 | GUIX_ASSERT_LIBGCRYPT_USABLE |
| 85 | 95 | ||
| 96 | AC_CACHE_SAVE | ||
| 97 | |||
| 98 | m4_include([config-daemon.ac]) | ||
| 86 | 99 | ||
| 87 | AC_CONFIG_FILES([Makefile | 100 | AC_CONFIG_FILES([Makefile |
| 88 | po/Makefile.in | 101 | po/Makefile.in |
diff --git a/daemon.am b/daemon.am new file mode 100644 index 00000000000..e150e54d6bf --- /dev/null +++ b/daemon.am | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | # Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | # | ||
| 4 | # This file is part of Guix. | ||
| 5 | # | ||
| 6 | # Guix is free software; you can redistribute it and/or modify it | ||
| 7 | # under the terms of the GNU General Public License as published by | ||
| 8 | # the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | # your option) any later version. | ||
| 10 | # | ||
| 11 | # Guix is distributed in the hope that it will be useful, but | ||
| 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License | ||
| 17 | # along with Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | # | ||
| 20 | # Integration of the `guix-daemon' code taken from upstream Nix. | ||
| 21 | # | ||
| 22 | |||
| 23 | BUILT_SOURCES = nix/libstore/schema.sql.hh | ||
| 24 | CLEANFILES += $(BUILT_SOURCES) | ||
| 25 | |||
| 26 | noinst_LIBRARIES = libformat.a libutil.a libstore.a | ||
| 27 | |||
| 28 | libformat_a_SOURCES = \ | ||
| 29 | nix/boost/format/free_funcs.cc \ | ||
| 30 | nix/boost/format/parsing.cc \ | ||
| 31 | nix/boost/format/format_implementation.cc | ||
| 32 | |||
| 33 | libformat_headers = \ | ||
| 34 | nix/boost/weak_ptr.hpp \ | ||
| 35 | nix/boost/throw_exception.hpp \ | ||
| 36 | nix/boost/checked_delete.hpp \ | ||
| 37 | nix/boost/shared_ptr.hpp \ | ||
| 38 | nix/boost/format.hpp \ | ||
| 39 | nix/boost/assert.hpp \ | ||
| 40 | nix/boost/format/macros_default.hpp \ | ||
| 41 | nix/boost/format/format_fwd.hpp \ | ||
| 42 | nix/boost/format/format_class.hpp \ | ||
| 43 | nix/boost/format/exceptions.hpp \ | ||
| 44 | nix/boost/format/group.hpp \ | ||
| 45 | nix/boost/format/feed_args.hpp \ | ||
| 46 | nix/boost/format/internals_fwd.hpp \ | ||
| 47 | nix/boost/format/internals.hpp \ | ||
| 48 | nix/boost/detail/workaround.hpp \ | ||
| 49 | nix/boost/detail/shared_count.hpp \ | ||
| 50 | nix/boost/enable_shared_from_this.hpp | ||
| 51 | |||
| 52 | libformat_a_CPPFLAGS = \ | ||
| 53 | -I$(top_srcdir)/nix | ||
| 54 | |||
| 55 | libutil_a_SOURCES = \ | ||
| 56 | nix/libutil/archive.cc \ | ||
| 57 | nix/libutil/serialise.cc \ | ||
| 58 | nix/libutil/immutable.cc \ | ||
| 59 | nix/libutil/util.cc \ | ||
| 60 | nix/libutil/xml-writer.cc \ | ||
| 61 | nix/libutil/hash.cc \ | ||
| 62 | nix/libutil/gcrypt-hash.cc | ||
| 63 | |||
| 64 | libutil_headers = \ | ||
| 65 | nix/libutil/immutable.hh \ | ||
| 66 | nix/libutil/hash.hh \ | ||
| 67 | nix/libutil/serialise.hh \ | ||
| 68 | nix/libutil/xml-writer.hh \ | ||
| 69 | nix/libutil/util.hh \ | ||
| 70 | nix/libutil/archive.hh \ | ||
| 71 | nix/libutil/types.hh \ | ||
| 72 | nix/libutil/gcrypt-hash.hh \ | ||
| 73 | nix/libutil/md5.h \ | ||
| 74 | nix/libutil/sha1.h \ | ||
| 75 | nix/libutil/sha256.h | ||
| 76 | |||
| 77 | libutil_a_CPPFLAGS = \ | ||
| 78 | -I$(top_builddir)/nix \ | ||
| 79 | -I$(top_srcdir)/nix/libutil \ | ||
| 80 | $(libformat_a_CPPFLAGS) | ||
| 81 | |||
| 82 | libstore_a_SOURCES = \ | ||
| 83 | nix/libstore/gc.cc \ | ||
| 84 | nix/libstore/globals.cc \ | ||
| 85 | nix/libstore/misc.cc \ | ||
| 86 | nix/libstore/references.cc \ | ||
| 87 | nix/libstore/store-api.cc \ | ||
| 88 | nix/libstore/optimise-store.cc \ | ||
| 89 | nix/libstore/local-store.cc \ | ||
| 90 | nix/libstore/remote-store.cc \ | ||
| 91 | nix/libstore/build.cc \ | ||
| 92 | nix/libstore/pathlocks.cc \ | ||
| 93 | nix/libstore/derivations.cc | ||
| 94 | |||
| 95 | libstore_headers = \ | ||
| 96 | nix/libstore/references.hh \ | ||
| 97 | nix/libstore/pathlocks.hh \ | ||
| 98 | nix/libstore/globals.hh \ | ||
| 99 | nix/libstore/schema.sql.hh \ | ||
| 100 | nix/libstore/worker-protocol.hh \ | ||
| 101 | nix/libstore/remote-store.hh \ | ||
| 102 | nix/libstore/derivations.hh \ | ||
| 103 | nix/libstore/misc.hh \ | ||
| 104 | nix/libstore/local-store.hh \ | ||
| 105 | nix/libstore/store-api.hh | ||
| 106 | |||
| 107 | libstore_a_CPPFLAGS = \ | ||
| 108 | $(libutil_a_CPPFLAGS) \ | ||
| 109 | -I$(top_srcdir)/nix/libstore \ | ||
| 110 | -DNIX_STORE_DIR=\"$(storedir)\" \ | ||
| 111 | -DNIX_DATA_DIR=\"$(datadir)\" \ | ||
| 112 | -DNIX_STATE_DIR=\"$(localstatedir)/nix\" \ | ||
| 113 | -DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \ | ||
| 114 | -DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \ | ||
| 115 | -DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \ | ||
| 116 | -DNIX_BIN_DIR=\"$(bindir)\" \ | ||
| 117 | -DOPENSSL_PATH="\"FIXME--no OpenSSL support\"" | ||
| 118 | |||
| 119 | libstore_a_CFLAGS = \ | ||
| 120 | $(SQLITE3_CFLAGS) $(LIBGCRYPT_CFLAGS) | ||
| 121 | |||
| 122 | bin_PROGRAMS = guix-daemon | ||
| 123 | |||
| 124 | guix_daemon_SOURCES = \ | ||
| 125 | nix/nix-daemon/nix-daemon.cc \ | ||
| 126 | nix/nix-daemon/guix-daemon.cc | ||
| 127 | |||
| 128 | guix_daemon_CPPFLAGS = \ | ||
| 129 | $(libutil_a_CPPFLAGS) \ | ||
| 130 | -I$(top_srcdir)/nix/libstore | ||
| 131 | |||
| 132 | guix_daemon_LDADD = \ | ||
| 133 | libstore.a libutil.a libformat.a -lbz2 \ | ||
| 134 | $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS) | ||
| 135 | |||
| 136 | |||
| 137 | noinst_HEADERS = \ | ||
| 138 | $(libformat_headers) $(libutil_headers) $(libstore_headers) | ||
| 139 | |||
| 140 | nix/libstore/schema.sql.hh: nix/libstore/schema.sql | ||
| 141 | $(GUILE) --no-auto-compile -c \ | ||
| 142 | "(use-modules (rnrs io ports)) \ | ||
| 143 | (call-with-output-file \"$@\" \ | ||
| 144 | (lambda (out) \ | ||
| 145 | (call-with-input-file \"$^\" \ | ||
| 146 | (lambda (in) \ | ||
| 147 | (write (get-string-all in) out)))))" | ||
| 148 | |||
| 149 | EXTRA_DIST += \ | ||
| 150 | nix/libstore/schema.sql \ | ||
| 151 | nix/AUTHORS \ | ||
| 152 | nix/COPYING | ||
diff --git a/m4/guix.m4 b/m4/guix.m4 index 29f928f6530..9b5184ff55a 100644 --- a/m4/guix.m4 +++ b/m4/guix.m4 | |||
| @@ -33,3 +33,32 @@ AC_DEFUN([GUIX_ASSERT_LIBGCRYPT_USABLE], | |||
| 33 | if test "x$guix_cv_libgcrypt_usable_p" != "xyes"; then | 33 | if test "x$guix_cv_libgcrypt_usable_p" != "xyes"; then |
| 34 | AC_MSG_ERROR([GNU libgcrypt does not appear to be usable; see `--with-libgcrypt-prefix' and `README'.]) | 34 | AC_MSG_ERROR([GNU libgcrypt does not appear to be usable; see `--with-libgcrypt-prefix' and `README'.]) |
| 35 | fi]) | 35 | fi]) |
| 36 | |||
| 37 | dnl GUIX_SYSTEM_TYPE | ||
| 38 | dnl | ||
| 39 | dnl Determine the Guix host system type, and store it in the | ||
| 40 | dnl `guix_system' variable. | ||
| 41 | AC_DEFUN([GUIX_SYSTEM_TYPE], [ | ||
| 42 | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
| 43 | AC_ARG_WITH(system, AC_HELP_STRING([--with-system=SYSTEM], | ||
| 44 | [Platform identifier (e.g., `i686-linux').]), | ||
| 45 | [guix_system="$withval"], | ||
| 46 | [case "$host_cpu" in | ||
| 47 | i*86) | ||
| 48 | machine_name="i686";; | ||
| 49 | amd64) | ||
| 50 | machine_name="x86_64";; | ||
| 51 | *) | ||
| 52 | machine_name="$host_cpu";; | ||
| 53 | esac | ||
| 54 | |||
| 55 | case "$host_os" in | ||
| 56 | linux-gnu*) | ||
| 57 | # For backward compatibility, strip the `-gnu' part. | ||
| 58 | guix_system="$machine_name-linux";; | ||
| 59 | *) | ||
| 60 | # Strip the version number from names such as `gnu0.3', | ||
| 61 | # `darwin10.2.0', etc. | ||
| 62 | guix_system="$machine_name-`echo $host_os | "$SED" -e's/@<:@0-9.@:>@*$//g'`";; | ||
| 63 | esac]) | ||
| 64 | ]) | ||
diff --git a/nix/.gitignore b/nix/.gitignore new file mode 100644 index 00000000000..92d0520cc77 --- /dev/null +++ b/nix/.gitignore | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | *.a | ||
| 2 | *.o | ||
| 3 | .deps | ||
| 4 | .dirstamp | ||
diff --git a/nix/boost/.gitignore b/nix/boost/.gitignore new file mode 100644 index 00000000000..1f188e3b65e --- /dev/null +++ b/nix/boost/.gitignore | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | *.hpp | ||
| 2 | *.cpp | ||
| 3 | *.cc | ||
diff --git a/nix/libstore/.gitignore b/nix/libstore/.gitignore new file mode 100644 index 00000000000..512a0d022f9 --- /dev/null +++ b/nix/libstore/.gitignore | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | *.cc | ||
| 2 | *.hh | ||
| 3 | /schema.sql | ||
diff --git a/nix/libutil/.gitignore b/nix/libutil/.gitignore new file mode 100644 index 00000000000..e539428b1b9 --- /dev/null +++ b/nix/libutil/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | *.cc | ||
| 2 | *.hh | ||
diff --git a/nix/libutil/gcrypt-hash.cc b/nix/libutil/gcrypt-hash.cc new file mode 100644 index 00000000000..de7e5afc1a1 --- /dev/null +++ b/nix/libutil/gcrypt-hash.cc | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <config.h> | ||
| 20 | |||
| 21 | #include <gcrypt-hash.hh> | ||
| 22 | #include <assert.h> | ||
| 23 | |||
| 24 | extern "C" { | ||
| 25 | |||
| 26 | void | ||
| 27 | guix_hash_init (struct guix_hash_context *ctx, gcry_md_algo_t algo) | ||
| 28 | { | ||
| 29 | gcry_error_t err; | ||
| 30 | |||
| 31 | err = gcry_md_open (&ctx->md_handle, algo, 0); | ||
| 32 | assert (err == GPG_ERR_NO_ERROR); | ||
| 33 | } | ||
| 34 | |||
| 35 | void | ||
| 36 | guix_hash_update (struct guix_hash_context *ctx, const void *buffer, size_t len) | ||
| 37 | { | ||
| 38 | gcry_md_write (ctx->md_handle, buffer, len); | ||
| 39 | } | ||
| 40 | |||
| 41 | void | ||
| 42 | guix_hash_final (void *resbuf, struct guix_hash_context *ctx, | ||
| 43 | gcry_md_algo_t algo) | ||
| 44 | { | ||
| 45 | memcpy (resbuf, gcry_md_read (ctx->md_handle, algo), | ||
| 46 | gcry_md_get_algo_dlen (algo)); | ||
| 47 | gcry_md_close (ctx->md_handle); | ||
| 48 | } | ||
| 49 | |||
| 50 | } | ||
diff --git a/nix/libutil/gcrypt-hash.hh b/nix/libutil/gcrypt-hash.hh new file mode 100644 index 00000000000..1e26398540b --- /dev/null +++ b/nix/libutil/gcrypt-hash.hh | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | /* An OpenSSL-like interface to GNU libgcrypt cryptographic hash | ||
| 20 | functions. */ | ||
| 21 | |||
| 22 | #pragma once | ||
| 23 | #include <gcrypt.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | extern "C" { | ||
| 27 | |||
| 28 | struct guix_hash_context | ||
| 29 | { | ||
| 30 | gcry_md_hd_t md_handle; | ||
| 31 | }; | ||
| 32 | |||
| 33 | extern void guix_hash_init (struct guix_hash_context *ctx, gcry_md_algo_t algo); | ||
| 34 | extern void guix_hash_update (struct guix_hash_context *ctx, const void *buffer, | ||
| 35 | size_t len); | ||
| 36 | extern void guix_hash_final (void *resbuf, struct guix_hash_context *ctx, | ||
| 37 | gcry_md_algo_t algo); | ||
| 38 | |||
| 39 | } | ||
diff --git a/nix/libutil/md5.h b/nix/libutil/md5.h new file mode 100644 index 00000000000..c275e381f82 --- /dev/null +++ b/nix/libutil/md5.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define MD5_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | MD5_Init (struct MD5_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_MD5); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define MD5_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | MD5_Final (void *resbuf, struct MD5_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (ctx, ctx, GCRY_MD_MD5); | ||
| 35 | } | ||
diff --git a/nix/libutil/sha1.h b/nix/libutil/sha1.h new file mode 100644 index 00000000000..8af92725ea1 --- /dev/null +++ b/nix/libutil/sha1.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define SHA_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | SHA1_Init (struct SHA_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_SHA1); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define SHA1_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | SHA1_Final (void *resbuf, struct SHA_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (ctx, ctx, GCRY_MD_SHA1); | ||
| 35 | } | ||
diff --git a/nix/libutil/sha256.h b/nix/libutil/sha256.h new file mode 100644 index 00000000000..c436d6402c8 --- /dev/null +++ b/nix/libutil/sha256.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define SHA256_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | SHA256_Init (struct SHA256_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_SHA256); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define SHA256_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | SHA256_Final (void *resbuf, struct SHA256_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (ctx, ctx, GCRY_MD_SHA256); | ||
| 35 | } | ||
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc new file mode 100644 index 00000000000..43d41134937 --- /dev/null +++ b/nix/nix-daemon/guix-daemon.cc | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <config.h> | ||
| 20 | |||
| 21 | #include <types.hh> | ||
| 22 | #include "shared.hh" | ||
| 23 | #include <globals.hh> | ||
| 24 | |||
| 25 | #include <stdlib.h> | ||
| 26 | #include <argp.h> | ||
| 27 | |||
| 28 | /* Variables used by `nix-daemon.cc'. */ | ||
| 29 | volatile ::sig_atomic_t blockInt; | ||
| 30 | char **argvSaved; | ||
| 31 | |||
| 32 | using namespace nix; | ||
| 33 | |||
| 34 | /* Entry point in `nix-daemon.cc'. */ | ||
| 35 | extern void run (Strings args); | ||
| 36 | |||
| 37 | |||
| 38 | /* Command-line options. */ | ||
| 39 | |||
| 40 | const char *argp_program_version = | ||
| 41 | "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION; | ||
| 42 | const char *argp_program_bug_address = PACKAGE_BUGREPORT; | ||
| 43 | |||
| 44 | static char doc[] = | ||
| 45 | "guix-daemon -- perform derivation builds and store accesses\ | ||
| 46 | \v\ | ||
| 47 | This program is a daemon meant to run in the background. It serves \ | ||
| 48 | requests sent over a Unix-domain socket. It accesses the store, and \ | ||
| 49 | builds derivations on behalf of its clients."; | ||
| 50 | |||
| 51 | #define GUIX_OPT_SYSTEM 1 | ||
| 52 | #define GUIX_OPT_DISABLE_CHROOT 2 | ||
| 53 | #define GUIX_OPT_DISABLE_LOG_COMPRESSION 3 | ||
| 54 | |||
| 55 | static const struct argp_option options[] = | ||
| 56 | { | ||
| 57 | { "system", GUIX_OPT_SYSTEM, "SYSTEM", 0, | ||
| 58 | "Assume SYSTEM as the current system type" }, | ||
| 59 | { "build-cores", 'C', "N", 0, | ||
| 60 | "Use N CPU cores to build each derivation; 0 means as many as available" }, | ||
| 61 | { "max-jobs", 'M', "N", 0, | ||
| 62 | "Allow at most N build jobs" }, | ||
| 63 | { "disable-chroot", GUIX_OPT_DISABLE_CHROOT, 0, 0, | ||
| 64 | "Disable chroot builds" }, | ||
| 65 | { "disable-log-compression", GUIX_OPT_DISABLE_LOG_COMPRESSION, 0, 0, | ||
| 66 | "Disable compression of the build logs" }, | ||
| 67 | { 0, 0, 0, 0, 0 } | ||
| 68 | }; | ||
| 69 | |||
| 70 | /* Parse a single option. */ | ||
| 71 | static error_t | ||
| 72 | parse_opt (int key, char *arg, struct argp_state *state) | ||
| 73 | { | ||
| 74 | switch (key) | ||
| 75 | { | ||
| 76 | case GUIX_OPT_DISABLE_CHROOT: | ||
| 77 | settings.useChroot = false; | ||
| 78 | break; | ||
| 79 | case GUIX_OPT_DISABLE_LOG_COMPRESSION: | ||
| 80 | settings.compressLog = false; | ||
| 81 | break; | ||
| 82 | case 'C': | ||
| 83 | settings.buildCores = atoi (arg); | ||
| 84 | break; | ||
| 85 | case 'M': | ||
| 86 | settings.maxBuildJobs = atoi (arg); | ||
| 87 | break; | ||
| 88 | case GUIX_OPT_SYSTEM: | ||
| 89 | settings.thisSystem = arg; | ||
| 90 | break; | ||
| 91 | default: | ||
| 92 | return ARGP_ERR_UNKNOWN; | ||
| 93 | } | ||
| 94 | |||
| 95 | return 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | /* Argument parsing. */ | ||
| 99 | static struct argp argp = { options, parse_opt, 0, doc }; | ||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | int | ||
| 104 | main (int argc, char *argv[]) | ||
| 105 | { | ||
| 106 | Strings nothing; | ||
| 107 | |||
| 108 | settings.useChroot = true; | ||
| 109 | settings.processEnvironment (); | ||
| 110 | |||
| 111 | argp_parse (&argp, argc, argv, 0, 0, 0); | ||
| 112 | |||
| 113 | argvSaved = argv; | ||
| 114 | run (nothing); | ||
| 115 | } | ||
diff --git a/nix/nix-daemon/shared.hh b/nix/nix-daemon/shared.hh new file mode 100644 index 00000000000..a03c09c0366 --- /dev/null +++ b/nix/nix-daemon/shared.hh | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*- | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of Guix. | ||
| 5 | |||
| 6 | Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | /* Replacement for Nix's libmain/shared.hh. */ | ||
| 20 | |||
| 21 | #pragma once | ||
| 22 | |||
| 23 | #include <string> | ||
| 24 | |||
| 25 | #include <stdlib.h> | ||
| 26 | #include <signal.h> | ||
| 27 | |||
| 28 | static inline void | ||
| 29 | showManPage (const char *name) | ||
| 30 | { | ||
| 31 | /* This idea is evil. Abort. */ | ||
| 32 | abort (); | ||
| 33 | } | ||
| 34 | |||
| 35 | extern volatile ::sig_atomic_t blockInt; | ||
| 36 | |||
| 37 | extern char **argvSaved; | ||
