From 60d977110c7facac76dbb14e88396c5c3f552e3f Mon Sep 17 00:00:00 2001 From: zerosummed Date: Fri, 18 Apr 2025 21:37:23 +0300 Subject: [PATCH] fix?(package): `postgreact`: ~stir the stupid shit till it works [3] --- flake.nix | 32 ++++++--------------- package/c/postgreact/.gitignore | 3 ++ package/c/postgreact/Makefile | 18 ++++++------ package/c/postgreact/default.nix | 33 +++++++++++++++++++++- package/c/postgreact/postgreact.c | 10 ++----- package/c/postgreact/postgreact.control.in | 4 +-- package/c/postgreact/postgreact.h | 5 ++++ 7 files changed, 63 insertions(+), 42 deletions(-) create mode 100644 package/c/postgreact/.gitignore diff --git a/flake.nix b/flake.nix index a1023bc..a2e2140 100644 --- a/flake.nix +++ b/flake.nix @@ -133,10 +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; - #}; - #postgreact = pkgs.callPackage ./package/c/postgreact {}; + #hmpl = pkgs.callPackage ./package/c/hmpl/default.nix { + # hectic = self.packages.${system}.hectic; + #}; + postgreact = pkgs.callPackage ./package/c/postgreact {}; }; devShells.${system} = let @@ -457,22 +457,6 @@ }; nativeBuildInputs = with prev; [pkg-config curl]; }; - buildPostgreactExt = versionSuffix: - buildPostgresqlExtension { - postgresql = prev."postgresql_${versionSuffix}"; - } (rec { - pname = "postgreact"; - version = "1.0"; - src = ./package/c/${pname}; - nativeBuildInputs = with prev; [pkg-config]; # ??? - meta = with lib; { - description = "PostgreSQL extension for simple templating."; - homepage = "https://github.com/hectic-lab/util.nix"; - license = licenses.asl20; - platforms = postgresql.meta.platforms; - maintainers = with maintainers; []; - }; - }); in { hectic = self.packages.${prev.system}; postgresql_17 = @@ -484,7 +468,7 @@ http = buildHttpExt "17"; pg_smtp_client = buildSmtpExt "17"; plhaskell = buildPlHaskellExt "15"; - postgreact = buildPostgreactExt "17"; + postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;}; }; }; postgresql_16 = @@ -496,7 +480,7 @@ http = buildHttpExt "16"; pg_smtp_client = buildSmtpExt "16"; plhaskell = buildPlHaskellExt "15"; - postgreact = buildPostgreactExt "16"; + postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;}; }; }; postgresql_15 = @@ -508,7 +492,7 @@ http = buildHttpExt "15"; pg_smtp_client = buildSmtpExt "15"; plhaskell = buildPlHaskellExt "15"; - postgreact = buildPostgreactExt "15"; + postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;}; }; }; postgresql_14 = @@ -520,7 +504,7 @@ http = buildHttpExt "14"; pg_smtp_client = buildSmtpExt "14"; plhaskell = buildPlHaskellExt "15"; - postgreact = buildPostgreactExt "15"; + postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;}; }; }; writers = let diff --git a/package/c/postgreact/.gitignore b/package/c/postgreact/.gitignore new file mode 100644 index 0000000..cde82a3 --- /dev/null +++ b/package/c/postgreact/.gitignore @@ -0,0 +1,3 @@ +package/c/postgreact/postgreact.control +package/c/postgreact/postgreact.o +package/c/postgreact/postgreact.so diff --git a/package/c/postgreact/Makefile b/package/c/postgreact/Makefile index 170068a..629dd01 100644 --- a/package/c/postgreact/Makefile +++ b/package/c/postgreact/Makefile @@ -1,16 +1,18 @@ EXTENSION ?= postgreact EXTENSION_VERSION ?= 1.0 - -# INFO(nrv): just in case idk how pgxs Makefile and shit all work -EXTVERSION = $(EXTENSION_VERSION) +EXTENSION_COMMENT ?= My first extension MODULE_big = $(EXTENSION) -DATA = $(EXTENSION)--$(EXTENSION_VERSION).sql +DATA = $(EXTENSION)--$(EXTENSION_VERSION).sql $(EXTENSION).control 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) + +.PHONY: $(EXTENSION).control + +$(EXTENSION).control: + sed "s/@EXTENSION_VERSION@/$(EXTENSION_VERSION)/g; s/@EXTENSION_COMMENT@/$(EXTENSION_COMMENT)/g; s/@EXTENSION@/$(EXTENSION)/g" $(EXTENSION).control.in > $@ + include $(PGXS) + +# vim:wrap diff --git a/package/c/postgreact/default.nix b/package/c/postgreact/default.nix index a2d4075..acc3a40 100644 --- a/package/c/postgreact/default.nix +++ b/package/c/postgreact/default.nix @@ -1,11 +1,42 @@ { lib, -}: { + stdenv, + postgresql, + ... +}: +stdenv.mkDerivation rec { pname = "postgreact"; version = "1.0"; src = ./.; + USE_PGXS = 1; + EXTENSION = pname; + EXTENSION_VERSION = version; + EXTENSION_COMMENT = meta.description; + buildInputs = [ + postgresql ]; + + buildPhase = ''make all''; + + installPhase = '' + mkdir -p $out/lib/postgresql $out/share/postgresql/extension + + # Install compiled library + install -m 755 -D 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--${EXTENSION_VERSION}.sql $out/share/postgresql/extension/postgreact--${EXTENSION_VERSION}.sql + ''; + + meta = with lib; { + description = "PostgreSQL extension for simple templating."; + homepage = "https://github.com/yukkop/util.nix"; + license = licenses.asl20; + platforms = postgresql.meta.platforms; + maintainers = with maintainers; []; + }; } diff --git a/package/c/postgreact/postgreact.c b/package/c/postgreact/postgreact.c index efc0cb1..852fc96 100644 --- a/package/c/postgreact/postgreact.c +++ b/package/c/postgreact/postgreact.c @@ -1,14 +1,10 @@ #include "postgres.h" #include "fmgr.h" #include "utils/builtins.h" /* for text_to_cstring and cstring_to_text */ +#include "postgreact.h" -#ifdef PG_MODULE_MAGIC -PG_MODULE_MAGIC; -#endif - -Datum hello(PG_FUNCTION_ARGS) -{ - PG_RETURN_TEXT_P(cstring_to_text("Eblan!")); +Datum hello(PG_FUNCTION_ARGS) { + PG_RETURN_TEXT_P(cstring_to_text("Eblan!")); } void _PG_init(void) { diff --git a/package/c/postgreact/postgreact.control.in b/package/c/postgreact/postgreact.control.in index a7bc821..51233d2 100644 --- a/package/c/postgreact/postgreact.control.in +++ b/package/c/postgreact/postgreact.control.in @@ -1,4 +1,4 @@ -comment = 'My first extension' +comment = '@EXTENSION_COMMENT@' default_version = '@EXTENSION_VERSION@' -module_pathname = '$libdir/postgreact' +module_pathname = '$libdir/@EXTENSION@' relocatable = false diff --git a/package/c/postgreact/postgreact.h b/package/c/postgreact/postgreact.h index 348c5ea..74a5226 100644 --- a/package/c/postgreact/postgreact.h +++ b/package/c/postgreact/postgreact.h @@ -1,3 +1,6 @@ +#ifndef POSTGREACT_H +#define POSTGREACT_H + #include "postgres.h" #ifdef PG_MODULE_MAGIC @@ -9,3 +12,5 @@ void _PG_fini(void); Datum hello(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(hello); + +#endif // POSTGREACT_H