@@ -0,0 +1,91 @@
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+
15+let
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;
40+in
41+rustPlatform.buildRustPackage rec {
42+ pname = "materialize";
43+ version = "0.7.1";
44+ rev = "f4bd159fa73d37d44f8ed3f1db13c0c2ff85566f";
45+
46+ src = fetchFromGitHub {
47+ owner = "MaterializeInc";
48+ repo = pname;
49+ inherit rev;
50+ hash = "sha256-8nonB/KRv4qOGvJhh0v3UwlBzAXfzb3afeCm/7/E0AU=";
51+ };
52+
53+ cargoSha256 = "sha256-5slgICqLZFqxPymgHvq98BtcD70hfJMr36pvAoQKEJ4=";
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+ buildInputs = [ openssl ]
60+ ++ lib.optionals stdenv.isDarwin [ libiconv DiskArbitration Foundation ];
61+
62+ # Skip tests that use the network
63+ checkFlags = [
64+ "--exact"
65+ "--skip test_client"
66+ "--skip test_client_errors"
67+ "--skip test_no_block"
68+ ];
69+
70+ postPatch = ''
71+ ${lib.concatStringsSep "\n" (map fetchNpmPackage npmPackages)}
72+ substituteInPlace ./misc/dist/materialized.service \
73+ --replace /usr/bin $out/bin \
74+ --replace _Materialize root
75+ '';
76+
77+ MZ_DEV_BUILD_SHA = rev;
78+ cargoBuildFlags = [ "--package materialized" ];
79+
80+ postInstall = ''
81+ install --mode=444 -D ./misc/dist/materialized.service $out/etc/systemd/system/materialized.service
82+ '';
83+
84+ meta = with lib; {
85+ homepage = "https://materialize.com";
86+ description = "A streaming SQL materialized view engine for real-time applications";
87+ license = licenses.bsl11;
88+ platforms = [ "x86_64-linux" "x86_64-darwin" ];
89+ maintainers = [ maintainers.petrosagg ];
90+ };
91+}