···
master-password = ${cfg.replication.masterPassword}
master-port = ${toString cfg.replication.masterPort}
33
+
${optionalString (cfg.ensureUsers != [])
35
+
plugin-load-add = auth_socket.so
···
initialScript = mkOption {
description = "A file containing SQL statements to be executed on the first startup. Can be used for granting certain permissions on the database";
130
+
ensureDatabases = mkOption {
133
+
Ensures that the specified databases exist.
134
+
This option will never delete existing databases, especially not when the value of this
135
+
option is changed. This means that databases created once through this option or
136
+
otherwise have to be removed manually.
144
+
ensureUsers = mkOption {
147
+
Ensures that the specified users exist and have at least the ensured permissions.
148
+
The MySQL users will be identified using Unix socket authentication. This authenticates the Unix user with the
149
+
same name only, and that without the need for a password.
150
+
This option will never delete existing users or remove permissions, especially not when the value of this
151
+
option is changed. This means that users created and permissions assigned once through this option or
152
+
otherwise have to be removed manually.
156
+
name = "nextcloud";
157
+
ensurePermissions = {
158
+
"nextcloud.*" = "ALL PRIVILEGES";
163
+
ensurePermissions = {
164
+
"*.*" = "SELECT, LOCK TABLES";
# FIXME: remove this option; it's a really bad idea.
···
353
+
${optionalString (cfg.ensureDatabases != []) ''
355
+
${concatMapStrings (database: ''
356
+
echo "CREATE DATABASE IF NOT EXISTS ${database};"
357
+
'') cfg.ensureDatabases}
358
+
) | ${mysql}/bin/mysql -u root -N
361
+
${concatMapStrings (user:
363
+
( echo "CREATE USER IF NOT EXISTS '${user.name}'@'localhost' IDENTIFIED WITH ${if mysql == pkgs.mariadb then "unix_socket" else "auth_socket"};"
364
+
${concatStringsSep "\n" (mapAttrsToList (database: permission: ''
365
+
echo "GRANT ${permission} ON ${database} TO '${user.name}'@'localhost';"
366
+
'') user.ensurePermissions)}
367
+
) | ${mysql}/bin/mysql -u root -N
368
+
'') cfg.ensureUsers}