{ungoogled-,}chromium,chromedriver: 130.0.6723.58 -> 130.0.6723.69 (#351519)
[NixPkgs.git] / pkgs / servers / clickhouse / default.nix
blob9a6a4e47132c19870e70fe07076a997a987b2069
1 { lib
2 , llvmPackages
3 , fetchFromGitHub
4 , fetchpatch
5 , cmake
6 , ninja
7 , python3
8 , perl
9 , nasm
10 , yasm
11 , nixosTests
12 , darwin
13 , findutils
14 , libiconv
16 , rustSupport ? true
18 , corrosion
19 , rustc
20 , cargo
21 , rustPlatform
24 let
25   inherit (llvmPackages) stdenv;
26   mkDerivation = (
27     if stdenv.hostPlatform.isDarwin
28     then darwin.apple_sdk_11_0.llvmPackages_16.stdenv
29     else llvmPackages.stdenv).mkDerivation;
30 in mkDerivation rec {
31   pname = "clickhouse";
32   version = "24.3.7.30";
34   src = fetchFromGitHub rec {
35     owner = "ClickHouse";
36     repo = "ClickHouse";
37     rev = "v${version}-lts";
38     fetchSubmodules = true;
39     name = "clickhouse-${rev}.tar.gz";
40     hash = "sha256-xIqn1cRbuD3NpUC2c7ZzvC8EAmg+XOXCkp+g/HTdIc0=";
41     postFetch = ''
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
53       tar -I 'gzip -n' \
54         --sort=name \
55         --mtime=1970-01-01 \
56         --owner=0 --group=0 \
57         --numeric-owner --mode=go=rX,u+rw,a-s \
58         --transform='s@^@source/@S' \
59         -cf temp  -C "$out" .
60       rm -r "$out"
61       mv temp "$out"
62     '';
63   };
65   patches = [
66     # They updated the Cargo.toml without updating the Cargo.lock :/
67     (fetchpatch {
68       url = "https://github.com/ClickHouse/ClickHouse/commit/bccd33932b5fe17ced2dc2f27813da0b1c034afa.patch";
69       revert = true;
70       hash = "sha256-4idwr+G8WGuT/VILKtDIJIvbCvi6pZokJFze4dP6ExE=";
71     })
72     (fetchpatch {
73       url = "https://github.com/ClickHouse/ClickHouse/commit/b6bd5ecb199ef8a10e3008a4ea3d96087db8a8c1.patch";
74       revert = true;
75       hash = "sha256-nbb/GV2qWEZ+BEfT6/9//yZf4VWdhOdJCI3PLeh6o0M=";
76     })
77   ];
79   strictDeps = true;
80   nativeBuildInputs = [
81     cmake
82     ninja
83     python3
84     perl
85     llvmPackages.lld
86   ] ++ lib.optionals stdenv.hostPlatform.isx86_64 [
87     nasm
88     yasm
89   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
90     llvmPackages.bintools
91     findutils
92     darwin.bootstrap_cmds
93   ] ++ lib.optionals rustSupport [
94     rustc
95     cargo
96     rustPlatform.cargoSetupHook
97   ];
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";
104     repo = "corrosion";
105     rev = "v0.3.5";
106     hash = "sha256-r/jrck4RiQynH1+Hx4GyIHpw/Kkr8dHe1+vTHg+fdRs=";
107   } else null;
108   corrosionDeps = if rustSupport then rustPlatform.fetchCargoTarball {
109     src = corrosionSrc;
110     name = "corrosion-deps";
111     preBuild = "cd generator";
112     hash = "sha256-dhUgpwSjE9NZ2mCkhGiydI51LIOClA5wwk1O3mnnbM8=";
113   } else null;
114   rustDeps = if rustSupport then rustPlatform.fetchCargoTarball {
115     inherit src;
116     name = "rust-deps";
117     preBuild = "cd rust";
118     hash = "sha256-rbEfCRB2QAZ2WBgSLYYUqeYtI4Y5d9oQ2G8/mPirIp4=";
119   } else null;
121   dontCargoSetupPostUnpack = true;
122   postUnpack = lib.optionalString rustSupport ''
123     pushd source
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"
131     popd
133     pushd rust
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
139     popd
141     popd
142   '';
144   postPatch = ''
145     patchShebangs src/
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
164     popd
166     pushd rust
167     cargoDepsCopy="$rustDepsCopy" cargoSetupPostPatchHook
168     popd
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'
175   '';
177   cmakeFlags = [
178     "-DENABLE_TESTS=OFF"
179     "-DCOMPILER_CACHE=disabled"
180     "-DENABLE_EMBEDDED_COMPILER=ON"
181   ];
183   env = {
184     NIX_CFLAGS_COMPILE =
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";
190   };
192   # https://github.com/ClickHouse/ClickHouse/issues/49988
193   hardeningDisable = [ "fortify" ];
195   postInstall = ''
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>"
204   '';
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;
211   meta = with lib; {
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;
220   };