fix?(package): postgreact: ~stir the stupid shit till it works [3]

This commit is contained in:
zerosummed
2025-04-18 21:37:23 +03:00
parent aec4876832
commit 60d977110c
7 changed files with 63 additions and 42 deletions

View File

@@ -133,10 +133,10 @@
pg-migration = pkgs.callPackage ./package/postgres/pg-migration/default.nix rust.commonArgs; pg-migration = pkgs.callPackage ./package/postgres/pg-migration/default.nix rust.commonArgs;
c-hectic = pkgs.callPackage ./package/c/hectic/default.nix {}; c-hectic = pkgs.callPackage ./package/c/hectic/default.nix {};
watch = pkgs.callPackage ./package/c/watch/default.nix {}; watch = pkgs.callPackage ./package/c/watch/default.nix {};
#hmpl = pkgs.callPackage ./package/c/hmpl/default.nix { #hmpl = pkgs.callPackage ./package/c/hmpl/default.nix {
# hectic = self.packages.${system}.hectic; # hectic = self.packages.${system}.hectic;
#}; #};
#postgreact = pkgs.callPackage ./package/c/postgreact {}; postgreact = pkgs.callPackage ./package/c/postgreact {};
}; };
devShells.${system} = let devShells.${system} = let
@@ -457,22 +457,6 @@
}; };
nativeBuildInputs = with prev; [pkg-config curl]; 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 { in {
hectic = self.packages.${prev.system}; hectic = self.packages.${prev.system};
postgresql_17 = postgresql_17 =
@@ -484,7 +468,7 @@
http = buildHttpExt "17"; http = buildHttpExt "17";
pg_smtp_client = buildSmtpExt "17"; pg_smtp_client = buildSmtpExt "17";
plhaskell = buildPlHaskellExt "15"; plhaskell = buildPlHaskellExt "15";
postgreact = buildPostgreactExt "17"; postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
}; };
}; };
postgresql_16 = postgresql_16 =
@@ -496,7 +480,7 @@
http = buildHttpExt "16"; http = buildHttpExt "16";
pg_smtp_client = buildSmtpExt "16"; pg_smtp_client = buildSmtpExt "16";
plhaskell = buildPlHaskellExt "15"; plhaskell = buildPlHaskellExt "15";
postgreact = buildPostgreactExt "16"; postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
}; };
}; };
postgresql_15 = postgresql_15 =
@@ -508,7 +492,7 @@
http = buildHttpExt "15"; http = buildHttpExt "15";
pg_smtp_client = buildSmtpExt "15"; pg_smtp_client = buildSmtpExt "15";
plhaskell = buildPlHaskellExt "15"; plhaskell = buildPlHaskellExt "15";
postgreact = buildPostgreactExt "15"; postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
}; };
}; };
postgresql_14 = postgresql_14 =
@@ -520,7 +504,7 @@
http = buildHttpExt "14"; http = buildHttpExt "14";
pg_smtp_client = buildSmtpExt "14"; pg_smtp_client = buildSmtpExt "14";
plhaskell = buildPlHaskellExt "15"; plhaskell = buildPlHaskellExt "15";
postgreact = buildPostgreactExt "15"; postgreact = self.packages.${prev.system}.postgreact.override {postgresql = prev.postgresql_17;};
}; };
}; };
writers = let writers = let

3
package/c/postgreact/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
package/c/postgreact/postgreact.control
package/c/postgreact/postgreact.o
package/c/postgreact/postgreact.so

View File

@@ -1,16 +1,18 @@
EXTENSION ?= postgreact EXTENSION ?= postgreact
EXTENSION_VERSION ?= 1.0 EXTENSION_VERSION ?= 1.0
EXTENSION_COMMENT ?= My first extension
# INFO(nrv): just in case idk how pgxs Makefile and shit all work
EXTVERSION = $(EXTENSION_VERSION)
MODULE_big = $(EXTENSION) MODULE_big = $(EXTENSION)
DATA = $(EXTENSION)--$(EXTENSION_VERSION).sql DATA = $(EXTENSION)--$(EXTENSION_VERSION).sql $(EXTENSION).control
OBJS = $(EXTENSION).o OBJS = $(EXTENSION).o
PG_CONFIG = pg_config PG_CONFIG = pg_config
$(BUILD_DIR)/$(EXTENSION).control:
sed "s/@EXTENSION_VERSION@/$(EXTVERSION)/g" $(EXTENSION).control.in > $@
PGXS := $(shell $(PG_CONFIG) --pgxs) 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) include $(PGXS)
# vim:wrap

View File

@@ -1,11 +1,42 @@
{ {
lib, lib,
}: { stdenv,
postgresql,
...
}:
stdenv.mkDerivation rec {
pname = "postgreact"; pname = "postgreact";
version = "1.0"; version = "1.0";
src = ./.; src = ./.;
USE_PGXS = 1;
EXTENSION = pname;
EXTENSION_VERSION = version;
EXTENSION_COMMENT = meta.description;
buildInputs = [ 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; [];
};
} }

View File

@@ -1,14 +1,10 @@
#include "postgres.h" #include "postgres.h"
#include "fmgr.h" #include "fmgr.h"
#include "utils/builtins.h" /* for text_to_cstring and cstring_to_text */ #include "utils/builtins.h" /* for text_to_cstring and cstring_to_text */
#include "postgreact.h"
#ifdef PG_MODULE_MAGIC Datum hello(PG_FUNCTION_ARGS) {
PG_MODULE_MAGIC; PG_RETURN_TEXT_P(cstring_to_text("Eblan!"));
#endif
Datum hello(PG_FUNCTION_ARGS)
{
PG_RETURN_TEXT_P(cstring_to_text("Eblan!"));
} }
void _PG_init(void) { void _PG_init(void) {

View File

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

View File

@@ -1,3 +1,6 @@
#ifndef POSTGREACT_H
#define POSTGREACT_H
#include "postgres.h" #include "postgres.h"
#ifdef PG_MODULE_MAGIC #ifdef PG_MODULE_MAGIC
@@ -9,3 +12,5 @@ void _PG_fini(void);
Datum hello(PG_FUNCTION_ARGS); Datum hello(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(hello); PG_FUNCTION_INFO_V1(hello);
#endif // POSTGREACT_H