summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/aerospike.nix20
-rw-r--r--nixos/modules/services/databases/cassandra.nix11
-rw-r--r--nixos/modules/services/databases/clickhouse.nix9
-rw-r--r--nixos/modules/services/databases/cockroachdb.nix9
-rw-r--r--nixos/modules/services/databases/couchdb.nix9
-rw-r--r--nixos/modules/services/databases/dgraph.nix2
-rw-r--r--nixos/modules/services/databases/firebird.nix10
-rw-r--r--nixos/modules/services/databases/hbase-standalone.nix10
-rw-r--r--nixos/modules/services/databases/influxdb.nix8
-rw-r--r--nixos/modules/services/databases/influxdb2.nix8
-rw-r--r--nixos/modules/services/databases/lldap.nix3
-rw-r--r--nixos/modules/services/databases/monetdb.nix7
-rw-r--r--nixos/modules/services/databases/mongodb.nix9
-rw-r--r--nixos/modules/services/databases/neo4j.nix9
-rw-r--r--nixos/modules/services/databases/openldap.nix10
-rw-r--r--nixos/modules/services/databases/opentsdb.nix9
-rw-r--r--nixos/modules/services/databases/pgbouncer.nix9
-rw-r--r--nixos/modules/services/databases/pgmanage.nix9
-rw-r--r--nixos/modules/services/databases/postgresql.md121
-rw-r--r--nixos/modules/services/databases/postgresql.nix79
-rw-r--r--nixos/modules/services/databases/redis.nix11
-rw-r--r--nixos/modules/services/databases/surrealdb.nix9
-rw-r--r--nixos/modules/services/databases/victoriametrics.nix9
23 files changed, 212 insertions, 178 deletions
diff --git a/nixos/modules/services/databases/aerospike.nix b/nixos/modules/services/databases/aerospike.nix
index 21df4cd0577b..4923c0f00ddb 100644
--- a/nixos/modules/services/databases/aerospike.nix
+++ b/nixos/modules/services/databases/aerospike.nix
@@ -41,12 +41,7 @@ in
services.aerospike = {
enable = mkEnableOption (lib.mdDoc "Aerospike server");
- package = mkOption {
- default = pkgs.aerospike;
- defaultText = literalExpression "pkgs.aerospike";
- type = types.package;
- description = lib.mdDoc "Which Aerospike derivation to use";
- };
+ package = mkPackageOption pkgs "aerospike" { };
workDir = mkOption {
type = types.str;
@@ -113,6 +108,11 @@ in
};
users.groups.aerospike.gid = config.ids.gids.aerospike;
+ boot.kernel.sysctl = {
+ "net.core.rmem_max" = mkDefault 15728640;
+ "net.core.wmem_max" = mkDefault 5242880;
+ };
+
systemd.services.aerospike = rec {
description = "Aerospike server";
@@ -136,14 +136,6 @@ in
echo "kernel.shmmax too low, setting to 1GB"
${pkgs.procps}/bin/sysctl -w kernel.shmmax=1073741824
fi
- if [ $(echo "$(cat /proc/sys/net/core/rmem_max) < 15728640" | ${pkgs.bc}/bin/bc) == "1" ]; then
- echo "increasing socket buffer limit (/proc/sys/net/core/rmem_max): $(cat /proc/sys/net/core/rmem_max) -> 15728640"
- echo 15728640 > /proc/sys/net/core/rmem_max
- fi
- if [ $(echo "$(cat /proc/sys/net/core/wmem_max) < 5242880" | ${pkgs.bc}/bin/bc) == "1" ]; then
- echo "increasing socket buffer limit (/proc/sys/net/core/wmem_max): $(cat /proc/sys/net/core/wmem_max) -> 5242880"
- echo 5242880 > /proc/sys/net/core/wmem_max
- fi
install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}"
install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}/smd"
install -d -m0700 -o ${serviceConfig.User} -g ${serviceConfig.Group} "${cfg.workDir}/udf"
diff --git a/nixos/modules/services/databases/cassandra.nix b/nixos/modules/services/databases/cassandra.nix
index cd816ffaf0dd..adf7213dd13f 100644
--- a/nixos/modules/services/databases/cassandra.nix
+++ b/nixos/modules/services/databases/cassandra.nix
@@ -11,6 +11,7 @@ let
recursiveUpdate
mdDoc
mkEnableOption
+ mkPackageOption
mkIf
mkOption
types
@@ -155,14 +156,8 @@ in
'';
};
- package = mkOption {
- type = types.package;
- default = pkgs.cassandra;
- defaultText = literalExpression "pkgs.cassandra";
- example = literalExpression "pkgs.cassandra_3_11";
- description = mdDoc ''
- The Apache Cassandra package to use.
- '';
+ package = mkPackageOption pkgs "cassandra" {
+ example = "cassandra_3_11";
};
jvmOpts = mkOption {
diff --git a/nixos/modules/services/databases/clickhouse.nix b/nixos/modules/services/databases/clickhouse.nix
index dca352ef72fe..288046677721 100644
--- a/nixos/modules/services/databases/clickhouse.nix
+++ b/nixos/modules/services/databases/clickhouse.nix
@@ -13,14 +13,7 @@ with lib;
enable = mkEnableOption (lib.mdDoc "ClickHouse database server");
- package = mkOption {
- type = types.package;
- default = pkgs.clickhouse;
- defaultText = lib.literalExpression "pkgs.clickhouse";
- description = lib.mdDoc ''
- ClickHouse package to use.
- '';
- };
+ package = mkPackageOption pkgs "clickhouse" { };
};
diff --git a/nixos/modules/services/databases/cockroachdb.nix b/nixos/modules/services/databases/cockroachdb.nix
index ff77d30588fe..789f086158db 100644
--- a/nixos/modules/services/databases/cockroachdb.nix
+++ b/nixos/modules/services/databases/cockroachdb.nix
@@ -145,13 +145,8 @@ in
'';
};
- package = mkOption {
- type = types.package;
- default = pkgs.cockroachdb;
- defaultText = literalExpression "pkgs.cockroachdb";
- description = lib.mdDoc ''
- The CockroachDB derivation to use for running the service.
-
+ package = mkPackageOption pkgs "cockroachdb" {
+ extraDescription = ''
This would primarily be useful to enable Enterprise Edition features
in your own custom CockroachDB build (Nixpkgs CockroachDB binaries
only contain open source features and open source code).
diff --git a/nixos/modules/services/databases/couchdb.nix b/nixos/modules/services/databases/couchdb.nix
index bfecfbb3664f..72212c390413 100644
--- a/nixos/modules/services/databases/couchdb.nix
+++ b/nixos/modules/services/databases/couchdb.nix
@@ -36,14 +36,7 @@ in {
enable = mkEnableOption (lib.mdDoc "CouchDB Server");
- package = mkOption {
- type = types.package;
- default = pkgs.couchdb3;
- defaultText = literalExpression "pkgs.couchdb3";
- description = lib.mdDoc ''
- CouchDB package to use.
- '';
- };
+ package = mkPackageOption pkgs "couchdb3" { };
adminUser = mkOption {
type = types.str;
diff --git a/nixos/modules/services/databases/dgraph.nix b/nixos/modules/services/databases/dgraph.nix
index 7f005a9971a6..479754a6447d 100644
--- a/nixos/modules/services/databases/dgraph.nix
+++ b/nixos/modules/services/databases/dgraph.nix
@@ -55,7 +55,7 @@ in
services.dgraph = {
enable = mkEnableOption (lib.mdDoc "Dgraph native GraphQL database with a graph backend");
- package = lib.mkPackageOptionMD pkgs "dgraph" { };
+ package = lib.mkPackageOption pkgs "dgraph" { };
settings = mkOption {
type = settingsFormat.type;
diff --git a/nixos/modules/services/databases/firebird.nix b/nixos/modules/services/databases/firebird.nix
index 6b8c244a7789..431233ce5ed4 100644
--- a/nixos/modules/services/databases/firebird.nix
+++ b/nixos/modules/services/databases/firebird.nix
@@ -42,13 +42,9 @@ in
enable = mkEnableOption (lib.mdDoc "the Firebird super server");
- package = mkOption {
- default = pkgs.firebird;
- defaultText = literalExpression "pkgs.firebird";
- type = types.package;
- example = literalExpression "pkgs.firebird_3";
- description = lib.mdDoc ''
- Which Firebird package to be installed: `pkgs.firebird_3`
+ package = mkPackageOption pkgs "firebird" {
+ example = "firebird_3";
+ extraDescription = ''
For SuperServer use override: `pkgs.firebird_3.override { superServer = true; };`
'';
};
diff --git a/nixos/modules/services/databases/hbase-standalone.nix b/nixos/modules/services/databases/hbase-standalone.nix
index 1ee73ec8d1ff..08ae7625d50a 100644
--- a/nixos/modules/services/databases/hbase-standalone.nix
+++ b/nixos/modules/services/databases/hbase-standalone.nix
@@ -46,15 +46,7 @@ in {
Do not use this configuration for production nor for evaluating HBase performance.
'');
- package = mkOption {
- type = types.package;
- default = pkgs.hbase;
- defaultText = literalExpression "pkgs.hbase";
- description = lib.mdDoc ''
- HBase package to use.
- '';
- };
-
+ package = mkPackageOption pkgs "hbase" { };
user = mkOption {
type = types.str;
diff --git a/nixos/modules/services/databases/influxdb.nix b/nixos/modules/services/databases/influxdb.nix
index b3361d2014ca..adb212ab08d0 100644
--- a/nixos/modules/services/databases/influxdb.nix
+++ b/nixos/modules/services/databases/influxdb.nix
@@ -116,12 +116,7 @@ in
type = types.bool;
};
- package = mkOption {
- default = pkgs.influxdb;
- defaultText = literalExpression "pkgs.influxdb";
- description = lib.mdDoc "Which influxdb derivation to use";
- type = types.package;
- };
+ package = mkPackageOption pkgs "influxdb" { };
user = mkOption {
default = "influxdb";
@@ -166,6 +161,7 @@ in
ExecStart = ''${cfg.package}/bin/influxd -config "${configFile}"'';
User = cfg.user;
Group = cfg.group;
+ Restart = "on-failure";
};
postStart =
let
diff --git a/nixos/modules/services/databases/influxdb2.nix b/nixos/modules/services/databases/influxdb2.nix
index 3740cd01b5dc..2a67d87d4bbb 100644
--- a/nixos/modules/services/databases/influxdb2.nix
+++ b/nixos/modules/services/databases/influxdb2.nix
@@ -19,6 +19,7 @@ let
mapAttrsToList
mdDoc
mkEnableOption
+ mkPackageOption
mkIf
mkOption
nameValuePair
@@ -278,12 +279,7 @@ in
services.influxdb2 = {
enable = mkEnableOption (mdDoc "the influxdb2 server");
- package = mkOption {
- default = pkgs.influxdb2-server;
- defaultText = literalExpression "pkgs.influxdb2";
- description = mdDoc "influxdb2 derivation to use.";
- type = types.package;
- };
+ package = mkPackageOption pkgs "influxdb2" { };
settings = mkOption {
default = { };
diff --git a/nixos/modules/services/databases/lldap.nix b/nixos/modules/services/databases/lldap.nix
index 960792d0805f..e821da8e58aa 100644
--- a/nixos/modules/services/databases/lldap.nix
+++ b/nixos/modules/services/databases/lldap.nix
@@ -8,7 +8,7 @@ in
options.services.lldap = with lib; {
enable = mkEnableOption (mdDoc "lldap");
- package = mkPackageOptionMD pkgs "lldap" { };
+ package = mkPackageOption pkgs "lldap" { };
environment = mkOption {
type = with types; attrsOf str;
@@ -104,6 +104,7 @@ in
config = lib.mkIf cfg.enable {
systemd.services.lldap = {
description = "Lightweight LDAP server (lldap)";
+ wants = [ "network-online.target" ];
after = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
diff --git a/nixos/modules/services/databases/monetdb.nix b/nixos/modules/services/databases/monetdb.nix
index 5573b530a913..1dddeda0959c 100644
--- a/nixos/modules/services/databases/monetdb.nix
+++ b/nixos/modules/services/databases/monetdb.nix
@@ -14,12 +14,7 @@ in {
enable = mkEnableOption (lib.mdDoc "the MonetDB database server");
- package = mkOption {
- type = types.package;
- default = pkgs.monetdb;
- defaultText = literalExpression "pkgs.monetdb";
- description = lib.mdDoc "MonetDB package to use.";
- };
+ package = mkPackageOption pkgs "monetdb" { };
user = mkOption {
type = types.str;
diff --git a/nixos/modules/services/databases/mongodb.nix b/nixos/modules/services/databases/mongodb.nix
index 8f3be1492e9e..f10364bc76c1 100644
--- a/nixos/modules/services/databases/mongodb.nix
+++ b/nixos/modules/services/databases/mongodb.nix
@@ -31,14 +31,7 @@ in
enable = mkEnableOption (lib.mdDoc "the MongoDB server");
- package = mkOption {
- default = pkgs.mongodb;
- defaultText = literalExpression "pkgs.mongodb";
- type = types.package;
- description = lib.mdDoc ''
- Which MongoDB derivation to use.
- '';
- };
+ package = mkPackageOption pkgs "mongodb" { };
user = mkOption {
type = types.str;
diff --git a/nixos/modules/services/databases/neo4j.nix b/nixos/modules/services/databases/neo4j.nix
index 090502424028..56b916ee3758 100644
--- a/nixos/modules/services/databases/neo4j.nix
+++ b/nixos/modules/services/databases/neo4j.nix
@@ -174,14 +174,7 @@ in {
'';
};
- package = mkOption {
- type = types.package;
- default = pkgs.neo4j;
- defaultText = literalExpression "pkgs.neo4j";
- description = lib.mdDoc ''
- Neo4j package to use.
- '';
- };
+ package = mkPackageOption pkgs "neo4j" { };
readOnly = mkOption {
type = types.bool;
diff --git a/nixos/modules/services/databases/openldap.nix b/nixos/modules/services/databases/openldap.nix
index cba3442023cb..df36e37976a4 100644
--- a/nixos/modules/services/databases/openldap.nix
+++ b/nixos/modules/services/databases/openldap.nix
@@ -91,13 +91,8 @@ in {
description = lib.mdDoc "Whether to enable the ldap server.";
};
- package = mkOption {
- type = types.package;
- default = pkgs.openldap;
- defaultText = literalExpression "pkgs.openldap";
- description = lib.mdDoc ''
- OpenLDAP package to use.
-
+ package = mkPackageOption pkgs "openldap" {
+ extraDescription = ''
This can be used to, for example, set an OpenLDAP package
with custom overrides to enable modules or other
functionality.
@@ -299,6 +294,7 @@ in {
"man:slapd-mdb"
];
wantedBy = [ "multi-user.target" ];
+ wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = {
User = cfg.user;
diff --git a/nixos/modules/services/databases/opentsdb.nix b/nixos/modules/services/databases/opentsdb.nix
index 288b716fce03..25f413db809f 100644
--- a/nixos/modules/services/databases/opentsdb.nix
+++ b/nixos/modules/services/databases/opentsdb.nix
@@ -17,14 +17,7 @@ in {
enable = mkEnableOption (lib.mdDoc "OpenTSDB");
- package = mkOption {
- type = types.package;
- default = pkgs.opentsdb;
- defaultText = literalExpression "pkgs.opentsdb";
- description = lib.mdDoc ''
- OpenTSDB package to use.
- '';
- };
+ package = mkPackageOption pkgs "opentsdb" { };
user = mkOption {
type = types.str;
diff --git a/nixos/modules/services/databases/pgbouncer.nix b/nixos/modules/services/databases/pgbouncer.nix
index 1aec03c114d1..65b287e84442 100644
--- a/nixos/modules/services/databases/pgbouncer.nix
+++ b/nixos/modules/services/databases/pgbouncer.nix
@@ -82,14 +82,7 @@ in {
enable = mkEnableOption (lib.mdDoc "PostgreSQL connection pooler");
- package = mkOption {
- type = types.package;
- default = pkgs.pgbouncer;
- defaultText = literalExpression "pkgs.pgbouncer";
- description = lib.mdDoc ''
- The pgbouncer package to use.
- '';
- };
+ package = mkPackageOption pkgs "pgbouncer" { };
openFirewall = mkOption {
type = types.bool;
diff --git a/nixos/modules/services/databases/pgmanage.nix b/nixos/modules/services/databases/pgmanage.nix
index a0933a5ffc45..4b963aee4640 100644
--- a/nixos/modules/services/databases/pgmanage.nix
+++ b/nixos/modules/services/databases/pgmanage.nix
@@ -46,14 +46,7 @@ in {
options.services.pgmanage = {
enable = mkEnableOption (lib.mdDoc "PostgreSQL Administration for the web");
- package = mkOption {
- type = types.package;
- default = pkgs.pgmanage;
- defaultText = literalExpression "pkgs.pgmanage";
- description = lib.mdDoc ''
- The pgmanage package to use.
- '';
- };
+ package = mkPackageOption pkgs "pgmanage" { };
connections = mkOption {
type = types.attrsOf types.str;
diff --git a/nixos/modules/services/databases/postgresql.md b/nixos/modules/services/databases/postgresql.md
index d65d9616e2f2..7d141f12b5de 100644
--- a/nixos/modules/services/databases/postgresql.md
+++ b/nixos/modules/services/databases/postgresql.md
@@ -39,6 +39,125 @@ By default, PostgreSQL stores its databases in {file}`/var/lib/postgresql/$psqlS
services.postgresql.dataDir = "/data/postgresql";
```
+## Initializing {#module-services-postgres-initializing}
+
+As of NixOS 23.11,
+`services.postgresql.ensureUsers.*.ensurePermissions` has been
+deprecated, after a change to default permissions in PostgreSQL 15
+invalidated most of its previous use cases:
+
+- In psql < 15, `ALL PRIVILEGES` used to include `CREATE TABLE`, where
+ in psql >= 15 that would be a separate permission
+- psql >= 15 instead gives only the database owner create permissions
+- Even on psql < 15 (or databases migrated to >= 15), it is
+ recommended to manually assign permissions along these lines
+ - https://www.postgresql.org/docs/release/15.0/
+ - https://www.postgresql.org/docs/15/ddl-schemas.html#DDL-SCHEMAS-PRIV
+
+### Assigning ownership {#module-services-postgres-initializing-ownership}
+
+Usually, the database owner should be a database user of the same
+name. This can be done with
+`services.postgresql.ensureUsers.*.ensureDBOwnership = true;`.
+
+If the database user name equals the connecting system user name,
+postgres by default will accept a passwordless connection via unix
+domain socket. This makes it possible to run many postgres-backed
+services without creating any database secrets at all
+
+### Assigning extra permissions {#module-services-postgres-initializing-extra-permissions}
+
+For many cases, it will be enough to have the database user be the
+owner. Until `services.postgresql.ensureUsers.*.ensurePermissions` has
+been re-thought, if more users need access to the database, please use
+one of the following approaches:
+
+**WARNING:** `services.postgresql.initialScript` is not recommended
+for `ensurePermissions` replacement, as that is *only run on first
+start of PostgreSQL*.
+
+**NOTE:** all of these methods may be obsoleted, when `ensure*` is
+reworked, but it is expected that they will stay viable for running
+database migrations.
+
+**NOTE:** please make sure that any added migrations are idempotent (re-runnable).
+
+#### as superuser {#module-services-postgres-initializing-extra-permissions-superuser}
+
+**Advantage:** compatible with postgres < 15, because it's run
+as the database superuser `postgres`.
+
+##### in database `postStart` {#module-services-postgres-initializing-extra-permissions-superuser-post-start}
+
+**Disadvantage:** need to take care of ordering yourself. In this
+example, `mkAfter` ensures that permissions are assigned after any
+databases from `ensureDatabases` and `extraUser1` from `ensureUsers`
+are already created.
+
+```nix
+ systemd.services.postgresql.postStart = lib.mkAfter ''
+ $PSQL service1 -c 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO "extraUser1"'
+ $PSQL service1 -c 'GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "extraUser1"'
+ # ....
+ '';
+```
+
+##### in intermediate oneshot service {#module-services-postgres-initializing-extra-permissions-superuser-oneshot}
+
+```nix
+ systemd.services."migrate-service1-db1" = {
+ serviceConfig.Type = "oneshot";
+ requiredBy = "service1.service";
+ before = "service1.service";
+ after = "postgresql.service";
+ serviceConfig.User = "postgres";
+ environment.PSQL = "psql --port=${toString services.postgresql.port}";
+ path = [ postgresql ];
+ script = ''
+ $PSQL service1 -c 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO "extraUser1"'
+ $PSQL service1 -c 'GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "extraUser1"'
+ # ....
+ '';
+ };
+```
+
+#### as service user {#module-services-postgres-initializing-extra-permissions-service-user}
+
+**Advantage:** re-uses systemd's dependency ordering;
+
+**Disadvantage:** relies on service user having grant permission. To be combined with `ensureDBOwnership`.
+
+##### in service `preStart` {#module-services-postgres-initializing-extra-permissions-service-user-pre-start}
+
+```nix
+ environment.PSQL = "psql --port=${toString services.postgresql.port}";
+ path = [ postgresql ];
+ systemd.services."service1".preStart = ''
+ $PSQL -c 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO "extraUser1"'
+ $PSQL -c 'GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "extraUser1"'
+ # ....
+ '';
+```
+
+##### in intermediate oneshot service {#module-services-postgres-initializing-extra-permissions-service-user-oneshot}
+
+```nix
+ systemd.services."migrate-service1-db1" = {
+ serviceConfig.Type = "oneshot";
+ requiredBy = "service1.service";
+ before = "service1.service";
+ after = "postgresql.service";
+ serviceConfig.User = "service1";
+ environment.PSQL = "psql --port=${toString services.postgresql.port}";
+ path = [ postgresql ];
+ script = ''
+ $PSQL -c 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO "extraUser1"'
+ $PSQL -c 'GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "extraUser1"'
+ # ....
+ '';
+ };
+```
+
## Upgrading {#module-services-postgres-upgrading}
::: {.note}
@@ -139,7 +258,7 @@ postgresql_15.pkgs.pg_partman postgresql_15.pkgs.pgroonga
To add plugins via NixOS configuration, set `services.postgresql.extraPlugins`:
```
services.postgresql.package = pkgs.postgresql_12;
-services.postgresql.extraPlugins = with pkgs.postgresql_12.pkgs; [
+services.postgresql.extraPlugins = ps: with ps; [
pg_repack
postgis
];
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix
index af4db5c9611f..ed5915735730 100644
--- a/nixos/modules/services/databases/postgresql.nix
+++ b/nixos/modules/services/databases/postgresql.nix
@@ -18,7 +18,7 @@ let
in
if cfg.extraPlugins == []
then base
- else base.withPackages (_: cfg.extraPlugins);
+ else base.withPackages cfg.extraPlugins;
toStr = value:
if true == value then "yes"
@@ -53,12 +53,8 @@ in
enableJIT = mkEnableOption (lib.mdDoc "JIT support");
- package = mkOption {
- type = types.package;
- example = literalExpression "pkgs.postgresql_15";
- description = lib.mdDoc ''
- PostgreSQL package to use.
- '';
+ package = mkPackageOption pkgs "postgresql" {
+ example = "postgresql_15";
};
port = mkOption {
@@ -168,7 +164,12 @@ in
ensurePermissions = mkOption {
type = types.attrsOf types.str;
default = {};
+ visible = false; # This option has been deprecated.
description = lib.mdDoc ''
+ This option is DEPRECATED and should not be used in nixpkgs anymore,
+ use `ensureDBOwnership` instead. It can also break with newer
+ versions of PostgreSQL (≥ 15).
+
Permissions to ensure for the user, specified as an attribute set.
The attribute names specify the database and tables to grant the permissions for.
The attribute values specify the permissions to grant. You may specify one or
@@ -187,6 +188,16 @@ in
'';
};
+ ensureDBOwnership = mkOption {
+ type = types.bool;
+ default = false;
+ description = mdDoc ''
+ Grants the user ownership to a database with the same name.
+ This database must be defined manually in
+ [](#opt-services.postgresql.ensureDatabases).
+ '';
+ };
+
ensureClauses = mkOption {
description = lib.mdDoc ''
An attrset of clauses to grant to the user. Under the hood this uses the
@@ -338,26 +349,21 @@ in
});
default = [];
description = lib.mdDoc ''
- Ensures that the specified users exist and have at least the ensured permissions.
+ Ensures that the specified users exist.
The PostgreSQL users will be identified using peer authentication. This authenticates the Unix user with the
same name only, and that without the need for a password.
- This option will never delete existing users or remove permissions, especially not when the value of this
- option is changed. This means that users created and permissions assigned once through this option or
- otherwise have to be removed manually.
+ This option will never delete existing users or remove DB ownership of databases
+ once granted with `ensureDBOwnership = true;`. This means that this must be
+ cleaned up manually when changing after changing the config in here.
'';
example = literalExpression ''
[
{
name = "nextcloud";
- ensurePermissions = {
- "DATABASE nextcloud" = "ALL PRIVILEGES";
- };
}
{
name = "superuser";
- ensurePermissions = {
- "ALL TABLES IN SCHEMA public" = "ALL PRIVILEGES";
- };
+ ensureDBOwnership = true;
}
]
'';
@@ -385,12 +391,11 @@ in
};
extraPlugins = mkOption {
- type = types.listOf types.path;
- default = [];
- example = literalExpression "with pkgs.postgresql_15.pkgs; [ postgis pg_repack ]";
+ type = with types; coercedTo (listOf path) (path: _ignorePg: path) (functionTo (listOf path));
+ default = _: [];
+ example = literalExpression "ps: with ps; [ postgis pg_repack ]";
description = lib.mdDoc ''
- List of PostgreSQL plugins. PostgreSQL version for each plugin should
- match version for `services.postgresql.package` value.
+ List of PostgreSQL plugins.
'';
};
@@ -399,7 +404,7 @@ in
default = {};
description = lib.mdDoc ''
PostgreSQL configuration. Refer to
- <https://www.postgresql.org/docs/15/config-setting.html#CONFIG-SETTING-CONFIGURATION-FILE>
+ <https://www.postgresql.org/docs/current/config-setting.html#CONFIG-SETTING-CONFIGURATION-FILE>
for an overview of `postgresql.conf`.
::: {.note}
@@ -445,6 +450,27 @@ in
config = mkIf cfg.enable {
+ assertions = map ({ name, ensureDBOwnership, ... }: {
+ assertion = ensureDBOwnership -> builtins.elem name cfg.ensureDatabases;
+ message = ''
+ For each database user defined with `services.postgresql.ensureUsers` and
+ `ensureDBOwnership = true;`, a database with the same name must be defined
+ in `services.postgresql.ensureDatabases`.
+
+ Offender: ${name} has not been found among databases.
+ '';
+ }) cfg.ensureUsers;
+ # `ensurePermissions` is now deprecated, let's avoid it.
+ warnings = lib.optional (any ({ ensurePermissions, ... }: ensurePermissions != {}) cfg.ensureUsers) "
+ `services.postgresql.ensureUsers.*.ensurePermissions` is used in your expressions,
+ this option is known to be broken with newer PostgreSQL versions,
+ consider migrating to `services.postgresql.ensureUsers.*.ensureDBOwnership` or
+ consult the release notes or manual for more migration guidelines.
+
+ This option will be removed in NixOS 24.05 unless it sees significant
+ maintenance improvements.
+ ";