fix?(package): postgreact

This commit is contained in:
zerosummed
2025-04-17 05:20:41 +03:00
parent 29ff6989e5
commit fb8fa34ff2
10 changed files with 76 additions and 47 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake .#postgres-c

View File

@@ -133,9 +133,10 @@
pg-migration = pkgs.callPackage ./package/postgres/pg-migration/default.nix rust.commonArgs;
c-hectic = pkgs.callPackage ./package/c/hectic/default.nix {};
watch = pkgs.callPackage ./package/c/watch/default.nix {};
hmpl = pkgs.callPackage ./package/c/hmpl/default.nix {
hectic = self.packages.${system}.hectic;
};
#hmpl = pkgs.callPackage ./package/c/hmpl/default.nix {
# hectic = self.packages.${system}.hectic;
#};
postgreact = pkgs.callPackage ./package/c/postgreact {};
};
devShells.${system} = let
@@ -467,7 +468,7 @@
http = buildHttpExt "17";
pg_smtp_client = buildSmtpExt "17";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_17;};
postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
};
};
postgresql_16 =
@@ -479,7 +480,7 @@
http = buildHttpExt "16";
pg_smtp_client = buildSmtpExt "16";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_16;};
postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
};
};
postgresql_15 =
@@ -491,7 +492,7 @@
http = buildHttpExt "15";
pg_smtp_client = buildSmtpExt "15";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_15;};
postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
};
};
postgresql_14 =
@@ -503,7 +504,7 @@
http = buildHttpExt "14";
pg_smtp_client = buildSmtpExt "14";
plhaskell = buildPlHaskellExt "15";
postgreact = prev.callPackage ./package/c/postgreact/default.nix {postgresql = prev.postgresql_14;};
postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
};
};
writers = let

View File

@@ -0,0 +1,16 @@
EXTENSION ?= postgreact
EXTENSION_VERSION ?= 1.0
# INFO(nrv): just in case idk how pgxs Makefile and shit all work
EXTVERSION = $(EXTENSION_VERSION)
MODULE_big = $(EXTENSION)
DATA = $(EXTENSION)--$(EXTENSION_VERSION).sql
OBJS = $(EXTENSION).o
PG_CONFIG = pg_config
$(BUILD_DIR)/$(EXTENSION).control:
sed "s/@EXTENSION_VERSION@/$(EXTVERSION)/g" $(EXTENSION).control.in > $@
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

View File

@@ -1,39 +1,29 @@
{
lib,
stdenv,
fetchFromGitHub,
curl,
postgresql,
...
buildPostgresqlExtension,
}:
stdenv.mkDerivation {
buildPostgresqlExtension rec {
pname = "postgreact";
version = "0.1";
version = "1.0";
buildInputs = [
];
EXTENSION = pname;
EXTENSION_VERSION = version;
src = ./.;
buildInputs = [
postgresql
];
buildPhase = ''
mkdir -p target
sh ./make.sh build
'';
installPhase = ''
mkdir -p $out/lib/postgresql $out/share/postgresql/extension
# Install compiled library
install -m 755 -D target/postgreact.so $out/lib/postgresql/postgreact.so
# Install control and SQL files
install -m 644 -D postgreact.control $out/share/postgresql/extension/postgreact.control
install -m 644 -D postgreact--0.1.sql $out/share/postgresql/extension/postgreact--0.1.sql
'';
env.NIX_CFLAGS_COMPILE = "-Wno-error";
meta = with lib; {
description = "PostgreSQL extension for reactive functions";
homepage = "https://github.com/yukkop/util.nix";
license = licenses.mit;
description = "PostgreSQL extension for simple templating.";
homepage = "https://github.com/hectic-lab/util.nix";
license = licenses.asl20;
platforms = postgresql.meta.platforms;
maintainers = with maintainers; [];
};

View File

@@ -7,6 +7,8 @@
# --color Pass -fdiagnostics-color=always to compiler.
# help, --help Show this help message.
set -u
check_dependencies() {
for dep in gcc pg_config; do
if ! command -v "$dep" >/dev/null 2>&1; then
@@ -91,7 +93,7 @@ case "$MODE" in
# Copy extension files to target directory
cp postgreact.control target/
cp postgreact--0.1.sql target/
cp postgreact--${EXTENSION_VERSION}.sql target/
echo "Build complete. Files available in target/ directory."
;;
@@ -99,4 +101,4 @@ case "$MODE" in
print_help
exit 1
;;
esac
esac

View File

@@ -3,6 +3,10 @@
-- Define the hello function that uses our C implementation
CREATE FUNCTION hello()
RETURNS text
AS 'postgreact', 'hello'
LANGUAGE C STRICT;
RETURNS
TEXT
STRICT VOLATILE
LANGUAGE C
AS
'MODULE_PATHNAME', 'hello'
;

View File

@@ -6,11 +6,15 @@
PG_MODULE_MAGIC;
#endif
/* Define the function hello */
PG_FUNCTION_INFO_V1(hello);
/* Implement the function */
Datum hello(PG_FUNCTION_ARGS)
{
PG_RETURN_TEXT_P(cstring_to_text("Hello, world!"));
}
PG_RETURN_TEXT_P(cstring_to_text("Eblan!"));
}
void _PG_init(void) {
}
void _PG_fini(void) {
}

View File

@@ -1,4 +0,0 @@
comment = 'My first extension'
default_version = '1.0'
module_pathname = $libdir/postgreact
relocatable = true

View File

@@ -0,0 +1,4 @@
comment = 'My first extension'
default_version = '@EXTENSION_VERSION@'
module_pathname = '$libdir/postgreact'
relocatable = false

View File

@@ -0,0 +1,11 @@
#include "postgres.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
void _PG_init(void);
void _PG_fini(void);
Datum hello(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(hello);