25 inherit (llvmPackages) stdenv;
27 if stdenv.hostPlatform.isDarwin
28 then darwin.apple_sdk_11_0.llvmPackages_16.stdenv
29 else llvmPackages.stdenv).mkDerivation;
32 version = "24.3.7.30";
34 src = fetchFromGitHub rec {
37 rev = "v${version}-lts";
38 fetchSubmodules = true;
39 name = "clickhouse-${rev}.tar.gz";
40 hash = "sha256-xIqn1cRbuD3NpUC2c7ZzvC8EAmg+XOXCkp+g/HTdIc0=";
42 # delete files that make the source too big
43 rm -rf $out/contrib/llvm-project/llvm/test
44 rm -rf $out/contrib/llvm-project/clang/test
45 rm -rf $out/contrib/croaring/benchmarks
47 # fix case insensitivity on macos https://github.com/NixOS/nixpkgs/issues/39308
48 rm -rf $out/contrib/sysroot/linux-*
49 rm -rf $out/contrib/liburing/man
51 # compress to not exceed the 2GB output limit
52 # try to make a deterministic tarball
57 --numeric-owner --mode=go=rX,u+rw,a-s \
58 --transform='s@^@source/@S' \
66 # They updated the Cargo.toml without updating the Cargo.lock :/
68 url = "https://github.com/ClickHouse/ClickHouse/commit/bccd33932b5fe17ced2dc2f27813da0b1c034afa.patch";
70 hash = "sha256-4idwr+G8WGuT/VILKtDIJIvbCvi6pZokJFze4dP6ExE=";
73 url = "https://github.com/ClickHouse/ClickHouse/commit/b6bd5ecb199ef8a10e3008a4ea3d96087db8a8c1.patch";
75 hash = "sha256-nbb/GV2qWEZ+BEfT6/9//yZf4VWdhOdJCI3PLeh6o0M=";
86 ] ++ lib.optionals stdenv.hostPlatform.isx86_64 [
89 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
93 ] ++ lib.optionals rustSupport [
96 rustPlatform.cargoSetupHook
99 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
101 # their vendored version is too old and missing this patch: https://github.com/corrosion-rs/corrosion/pull/205
102 corrosionSrc = if rustSupport then fetchFromGitHub {
103 owner = "corrosion-rs";
106 hash = "sha256-r/jrck4RiQynH1+Hx4GyIHpw/Kkr8dHe1+vTHg+fdRs=";
108 corrosionDeps = if rustSupport then rustPlatform.fetchCargoTarball {
110 name = "corrosion-deps";
111 preBuild = "cd generator";
112 hash = "sha256-dhUgpwSjE9NZ2mCkhGiydI51LIOClA5wwk1O3mnnbM8=";
114 rustDeps = if rustSupport then rustPlatform.fetchCargoTarball {
117 preBuild = "cd rust";
118 hash = "sha256-rbEfCRB2QAZ2WBgSLYYUqeYtI4Y5d9oQ2G8/mPirIp4=";
121 dontCargoSetupPostUnpack = true;
122 postUnpack = lib.optionalString rustSupport ''
125 rm -rf contrib/corrosion
126 cp -r --no-preserve=mode $corrosionSrc contrib/corrosion
128 pushd contrib/corrosion/generator
129 cargoDeps="$corrosionDeps" cargoSetupPostUnpackHook
130 corrosionDepsCopy="$cargoDepsCopy"
134 cargoDeps="$rustDeps" cargoSetupPostUnpackHook
135 rustDepsCopy="$cargoDepsCopy"
136 cat .cargo/config.toml >> .cargo/config.toml.in
137 cat .cargo/config.toml >> skim/.cargo/config.toml.in
138 rm .cargo/config.toml
147 substituteInPlace src/Storages/System/StorageSystemLicenses.sh \
148 --replace 'git rev-parse --show-toplevel' '$src'
149 substituteInPlace utils/check-style/check-duplicate-includes.sh \
150 --replace 'git rev-parse --show-toplevel' '$src'
151 substituteInPlace utils/check-style/check-ungrouped-includes.sh \
152 --replace 'git rev-parse --show-toplevel' '$src'
153 substituteInPlace utils/list-licenses/list-licenses.sh \
154 --replace 'git rev-parse --show-toplevel' '$src'
155 substituteInPlace utils/check-style/check-style \
156 --replace 'git rev-parse --show-toplevel' '$src'
157 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
158 sed -i 's|gfind|find|' cmake/tools.cmake
159 sed -i 's|ggrep|grep|' cmake/tools.cmake
160 '' + lib.optionalString rustSupport ''
162 pushd contrib/corrosion/generator
163 cargoDepsCopy="$corrosionDepsCopy" cargoSetupPostPatchHook
167 cargoDepsCopy="$rustDepsCopy" cargoSetupPostPatchHook
170 cargoSetupPostPatchHook() { true; }
171 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
172 # Make sure Darwin invokes lld.ld64 not lld.
173 substituteInPlace cmake/tools.cmake \
174 --replace '--ld-path=''${LLD_PATH}' '-fuse-ld=lld'
179 "-DCOMPILER_CACHE=disabled"
180 "-DENABLE_EMBEDDED_COMPILER=ON"
185 # undefined reference to '__sync_val_compare_and_swap_16'
186 lib.optionalString stdenv.hostPlatform.isx86_64 " -mcx16" +
187 # Silence ``-Wimplicit-const-int-float-conversion` error in MemoryTracker.cpp and
188 # ``-Wno-unneeded-internal-declaration` TreeOptimizer.cpp.
189 lib.optionalString stdenv.hostPlatform.isDarwin " -Wno-implicit-const-int-float-conversion -Wno-unneeded-internal-declaration";
192 # https://github.com/ClickHouse/ClickHouse/issues/49988
193 hardeningDisable = [ "fortify" ];
196 rm -rf $out/share/clickhouse-test
198 sed -i -e '\!<log>/var/log/clickhouse-server/clickhouse-server\.log</log>!d' \
199 $out/etc/clickhouse-server/config.xml
200 substituteInPlace $out/etc/clickhouse-server/config.xml \
201 --replace "<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>" "<console>1</console>"
202 substituteInPlace $out/etc/clickhouse-server/config.xml \
203 --replace "<level>trace</level>" "<level>warning</level>"
206 # Builds in 7+h with 2 cores, and ~20m with a big-parallel builder.
207 requiredSystemFeatures = [ "big-parallel" ];
209 passthru.tests.clickhouse = nixosTests.clickhouse;
212 homepage = "https://clickhouse.com";
213 description = "Column-oriented database management system";
214 license = licenses.asl20;
215 maintainers = with maintainers; [ orivej mbalatsko ];
217 # not supposed to work on 32-bit https://github.com/ClickHouse/ClickHouse/pull/23959#issuecomment-835343685
218 platforms = lib.filter (x: (lib.systems.elaborate x).is64bit) (platforms.linux ++ platforms.darwin);
219 broken = stdenv.buildPlatform != stdenv.hostPlatform;