;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2018 Marius Bakke ;;; Copyright © 2017 Rutger Helling ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu packages storage) #:use-module (guix download) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix packages) #:use-module (guix utils) #:use-module (guix build-system cmake) #:use-module (gnu packages) #:use-module (gnu packages admin) #:use-module (gnu packages assembly) #:use-module (gnu packages authentication) #:use-module (gnu packages bdw-gc) #:use-module (gnu packages boost) #:use-module (gnu packages check) #:use-module (gnu packages compression) #:use-module (gnu packages crypto) #:use-module (gnu packages cryptsetup) #:use-module (gnu packages curl) #:use-module (gnu packages databases) #:use-module (gnu packages disk) #:use-module (gnu packages gcc) #:use-module (gnu packages gnuzilla) #:use-module (gnu packages gperf) #:use-module (gnu packages jemalloc) #:use-module (gnu packages linux) #:use-module (gnu packages lua) #:use-module (gnu packages openldap) #:use-module (gnu packages perl) #:use-module (gnu packages pkg-config) #:use-module (gnu packages python) #:use-module
#pragma once

#include "config.h"
#include "types.hh"

#include <map>
#include <sys/types.h>


namespace nix {

enum CompressionType
{
    COMPRESSION_NONE = 0,
    COMPRESSION_GZIP = 1
#if HAVE_BZLIB_H
    , COMPRESSION_BZIP2 = 2
#endif
};

struct Settings {

    typedef std::map<string, string> SettingsMap;

    Settings();

    void processEnvironment();

    void set(const string & name, const string & value);

    string get(const string & name, const string & def);

    Strings get(const string & name, const Strings & def);

    bool get(const string & name, bool def);

    int get(const string & name, int def);

    void update();

    string pack();

    SettingsMap getOverrides();

    /* The directory where we store sources and derived files. */
    Path nixStore;

    /* The directory where we log various operations. */
    Path nixLogDir;

    /* The directory where state is stored. */
    Path nixStateDir;

    /* The directory where we keep the SQLite database. */
    Path nixDBPath;

    /* The directory where configuration files are stored. */
    Path nixConfDir;

    /* The directory where the main programs are stored. */
    Path nixBinDir;

    /* File name of the socket the daemon listens to.  */
    Path nixDaemonSocketFile;

    /* Absolute file name of the 'guix' program.  */
    Path guixProgram;

    /* Whether to keep temporary directories of failed builds. */
    bool keepFailed;

    /* Whether to keep building subgoals when a sibling (another
       subgoal of the same goal) fails. */
    bool keepGoing;

    /* User and groud id of the client issuing the build request.  Used to set
       the owner and group of the kept temporary directories of failed
       builds. */
    uid_t clientUid;
    gid_t clientGid;

    /* Whether, if we cannot realise the known closure corresponding
       to a derivation, we should try to normalise the derivation
       instead. */
    bool tryFallback;

    /* Verbosity level for build output. */
    Verbosity buildVerbosity;

    /* Maximum number of parallel build jobs.  0 means unlimited. */
    unsigned int maxBuildJobs;

    /* Number of CPU cores to utilize in parallel within a build,
       i.e. by passing this number to Make via '-j'. 0 means that the
       number of actual CPU cores on the local host ought to be
       auto-detected. */
    unsigned int buildCores;

    /* Read-only mode.  Don't copy stuff to the store, don't change
       the database. */
    bool readOnlyMode;

    /* The canonical system name, as returned by config.guess. */
    string thisSystem;

    /* The maximum time in seconds that a builer can go without
       producing any output on stdout/stderr before it is killed.  0
       means infinity. */
    time_t maxSilentTime;

    /* The maximum duration in seconds that a builder can run.  0
       means infinity.  */
    time_t buildTimeout;

    /* Whether to use build hooks (for distributed builds).  Sometimes
       users want to disable this from the command-line. */
    bool useBuildHook;

    /* Whether buildDerivations() should print out lines on stderr in
       a fixed format to allow its progress to be monitored.  Each
       line starts with a "@".  The following are defined:

       @ build-started <drvpath> <outpath> <system> <logfile> <pid>
       @ build-failed <drvpath> <outpath> <exitcode> <error text>
       @ build-succeeded <drvpath> <outpath>
       @ substituter-started <outpath> <substituter>
       @ substituter-failed <outpath> <exitcode> <error text>
       @ substituter-succeeded <outpath>

       Best combined with --no-build-output, otherwise stderr might
       conceivably contain lines in this format printed by the
       builders. */
    bool printBuildTrace;

    /* When true, 'buildDerivations' prefixes lines coming from builders so
       that clients know exactly which line comes from which builder, and
       which line comes from the daemon itself.  The prefix for data coming
       from builders is "log:PID:LEN:DATA" where PID uniquely identifies the
       builder (PID is given in "build-started" traces.)  */
    bool multiplexedBuildOutput;

    /* Amount of reserved space for the garbage collector
       (/nix/var/nix/db/reserved). */
    off_t reservedSize;

    /* Whether SQLite should use fsync. */
    bool fsyncMetadata;

    /* Whether SQLite should use WAL mode. */
    bool useSQLiteWAL;

    /* Whether to call sync() before registering a path as valid. */
    bool syncBeforeRegistering;

    /* Whether to use substitutes. */
    bool useSubstitutes;

    /* The Unix group that contains the build users. */
    string buildUsersGroup;

    /* Whether to build in chroot. */
    bool useChroot;

    /* Whether to impersonate a Linux 2.6 machine on newer kernels. */
    bool impersonateLinux26;

    /* Whether to store build logs. */
    bool keepLog;

    /* Whether to compress logs. */
    enum CompressionType logCompression;

    /* Maximum number of bytes a builder can write to stdout/stderr
       before being killed (0 means no limit). */
    unsigned long maxLogSize;

    /* Whether to cache build failures. */
    bool cacheFailure;

    /* How often (in seconds) to poll for locks. */
    unsigned int pollInterval;

    /* Whether to check if new GC roots can in fact be found by the
       garbage collector. */
    bool checkRootReachability;

    /* Whether the garbage collector should keep outputs of live
       derivations. */
    bool gcKeepOutputs;

    /* Whether the garbage collector should keep derivers of live
       paths. */
    bool gcKeepDerivations;

    /* Whether to automatically replace files with identical contents
       with hard links. */
    bool autoOptimiseStore;

    /* Whether to add derivations as a dependency of user environments
       (to prevent them from being GCed). */
    bool envKeepDerivations;

    /* Whether to lock the Nix client and worker to the same CPU. */
    bool lockCPU;

    /* Whether to show a stack trace if Nix evaluation fails. */
    bool showTrace;

private:
    SettingsMap settings, overrides;

    void _get(string & res, const string & name);
    void _get(bool & res, const string & name);
    void _get(StringSet & res, const string & name);
    void _get(Strings & res, const string & name);
    template<class N> void _get(N & res, const string & name);
};


// FIXME: don't use a global variable.
extern Settings settings;


extern const string nixVersion;


}
_test\\(cephtool-test-mon\\.sh.*$") "\n") ;; This fails due to missing '/etc/fstab'. (("^add_ceph_test\\(cephtool-test-rados\\.sh.*$") "\n") ;; `Bad messages to stderr: OSD has the store locked' (("^add_ceph_test\\(ceph_objectstore_tool\\.py.*$") "\n") ;; The bundled python-cram fork needs patching to work on ;; guix, and the system version does not support --error-dir. ;; https://bitbucket.org/brodie/cram/issues/9 (("^add_ceph_test\\(run-cli-tests.*$") "\n") ;; FIXME: tox/virtualenv/pip does not discover the ;; required packages and tries to go online. (("^add_test\\(NAME run-tox-ceph-disk.*$") "\n") (("^add_test\\(NAME run-tox-ceph-detect-init.*$") "\n") ;; Also remove from the set_property block. (("run-tox-ceph-disk") "") (("run-tox-ceph-detect-init") "")) ;; TODO: This also seems to fail because of /etc/os-release. ;; How to make src/common/util.cc behave without it. (substitute* "src/test/crush/CMakeLists.txt" (("^add_ceph_test\\(crush-classes\\.sh.*$") "\n")) ;; More 'ceph-disk' issues here.. :-( (substitute* "src/test/erasure-code/CMakeLists.txt" (("^add_ceph_test\\(test-erasure-code-plugins\\.sh.*$") "\n") (("^add_ceph_test\\(test-erasure-code\\.sh.*$") "\n") (("^add_ceph_test\\(test-erasure-eio\\.sh.*$") "\n")) (substitute* "src/test/libradosstriper/CMakeLists.txt" (("^add_ceph_test\\(rados-striper\\.sh.*$") "\n")) (substitute* "src/test/mon/CMakeLists.txt" (("^add_ceph_test\\(osd-crush\\.sh.*$") "\n") (("^add_ceph_test\\(test_pool_quota\\.sh.*$") "\n") (("^add_ceph_test\\(osd-pool-create\\.sh.*$") "\n")) (substitute* "src/test/osd/CMakeLists.txt" (("^add_ceph_test\\(osd-bench\\.sh.*$") "\n") (("^add_ceph_test\\(osd-config\\.sh.*$") "\n") (("add_ceph_test\\(osd-dup\\.sh.*$") "\n") (("^add_ceph_test\\(osd-markdown\\.sh.*$") "\n") (("^add_ceph_test\\(osd-reactivate\\.sh.*$") "\n") (("^add_ceph_test\\(osd-reuse-id\\.sh.*$") "\n") (("^add_ceph_test\\(osd-scrub-repair\\.sh.*$") "\n") (("^add_ceph_test\\(osd-scrub-snaps\\.sh.*$") "\n") (("^add_ceph_test\\(osd-copy-from\\.sh.*$") "\n") (("^add_ceph_test\\(osd-fast-mark-down\\.sh.*$") "\n")) #t))) (add-before 'configure 'gcc-workaround (lambda _ (unsetenv "C_INCLUDE_PATH") (unsetenv "CPLUS_INCLUDE_PATH") #t)) (add-before 'check 'set-check-environment (lambda _ ;; Run tests in parallel. (setenv "CTEST_PARALLEL_LEVEL" (number->string (parallel-job-count))) ;; `pip' requires write access in $HOME. (setenv "HOME" "/tmp") #t)) (add-before 'install 'set-install-environment (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (py2sitedir (string-append out "/lib/python2.7/site-packages")) (py3sitedir (string-append out "/lib/python" ,(version-major+minor (package-version python)) "/site-packages"))) ;; The Python install scripts refuses to function if ;; the install directory is not on PYTHONPATH. (setenv "PYTHONPATH" (string-append py2sitedir ":" py3sitedir ":" (getenv "PYTHONPATH"))) #t))) (add-after 'install 'wrap-python-scripts (lambda* (#:key inputs outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (scripts '("ceph" "ceph-mgr" "ceph-volume" "ceph-detect-init" "ceph-disk")) ;deprecated (prettytable (assoc-ref inputs "python2-prettytable")) (six (assoc-ref inputs "python2-six")) (sitedir (lambda (package) (string-append package "/lib/python2.7/site-packages"))) (PYTHONPATH (string-append (sitedir out) ":" (sitedir six) ":" (sitedir prettytable)))) (for-each (lambda (executable) (wrap-program (string-append out "/bin/" executable) `("PYTHONPATH" ":" prefix (,PYTHONPATH)))) scripts) #t)))))) (outputs '("out" "lib")) (native-inputs `(("gcc" ,gcc-7) ;7 or later is required ("gperf" ,gperf) ("pkg-config" ,pkg-config) ("python-cython" ,python-cython) ("python-sphinx" ,python-sphinx) ("yasm" ,yasm) ;; For tests. ("inetutils" ,inetutils) ("jq" ,jq) ("perl" ,perl) ("xmlstarlet" ,xmlstarlet) ("python2-cram" ,python2-cram) ("python2-virtualenv" ,python2-virtualenv) ;; These dependencies are taken from test-requirements.txt ;; of ceph-disk and ceph-detect-init. The latter can also ;; test against python3, but let's try to get python2 tests ;; working first since that is the default. ("python2-configobj" ,python2-configobj) ("python2-coverage" ,python2-coverage) ("python2-discover" ,python2-discover) ("python2-fixtures" ,python2-fixtures) ("python2-flake8" ,python2-flake8) ("python2-mock" ,python2-mock) ("python2-nose" ,python2-nose) ("python2-pip" ,python2-pip) ("python2-pytest" ,python2-pytest) ("python2-subunit" ,python2-subunit) ("python2-testrepository" ,python2-testrepository) ("python2-testtools" ,python2-testtools) ("python2-tox" ,python2-tox))) (inputs `(("boost" ,boost) ("curl" ,curl) ("cryptsetup" ,cryptsetup) ("expat" ,expat) ("fcgi" ,fcgi) ("fuse" ,fuse) ("gptfdisk" ,gptfdisk) ("jemalloc" ,jemalloc) ("keyutils" ,keyutils) ("leveldb" ,leveldb) ("libaio" ,libaio) ("libatomic-ops" ,libatomic-ops) ("lua" ,lua) ("lz4" ,lz4) ("oath-toolkit" ,oath-toolkit) ("openldap" ,openldap) ("openssl" ,openssl) ("nss" ,nss) ("parted" ,parted) ("python@2" ,python-2) ("python2-prettytable" ,python2-prettytable) ;used by ceph_daemon.py ("python2-six" ,python2-six) ;for ceph-mgr + plugins ("python@3" ,python-3) ("rapidjson" ,rapidjson) ("rocksdb" ,rocksdb) ("snappy" ,snappy) ("udev" ,eudev) ("util-linux" ,util-linux) ("zlib" ,zlib))) (home-page "https://ceph.com/") (synopsis "Distributed object store and file system") (description "Ceph is a distributed storage system designed for reliability and performance. It provides network-based block devices (RBD), a POSIX compliant file system (CephFS), and offers compatibility with various storage protocols (S3, NFS, and others) through the RADOS gateway.") ;; The Ceph libraries are LGPL2.1 and most of the utilities fall under ;; GPL2. The installed erasure code plugins are BSD-3 licensed and do ;; not use the GPL code. The source archive includes a number of files ;; carrying other licenses; consult COPYING for more information. Note ;; that COPYING does not cover third-party bundled software. (license (list license:lgpl2.1 license:gpl2 ;some files are 'or later' license:cc-by-sa3.0 ;documentation license:bsd-3 ;isa-l,jerasure,++ license:expat)))) ;civetweb,java bindings