diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..f12653d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake .#postgres-c diff --git a/flake.nix b/flake.nix index 35e5b92..7d2e45f 100644 --- a/flake.nix +++ b/flake.nix @@ -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 diff --git a/package/c/postgreact/Makefile b/package/c/postgreact/Makefile new file mode 100644 index 0000000..170068a --- /dev/null +++ b/package/c/postgreact/Makefile @@ -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) diff --git a/package/c/postgreact/default.nix b/package/c/postgreact/default.nix index 76066bc..d985bb8 100644 --- a/package/c/postgreact/default.nix +++ b/package/c/postgreact/default.nix @@ -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; []; }; diff --git a/package/c/postgreact/make.sh b/package/c/postgreact/make.sh index 3f8e91c..09b816f 100755 --- a/package/c/postgreact/make.sh +++ b/package/c/postgreact/make.sh @@ -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 \ No newline at end of file +esac diff --git a/package/c/postgreact/postgreact--0.1.sql b/package/c/postgreact/postgreact--1.0.sql similarity index 71% rename from package/c/postgreact/postgreact--0.1.sql rename to package/c/postgreact/postgreact--1.0.sql index 73c7685..bca1d87 100644 --- a/package/c/postgreact/postgreact--0.1.sql +++ b/package/c/postgreact/postgreact--1.0.sql @@ -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' +; diff --git a/package/c/postgreact/postgreact.c b/package/c/postgreact/postgreact.c index 98b34ec..efc0cb1 100644 --- a/package/c/postgreact/postgreact.c +++ b/package/c/postgreact/postgreact.c @@ -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!")); -} \ No newline at end of file + PG_RETURN_TEXT_P(cstring_to_text("Eblan!")); +} + +void _PG_init(void) { + +} +void _PG_fini(void) { + +} + diff --git a/package/c/postgreact/postgreact.control b/package/c/postgreact/postgreact.control deleted file mode 100644 index 6843cfe..0000000 --- a/package/c/postgreact/postgreact.control +++ /dev/null @@ -1,4 +0,0 @@ -comment = 'My first extension' -default_version = '1.0' -module_pathname = $libdir/postgreact -relocatable = true diff --git a/package/c/postgreact/postgreact.control.in b/package/c/postgreact/postgreact.control.in new file mode 100644 index 0000000..a7bc821 --- /dev/null +++ b/package/c/postgreact/postgreact.control.in @@ -0,0 +1,4 @@ +comment = 'My first extension' +default_version = '@EXTENSION_VERSION@' +module_pathname = '$libdir/postgreact' +relocatable = false diff --git a/package/c/postgreact/postgreact.h b/package/c/postgreact/postgreact.h new file mode 100644 index 0000000..348c5ea --- /dev/null +++ b/package/c/postgreact/postgreact.h @@ -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);