anchor.diff:      (mkWith   false                        "profiler"          null)
       (mkWith   false                        "debug"             null)
       (mkEnable false                        "coverage"          null)
  -    (mkWith   (fuse != null)               "fuse"              null)
  -    (mkWith   (malloc == jemalloc)         "jemalloc"          null)
  -    (mkWith   (malloc == gperftools)       "tcmalloc"          null)
  +    (mkWith   (optFuse != null)            "fuse"              null)
  +    (mkWith   (malloc == optJemalloc)      "jemalloc"          null)
  +    (mkWith   (malloc == optGperftools)    "tcmalloc"          null)
       (mkEnable false                        "pgrefdebugging"    null)
       (mkEnable false                        "cephfs-java"       null)
       (mkEnable hasXio                       "xio"               null)
  -    (mkWith   (libatomic_ops != null)      "libatomic-ops"     null)
  +    (mkWith   (optLibatomic_ops != null)   "libatomic-ops"     null)
       (mkWith   true                         "ocf"               null)
       (mkWith   hasKinetic                   "kinetic"           null)
       (mkWith   hasRocksdb                   "librocksdb"        null)
       (mkWith   false                        "librocksdb-static" null)
  -    (mkWith   (libs3 != null)              "system-libs3"      null)
  +    (mkWith   (optLibs3 != null)           "system-libs3"      null)
       (mkWith   true                         "rest-bench"        null)
     ] ++ optional stdenv.isLinux [
  -    (mkWith   (libaio != null)             "libaio"            null)
  -    (mkWith   (libxfs != null)             "libxfs"            null)
  -    (mkWith   (zfs != null)                "libzfs"            null)
  +    (mkWith   (optLibaio != null)             "libaio"            null)
  +    (mkWith   (optLibxfs != null)             "libxfs"            null)
  +    (mkWith   (optZfs != null)                "libzfs"            null)
     ] ++ optional (versionAtLeast version "10.0.0") [
       (mkWith   true                         "man-pages"         null)
       (mkWith   false                        "tcmalloc-minimal"  null)
  
positive.code: 
    nativeBuildInputs = [ autoconf automake makeWrapper pkgconfig libtool which ];
    buildInputs = buildInputs ++ cryptoLibsMap.${cryptoStr} ++ [
      boost python libxml2 yasm libatomic_ops libs3 malloc pythonPackages.flask zlib
    ] ++ optional (versionAtLeast version "9.0.0") [
      git                   # Used for the gitversion string
      pythonPackages.sphinx # Used for docs
    ] ++ optional stdenv.isLinux [
      linuxHeaders libuuid udev keyutils libaio libxfs zfs
    ] ++ optional hasServer [
      snappy leveldb
    ] ++ optional hasRadosgw [
      fcgi expat curl fuse libedit
    ] ++ optional hasXio [
      accelio libibverbs librdmacm
    ] ++ optional hasRocksdb [
      rocksdb
    ] ++ optional hasKinetic [
      kinetic-cpp-client
    ];
  
    postPatch = ''
  
negative.code: # We must have one crypto library
  assert cryptopp != null || (nss != null && nspr != null);
  
  with stdenv;
  with stdenv.lib;
  let
    optSnappy = shouldUsePkg snappy;
    optLeveldb = shouldUsePkg leveldb;
    optYasm = shouldUsePkg yasm;
    optFcgi = shouldUsePkg fcgi;
    optExpat = shouldUsePkg expat;
    optCurl = shouldUsePkg curl;
    optFuse = shouldUsePkg fuse;
    optAccelio = shouldUsePkg accelio;
    optLibibverbs = shouldUsePkg libibverbs;
    optLibrdmacm = shouldUsePkg librdmacm;
    optLibedit = shouldUsePkg libedit;
    optLibatomic_ops = shouldUsePkg libatomic_ops;
    optKinetic-cpp-client = shouldUsePkg kinetic-cpp-client;
    optRocksdb = shouldUsePkg rocksdb;
    optLibs3 = shouldUsePkg libs3;
  
    optJemalloc = shouldUsePkg jemalloc;
    optGperftools = shouldUsePkg gperftools;
  
    optCryptopp = shouldUsePkg cryptopp;
    optNss = shouldUsePkg nss;
    optNspr = shouldUsePkg nspr;
  
    optLibaio = shouldUsePkg libaio;
    optLibxfs = shouldUsePkg libxfs;
    optZfs = shouldUsePkg zfs;
  
    hasServer = optSnappy != null && optLeveldb != null;
    hasMon = hasServer;
    hasMds = hasServer;
    hasOsd = hasServer;
    hasRadosgw = optFcgi != null && optExpat != null && optCurl != null && optLibedit != null;
  
    hasXio = (stdenv.isLinux || stdenv.isFreeBSD) &&
      versionAtLeast version "0.95" &&
      optAccelio != null && optLibibverbs != null && optLibrdmacm != null;
  
    hasRocksdb = versionAtLeast version "0.95" && optRocksdb != null;
  
    # TODO: Reenable when kinetic support is fixed
    #hasKinetic = versionAtLeast version "0.95" && optKinetic-cpp-client != null;
    hasKinetic = false;
  
    # Malloc implementation (can be jemalloc, tcmalloc or null)
    malloc = if optJemalloc != null then optJemalloc else optGperftools;
  
    # We prefer nss over cryptopp
    cryptoStr = if optNss != null && optNspr != null then "nss" else
      if optCryptopp != null then "cryptopp" else "none";
    cryptoLibsMap = {
      nss = [ optNss optNspr ];
      cryptopp = [ optCryptopp ];
      none = [ ];
    };
  
  