@@ -34,10 +34,10 @@ let
3434 define('MYSQL_CHARSET', 'UTF8');
3535
3636 define('DB_TYPE', '${cfg.database.type}');
37− define('DB_HOST', '${cfg.database.host}');
37+ define('DB_HOST', '${optionalString (cfg.database.host != null) cfg.database.host}');
3838 define('DB_USER', '${cfg.database.user}');
3939 define('DB_NAME', '${cfg.database.name}');
40− define('DB_PASS', '${escape ["'" "\\"] cfg.database.password}');
40+ define('DB_PASS', '${optionalString (cfg.database.password != null) (escape ["'" "\\"] cfg.database.password)}');
4141 define('DB_PORT', '${toString dbPort}');
4242
4343 define('AUTH_AUTO_CREATE', ${boolToString cfg.auth.autoCreate});
@@ -141,10 +141,10 @@ let
141141 };
142142
143143 host = mkOption {
144− type = types.str;
145− default = "localhost";
144+ type = types.nullOr types.str;
145+ default = null;
146146 description = ''
147− Host of the database.
147+ Host of the database. Leave null to use Unix domain socket.
148148 '';
149149 };
150150
@@ -510,25 +510,23 @@ let
510510 description = "Tiny Tiny RSS feeds update daemon";
511511
512512 preStart = let
513− callSql = if cfg.database.type == "pgsql" then (e: ''
514− ${optionalString (cfg.database.password != null)
515− "PGPASSWORD=${cfg.database.password}"} ${pkgs.postgresql95}/bin/psql \
516− -U ${cfg.database.user} \
517− -h ${cfg.database.host} \
518− --port ${toString dbPort} \
519− -c '${e}' \
520− ${cfg.database.name}'')
521−
522− else if cfg.database.type == "mysql" then (e: ''
523− echo '${e}' | ${pkgs.mysql}/bin/mysql \
524− ${optionalString (cfg.database.password != null)
525− "-p${cfg.database.password}"} \
526− -u ${cfg.database.user} \
527− -h ${cfg.database.host} \
528− -P ${toString dbPort} \
529− ${cfg.database.name}'')
530−
531− else "";
513+ callSql = e:
514+ if cfg.database.type == "pgsql" then ''
515+ ${optionalString (cfg.database.password != null) "PGPASSWORD=${cfg.database.password}"} \
516+ ${pkgs.postgresql95}/bin/psql \
517+ -U ${cfg.database.user} \
518+ ${optionalString (cfg.database.host != null) "-h ${cfg.database.host} --port ${toString dbPort}"} \
519+ -c '${e}' \
520+ ${cfg.database.name}''
521+
522+ else if cfg.database.type == "mysql" then ''
523+ echo '${e}' | ${pkgs.mysql}/bin/mysql \
524+ -u ${cfg.database.user} \
525+ ${optionalString (cfg.database.password != null) "-p${cfg.database.password}"} \
526+ ${optionalString (cfg.database.host != null) "-h ${cfg.database.host} -P ${toString dbPort}"} \
527+ ${cfg.database.name}''
528+
529+ else "";
532530
533531 in ''
534532 rm -rf "${cfg.root}/*"
@@ -537,8 +535,9 @@ let
537535 ln -sf "${tt-rss-config}" "${cfg.root}/config.php"
538536 chown -R "${cfg.user}" "${cfg.root}"
539537 chmod -R 755 "${cfg.root}"
540− '' + (optionalString (cfg.database.type == "pgsql") ''
538+ ''
541539
540+ + (optionalString (cfg.database.type == "pgsql") ''
542541 exists=$(${callSql "select count(*) > 0 from pg_tables where tableowner = user"} \
543542 | tail -n+3 | head -n-2 | sed -e 's/[ \n\t]*//')
544543
@@ -547,8 +546,9 @@ let
547546 else
548547 echo 'The database contains some data. Leaving it as it is.'
549548 fi;
550− '') + (optionalString (cfg.database.type == "mysql") ''
549+ '')
551550
551+ + (optionalString (cfg.database.type == "mysql") ''
552552 exists=$(${callSql "select count(*) > 0 from information_schema.tables where table_schema = schema()"} \
553553 | tail -n+2 | sed -e 's/[ \n\t]*//')
554554