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
15let
16 fetchNpmPackage = {name, version, hash, js_prod_file, js_dev_file, ...} @ args:
17 let
18 package = fetchzip {
19 url = "https://registry.npmjs.org/${name}/-/${baseNameOf name}-${version}.tgz";
20 inherit hash;
21 };
22
23 static = "./src/materialized/src/http/static";
24 cssVendor = "./src/materialized/src/http/static/css/vendor";
25 jsProdVendor = "./src/materialized/src/http/static/js/vendor";
26 jsDevVendor = "./src/materialized/src/http/static-dev/js/vendor";
27
28 files = with args; [
29 { src = js_prod_file; dst = "${jsProdVendor}/${name}.js"; }
30 { src = js_dev_file; dst = "${jsDevVendor}/${name}.js"; }
31 ] ++ lib.optional (args ? css_file) { src = css_file; dst = "${cssVendor}/${name}.css"; }
32 ++ lib.optional (args ? extra_file) { src = extra_file.src; dst = "${static}/${extra_file.dst}"; };
33 in
34 lib.concatStringsSep "\n" (lib.forEach files ({src, dst}: ''
35 mkdir -p "${dirOf dst}"
36 cp "${package}/${src}" "${dst}"
37 ''));
38
39 npmPackages = import ./npm_deps.nix;
40in
41rustPlatform.buildRustPackage rec {
42 pname = "materialize";
43 version = "0.17.0";
44 MZ_DEV_BUILD_SHA = "9f8cf75b461d288335cb6a7a73aaa670bab4a466";
45
46 src = fetchFromGitHub {
47 owner = "MaterializeInc";
48 repo = pname;
49 rev = "v${version}";
50 hash = "sha256-wKYU5S77VoOX7UA9/d21Puz9NYs/om08eNM69/m3Orc=";
51 };
52
53 cargoHash = "sha256-GTkn/fUprkpsDeQxtzdmS7Fub9QODO5/4nh9ERswOY0=";
54
55 nativeBuildInputs = [ cmake perl pkg-config ]
56 # Provides the mig command used by the krb5-src build script
57 ++ lib.optional stdenv.isDarwin bootstrap_cmds;
58
59 # Needed to get openssl-sys to use pkg-config.
60 OPENSSL_NO_VENDOR = 1;
61
62 buildInputs = [ openssl ]
63 ++ lib.optionals stdenv.isDarwin [ libiconv DiskArbitration Foundation ];
64
65 # Skip tests that use the network
66 checkFlags = [
67 "--exact"
68 "--skip test_client"
69 "--skip test_client_errors"
70 "--skip test_client_all_subjects"
71 "--skip test_client_subject_and_references"
72 "--skip test_no_block"
73 "--skip test_safe_mode"
74 "--skip test_tls"
75 ];
76
77 postPatch = ''
78 ${lib.concatStringsSep "\n" (map fetchNpmPackage npmPackages)}
79 substituteInPlace ./misc/dist/materialized.service \
80 --replace /usr/bin $out/bin \
81 --replace _Materialize root
82 '';
83
84 cargoBuildFlags = [ "--bin materialized" ];
85
86 postInstall = ''
87 install --mode=444 -D ./misc/dist/materialized.service $out/etc/systemd/system/materialized.service
88 '';
89
90 meta = with lib; {
91 homepage = "https://materialize.com";
92 description = "A streaming SQL materialized view engine for real-time applications";
93 license = licenses.bsl11;
94 platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ];
95 maintainers = [ maintainers.petrosagg ];
96 };
97}