@@ -188,8 +188,7 @@ let
188188 /* date format to be used while writing to the owncloud logfile */
189189 'logdateformat' => 'F d, Y H:i:s',
190190
191− /* timezone used while writing to the owncloud logfile (default: UTC) */
192− 'logtimezone' => '${serverInfo.fullConfig.time.timeZone}',
191+ ${tzSetting}
193192
194193 /* Append all database queries and parameters to the log file.
195194 (watch out, this option can increase the size of your log file)*/
@@ -339,6 +338,31 @@ let
339338
340339 '';
341340
341+ tzSetting = let tz = serverInfo.fullConfig.time.timeZone; in optionalString (!isNull tz) ''
342+ /* timezone used while writing to the owncloud logfile (default: UTC) */
343+ 'logtimezone' => '${tz}',
344+ '';
345+
346+ postgresql = serverInfo.fullConfig.services.postgresql.package;
347+
348+ setupDb = pkgs.writeScript "setup-owncloud-db" ''
349+ #!${pkgs.stdenv.shell}
350+ PATH="${postgresql}/bin"
351+ createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
352+ createdb "${config.dbName}" -O "${config.dbUser}" || true
353+ psql -U postgres -d postgres -c "alter user ${config.dbUser} with password '${config.dbPassword}';" || true
354+
355+ QUERY="CREATE TABLE appconfig
356+ ( appid VARCHAR( 255 ) NOT NULL
357+ , configkey VARCHAR( 255 ) NOT NULL
358+ , configvalue VARCHAR( 255 ) NOT NULL
359+ );
360+ GRANT ALL ON appconfig TO ${config.dbUser};
361+ ALTER TABLE appconfig OWNER TO ${config.dbUser};"
362+
363+ psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
364+ '';
365+
342366in
343367
344368rec {
@@ -373,7 +397,7 @@ rec {
373397 defaultText = "pkgs.owncloud70";
374398 example = literalExample "pkgs.owncloud70";
375399 description = ''
376− PostgreSQL package to use.
400+ ownCloud package to use.
377401 '';
378402 };
379403
@@ -574,13 +598,7 @@ rec {
574598 chmod -R o-rwx ${config.dataDir}
575599 chown -R wwwrun:wwwrun ${config.dataDir}
576600
577− ${pkgs.postgresql}/bin/createuser -s -r postgres
578− ${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole "${config.dbUser}" || true
579− ${pkgs.postgresql}/bin/createdb "${config.dbName}" -O "${config.dbUser}" || true
580− ${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -U postgres -d postgres -c "alter user ${config.dbUser} with password '${config.dbPassword}';" || true
581−
582− QUERY="CREATE TABLE appconfig (appid VARCHAR( 255 ) NOT NULL ,configkey VARCHAR( 255 ) NOT NULL ,configvalue VARCHAR( 255 ) NOT NULL); GRANT ALL ON appconfig TO ${config.dbUser}; ALTER TABLE appconfig OWNER TO ${config.dbUser};"
583− ${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
601+ ${pkgs.sudo}/bin/sudo -u postgres ${setupDb}
584602 fi
585603
586604 if [ -e ${config.package}/config/ca-bundle.crt ]; then
@@ -591,7 +609,11 @@ rec {
591609
592610 chown wwwrun:wwwrun ${config.dataDir}/owncloud.log || true
593611
594− QUERY="INSERT INTO groups (gid) values('admin'); INSERT INTO users (uid,password) values('${config.adminUser}','${builtins.hashString "sha1" config.adminPassword}'); INSERT INTO group_user (gid,uid) values('admin','${config.adminUser}');"
595− ${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
612+ QUERY="INSERT INTO groups (gid) values('admin');
613+ INSERT INTO users (uid,password)
614+ values('${config.adminUser}','${builtins.hashString "sha1" config.adminPassword}');
615+ INSERT INTO group_user (gid,uid)
616+ values('admin','${config.adminUser}');"
617+ ${pkgs.sudo}/bin/sudo -u postgres ${postgresql}/bin/psql -h "/tmp" -U postgres -d ${config.dbName} -Atw -c "$QUERY" || true
596618 '';
597619}