From 9f00d8a38e5268b4799a32ce94f575e404021452 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 29 Jul 2021 12:05:51 +0200 Subject: [PATCH] modules: services: add postgresql Enable the service itself in other modules when needed, but pin the package in a single place. --- modules/services/default.nix | 1 + modules/services/drone.nix | 1 + modules/services/matrix.nix | 1 - modules/services/postgresql.nix | 18 ++++++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 modules/services/postgresql.nix diff --git a/modules/services/default.nix b/modules/services/default.nix index a0f11fd..29ae034 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -20,6 +20,7 @@ ./pirate.nix ./podgrab.nix ./postgresql-backup.nix + ./postgresql.nix ./quassel.nix ./rss-bridge.nix ./sabnzbd.nix diff --git a/modules/services/drone.nix b/modules/services/drone.nix index 50119ac..b1e80ea 100644 --- a/modules/services/drone.nix +++ b/modules/services/drone.nix @@ -81,6 +81,7 @@ in users.groups.drone = { }; services.postgresql = { + enable = true; ensureDatabases = [ "drone" ]; ensureUsers = [{ name = "drone"; diff --git a/modules/services/matrix.nix b/modules/services/matrix.nix index 8f8c82e..5d81448 100644 --- a/modules/services/matrix.nix +++ b/modules/services/matrix.nix @@ -63,7 +63,6 @@ in config = lib.mkIf cfg.enable { services.postgresql = { enable = true; - package = pkgs.postgresql_12; initialScript = pkgs.writeText "synapse-init.sql" '' CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse'; CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse" diff --git a/modules/services/postgresql.nix b/modules/services/postgresql.nix new file mode 100644 index 0000000..8da9ab7 --- /dev/null +++ b/modules/services/postgresql.nix @@ -0,0 +1,18 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.my.services.postgresql; +in +{ + options.my.services.postgresql = with lib; { + enable = my.mkDisableOption "postgres configuration"; + }; + + config = lib.mkMerge [ + # Let other services enable postgres when they need it + (lib.mkIf cfg.enable { + services.postgresql = { + package = pkgs.postgresql_12; + }; + }) + ]; +}