2023-05-24 13:37:59 +00:00
|
|
|
{ lib
|
2023-07-15 17:15:38 +00:00
|
|
|
, llvmPackages
|
2023-05-24 13:37:59 +00:00
|
|
|
, fetchFromGitHub
|
2023-07-15 17:15:38 +00:00
|
|
|
, fetchpatch
|
2023-05-24 13:37:59 +00:00
|
|
|
, cmake
|
|
|
|
, ninja
|
|
|
|
, python3
|
|
|
|
, perl
|
|
|
|
, yasm
|
2021-12-06 16:07:01 +00:00
|
|
|
, nixosTests
|
2023-07-15 17:15:38 +00:00
|
|
|
, darwin
|
|
|
|
, findutils
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
# currently for BLAKE3 hash function
|
|
|
|
, rustSupport ? true
|
|
|
|
|
|
|
|
, corrosion
|
|
|
|
, rustc
|
|
|
|
, cargo
|
|
|
|
, rustPlatform
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
let
|
|
|
|
inherit (llvmPackages) stdenv;
|
|
|
|
mkDerivation = (
|
|
|
|
if stdenv.isDarwin
|
|
|
|
then darwin.apple_sdk_11_0.llvmPackages_15.stdenv
|
|
|
|
else llvmPackages.stdenv).mkDerivation;
|
|
|
|
in mkDerivation rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "clickhouse";
|
2023-08-10 07:59:29 +00:00
|
|
|
version = "23.3.8.21";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
src = fetchFromGitHub rec {
|
2023-05-24 13:37:59 +00:00
|
|
|
owner = "ClickHouse";
|
|
|
|
repo = "ClickHouse";
|
|
|
|
rev = "v${version}-lts";
|
2020-07-18 16:06:22 +00:00
|
|
|
fetchSubmodules = true;
|
2023-07-15 17:15:38 +00:00
|
|
|
name = "clickhouse-${rev}.tar.gz";
|
2023-08-10 07:59:29 +00:00
|
|
|
hash = "sha256-bynr196H6g/GmvNTtrfB6QDdAScvYvbe7EIceoOwCKc=";
|
2023-07-15 17:15:38 +00:00
|
|
|
postFetch = ''
|
|
|
|
# delete files that make the source too big
|
|
|
|
rm -rf $out/contrib/llvm-project/llvm/test
|
|
|
|
rm -rf $out/contrib/llvm-project/clang/test
|
|
|
|
rm -rf $out/contrib/croaring/benchmarks
|
|
|
|
|
|
|
|
# fix case insensitivity on macos https://github.com/NixOS/nixpkgs/issues/39308
|
|
|
|
rm -rf $out/contrib/sysroot/linux-*
|
|
|
|
rm -rf $out/contrib/liburing/man
|
|
|
|
|
|
|
|
# compress to not exceed the 2GB output limit
|
|
|
|
# try to make a deterministic tarball
|
|
|
|
tar -I 'gzip -n' \
|
|
|
|
--sort=name \
|
|
|
|
--mtime=1970-01-01 \
|
|
|
|
--owner=0 --group=0 \
|
|
|
|
--numeric-owner --mode=go=rX,u+rw,a-s \
|
|
|
|
--transform='s@^@source/@S' \
|
|
|
|
-cf temp -C "$out" .
|
|
|
|
rm -r "$out"
|
|
|
|
mv temp "$out"
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
ninja
|
|
|
|
python3
|
|
|
|
perl
|
|
|
|
] ++ lib.optionals stdenv.isx86_64 [
|
|
|
|
yasm
|
2023-07-15 17:15:38 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
llvmPackages.bintools
|
|
|
|
findutils
|
|
|
|
darwin.bootstrap_cmds
|
2023-05-24 13:37:59 +00:00
|
|
|
] ++ lib.optionals rustSupport [
|
|
|
|
rustc
|
|
|
|
cargo
|
|
|
|
rustPlatform.cargoSetupHook
|
|
|
|
];
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
# their vendored version is too old and missing this patch: https://github.com/corrosion-rs/corrosion/pull/205
|
|
|
|
corrosionSrc = if rustSupport then fetchFromGitHub {
|
|
|
|
owner = "corrosion-rs";
|
|
|
|
repo = "corrosion";
|
|
|
|
rev = "v0.3.5";
|
|
|
|
hash = "sha256-r/jrck4RiQynH1+Hx4GyIHpw/Kkr8dHe1+vTHg+fdRs=";
|
|
|
|
} else null;
|
|
|
|
corrosionDeps = if rustSupport then rustPlatform.fetchCargoTarball {
|
|
|
|
src = corrosionSrc;
|
|
|
|
name = "corrosion-deps";
|
|
|
|
preBuild = "cd generator";
|
|
|
|
hash = "sha256-dhUgpwSjE9NZ2mCkhGiydI51LIOClA5wwk1O3mnnbM8=";
|
|
|
|
} else null;
|
2023-05-24 13:37:59 +00:00
|
|
|
blake3Deps = if rustSupport then rustPlatform.fetchCargoTarball {
|
|
|
|
inherit src;
|
|
|
|
name = "blake3-deps";
|
|
|
|
preBuild = "cd rust/BLAKE3";
|
|
|
|
hash = "sha256-lDMmmsyjEbTfI5NgTgT4+8QQrcUE/oUWfFgj1i19W0Q=";
|
|
|
|
} else null;
|
|
|
|
skimDeps = if rustSupport then rustPlatform.fetchCargoTarball {
|
|
|
|
inherit src;
|
|
|
|
name = "skim-deps";
|
|
|
|
preBuild = "cd rust/skim";
|
|
|
|
hash = "sha256-gEWB+U8QrM0yYyMXpwocszJZgOemdTlbSzKNkS0NbPk=";
|
|
|
|
} else null;
|
|
|
|
|
|
|
|
dontCargoSetupPostUnpack = true;
|
|
|
|
postUnpack = lib.optionalString rustSupport ''
|
|
|
|
pushd source
|
|
|
|
|
|
|
|
rm -rf contrib/corrosion
|
2023-08-10 07:59:29 +00:00
|
|
|
cp -r --no-preserve=mode $corrosionSrc contrib/corrosion
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
pushd contrib/corrosion/generator
|
|
|
|
cargoDeps="$corrosionDeps" cargoSetupPostUnpackHook
|
|
|
|
corrosionDepsCopy="$cargoDepsCopy"
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd rust/BLAKE3
|
|
|
|
cargoDeps="$blake3Deps" cargoSetupPostUnpackHook
|
|
|
|
blake3DepsCopy="$cargoDepsCopy"
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd rust/skim
|
|
|
|
cargoDeps="$skimDeps" cargoSetupPostUnpackHook
|
|
|
|
skimDepsCopy="$cargoDepsCopy"
|
|
|
|
popd
|
|
|
|
|
|
|
|
popd
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
postPatch = ''
|
|
|
|
patchShebangs src/
|
|
|
|
|
|
|
|
substituteInPlace src/Storages/System/StorageSystemLicenses.sh \
|
|
|
|
--replace 'git rev-parse --show-toplevel' '$src'
|
|
|
|
substituteInPlace utils/check-style/check-duplicate-includes.sh \
|
|
|
|
--replace 'git rev-parse --show-toplevel' '$src'
|
|
|
|
substituteInPlace utils/check-style/check-ungrouped-includes.sh \
|
|
|
|
--replace 'git rev-parse --show-toplevel' '$src'
|
|
|
|
substituteInPlace utils/list-licenses/list-licenses.sh \
|
|
|
|
--replace 'git rev-parse --show-toplevel' '$src'
|
|
|
|
substituteInPlace utils/check-style/check-style \
|
|
|
|
--replace 'git rev-parse --show-toplevel' '$src'
|
2023-07-15 17:15:38 +00:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
sed -i 's|gfind|find|' cmake/tools.cmake
|
|
|
|
sed -i 's|ggrep|grep|' cmake/tools.cmake
|
2023-05-24 13:37:59 +00:00
|
|
|
'' + lib.optionalString rustSupport ''
|
|
|
|
|
|
|
|
pushd contrib/corrosion/generator
|
|
|
|
cargoDepsCopy="$corrosionDepsCopy" cargoSetupPostPatchHook
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd rust/BLAKE3
|
|
|
|
cargoDepsCopy="$blake3DepsCopy" cargoSetupPostPatchHook
|
|
|
|
popd
|
|
|
|
|
|
|
|
pushd rust/skim
|
|
|
|
cargoDepsCopy="$skimDepsCopy" cargoSetupPostPatchHook
|
|
|
|
popd
|
|
|
|
|
|
|
|
cargoSetupPostPatchHook() { true; }
|
2020-07-18 16:06:22 +00:00
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
cmakeFlags = [
|
|
|
|
"-DENABLE_TESTS=OFF"
|
2023-07-15 17:15:38 +00:00
|
|
|
"-DCOMPILER_CACHE=disabled"
|
2020-12-07 07:45:13 +00:00
|
|
|
"-DENABLE_EMBEDDED_COMPILER=ON"
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
# https://github.com/ClickHouse/ClickHouse/issues/49988
|
|
|
|
hardeningDisable = [ "fortify" ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
postInstall = ''
|
|
|
|
rm -rf $out/share/clickhouse-test
|
|
|
|
|
|
|
|
sed -i -e '\!<log>/var/log/clickhouse-server/clickhouse-server\.log</log>!d' \
|
|
|
|
$out/etc/clickhouse-server/config.xml
|
|
|
|
substituteInPlace $out/etc/clickhouse-server/config.xml \
|
|
|
|
--replace "<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>" "<console>1</console>"
|
2023-05-24 13:37:59 +00:00
|
|
|
substituteInPlace $out/etc/clickhouse-server/config.xml \
|
|
|
|
--replace "<level>trace</level>" "<level>warning</level>"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
# Builds in 7+h with 2 cores, and ~20m with a big-parallel builder.
|
|
|
|
requiredSystemFeatures = [ "big-parallel" ];
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
passthru.tests.clickhouse = nixosTests.clickhouse;
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2022-09-30 11:47:45 +00:00
|
|
|
homepage = "https://clickhouse.com";
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Column-oriented database management system";
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ orivej ];
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
# not supposed to work on 32-bit https://github.com/ClickHouse/ClickHouse/pull/23959#issuecomment-835343685
|
2023-07-15 17:15:38 +00:00
|
|
|
platforms = lib.filter (x: (lib.systems.elaborate x).is64bit) (platforms.linux ++ platforms.darwin);
|
2023-05-24 13:37:59 +00:00
|
|
|
broken = stdenv.buildPlatform != stdenv.hostPlatform;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|