From 8453ab9ae978167ad527008c893f3f4d8de74e65 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Sun, 20 Jul 2025 16:54:59 +0200 Subject: [PATCH 1/3] Add database initialization Runs fieldpoc with `--init` if there are no tables in the database. --- nix/modules/fieldpoc.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nix/modules/fieldpoc.nix b/nix/modules/fieldpoc.nix index b4376db..643dab6 100644 --- a/nix/modules/fieldpoc.nix +++ b/nix/modules/fieldpoc.nix @@ -78,6 +78,10 @@ in { if [ ! -f "/var/lib/fieldpoc/extensions.json" ]; then echo '{"extensions": {}}' > /var/lib/fieldpoc/extensions.json fi + + if [ $(${config.services.postgresql.finalPackage}/bin/psql -q -t -A -c "select count(*) from information_schema.tables where table_schema='fieldpoc';") -eq 0 ]; then + ${pkgs.fieldpoc}/bin/fieldpoc -c /run/fieldpoc/config.json --debug --init + fi ''; }; From f8e585c83ff607e966631bf04c5b77ac889b9397 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Sun, 20 Jul 2025 16:57:09 +0200 Subject: [PATCH 2/3] Add postgresql as service requirement --- nix/modules/fieldpoc.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/modules/fieldpoc.nix b/nix/modules/fieldpoc.nix index 643dab6..24462ad 100644 --- a/nix/modules/fieldpoc.nix +++ b/nix/modules/fieldpoc.nix @@ -31,7 +31,7 @@ in { systemd.services.fieldpoc = { description = "Fieldpoc daemon"; wantedBy = [ "multi-user.target" ]; - requires = [ "network-online.target" "yate.service" ]; + requires = [ "network-online.target" "yate.service" "postgresql.service" ]; after = [ "network-online.target" "yate.service" ]; serviceConfig = { From 1660118c2eda6a654ee718ad1826cf3191f72149 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Sun, 20 Jul 2025 16:53:44 +0200 Subject: [PATCH 3/3] Fix database privileges Fixes psycopg2.errors.InsufficientPrivilege: permission denied for schema public --- nix/modules/fieldpoc.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/modules/fieldpoc.nix b/nix/modules/fieldpoc.nix index 24462ad..d834087 100644 --- a/nix/modules/fieldpoc.nix +++ b/nix/modules/fieldpoc.nix @@ -98,6 +98,7 @@ in { CREATE ROLE fieldpoc WITH LOGIN PASSWORD 'fieldpoc' CREATEDB; CREATE DATABASE fieldpoc; GRANT ALL PRIVILEGES ON DATABASE fieldpoc TO fieldpoc; + GRANT USAGE, CREATE ON SCHEMA public TO fieldpoc; ''; };