nixos/postgresql: drop ensurePermissions, fix ensureUsers for postgresql15
Closes #216989 First of all, a bit of context: in PostgreSQL, newly created users don't have the CREATE privilege on the public schema of a database even with `ALL PRIVILEGES` granted via `ensurePermissions` which is how most of the DB users are currently set up "declaratively"[1]. This means e.g. a freshly deployed Nextcloud service will break early because Nextcloud itself cannot CREATE any tables in the public schema anymore. The other issue here is that `ensurePermissions` is a mere hack. It's effectively a mixture of SQL code (e.g. `DATABASE foo` is relying on how a value is substituted in a query. You'd have to parse a subset of SQL to actually know which object are permissions granted to for a user). After analyzing the existing modules I realized that in every case with a single exception[2] the UNIX system user is equal to the db user is equal to the db name and I don't see a compelling reason why people would change that in 99% of the cases. In fact, some modules would even break if you'd change that because the declarations of the system user & the db user are mixed up[3]. So I decided to go with something new which restricts the ways to use `ensure*` options rather than expanding those[4]. Effectively this means that * The DB user _must_ be equal to the DB name. * Permissions are granted via `ensureDBOwnerhip` for an attribute-set in `ensureUsers`. That way, the user is actually the owner and can perform `CREATE`. * For such a postgres user, a database must be declared in `ensureDatabases`. For anything else, a custom state management should be implemented. This can either be `initialScript`, doing it manual, outside of the module or by implementing proper state management for postgresql[5], but the current state of `ensure*` isn't even declarative, but a convergent tool which is what Nix actually claims to _not_ do. Regarding existing setups: there are effectively two options: * Leave everything as-is (assuming that system user == db user == db name): then the DB user will automatically become the DB owner and everything else stays the same. * Drop the `createDatabase = true;` declarations: nothing will change because a removal of `ensure*` statements is ignored, so it doesn't matter at all whether this option is kept after the first deploy (and later on you'd usually restore from backups anyways). The DB user isn't the owner of the DB then, but for an existing setup this is irrelevant because CREATE on the public schema isn't revoked from existing users (only not granted for new users). [1] not really declarative though because removals of these statements are simply ignored for instance: https://github.com/NixOS/nixpkgs/issues/206467 [2] `services.invidious`: I removed the `ensure*` part temporarily because it IMHO falls into the category "manage the state on your own" (see the commit message). See also https://github.com/NixOS/nixpkgs/pull/265857 [3] e.g. roundcube had `"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";` [4] As opposed to other changes that are considered a potential fix, but also add more things like collation for DBs or passwords that are _never_ touched again when changing those. [5] As suggested in e.g. https://github.com/NixOS/nixpkgs/issues/206467
This commit is contained in:
parent
c42941c549
commit
48459567ae
47 changed files with 176 additions and 153 deletions
|
@ -165,25 +165,13 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
ensurePermissions = mkOption {
|
ensureDBOwnership = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.bool;
|
||||||
default = {};
|
default = false;
|
||||||
description = lib.mdDoc ''
|
description = mdDoc ''
|
||||||
Permissions to ensure for the user, specified as an attribute set.
|
Grants the user ownership to a database with the same name.
|
||||||
The attribute names specify the database and tables to grant the permissions for.
|
This database must be defined manually in
|
||||||
The attribute values specify the permissions to grant. You may specify one or
|
[](#opt-services.postgresql.ensureDatabases).
|
||||||
multiple comma-separated SQL privileges here.
|
|
||||||
|
|
||||||
For more information on how to specify the target
|
|
||||||
and on which privileges exist, see the
|
|
||||||
[GRANT syntax](https://www.postgresql.org/docs/current/sql-grant.html).
|
|
||||||
The attributes are used as `GRANT ''${attrValue} ON ''${attrName}`.
|
|
||||||
'';
|
|
||||||
example = literalExpression ''
|
|
||||||
{
|
|
||||||
"DATABASE \"nextcloud\"" = "ALL PRIVILEGES";
|
|
||||||
"ALL TABLES IN SCHEMA public" = "ALL PRIVILEGES";
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -338,26 +326,21 @@ in
|
||||||
});
|
});
|
||||||
default = [];
|
default = [];
|
||||||
description = lib.mdDoc ''
|
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
|
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.
|
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
|
This option will never delete existing users or remove DB ownership of databases
|
||||||
option is changed. This means that users created and permissions assigned once through this option or
|
once granted with `ensureDBOwnership = true;`. This means that this must be
|
||||||
otherwise have to be removed manually.
|
cleaned up manually when changing after changing the config in here.
|
||||||
'';
|
'';
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name = "nextcloud";
|
name = "nextcloud";
|
||||||
ensurePermissions = {
|
|
||||||
"DATABASE nextcloud" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "superuser";
|
name = "superuser";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"ALL TABLES IN SCHEMA public" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
'';
|
'';
|
||||||
|
@ -445,6 +428,19 @@ in
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = all
|
||||||
|
({ name, ensureDBOwnership, ... }: ensureDBOwnership -> builtins.elem name cfg.ensureDatabases)
|
||||||
|
cfg.ensureUsers;
|
||||||
|
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`.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
services.postgresql.settings =
|
services.postgresql.settings =
|
||||||
{
|
{
|
||||||
hba_file = "${pkgs.writeText "pg_hba.conf" cfg.authentication}";
|
hba_file = "${pkgs.writeText "pg_hba.conf" cfg.authentication}";
|
||||||
|
@ -557,11 +553,9 @@ in
|
||||||
concatMapStrings
|
concatMapStrings
|
||||||
(user:
|
(user:
|
||||||
let
|
let
|
||||||
userPermissions = concatStringsSep "\n"
|
dbOwnershipStmt = optionalString
|
||||||
(mapAttrsToList
|
user.ensureDBOwnership
|
||||||
(database: permission: ''$PSQL -tAc 'GRANT ${permission} ON ${database} TO "${user.name}"' '')
|
''$PSQL -tAc 'ALTER DATABASE "${user.name}" OWNER TO "${user.name}";' '';
|
||||||
user.ensurePermissions
|
|
||||||
);
|
|
||||||
|
|
||||||
filteredClauses = filterAttrs (name: value: value != null) user.ensureClauses;
|
filteredClauses = filterAttrs (name: value: value != null) user.ensureClauses;
|
||||||
|
|
||||||
|
@ -570,8 +564,9 @@ in
|
||||||
userClauses = ''$PSQL -tAc 'ALTER ROLE "${user.name}" ${concatStringsSep " " clauseSqlStatements}' '';
|
userClauses = ''$PSQL -tAc 'ALTER ROLE "${user.name}" ${concatStringsSep " " clauseSqlStatements}' '';
|
||||||
in ''
|
in ''
|
||||||
$PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname='${user.name}'" | grep -q 1 || $PSQL -tAc 'CREATE USER "${user.name}"'
|
$PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname='${user.name}'" | grep -q 1 || $PSQL -tAc 'CREATE USER "${user.name}"'
|
||||||
${userPermissions}
|
|
||||||
${userClauses}
|
${userClauses}
|
||||||
|
|
||||||
|
${dbOwnershipStmt}
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
cfg.ensureUsers
|
cfg.ensureUsers
|
||||||
|
|
|
@ -204,7 +204,7 @@ in
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
assertion = cfg.database.createLocally -> cfg.database.user == "zammad";
|
assertion = cfg.database.createLocally -> cfg.database.user == "zammad" && cfg.database.name == "zammad";
|
||||||
message = "services.zammad.database.user must be set to \"zammad\" if services.zammad.database.createLocally is set to true";
|
message = "services.zammad.database.user must be set to \"zammad\" if services.zammad.database.createLocally is set to true";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -231,7 +231,7 @@ in
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = cfg.database.user;
|
name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -121,7 +121,7 @@ in
|
||||||
ensureDatabases = [ "odoo" ];
|
ensureDatabases = [ "odoo" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "odoo";
|
name = "odoo";
|
||||||
ensurePermissions = { "DATABASE odoo" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -168,7 +168,7 @@ in {
|
||||||
|
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "listmonk";
|
name = "listmonk";
|
||||||
ensurePermissions = { "DATABASE listmonk" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
ensureDatabases = [ "listmonk" ];
|
ensureDatabases = [ "listmonk" ];
|
||||||
|
|
|
@ -179,14 +179,22 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = localDB -> cfg.database.username == cfg.database.dbname;
|
||||||
|
message = ''
|
||||||
|
When setting up a DB and its owner user, the owner and the DB name must be
|
||||||
|
equal!
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
services.postgresql = mkIf localDB {
|
services.postgresql = mkIf localDB {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureDatabases = [ cfg.database.dbname ];
|
ensureDatabases = [ cfg.database.dbname ];
|
||||||
ensureUsers = [ {
|
ensureUsers = [ {
|
||||||
name = cfg.database.username;
|
name = cfg.database.username;
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ in
|
||||||
default = null;
|
default = null;
|
||||||
example = "/run/keys/sympa-dbpassword";
|
example = "/run/keys/sympa-dbpassword";
|
||||||
description = lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
A file containing the password for {option}`services.sympa.database.user`.
|
A file containing the password for {option}`services.sympa.database.name`.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -342,6 +342,7 @@ in
|
||||||
|
|
||||||
db_type = cfg.database.type;
|
db_type = cfg.database.type;
|
||||||
db_name = cfg.database.name;
|
db_name = cfg.database.name;
|
||||||
|
db_user = cfg.database.name;
|
||||||
}
|
}
|
||||||
// (optionalAttrs (cfg.database.host != null) {
|
// (optionalAttrs (cfg.database.host != null) {
|
||||||
db_host = cfg.database.host;
|
db_host = cfg.database.host;
|
||||||
|
@ -355,9 +356,6 @@ in
|
||||||
// (optionalAttrs (cfg.database.port != null) {
|
// (optionalAttrs (cfg.database.port != null) {
|
||||||
db_port = cfg.database.port;
|
db_port = cfg.database.port;
|
||||||
})
|
})
|
||||||
// (optionalAttrs (cfg.database.user != null) {
|
|
||||||
db_user = cfg.database.user;
|
|
||||||
})
|
|
||||||
// (optionalAttrs (cfg.mta.type == "postfix") {
|
// (optionalAttrs (cfg.mta.type == "postfix") {
|
||||||
sendmail_aliases = "${dataDir}/sympa_transport";
|
sendmail_aliases = "${dataDir}/sympa_transport";
|
||||||
aliases_program = "${pkgs.postfix}/bin/postmap";
|
aliases_program = "${pkgs.postfix}/bin/postmap";
|
||||||
|
@ -393,7 +391,7 @@ in
|
||||||
users.groups.${group} = {};
|
users.groups.${group} = {};
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.user == user;
|
{ assertion = cfg.database.createLocally -> cfg.database.user == user && cfg.database.name == cfg.database.user;
|
||||||
message = "services.sympa.database.user must be set to ${user} if services.sympa.database.createLocally is set to true";
|
message = "services.sympa.database.user must be set to ${user} if services.sympa.database.createLocally is set to true";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
||||||
|
@ -579,7 +577,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.database.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,9 +74,9 @@ in
|
||||||
services.postgresql = lib.optionalAttrs cfg.createDatabase {
|
services.postgresql = lib.optionalAttrs cfg.createDatabase {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureDatabases = [ "matrix-sliding-sync" ];
|
ensureDatabases = [ "matrix-sliding-sync" ];
|
||||||
ensureUsers = [ rec {
|
ensureUsers = [ {
|
||||||
name = "matrix-sliding-sync";
|
name = "matrix-sliding-sync";
|
||||||
ensurePermissions."DATABASE \"${name}\"" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
} ];
|
} ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -135,9 +135,7 @@ in {
|
||||||
ensureDatabases = ["mautrix-facebook"];
|
ensureDatabases = ["mautrix-facebook"];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "mautrix-facebook";
|
name = "mautrix-facebook";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE \"mautrix-facebook\"" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,7 @@ in
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "atuin";
|
name = "atuin";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE atuin" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}];
|
}];
|
||||||
ensureDatabases = [ "atuin" ];
|
ensureDatabases = [ "atuin" ];
|
||||||
};
|
};
|
||||||
|
|
|
@ -357,6 +357,14 @@ in
|
||||||
assertion = cfg.database.createDatabase -> useSqlite || cfg.database.user == cfg.user;
|
assertion = cfg.database.createDatabase -> useSqlite || cfg.database.user == cfg.user;
|
||||||
message = "services.forgejo.database.user must match services.forgejo.user if the database is to be automatically provisioned";
|
message = "services.forgejo.database.user must match services.forgejo.user if the database is to be automatically provisioned";
|
||||||
}
|
}
|
||||||
|
{ assertion = cfg.database.createDatabase && usePostgresql -> cfg.database.user == cfg.database.name;
|
||||||
|
message = ''
|
||||||
|
When creating a database via NixOS, the db user and db name must be equal!
|
||||||
|
If you already have an existing DB+user and this assertion is new, you can safely set
|
||||||
|
`services.forgejo.createDatabase` to `false` because removal of `ensureUsers`
|
||||||
|
and `ensureDatabases` doesn't have any effect.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
services.forgejo.settings = {
|
services.forgejo.settings = {
|
||||||
|
@ -423,7 +431,7 @@ in
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = cfg.database.user;
|
name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -394,6 +394,14 @@ in
|
||||||
{ assertion = cfg.database.createDatabase -> useSqlite || cfg.database.user == cfg.user;
|
{ assertion = cfg.database.createDatabase -> useSqlite || cfg.database.user == cfg.user;
|
||||||
message = "services.gitea.database.user must match services.gitea.user if the database is to be automatically provisioned";
|
message = "services.gitea.database.user must match services.gitea.user if the database is to be automatically provisioned";
|
||||||
}
|
}
|
||||||
|
{ assertion = cfg.database.createDatabase && usePostgresql -> cfg.database.user == cfg.database.name;
|
||||||
|
message = ''
|
||||||
|
When creating a database via NixOS, the db user and db name must be equal!
|
||||||
|
If you already have an existing DB+user and this assertion is new, you can safely set
|
||||||
|
`services.gitea.createDatabase` to `false` because removal of `ensureUsers`
|
||||||
|
and `ensureDatabases` doesn't have any effect.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
services.gitea.settings = {
|
services.gitea.settings = {
|
||||||
|
@ -461,7 +469,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.database.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -267,7 +267,7 @@ in
|
||||||
{ assertion = cfg.database.passwordFile != null || cfg.database.socket != null;
|
{ assertion = cfg.database.passwordFile != null || cfg.database.socket != null;
|
||||||
message = "one of services.redmine.database.socket or services.redmine.database.passwordFile must be set";
|
message = "one of services.redmine.database.socket or services.redmine.database.passwordFile must be set";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.user == cfg.user;
|
{ assertion = cfg.database.createLocally -> cfg.database.user == cfg.user && cfg.database.user == cfg.database.name;
|
||||||
message = "services.redmine.database.user must be set to ${cfg.user} if services.redmine.database.createLocally is set true";
|
message = "services.redmine.database.user must be set to ${cfg.user} if services.redmine.database.createLocally is set true";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.socket != null;
|
{ assertion = cfg.database.createLocally -> cfg.database.socket != null;
|
||||||
|
@ -315,7 +315,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.database.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -242,6 +242,15 @@ in
|
||||||
} cfg.nginx.virtualHost ];
|
} cfg.nginx.virtualHost ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = srvCfg.user == srvCfg.postgresql.database;
|
||||||
|
message = ''
|
||||||
|
When creating a database via NixOS, the db user and db name must be equal!
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
services.postgresql = mkIf cfg.postgresql.enable {
|
services.postgresql = mkIf cfg.postgresql.enable {
|
||||||
authentication = ''
|
authentication = ''
|
||||||
local ${srvCfg.postgresql.database} ${srvCfg.user} trust
|
local ${srvCfg.postgresql.database} ${srvCfg.user} trust
|
||||||
|
@ -249,7 +258,7 @@ in
|
||||||
ensureDatabases = [ srvCfg.postgresql.database ];
|
ensureDatabases = [ srvCfg.postgresql.database ];
|
||||||
ensureUsers = map (name: {
|
ensureUsers = map (name: {
|
||||||
inherit name;
|
inherit name;
|
||||||
ensurePermissions = { "DATABASE \"${srvCfg.postgresql.database}\"" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}) [srvCfg.user];
|
}) [srvCfg.user];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ in
|
||||||
{ assertion = !config.services.zabbixServer.enable;
|
{ assertion = !config.services.zabbixServer.enable;
|
||||||
message = "Please choose one of services.zabbixServer or services.zabbixProxy.";
|
message = "Please choose one of services.zabbixServer or services.zabbixProxy.";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.user == user;
|
{ assertion = cfg.database.createLocally -> cfg.database.user == user && cfg.database.name == cfg.database.user;
|
||||||
message = "services.zabbixProxy.database.user must be set to ${user} if services.zabbixProxy.database.createLocally is set true";
|
message = "services.zabbixProxy.database.user must be set to ${user} if services.zabbixProxy.database.createLocally is set true";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
||||||
|
@ -252,7 +252,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.database.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -191,7 +191,7 @@ in
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.user == user;
|
{ assertion = cfg.database.createLocally -> cfg.database.user == user && cfg.database.user == cfg.database.name;
|
||||||
message = "services.zabbixServer.database.user must be set to ${user} if services.zabbixServer.database.createLocally is set true";
|
message = "services.zabbixServer.database.user must be set to ${user} if services.zabbixServer.database.createLocally is set true";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
||||||
|
@ -240,7 +240,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.database.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,7 @@ in {
|
||||||
ensureDatabases = [ "hockeypuck" ];
|
ensureDatabases = [ "hockeypuck" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "hockeypuck";
|
name = "hockeypuck";
|
||||||
ensurePermissions."DATABASE hockeypuck" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
|
@ -149,8 +149,8 @@ in {
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.username == name;
|
{ assertion = cfg.database.createLocally -> cfg.database.username == name && cfg.database.database == cfg.database.username;
|
||||||
message = "services.coder.database.username must be set to ${user} if services.coder.database.createLocally is set true";
|
message = "services.coder.database.username must be set to ${name} if services.coder.database.createLocally is set true";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -193,10 +193,8 @@ in {
|
||||||
cfg.database.database
|
cfg.database.database
|
||||||
];
|
];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = cfg.database.username;
|
name = cfg.user;
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE \"${cfg.database.database}\"" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,9 +128,7 @@ in
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "gotosocial";
|
name = "gotosocial";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE gotosocial" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -112,12 +112,6 @@ let
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureDatabases = lib.singleton cfg.settings.db.dbname;
|
ensureDatabases = lib.singleton cfg.settings.db.dbname;
|
||||||
ensureUsers = lib.singleton {
|
|
||||||
name = cfg.settings.db.user;
|
|
||||||
ensurePermissions = {
|
|
||||||
"DATABASE ${cfg.settings.db.dbname}" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
# This is only needed because the unix user invidious isn't the same as
|
# This is only needed because the unix user invidious isn't the same as
|
||||||
# the database user. This tells postgres to map one to the other.
|
# the database user. This tells postgres to map one to the other.
|
||||||
identMap = ''
|
identMap = ''
|
||||||
|
|
|
@ -146,7 +146,7 @@ in
|
||||||
ensureDatabases = [ cfg.settings.database.database ];
|
ensureDatabases = [ cfg.settings.database.database ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = cfg.settings.database.user;
|
name = cfg.settings.database.user;
|
||||||
ensurePermissions."DATABASE ${cfg.settings.database.database}" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -557,7 +557,7 @@ in {
|
||||||
config = lib.mkIf cfg.enable (lib.mkMerge [{
|
config = lib.mkIf cfg.enable (lib.mkMerge [{
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
assertion = databaseActuallyCreateLocally -> (cfg.user == cfg.database.user);
|
assertion = databaseActuallyCreateLocally -> (cfg.user == cfg.database.user && cfg.database.user == cfg.database.name);
|
||||||
message = ''
|
message = ''
|
||||||
For local automatic database provisioning (services.mastodon.database.createLocally == true) with peer
|
For local automatic database provisioning (services.mastodon.database.createLocally == true) with peer
|
||||||
authentication (services.mastodon.database.host == "/run/postgresql") to work services.mastodon.user
|
authentication (services.mastodon.database.host == "/run/postgresql") to work services.mastodon.user
|
||||||
|
@ -799,8 +799,8 @@ in {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = cfg.database.user;
|
name = cfg.database.name;
|
||||||
ensurePermissions."DATABASE ${cfg.database.name}" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
|
|
|
@ -454,7 +454,7 @@ in
|
||||||
{ assertion = cfg.database.createLocally -> (cfg.database.type == "mysql" || cfg.database.type == "postgres");
|
{ assertion = cfg.database.createLocally -> (cfg.database.type == "mysql" || cfg.database.type == "postgres");
|
||||||
message = "services.mediawiki.createLocally is currently only supported for database type 'mysql' and 'postgres'";
|
message = "services.mediawiki.createLocally is currently only supported for database type 'mysql' and 'postgres'";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.user == user;
|
{ assertion = cfg.database.createLocally -> cfg.database.user == user && cfg.database.name == cfg.database.user;
|
||||||
message = "services.mediawiki.database.user must be set to ${user} if services.mediawiki.database.createLocally is set true";
|
message = "services.mediawiki.database.user must be set to ${user} if services.mediawiki.database.createLocally is set true";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.socket != null;
|
{ assertion = cfg.database.createLocally -> cfg.database.socket != null;
|
||||||
|
@ -486,7 +486,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = cfg.database.user;
|
name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE \"${cfg.database.name}\"" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,10 @@ let
|
||||||
|
|
||||||
defaultAddress = "localhost:8080";
|
defaultAddress = "localhost:8080";
|
||||||
|
|
||||||
dbUser = "miniflux";
|
|
||||||
dbName = "miniflux";
|
|
||||||
|
|
||||||
pgbin = "${config.services.postgresql.package}/bin";
|
pgbin = "${config.services.postgresql.package}/bin";
|
||||||
preStart = pkgs.writeScript "miniflux-pre-start" ''
|
preStart = pkgs.writeScript "miniflux-pre-start" ''
|
||||||
#!${pkgs.runtimeShell}
|
#!${pkgs.runtimeShell}
|
||||||
${pgbin}/psql "${dbName}" -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
${pgbin}/psql "miniflux" -c "CREATE EXTENSION IF NOT EXISTS hstore"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
|
|
||||||
|
@ -62,7 +59,7 @@ in
|
||||||
|
|
||||||
services.miniflux.config = {
|
services.miniflux.config = {
|
||||||
LISTEN_ADDR = mkDefault defaultAddress;
|
LISTEN_ADDR = mkDefault defaultAddress;
|
||||||
DATABASE_URL = "user=${dbUser} host=/run/postgresql dbname=${dbName}";
|
DATABASE_URL = "user=miniflux host=/run/postgresql dbname=miniflux";
|
||||||
RUN_MIGRATIONS = "1";
|
RUN_MIGRATIONS = "1";
|
||||||
CREATE_ADMIN = "1";
|
CREATE_ADMIN = "1";
|
||||||
};
|
};
|
||||||
|
@ -70,12 +67,10 @@ in
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureUsers = [ {
|
ensureUsers = [ {
|
||||||
name = dbUser;
|
name = "miniflux";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE ${dbName}" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
} ];
|
} ];
|
||||||
ensureDatabases = [ dbName ];
|
ensureDatabases = [ "miniflux" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.miniflux-dbsetup = {
|
systemd.services.miniflux-dbsetup = {
|
||||||
|
@ -97,7 +92,7 @@ in
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${cfg.package}/bin/miniflux";
|
ExecStart = "${cfg.package}/bin/miniflux";
|
||||||
User = dbUser;
|
User = "miniflux";
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
RuntimeDirectory = "miniflux";
|
RuntimeDirectory = "miniflux";
|
||||||
RuntimeDirectoryMode = "0700";
|
RuntimeDirectoryMode = "0700";
|
||||||
|
|
|
@ -212,6 +212,12 @@ in
|
||||||
assertion = cfg.nginx.enable -> (cfg.settings.":mobilizon"."Mobilizon.Web.Endpoint".http.ip == settingsFormat.lib.mkTuple [ 0 0 0 0 0 0 0 1 ]);
|
assertion = cfg.nginx.enable -> (cfg.settings.":mobilizon"."Mobilizon.Web.Endpoint".http.ip == settingsFormat.lib.mkTuple [ 0 0 0 0 0 0 0 1 ]);
|
||||||
message = "Setting the IP mobilizon listens on is only possible when the nginx config is not used, as it is hardcoded there.";
|
message = "Setting the IP mobilizon listens on is only possible when the nginx config is not used, as it is hardcoded there.";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
assertion = isLocalPostgres -> repoSettings.database == repoSettings.username;
|
||||||
|
message = ''
|
||||||
|
When creating a database via NixOS, the db user and db name must be equal!
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
services.mobilizon.settings = {
|
services.mobilizon.settings = {
|
||||||
|
@ -372,9 +378,7 @@ in
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = dbUser;
|
name = dbUser;
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE \"${repoSettings.database}\"" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
extraPlugins = with postgresql.pkgs; [ postgis ];
|
extraPlugins = with postgresql.pkgs; [ postgis ];
|
||||||
|
|
|
@ -194,7 +194,7 @@ in
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.user == user;
|
{ assertion = cfg.database.createLocally -> cfg.database.user == user && cfg.database.user == cfg.database.name;
|
||||||
message = "services.moodle.database.user must be set to ${user} if services.moodle.database.createLocally is set true";
|
message = "services.moodle.database.user must be set to ${user} if services.moodle.database.createLocally is set true";
|
||||||
}
|
}
|
||||||
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
{ assertion = cfg.database.createLocally -> cfg.database.passwordFile == null;
|
||||||
|
@ -220,7 +220,7 @@ in
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.database.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -257,9 +257,7 @@ in {
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "netbox";
|
name = "netbox";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE netbox" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -1042,7 +1042,7 @@ in {
|
||||||
ensureDatabases = [ cfg.config.dbname ];
|
ensureDatabases = [ cfg.config.dbname ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = cfg.config.dbuser;
|
name = cfg.config.dbuser;
|
||||||
ensurePermissions = { "DATABASE ${cfg.config.dbname}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ in
|
||||||
ensureDatabases = [ "onlyoffice" ];
|
ensureDatabases = [ "onlyoffice" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "onlyoffice";
|
name = "onlyoffice";
|
||||||
ensurePermissions = { "DATABASE \"onlyoffice\"" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -581,7 +581,7 @@ in
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "outline";
|
name = "outline";
|
||||||
ensurePermissions."DATABASE outline" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
ensureDatabases = [ "outline" ];
|
ensureDatabases = [ "outline" ];
|
||||||
};
|
};
|
||||||
|
|
|
@ -186,9 +186,7 @@ in {
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "peering-manager";
|
name = "peering-manager";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE \"peering-manager\"" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -271,7 +271,6 @@ in {
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = user;
|
name = user;
|
||||||
ensurePermissions = { };
|
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -529,6 +529,15 @@ let
|
||||||
assertion = cfg.database.password != null -> cfg.database.passwordFile == null;
|
assertion = cfg.database.password != null -> cfg.database.passwordFile == null;
|
||||||
message = "Cannot set both password and passwordFile";
|
message = "Cannot set both password and passwordFile";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
assertion = cfg.database.createLocally -> cfg.database.name == cfg.user && cfg.database.user == cfg.user;
|
||||||
|
message = ''
|
||||||
|
When creating a database via NixOS, the db user and db name must be equal!
|
||||||
|
If you already have an existing DB+user and this assertion is new, you can safely set
|
||||||
|
`services.tt-rss.database.createLocally` to `false` because removal of `ensureUsers`
|
||||||
|
and `ensureDatabases` doesn't have any effect.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
|
services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
|
||||||
|
@ -632,8 +641,8 @@ let
|
||||||
enable = mkDefault true;
|
enable = mkDefault true;
|
||||||
ensureDatabases = [ cfg.database.name ];
|
ensureDatabases = [ cfg.database.name ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = cfg.user;
|
{ name = cfg.database.user;
|
||||||
ensurePermissions = { "DATABASE ${cfg.database.name}" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,7 +93,7 @@ in with lib; {
|
||||||
ensureDatabases = [ "hydron" ];
|
ensureDatabases = [ "hydron" ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = "hydron";
|
{ name = "hydron";
|
||||||
ensurePermissions = { "DATABASE hydron" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,7 +49,7 @@ import ./make-test-python.nix ({ lib, ... }: {
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "dex";
|
name = "dex";
|
||||||
ensurePermissions = { "DATABASE dex" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ with import ../lib/testing-python.nix { inherit system; };
|
||||||
ensureDatabases = [ "ferretdb" ];
|
ensureDatabases = [ "ferretdb" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "ferretdb";
|
name = "ferretdb";
|
||||||
ensurePermissions."DATABASE ferretdb" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: {
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "freshrss";
|
name = "freshrss";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE freshrss" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
initialScript = pkgs.writeText "postgresql-password" ''
|
initialScript = pkgs.writeText "postgresql-password" ''
|
||||||
|
|
|
@ -55,7 +55,7 @@ let
|
||||||
ensureDatabases = [ "grafana" ];
|
ensureDatabases = [ "grafana" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "grafana";
|
name = "grafana";
|
||||||
ensurePermissions."DATABASE grafana" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
systemd.services.grafana.after = [ "postgresql.service" ];
|
systemd.services.grafana.after = [ "postgresql.service" ];
|
||||||
|
|
|
@ -35,7 +35,7 @@ in {
|
||||||
ensureDatabases = [ "hockeypuck" ];
|
ensureDatabases = [ "hockeypuck" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "hockeypuck";
|
name = "hockeypuck";
|
||||||
ensurePermissions."DATABASE hockeypuck" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,13 +9,11 @@ in {
|
||||||
nodes.hass = { pkgs, ... }: {
|
nodes.hass = { pkgs, ... }: {
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
ensureDatabases = [ "hass" ];
|
||||||
# FIXME: hack for https://github.com/NixOS/nixpkgs/issues/216989
|
ensureUsers = [{
|
||||||
# Should be replaced with ensureUsers again when a solution for that is found
|
name = "hass";
|
||||||
initialScript = pkgs.writeText "hass-setup-db.sql" ''
|
ensureDBOwnership = true;
|
||||||
CREATE ROLE hass WITH LOGIN;
|
}];
|
||||||
CREATE DATABASE hass WITH OWNER hass;
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
services.home-assistant = {
|
services.home-assistant = {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import ./make-test-python.nix ({ lib, ... }: {
|
||||||
ensureDatabases = [ "paperless" ];
|
ensureDatabases = [ "paperless" ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = config.services.paperless.user;
|
{ name = config.services.paperless.user;
|
||||||
ensurePermissions = { "DATABASE \"paperless\"" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,14 +19,6 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
||||||
authentication = ''
|
authentication = ''
|
||||||
host all all localhost trust
|
host all all localhost trust
|
||||||
'';
|
'';
|
||||||
ensureUsers = [
|
|
||||||
{
|
|
||||||
name = "postgres";
|
|
||||||
ensurePermissions = {
|
|
||||||
"DATABASE \"postgres\"" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
services.pgadmin = {
|
services.pgadmin = {
|
||||||
|
|
|
@ -24,13 +24,11 @@ in
|
||||||
services = {
|
services = {
|
||||||
postgresql = {
|
postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureDatabases = [ "testdb" ];
|
ensureDatabases = [ "test" ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "testuser";
|
name = "test";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE testdb" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}];
|
}];
|
||||||
authentication = ''
|
authentication = ''
|
||||||
local testdb testuser scram-sha-256
|
local testdb testuser scram-sha-256
|
||||||
|
@ -40,7 +38,7 @@ in
|
||||||
pgbouncer = {
|
pgbouncer = {
|
||||||
enable = true;
|
enable = true;
|
||||||
listenAddress = "localhost";
|
listenAddress = "localhost";
|
||||||
databases = { testdb = "host=/run/postgresql/ port=5432 auth_user=testuser dbname=testdb"; };
|
databases = { test = "host=/run/postgresql/ port=5432 auth_user=testuser dbname=test"; };
|
||||||
authType = "scram-sha-256";
|
authType = "scram-sha-256";
|
||||||
authFile = testAuthFile;
|
authFile = testAuthFile;
|
||||||
};
|
};
|
||||||
|
@ -55,7 +53,7 @@ in
|
||||||
|
|
||||||
# Test if we can make a query through PgBouncer
|
# Test if we can make a query through PgBouncer
|
||||||
one.wait_until_succeeds(
|
one.wait_until_succeeds(
|
||||||
"psql 'postgres://testuser:testpass@localhost:6432/testdb' -c 'SELECT 1;'"
|
"psql 'postgres://testuser:testpass@localhost:6432/test' -c 'SELECT 1;'"
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
|
@ -87,9 +87,7 @@ let
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{
|
{
|
||||||
name = "powerdnsadmin";
|
name = "powerdnsadmin";
|
||||||
ensurePermissions = {
|
ensureDBOwnership = true;
|
||||||
"DATABASE powerdnsadmin" = "ALL PRIVILEGES";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -156,7 +156,7 @@ in
|
||||||
ensureDatabases = [ "sftpgo" ];
|
ensureDatabases = [ "sftpgo" ];
|
||||||
ensureUsers = [{
|
ensureUsers = [{
|
||||||
name = "sftpgo";
|
name = "sftpgo";
|
||||||
ensurePermissions."DATABASE sftpgo" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,29 @@ import ./make-test-python.nix ({ lib, ... }: {
|
||||||
nodes.machine = { pkgs, ... }: {
|
nodes.machine = { pkgs, ... }: {
|
||||||
services.tandoor-recipes = {
|
services.tandoor-recipes = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
extraConfig = {
|
||||||
|
DB_ENGINE = "django.db.backends.postgresql";
|
||||||
|
POSTGRES_HOST = "/run/postgresql";
|
||||||
|
POSTGRES_USER = "tandoor_recipes";
|
||||||
|
POSTGRES_DB = "tandoor_recipes";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.postgresql = {
|
||||||
|
enable = true;
|
||||||
|
ensureDatabases = [ "tandoor_recipes" ];
|
||||||
|
ensureUsers = [
|
||||||
|
{
|
||||||
|
name = "tandoor_recipes";
|
||||||
|
ensureDBOwnership = true;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services = {
|
||||||
|
tandoor-recipes = {
|
||||||
|
after = [ "postgresql.service" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: {
|
||||||
ensureDatabases = [ "vikunja-api" ];
|
ensureDatabases = [ "vikunja-api" ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = "vikunja-api";
|
{ name = "vikunja-api";
|
||||||
ensurePermissions = { "DATABASE \"vikunja-api\"" = "ALL PRIVILEGES"; };
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,14 +10,15 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings.db.host = "/run/postgresql";
|
settings.db.host = "/run/postgresql";
|
||||||
settings.db.user = "wiki-js";
|
settings.db.user = "wiki-js";
|
||||||
|
settings.db.db = "wiki-js";
|
||||||
settings.logLevel = "debug";
|
settings.logLevel = "debug";
|
||||||
};
|
};
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
enable = true;
|
enable = true;
|
||||||
ensureDatabases = [ "wiki" ];
|
ensureDatabases = [ "wiki-js" ];
|
||||||
ensureUsers = [
|
ensureUsers = [
|
||||||
{ name = "wiki-js";
|
{ name = "wiki-js";
|
||||||
ensurePermissions."DATABASE wiki" = "ALL PRIVILEGES";
|
ensureDBOwnership = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue