nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 272 lines 8.4 kB view raw
1{ 2 lts ? false, 3 version, 4 rev, 5 hash, 6}: 7 8{ 9 lib, 10 stdenv, 11 llvmPackages_19, 12 fetchFromGitHub, 13 fetchpatch, 14 cmake, 15 ninja, 16 python3, 17 perl, 18 nasm, 19 yasm, 20 nixosTests, 21 darwin, 22 findutils, 23 libiconv, 24 removeReferencesTo, 25 rustSupport ? true, 26 rustc, 27 cargo, 28 rustPlatform, 29 nix-update-script, 30 versionCheckHook, 31}: 32let 33 llvmStdenv = llvmPackages_19.stdenv; 34in 35llvmStdenv.mkDerivation (finalAttrs: { 36 pname = "clickhouse"; 37 inherit version; 38 inherit rev; 39 40 src = fetchFromGitHub rec { 41 owner = "ClickHouse"; 42 repo = "ClickHouse"; 43 tag = "v${finalAttrs.version}"; 44 fetchSubmodules = true; 45 name = "clickhouse-${tag}.tar.gz"; 46 inherit hash; 47 postFetch = '' 48 # Delete files that make the source too big 49 rm -rf $out/contrib/arrow/docs/ 50 rm -rf $out/contrib/arrow/testing/ 51 rm -rf $out/contrib/aws/generated/protocol-tests/ 52 rm -rf $out/contrib/aws/generated/smoke-tests/ 53 rm -rf $out/contrib/aws/generated/tests/ 54 rm -rf $out/contrib/aws/tools/ 55 rm -rf $out/contrib/cld2/internal/test_shuffle_1000_48_666.utf8.gz 56 rm -rf $out/contrib/croaring/benchmarks/ 57 rm -rf $out/contrib/boost/doc/ 58 rm -rf $out/contrib/boost/libs/*/bench/ 59 rm -rf $out/contrib/boost/libs/*/example/ 60 rm -rf $out/contrib/boost/libs/*/doc/ 61 rm -rf $out/contrib/boost/libs/*/test/ 62 rm -rf $out/contrib/google-cloud-cpp/ci/abi-dumps/ 63 rm -rf $out/contrib/icu/icu4c/source/test/ 64 rm -rf $out/contrib/icu/icu4j/main/core/src/test/ 65 rm -rf $out/contrib/icu/icu4j/perf-tests/ 66 rm -rf $out/contrib/llvm-project/*/docs/ 67 rm -rf $out/contrib/llvm-project/*/test/ 68 rm -rf $out/contrib/llvm-project/*/unittests/ 69 rm -rf $out/contrib/postgres/doc/ 70 71 # As long as we're not running tests, remove test files 72 rm -rf $out/tests/ 73 74 # fix case insensitivity on macos https://github.com/NixOS/nixpkgs/issues/39308 75 rm -rf $out/contrib/sysroot/linux-* 76 rm -rf $out/contrib/liburing/man 77 78 # Compress to not exceed the 2GB output limit 79 echo "Creating deterministic source tarball..." 80 81 tar -I 'gzip -n' \ 82 --sort=name \ 83 --mtime=1970-01-01 \ 84 --owner=0 --group=0 \ 85 --numeric-owner --mode=go=rX,u+rw,a-s \ 86 --transform='s@^@source/@S' \ 87 -cf temp -C "$out" . 88 89 echo "Finished creating deterministic source tarball!" 90 91 rm -r "$out" 92 mv temp "$out" 93 ''; 94 }; 95 96 strictDeps = true; 97 nativeBuildInputs = [ 98 cmake 99 ninja 100 python3 101 perl 102 llvmPackages_19.lld 103 removeReferencesTo 104 ] 105 ++ lib.optionals stdenv.hostPlatform.isx86_64 [ 106 nasm 107 yasm 108 ] 109 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 110 llvmPackages_19.bintools 111 findutils 112 darwin.bootstrap_cmds 113 ] 114 ++ lib.optionals rustSupport [ 115 rustc 116 cargo 117 rustPlatform.cargoSetupHook 118 ]; 119 120 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]; 121 122 dontCargoSetupPostUnpack = true; 123 124 patches = 125 lib.optional (lib.versions.majorMinor version == "25.8") (fetchpatch { 126 # Disable building WASM lexer 127 url = "https://github.com/ClickHouse/ClickHouse/commit/67a42b78cdf1c793e78c1adbcc34162f67044032.patch"; 128 hash = "sha256-7VF+JSztqTWD+aunCS3UVNxlRdwHc2W5fNqzDyeo3Fc="; 129 }) 130 ++ 131 132 lib.optional (lib.versions.majorMinor version == "25.8" && stdenv.hostPlatform.isDarwin) 133 (fetchpatch { 134 # Do not intercept memalign on darwin 135 url = "https://github.com/ClickHouse/ClickHouse/commit/0cfd2dbe981727fb650f3b9935f5e7e7e843180f.patch"; 136 hash = "sha256-1iNYZbugX2g2dxNR1ZiUthzPnhLUR8g118aG23yhgUo="; 137 }) 138 ++ lib.optional (!lib.versionAtLeast version "25.11" && stdenv.hostPlatform.isDarwin) (fetchpatch { 139 # Remove flaky macOS SDK version detection 140 url = "https://github.com/ClickHouse/ClickHouse/commit/11e172a37bd0507d595d27007170090127273b33.patch"; 141 hash = "sha256-oI7MrjMgJpIPTsci2IqEOs05dUGEMnjI/WqGp2N+rps="; 142 }); 143 144 postPatch = '' 145 patchShebangs src/ utils/ 146 '' 147 + lib.optionalString stdenv.hostPlatform.isDarwin '' 148 substituteInPlace cmake/tools.cmake \ 149 --replace-fail 'gfind' 'find' \ 150 --replace-fail 'ggrep' 'grep' \ 151 --replace-fail '--ld-path=''${LLD_PATH}' '-fuse-ld=lld' 152 153 substituteInPlace utils/list-licenses/list-licenses.sh \ 154 --replace-fail 'gfind' 'find' \ 155 --replace-fail 'ggrep' 'grep' 156 '' 157 # Rust is handled by cmake 158 + lib.optionalString rustSupport '' 159 cargoSetupPostPatchHook() { true; } 160 ''; 161 162 # Set the version the same way as ClickHouse CI does. 163 # 164 # https://github.com/clickhouse/clickhouse/blob/31127f21f8bb7ff21f737c4822de10ef5859c702/ci/jobs/scripts/clickhouse_version.py#L11-L20 165 # https://github.com/clickhouse/clickhouse/blob/31127f21f8bb7ff21f737c4822de10ef5859c702/ci/jobs/build_clickhouse.py#L179 166 preConfigure = 167 let 168 gitTagName = finalAttrs.version; 169 versionStr = builtins.elemAt (lib.splitString "-" gitTagName) 0; 170 171 parts = lib.splitVersion versionStr; 172 173 major = builtins.elemAt parts 0; 174 minor = builtins.elemAt parts 1; 175 patch = builtins.elemAt parts 2; 176 177 # The full commit hash is already available here: 178 gitHash = rev; 179 in 180 '' 181 cat <<'EOF' > cmake/autogenerated_versions.txt 182 SET(VERSION_REVISION 0) 183 SET(VERSION_MAJOR ${major}) 184 SET(VERSION_MINOR ${minor}) 185 SET(VERSION_PATCH ${patch}) 186 SET(VERSION_GITHASH ${gitHash}) 187 SET(VERSION_DESCRIBE ${gitTagName}) 188 SET(VERSION_STRING ${versionStr}) 189 EOF 190 ''; 191 192 cmakeFlags = [ 193 "-DENABLE_CHDIG=OFF" 194 "-DENABLE_TESTS=OFF" 195 "-DENABLE_DELTA_KERNEL_RS=0" 196 "-DCOMPILER_CACHE=disabled" 197 ] 198 ++ lib.optional ( 199 stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 200 ) "-DNO_ARMV81_OR_HIGHER=1"; 201 202 env = { 203 CARGO_HOME = "$PWD/../.cargo/"; 204 NIX_CFLAGS_COMPILE = 205 # undefined reference to '__sync_val_compare_and_swap_16' 206 lib.optionalString stdenv.hostPlatform.isx86_64 " -mcx16" 207 + 208 # Silence ``-Wimplicit-const-int-float-conversion` error in MemoryTracker.cpp and 209 # ``-Wno-unneeded-internal-declaration` TreeOptimizer.cpp. 210 lib.optionalString stdenv.hostPlatform.isDarwin 211 " -Wno-implicit-const-int-float-conversion -Wno-unneeded-internal-declaration"; 212 }; 213 214 # https://github.com/ClickHouse/ClickHouse/issues/49988 215 hardeningDisable = [ "fortify" ]; 216 217 nativeInstallCheckInputs = [ versionCheckHook ]; 218 doInstallCheck = true; 219 preVersionCheck = '' 220 version=${builtins.head (lib.splitString "-" version)} 221 ''; 222 223 postInstall = '' 224 sed -i -e '\!<log>/var/log/clickhouse-server/clickhouse-server\.log</log>!d' \ 225 $out/etc/clickhouse-server/config.xml 226 substituteInPlace $out/etc/clickhouse-server/config.xml \ 227 --replace-fail "<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>" "<console>1</console>" \ 228 --replace-fail "<level>trace</level>" "<level>warning</level>" 229 remove-references-to -t ${llvmStdenv.cc} $out/bin/clickhouse 230 ''; 231 232 # canary for the remove-references-to hook failing 233 disallowedReferences = [ llvmStdenv.cc ]; 234 235 # Basic smoke test 236 doCheck = true; 237 checkPhase = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' 238 $NIX_BUILD_TOP/$sourceRoot/build/programs/clickhouse local --query 'SELECT 1' | grep 1 239 ''; 240 241 # Builds in 7+h with 2 cores, and ~20m with a big-parallel builder. 242 requiredSystemFeatures = [ "big-parallel" ]; 243 244 passthru = { 245 tests = if lts then nixosTests.clickhouse-lts else nixosTests.clickhouse; 246 247 updateScript = [ 248 ./update.sh 249 250 (if lts then ./lts.nix else ./package.nix) 251 ]; 252 }; 253 254 meta = { 255 homepage = "https://clickhouse.com"; 256 description = "Column-oriented database management system"; 257 license = lib.licenses.asl20; 258 changelog = "https://github.com/ClickHouse/ClickHouse/blob/v${version}/CHANGELOG.md"; 259 260 mainProgram = "clickhouse"; 261 262 # not supposed to work on 32-bit https://github.com/ClickHouse/ClickHouse/pull/23959#issuecomment-835343685 263 platforms = lib.filter (x: (lib.systems.elaborate x).is64bit) ( 264 lib.platforms.linux ++ lib.platforms.darwin 265 ); 266 broken = stdenv.buildPlatform != stdenv.hostPlatform; 267 268 maintainers = with lib.maintainers; [ 269 thevar1able 270 ]; 271 }; 272})