1{ stdenv
2, lib
3, fetchFromGitHub
4, fetchzip
5, rustPlatform
6, bootstrap_cmds
7, DiskArbitration
8, Foundation
9, cmake
10, libiconv
11, openssl
12, perl
13, pkg-config
14, protobuf
15, libclang
16, rdkafka
17}:
18
19let
20 fetchNpmPackage = {name, version, hash, js_prod_file, js_dev_file, ...} @ args:
21 let
22 package = fetchzip {
23 url = "https://registry.npmjs.org/${name}/-/${baseNameOf name}-${version}.tgz";
24 inherit hash;
25 };
26
27 files = with args; [
28 { src = js_prod_file; dst = "./src/environmentd/src/http/static/js/vendor/${name}.js"; }
29 { src = js_prod_file; dst = "./src/prof-http/src/http/static/js/vendor/${name}.js"; }
30 { src = js_dev_file; dst = "./src/environmentd/src/http/static-dev/js/vendor/${name}.js"; }
31 { src = js_dev_file; dst = "./src/prof-http/src/http/static-dev/js/vendor/${name}.js"; }
32 ] ++ lib.optionals (args ? css_file) [
33 { src = css_file; dst = "./src/environmentd/src/http/static/css/vendor/${name}.css"; }
34 { src = css_file; dst = "./src/prof-http/src/http/static/css/vendor/${name}.css"; }
35 ]
36 ++ lib.optionals (args ? extra_file) [
37 { src = extra_file.src; dst = "./src/environmentd/src/http/static/${extra_file.dst}";}
38 { src = extra_file.src; dst = "./src/prof-http/src/http/static/${extra_file.dst}";}
39 ];
40 in
41 lib.concatStringsSep "\n" (lib.forEach files ({src, dst}: ''
42 mkdir -p "${dirOf dst}"
43 cp "${package}/${src}" "${dst}"
44 ''));
45
46 npmPackages = import ./npm_deps.nix;
47in
48rustPlatform.buildRustPackage rec {
49 pname = "materialize";
50 version = "0.84.2";
51 MZ_DEV_BUILD_SHA = "9f8cf75b461d288335cb6a7a73aaa670bab4a466";
52
53 src = fetchFromGitHub {
54 owner = "MaterializeInc";
55 repo = pname;
56 rev = "v${version}";
57 hash = "sha256-+cvTCiTbuaPYPIyDxQlMWdJA5/6cbMoiTcSmjj5KPjs=";
58 fetchSubmodules = true;
59 };
60
61 postPatch = ''
62 ${lib.concatStringsSep "\n" (map fetchNpmPackage npmPackages)}
63 substituteInPlace ./misc/dist/materialized.service \
64 --replace /usr/bin $out/bin \
65 --replace _Materialize root
66 substituteInPlace ./src/catalog/build.rs \
67 --replace '&[ ' '&["."'
68 '';
69
70 # needed for internal protobuf c wrapper library
71 env.PROTOC = "${protobuf}/bin/protoc";
72 env.PROTOC_INCLUDE = "${protobuf}/include";
73 # needed to dynamically link rdkafka
74 env.CARGO_FEATURE_DYNAMIC_LINKING=1;
75
76 cargoLock = {
77 lockFile = ./Cargo.lock;
78 outputHashes = {
79 "columnation-0.1.0" = "sha256-VRDQqIVLayEnMHeth4cjsS/FYah3B3mwYEGnv8jpKs8=";
80 "differential-dataflow-0.12.0" = "sha256-cEmtDXOZSy4rDFZ7gCd7lx6wH+m1S9vphjb+wO4MSAM=";
81 "eventsource-client-0.11.0" = "sha256-FeEWV2yy1et5mna0TyAnakXlcIR42Aq97Lfjjlom8T0=";
82 "launchdarkly-server-sdk-1.0.0" = "sha256-fSWiV9mNf5WBkWDNckiUR3URQ8lJ4GZURxbYO/753sU=";
83 "librocksdb-sys-0.11.0+8.3.2" = "sha256-bnAvH2z9n26MYFhTN/+Yz+7lEdNKKmHJOoHkxTdZGvw=";
84 "openssh-0.9.9" = "sha256-2jaQN6PhavUtlWwqCn2VXEg213uj7BQ+FIrhnL3rb8Q=";
85 "postgres-0.19.5" = "sha256-i0mURHTCMrgaW1DD1CihWMdZ3zoNI14dCpq/ja8RW9E=";
86 "postgres_array-0.11.0" = "sha256-ealgPVExRIFUt0QVao8H7Q7u/PTuCbpGrk6Tm5jVwZ0=";
87 "proptest-1.0.0" = "sha256-sJbPQIVeHZZiRXssRpJWRbD9l8QnfwVcpGu6knjAe5o=";
88 "rdkafka-0.29.0" = "sha256-48CMvJ4PoVfKyiNMSpCGBtj36j2CF1E8a/QQ/urfiPc=";
89 "reqwest-middleware-0.2.3" = "sha256-zzlQycH5dmgM8ew1gy8m5r6Q2ib7LXnUeX69M3ih+sY=";
90 "serde-value-0.7.0" = "sha256-ewEYsf1+9MmLuSm5KbO326ngGB79i00lAp2NMHuuxw8=";
91 "timely-0.12.0" = "sha256-wJtHJ9ygPVusN5Io8SjZGo1r7lcrrcauESSC+9038AU=";
92 "tonic-build-0.9.2" = "sha256-cGvHjgmdr3NU1phwUfMvEE6uU12fOlhTlL2LoWeOO4I=";
93 "tracing-opentelemetry-0.22.0" = "sha256-mawDGrue/e3dPYVG0ANs9nZ+xmQyd1YTWH8QmE6VD0U=";
94 };
95 };
96
97 nativeBuildInputs = [
98 cmake
99 perl
100 pkg-config
101 rustPlatform.bindgenHook
102 ]
103 # Provides the mig command used by the krb5-src build script
104 ++ lib.optional stdenv.isDarwin bootstrap_cmds;
105
106 # Needed to get openssl-sys to use pkg-config.
107 OPENSSL_NO_VENDOR = 1;
108
109 buildInputs = [ openssl rdkafka libclang ]
110 ++ lib.optionals stdenv.isDarwin [ libiconv DiskArbitration Foundation ];
111
112 # the check phase requires linking with rocksdb which can be a problem since
113 # the rust rocksdb crate is not updated very often.
114 doCheck = false;
115
116 # Skip tests that use the network
117 checkFlags = [
118 "--exact"
119 "--skip test_client"
120 "--skip test_client_errors"
121 "--skip test_client_all_subjects"
122 "--skip test_client_subject_and_references"
123 "--skip test_no_block"
124 "--skip test_safe_mode"
125 "--skip test_tls"
126 ];
127
128 cargoBuildFlags = [ "--bin environmentd --bin clusterd" ];
129
130 postInstall = ''
131 install --mode=444 -D ./misc/dist/materialized.service $out/etc/systemd/system/materialized.service
132 '';
133
134 meta = with lib; {
135 homepage = "https://materialize.com";
136 description = "Streaming SQL materialized view engine for real-time applications";
137 license = licenses.bsl11;
138 platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ];
139 maintainers = [ maintainers.petrosagg ];
140 };
141}