2023-04-21 22:40:09 +02:00
|
|
|
{ lib
|
2023-06-12 19:39:12 +02:00
|
|
|
, llvmPackages
|
2023-04-21 22:40:09 +02:00
|
|
|
, fetchFromGitHub
|
2023-06-25 19:18:39 +02:00
|
|
|
, fetchpatch
|
2023-04-21 22:40:09 +02:00
|
|
|
, cmake
|
|
|
|
, ninja
|
|
|
|
, python3
|
|
|
|
, perl
|
2023-11-12 07:30:34 +01:00
|
|
|
, nasm
|
2023-04-21 22:40:09 +02:00
|
|
|
, yasm
|
2021-11-21 20:38:57 +01:00
|
|
|
, nixosTests
|
2023-06-12 19:39:12 +02:00
|
|
|
, darwin
|
|
|
|
, findutils
|
2024-04-04 22:48:58 +02:00
|
|
|
, libiconv
|
2023-05-18 14:41:03 +02:00
|
|
|
|
|
|
|
, rustSupport ? true
|
|
|
|
|
|
|
|
, corrosion
|
|
|
|
, rustc
|
|
|
|
, cargo
|
|
|
|
, rustPlatform
|
2018-06-11 10:37:06 +02:00
|
|
|
}:
|
2017-03-27 03:06:23 +02:00
|
|
|
|
2023-06-12 19:39:12 +02:00
|
|
|
let
|
|
|
|
inherit (llvmPackages) stdenv;
|
|
|
|
mkDerivation = (
|
|
|
|
if stdenv.isDarwin
|
2023-11-12 07:30:34 +01:00
|
|
|
then darwin.apple_sdk_11_0.llvmPackages_16.stdenv
|
2023-06-12 19:39:12 +02:00
|
|
|
else llvmPackages.stdenv).mkDerivation;
|
|
|
|
in mkDerivation rec {
|
2019-08-15 14:41:18 +02:00
|
|
|
pname = "clickhouse";
|
2024-04-04 22:48:58 +02:00
|
|
|
version = "24.3.2.23";
|
2021-05-08 14:50:53 +02:00
|
|
|
|
2023-06-05 23:39:51 +02:00
|
|
|
src = fetchFromGitHub rec {
|
2023-04-21 22:40:09 +02:00
|
|
|
owner = "ClickHouse";
|
|
|
|
repo = "ClickHouse";
|
2024-04-04 22:48:58 +02:00
|
|
|
rev = "v${version}-lts";
|
2020-07-07 18:57:20 +02:00
|
|
|
fetchSubmodules = true;
|
2023-06-21 08:50:22 +02:00
|
|
|
name = "clickhouse-${rev}.tar.gz";
|
2024-04-04 22:48:58 +02:00
|
|
|
hash = "sha256-2OdlePEFJu4k2ysSPqa3kwsPgVRIlaU1B80LmU5w0yQ=";
|
2023-06-05 23:39:51 +02:00
|
|
|
postFetch = ''
|
2023-06-12 19:39:12 +02:00
|
|
|
# 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
|
2023-06-21 08:50:22 +02:00
|
|
|
|
|
|
|
# compress to not exceed the 2GB output limit
|
|
|
|
# try to make a deterministic tarball
|
|
|
|
tar -I 'gzip -n' \
|
|
|
|
--sort=name \
|
|
|
|
--mtime=1970-01-01 \
|
2023-06-25 19:18:39 +02:00
|
|
|
--owner=0 --group=0 \
|
2023-06-21 08:50:22 +02:00
|
|
|
--numeric-owner --mode=go=rX,u+rw,a-s \
|
|
|
|
--transform='s@^@source/@S' \
|
|
|
|
-cf temp -C "$out" .
|
|
|
|
rm -r "$out"
|
|
|
|
mv temp "$out"
|
2023-06-05 23:39:51 +02:00
|
|
|
'';
|
2017-03-27 03:06:23 +02:00
|
|
|
};
|
|
|
|
|
2023-12-07 13:10:01 +01:00
|
|
|
patches = [
|
|
|
|
# They updated the Cargo.toml without updating the Cargo.lock :/
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/ClickHouse/ClickHouse/commit/bccd33932b5fe17ced2dc2f27813da0b1c034afa.patch";
|
|
|
|
revert = true;
|
|
|
|
hash = "sha256-4idwr+G8WGuT/VILKtDIJIvbCvi6pZokJFze4dP6ExE=";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/ClickHouse/ClickHouse/commit/b6bd5ecb199ef8a10e3008a4ea3d96087db8a8c1.patch";
|
|
|
|
revert = true;
|
|
|
|
hash = "sha256-nbb/GV2qWEZ+BEfT6/9//yZf4VWdhOdJCI3PLeh6o0M=";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2023-04-21 22:40:09 +02:00
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
ninja
|
|
|
|
python3
|
|
|
|
perl
|
2023-11-12 07:30:34 +01:00
|
|
|
llvmPackages.lld
|
2023-04-21 22:40:09 +02:00
|
|
|
] ++ lib.optionals stdenv.isx86_64 [
|
2023-11-12 07:30:34 +01:00
|
|
|
nasm
|
2023-04-21 22:40:09 +02:00
|
|
|
yasm
|
2023-06-12 19:39:12 +02:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
llvmPackages.bintools
|
|
|
|
findutils
|
|
|
|
darwin.bootstrap_cmds
|
2023-05-18 14:41:03 +02:00
|
|
|
] ++ lib.optionals rustSupport [
|
|
|
|
rustc
|
|
|
|
cargo
|
|
|
|
rustPlatform.cargoSetupHook
|
2023-04-21 22:40:09 +02:00
|
|
|
];
|
2017-03-27 03:06:23 +02:00
|
|
|
|
2024-04-04 22:48:58 +02:00
|
|
|
buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
|
|
|
|
|
2023-08-06 22:13:19 +02: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-11-12 07:30:34 +01:00
|
|
|
rustDeps = if rustSupport then rustPlatform.fetchCargoTarball {
|
2023-05-18 14:41:03 +02:00
|
|
|
inherit src;
|
2023-11-12 07:30:34 +01:00
|
|
|
name = "rust-deps";
|
|
|
|
preBuild = "cd rust";
|
2024-04-04 22:48:58 +02:00
|
|
|
hash = "sha256-rbEfCRB2QAZ2WBgSLYYUqeYtI4Y5d9oQ2G8/mPirIp4=";
|
2023-05-18 14:41:03 +02:00
|
|
|
} else null;
|
|
|
|
|
|
|
|
dontCargoSetupPostUnpack = true;
|
|
|
|
postUnpack = lib.optionalString rustSupport ''
|
|
|
|
pushd source
|
|
|
|
|
|
|
|
rm -rf contrib/corrosion
|
2023-08-06 22:13:19 +02:00
|
|
|
cp -r --no-preserve=mode $corrosionSrc contrib/corrosion
|
2023-05-18 14:41:03 +02:00
|
|
|
|
|
|
|
pushd contrib/corrosion/generator
|
|
|
|
cargoDeps="$corrosionDeps" cargoSetupPostUnpackHook
|
|
|
|
corrosionDepsCopy="$cargoDepsCopy"
|
|
|
|
popd
|
|
|
|
|
2023-11-12 07:30:34 +01:00
|
|
|
pushd rust
|
|
|
|
cargoDeps="$rustDeps" cargoSetupPostUnpackHook
|
|
|
|
rustDepsCopy="$cargoDepsCopy"
|
|
|
|
cat .cargo/config >> .cargo/config.toml.in
|
|
|
|
cat .cargo/config >> skim/.cargo/config.toml.in
|
|
|
|
rm .cargo/config
|
2023-05-18 14:41:03 +02:00
|
|
|
popd
|
|
|
|
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
|
2020-07-07 18:57:20 +02: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-06-12 19:39:12 +02:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
sed -i 's|gfind|find|' cmake/tools.cmake
|
|
|
|
sed -i 's|ggrep|grep|' cmake/tools.cmake
|
2023-05-18 14:41:03 +02:00
|
|
|
'' + lib.optionalString rustSupport ''
|
|
|
|
|
|
|
|
pushd contrib/corrosion/generator
|
|
|
|
cargoDepsCopy="$corrosionDepsCopy" cargoSetupPostPatchHook
|
|
|
|
popd
|
|
|
|
|
2023-11-12 07:30:34 +01:00
|
|
|
pushd rust
|
|
|
|
cargoDepsCopy="$rustDepsCopy" cargoSetupPostPatchHook
|
2023-05-18 14:41:03 +02:00
|
|
|
popd
|
|
|
|
|
|
|
|
cargoSetupPostPatchHook() { true; }
|
2023-11-15 11:49:06 +01:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
# Make sure Darwin invokes lld.ld64 not lld.
|
|
|
|
substituteInPlace cmake/tools.cmake \
|
|
|
|
--replace '--ld-path=''${LLD_PATH}' '-fuse-ld=lld'
|
2020-07-07 18:57:20 +02:00
|
|
|
'';
|
|
|
|
|
2018-08-08 00:54:32 +02:00
|
|
|
cmakeFlags = [
|
|
|
|
"-DENABLE_TESTS=OFF"
|
2023-06-12 19:39:12 +02:00
|
|
|
"-DCOMPILER_CACHE=disabled"
|
2020-12-05 13:45:15 +01:00
|
|
|
"-DENABLE_EMBEDDED_COMPILER=ON"
|
2019-01-06 05:16:10 +01:00
|
|
|
];
|
|
|
|
|
2024-04-04 22:48:58 +02:00
|
|
|
env = {
|
|
|
|
NIX_CFLAGS_COMPILE =
|
|
|
|
# undefined reference to '__sync_val_compare_and_swap_16'
|
|
|
|
lib.optionalString stdenv.isx86_64 " -mcx16" +
|
|
|
|
# Silence ``-Wimplicit-const-int-float-conversion` error in MemoryTracker.cpp and
|
|
|
|
# ``-Wno-unneeded-internal-declaration` TreeOptimizer.cpp.
|
|
|
|
lib.optionalString stdenv.isDarwin " -Wno-implicit-const-int-float-conversion -Wno-unneeded-internal-declaration";
|
2023-11-15 11:49:06 +01:00
|
|
|
};
|
|
|
|
|
2023-06-25 19:18:39 +02:00
|
|
|
# https://github.com/ClickHouse/ClickHouse/issues/49988
|
|
|
|
hardeningDisable = [ "fortify" ];
|
|
|
|
|
2018-07-29 00:56:04 +02:00
|
|
|
postInstall = ''
|
|
|
|
rm -rf $out/share/clickhouse-test
|
2018-12-19 15:06:53 +01:00
|
|
|
|
|
|
|
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>"
|
2022-09-12 06:53:11 +02:00
|
|
|
substituteInPlace $out/etc/clickhouse-server/config.xml \
|
|
|
|
--replace "<level>trace</level>" "<level>warning</level>"
|
2018-07-29 00:56:04 +02:00
|
|
|
'';
|
|
|
|
|
2021-04-25 16:36:22 +02:00
|
|
|
# Builds in 7+h with 2 cores, and ~20m with a big-parallel builder.
|
|
|
|
requiredSystemFeatures = [ "big-parallel" ];
|
|
|
|
|
2021-11-21 20:38:57 +01:00
|
|
|
passthru.tests.clickhouse = nixosTests.clickhouse;
|
|
|
|
|
2021-01-11 08:54:33 +01:00
|
|
|
meta = with lib; {
|
2022-09-03 11:33:45 +02:00
|
|
|
homepage = "https://clickhouse.com";
|
2017-03-27 03:06:23 +02:00
|
|
|
description = "Column-oriented database management system";
|
|
|
|
license = licenses.asl20;
|
2024-04-04 22:48:58 +02:00
|
|
|
maintainers = with maintainers; [ orivej mbalatsko ];
|
2023-04-21 22:40:09 +02:00
|
|
|
|
|
|
|
# not supposed to work on 32-bit https://github.com/ClickHouse/ClickHouse/pull/23959#issuecomment-835343685
|
2023-06-12 19:39:12 +02:00
|
|
|
platforms = lib.filter (x: (lib.systems.elaborate x).is64bit) (platforms.linux ++ platforms.darwin);
|
2023-04-21 22:40:09 +02:00
|
|
|
broken = stdenv.buildPlatform != stdenv.hostPlatform;
|
2017-03-27 03:06:23 +02:00
|
|
|
};
|
|
|
|
}
|