tt-rss service: Allow connecting to the database through Unix socket
This commit is contained in:
parent
3a4db71b35
commit
33d6371fd9
1 changed files with 24 additions and 24 deletions
|
@ -34,10 +34,10 @@ let
|
||||||
define('MYSQL_CHARSET', 'UTF8');
|
define('MYSQL_CHARSET', 'UTF8');
|
||||||
|
|
||||||
define('DB_TYPE', '${cfg.database.type}');
|
define('DB_TYPE', '${cfg.database.type}');
|
||||||
define('DB_HOST', '${cfg.database.host}');
|
define('DB_HOST', '${optionalString (cfg.database.host != null) cfg.database.host}');
|
||||||
define('DB_USER', '${cfg.database.user}');
|
define('DB_USER', '${cfg.database.user}');
|
||||||
define('DB_NAME', '${cfg.database.name}');
|
define('DB_NAME', '${cfg.database.name}');
|
||||||
define('DB_PASS', '${escape ["'" "\\"] cfg.database.password}');
|
define('DB_PASS', '${optionalString (cfg.database.password != null) (escape ["'" "\\"] cfg.database.password)}');
|
||||||
define('DB_PORT', '${toString dbPort}');
|
define('DB_PORT', '${toString dbPort}');
|
||||||
|
|
||||||
define('AUTH_AUTO_CREATE', ${boolToString cfg.auth.autoCreate});
|
define('AUTH_AUTO_CREATE', ${boolToString cfg.auth.autoCreate});
|
||||||
|
@ -141,10 +141,10 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
host = mkOption {
|
host = mkOption {
|
||||||
type = types.str;
|
type = types.nullOr types.str;
|
||||||
default = "localhost";
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Host of the database.
|
Host of the database. Leave null to use Unix domain socket.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -510,23 +510,21 @@ let
|
||||||
description = "Tiny Tiny RSS feeds update daemon";
|
description = "Tiny Tiny RSS feeds update daemon";
|
||||||
|
|
||||||
preStart = let
|
preStart = let
|
||||||
callSql = if cfg.database.type == "pgsql" then (e: ''
|
callSql = e:
|
||||||
${optionalString (cfg.database.password != null)
|
if cfg.database.type == "pgsql" then ''
|
||||||
"PGPASSWORD=${cfg.database.password}"} ${pkgs.postgresql95}/bin/psql \
|
${optionalString (cfg.database.password != null) "PGPASSWORD=${cfg.database.password}"} \
|
||||||
|
${pkgs.postgresql95}/bin/psql \
|
||||||
-U ${cfg.database.user} \
|
-U ${cfg.database.user} \
|
||||||
-h ${cfg.database.host} \
|
${optionalString (cfg.database.host != null) "-h ${cfg.database.host} --port ${toString dbPort}"} \
|
||||||
--port ${toString dbPort} \
|
|
||||||
-c '${e}' \
|
-c '${e}' \
|
||||||
${cfg.database.name}'')
|
${cfg.database.name}''
|
||||||
|
|
||||||
else if cfg.database.type == "mysql" then (e: ''
|
else if cfg.database.type == "mysql" then ''
|
||||||
echo '${e}' | ${pkgs.mysql}/bin/mysql \
|
echo '${e}' | ${pkgs.mysql}/bin/mysql \
|
||||||
${optionalString (cfg.database.password != null)
|
|
||||||
"-p${cfg.database.password}"} \
|
|
||||||
-u ${cfg.database.user} \
|
-u ${cfg.database.user} \
|
||||||
-h ${cfg.database.host} \
|
${optionalString (cfg.database.password != null) "-p${cfg.database.password}"} \
|
||||||
-P ${toString dbPort} \
|
${optionalString (cfg.database.host != null) "-h ${cfg.database.host} -P ${toString dbPort}"} \
|
||||||
${cfg.database.name}'')
|
${cfg.database.name}''
|
||||||
|
|
||||||
else "";
|
else "";
|
||||||
|
|
||||||
|
@ -537,8 +535,9 @@ let
|
||||||
ln -sf "${tt-rss-config}" "${cfg.root}/config.php"
|
ln -sf "${tt-rss-config}" "${cfg.root}/config.php"
|
||||||
chown -R "${cfg.user}" "${cfg.root}"
|
chown -R "${cfg.user}" "${cfg.root}"
|
||||||
chmod -R 755 "${cfg.root}"
|
chmod -R 755 "${cfg.root}"
|
||||||
'' + (optionalString (cfg.database.type == "pgsql") ''
|
''
|
||||||
|
|
||||||
|
+ (optionalString (cfg.database.type == "pgsql") ''
|
||||||
exists=$(${callSql "select count(*) > 0 from pg_tables where tableowner = user"} \
|
exists=$(${callSql "select count(*) > 0 from pg_tables where tableowner = user"} \
|
||||||
| tail -n+3 | head -n-2 | sed -e 's/[ \n\t]*//')
|
| tail -n+3 | head -n-2 | sed -e 's/[ \n\t]*//')
|
||||||
|
|
||||||
|
@ -547,8 +546,9 @@ let
|
||||||
else
|
else
|
||||||
echo 'The database contains some data. Leaving it as it is.'
|
echo 'The database contains some data. Leaving it as it is.'
|
||||||
fi;
|
fi;
|
||||||
'') + (optionalString (cfg.database.type == "mysql") ''
|
'')
|
||||||
|
|
||||||
|
+ (optionalString (cfg.database.type == "mysql") ''
|
||||||
exists=$(${callSql "select count(*) > 0 from information_schema.tables where table_schema = schema()"} \
|
exists=$(${callSql "select count(*) > 0 from information_schema.tables where table_schema = schema()"} \
|
||||||
| tail -n+2 | sed -e 's/[ \n\t]*//')
|
| tail -n+2 | sed -e 's/[ \n\t]*//')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue