modules: services: add postgresql

Enable the service itself in other modules when needed, but pin the
package in a single place.
This commit is contained in:
Bruno BELANYI 2021-07-29 12:05:51 +02:00
parent eba977b582
commit 99c33cd7ad
4 changed files with 20 additions and 1 deletions

View file

@ -20,6 +20,7 @@
./pirate.nix ./pirate.nix
./podgrab.nix ./podgrab.nix
./postgresql-backup.nix ./postgresql-backup.nix
./postgresql.nix
./quassel.nix ./quassel.nix
./rss-bridge.nix ./rss-bridge.nix
./sabnzbd.nix ./sabnzbd.nix

View file

@ -81,6 +81,7 @@ in
users.groups.drone = { }; users.groups.drone = { };
services.postgresql = { services.postgresql = {
enable = true;
ensureDatabases = [ "drone" ]; ensureDatabases = [ "drone" ];
ensureUsers = [{ ensureUsers = [{
name = "drone"; name = "drone";

View file

@ -63,7 +63,6 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
services.postgresql = { services.postgresql = {
enable = true; enable = true;
package = pkgs.postgresql_12;
initialScript = pkgs.writeText "synapse-init.sql" '' initialScript = pkgs.writeText "synapse-init.sql" ''
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse'; CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse" CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"

View file

@ -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;
};
})
];
}