<commit_before>{ stdenv, autoconf, automake, makeWrapper, pkgconfig, libtool, which, git
, boost, python, pythonPackages, libxml2, zlib

# Optional Dependencies
, snappy ? null, leveldb ? null, yasm ? null, fcgi ? null, expat ? null
, curl ? null, fuse ? null, accelio ? null, libibverbs ? null, librdmacm ? null
, libedit ? null, libatomic_ops ? null, kinetic-cpp-client ? null
, rocksdb ? null, libs3 ? null

# Mallocs
, jemalloc ? null, gperftools ? null

# Crypto Dependencies
, cryptopp ? null
, nss ? null, nspr ? null

# Linux Only Dependencies
, linuxHeaders, libuuid, udev, keyutils, libaio ? null, libxfs ? null
, zfs ? null

# Version specific arguments
, version, src, patches ? [], buildInputs ? []
, ...
}:

# We must have one crypto library
assert cryptopp != null || (nss != null && nspr != null);

with stdenv;
with stdenv.lib;
let
  mkFlag = trueStr: falseStr: cond: name: val:
    if cond == null then null else
      "--${if cond != false then trueStr else falseStr}${name}"
      + "${if val != null && cond != false then "=${val}" else ""}";

  mkEnable = mkFlag "enable-" "disable-";
  mkWith = mkFlag "with-" "without-";
  mkOther = mkFlag "" "" true;

  shouldUsePkg = pkg_: let pkg = (builtins.tryEval pkg_).value;
    in if lib.any (x: x == system) (pkg.meta.platforms or [])
      then pkg else null;

  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 = if versionAtLeast version "10.0.0" then null else 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 "9.0.3" &&
    optAccelio != null && optLibibverbs != null && optLibrdmacm != null;

  hasRocksdb = versionAtLeast version "9.0.0" && optRocksdb != null;

  # TODO: Reenable when kinetic support is fixed
  #hasKinetic = versionAtLeast version "9.0.0" && 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 = [ ];
  };

  wrapArgs = "--set PYTHONPATH \"$(toPythonPath $lib)\""
    + " --prefix PYTHONPATH : \"$(toPythonPath ${python.modules.readline})\""
    + " --prefix PYTHONPATH : \"$(toPythonPath ${pythonPackages.flask})\""
    + " --set PATH \"$out/bin\"";
in
stdenv.mkDerivation {
  name="ceph-${version}";

  inherit src;

  patches = patches ++ [
    ./0001-Makefile-env-Don-t-force-sbin.patch
  ];

  nativeBuildInputs = [ autoconf automake makeWrapper pkgconfig libtool which git ]
    ++ optionals (versionAtLeast version "9.0.2") [
      pythonPackages.setuptools pythonPackages.argparse
    ];
  buildInputs = buildInputs ++ cryptoLibsMap.${cryptoStr} ++ [
    boost python libxml2 optYasm optLibatomic_ops optLibs3 malloc pythonPackages.flask zlib
  ] ++ optional (versionAtLeast version "9.0.0") [
    pythonPackages.sphinx # Used for docs
  ] ++ optional stdenv.isLinux [
    linuxHeaders libuuid udev keyutils optLibaio optLibxfs optZfs
  ] ++ optional hasServer [
    optSnappy optLeveldb
  ] ++ optional hasRadosgw [
    optFcgi optExpat optCurl optFuse optLibedit<commit_msg>ceph: possible fix for zip timestamps<commit_after>{ stdenv, ensureNewerSourcesHook, autoconf, automake, makeWrapper, pkgconfig
, libtool, which, git
, boost, python, pythonPackages, libxml2, zlib

# Optional Dependencies
, snappy ? null, leveldb ? null, yasm ? null, fcgi ? null, expat ? null
, curl ? null, fuse ? null, accelio ? null, libibverbs ? null, librdmacm ? null
, libedit ? null, libatomic_ops ? null, kinetic-cpp-client ? null
, rocksdb ? null, libs3 ? null

# Mallocs
, jemalloc ? null, gperftools ? null

# Crypto Dependencies
, cryptopp ? null
, nss ? null, nspr ? null

# Linux Only Dependencies
, linuxHeaders, libuuid, udev, keyutils, libaio ? null, libxfs ? null
, zfs ? null

# Version specific arguments
, version, src, patches ? [], buildInputs ? []
, ...
}:

# We must have one crypto library
assert cryptopp != null || (nss != null && nspr != null);

with stdenv;
with stdenv.lib;
let
  mkFlag = trueStr: falseStr: cond: name: val:
    if cond == null then null else
      "--${if cond != false then trueStr else falseStr}${name}"
      + "${if val != null && cond != false then "=${val}" else ""}";

  mkEnable = mkFlag "enable-" "disable-";
  mkWith = mkFlag "with-" "without-";
  mkOther = mkFlag "" "" true;

  shouldUsePkg = pkg_: let pkg = (builtins.tryEval pkg_).value;
    in if lib.any (x: x == system) (pkg.meta.platforms or [])
      then pkg else null;

  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 = if versionAtLeast version "10.0.0" then null else 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 "9.0.3" &&
    optAccelio != null && optLibibverbs != null && optLibrdmacm != null;

  hasRocksdb = versionAtLeast version "9.0.0" && optRocksdb != null;

  # TODO: Reenable when kinetic support is fixed
  #hasKinetic = versionAtLeast version "9.0.0" && 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 = [ ];
  };

  wrapArgs = "--set PYTHONPATH \"$(toPythonPath $lib)\""
    + " --prefix PYTHONPATH : \"$(toPythonPath ${python.modules.readline})\""
    + " --prefix PYTHONPATH : \"$(toPythonPath ${pythonPackages.flask})\""
    + " --set PATH \"$out/bin\"";
in
stdenv.mkDerivation {
  name="ceph-${version}";

  inherit src;

  patches = patches ++ [
    ./0001-Makefile-env-Don-t-force-sbin.patch
  ];

  nativeBuildInputs = [
    autoconf automake makeWrapper pkgconfig libtool which git
    (ensureNewerSourcesHook { year = "1980"; })
  ]
    ++ optionals (versionAtLeast version "9.0.2") [
      pythonPackages.setuptools pythonPackages.argparse
    ];
  buildInputs = buildInputs ++ cryptoLibsMap.${cryptoStr} ++ [
    boost python libxml2 optYasm optLibatomic_ops optLibs3 malloc pythonPackages.flask zlib
  ] ++ optional (versionAtLeast version "9.0.0") [
    pythonPackages.sphinx # Used for docs
  ] ++ optional stdenv.isLinux [
    linuxHeaders libuuid udev keyutils optLibaio optLibxfs optZfs
  ] ++ optional hasServer [
    optSnappy optLeveldb
  ] ++ optional hasRadosgw [
    optFcgi optExpat optCurl optFuse optLibedit
{'fraction_non_alphanumeric': 0.11743077099850627, 'fraction_numerical': 0.007123980236699989, 'mean_word_length': 3.814159292035398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '397695', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3047, 'n_words': 816}