I would like to install a PostgreSQL database and create a user at the same time. This is my configuration:
mypostgresql = {
db = "SUPER";
user = "SUPER";
pass = "SUPER";
};
...
services.postgresql = {
enable = true;
package = pkgs.postgresql_11;
initialScript = pkgs.writeText "Initial-PostgreSQL-database" ''
CREATE DATABASE "${mypostgresql.db}";
CREATE USER "${mypostgresql.user}" WITH ENCRYPTED PASSWORD "${mypostgresql.pass}";
GRANT ALL PRIVILEGES ON DATABASE ${mypostgresql.db} TO ${mypostgresql.user};
'';
};
I think the problem is the apostrophe:
CREATE USER "SUPER" WITH ENCRYPTED PASSWORD "SUPER";
ERROR: syntax error at or near ""SUPER""
LINE 1: CREATE USER "SUPER" WITH ENCRYPTED PASSWORD "SUPER";
CREATE USER "SUPER" WITH ENCRYPTED PASSWORD 'SUPER';
CREATE ROLE
Please keep in mind the documentation for initialScript states the script will only be run the very first time postgresql starts. The script will have no impact on existing installs.