From d22c1c07196520c70c054e9dc127a37ce125a0d1 Mon Sep 17 00:00:00 2001 From: Florian Jacob Date: Sat, 20 May 2017 23:57:07 +0200 Subject: mysql service: Make initialDatabases.schema attribute optional --- nixos/modules/services/databases/mysql.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix index 6027f109285a..50766093307d 100644 --- a/nixos/modules/services/databases/mysql.nix +++ b/nixos/modules/services/databases/mysql.nix @@ -108,10 +108,13 @@ in initialDatabases = mkOption { default = []; - description = "List of database names and their initial schemas that should be used to create databases on the first startup of MySQL"; + description = '' + List of database names and their initial schemas that should be used to create databases on the first startup + of MySQL. The schema attribute is optional: If not specified, an empty database is created. + ''; example = [ { name = "foodatabase"; schema = literalExample "./foodatabase.sql"; } - { name = "bardatabase"; schema = literalExample "./bardatabase.sql"; } + { name = "bardatabase"; } ]; }; @@ -247,6 +250,8 @@ in if ! test -e "${cfg.dataDir}/${database.name}"; then echo "Creating initial database: ${database.name}" ( echo "create database ${database.name};" + + ${optionalString (database ? "schema") '' echo "use ${database.name};" if [ -f "${database.schema}" ] @@ -256,6 +261,7 @@ in then cat ${database.schema}/mysql-databases/*.sql fi + ''} ) | ${mysql}/bin/mysql -u root -N fi '') cfg.initialDatabases} -- cgit 1.4.1