Hi,
Now there's a package with the datasketches postgres extension available in
Nix packages, so any NixOS or Nix package manager user can easily install a
postgres instance with the datasketches extension.

For example, to set up a shell with pg and the extension, use the following
in your shell.nix file:

with import <nixpkgs> {};
mkShell {
  buildInputs = [
    ( postgresql_15.withPackages (builtInPackages: [
builtInPackages.apache_datasketches ]))
  ];
}

On Thu, May 25, 2023 at 10:32 AM Marko Mušnjak <marko.musn...@gmail.com>
wrote:

> Hi,
>
> I was playing around learning Nix and chose a little project for myself:
> build a postgres package with some extensions,
> including datasketches-postgresql. Since that took a lot of tinkering, I
> thought I'd share this here in case anyone ever needs it.
>
> The cause of the struggle seems to be in some build
> steps datasketches-postgresql needs, but Nix doesn't make very obvious.
>
> The working nix package is below:
>
> {
>   pkgs ? import <nixpkgs> {}
> }:
> let
>   postgres = pkgs.postgresql_15;
>   boost = pkgs.boost182;
>
>   cpp_version = "4.1.0";
>   cpp_sources = pkgs.fetchFromGitHub {
>     owner  = "apache";
>     repo   = "datasketches-cpp";
>     rev    = "refs/tags/${cpp_version}";
>     sha256 = "sha256-vPoFzRxOXlEAiiHH9M5S6255ahzaKsGNYS0cdHwrRYw=";
>   };
> in
> pkgs.stdenv.mkDerivation rec {
>   pname = "pg-datasketches";
>   version = "1.6.0";
>
>   src = pkgs.fetchFromGitHub {
>     owner  = "apache";
>     repo   = "datasketches-postgresql";
>     rev    = "refs/tags/${version}";
>     sha256 = "sha256-sz94fIe7nyWhjiw8FAm6ZzVpB0sAK5YxUrtbaZt/guA=";
>   };
>
>   nativeBuildInputs = [ postgres boost cpp_sources ];
>
>   patchPhase = ''
>     cp -r ${cpp_sources} datasketches-cpp
>   '';
>
>   installPhase = ''
>     install -D -m 644 ./datasketches.so -t $out/lib/
>     cat \
>       sql/datasketches_cpc_sketch.sql \
>       sql/datasketches_kll_float_sketch.sql \
>       sql/datasketches_kll_double_sketch.sql \
>       sql/datasketches_theta_sketch.sql \
>       sql/datasketches_frequent_strings_sketch.sql \
>       sql/datasketches_hll_sketch.sql \
>       sql/datasketches_aod_sketch.sql \
>       sql/datasketches_req_float_sketch.sql \
>       sql/datasketches_quantiles_double_sketch.sql \
>       > sql/datasketches--${version}.sql
>     install -D -m 644 ./datasketches.control -t
> $out/share/postgresql/extension
>     install -D -m 644 \
>       ./sql/datasketches--${version}.sql \
>       ./sql/datasketches--1.3.0--1.4.0.sql \
>       ./sql/datasketches--1.4.0--1.5.0.sql \
>       ./sql/datasketches--1.5.0--1.6.0.sql \
>       -t $out/share/postgresql/extension
>   '';
> }
>
> Cheers,
> Marko
>

Reply via email to