Skip to content

Commit

Permalink
nextcloud-notify_push: fix connecting to mysql via socket
Browse files Browse the repository at this point in the history
  • Loading branch information
st3iny committed Oct 12, 2024
1 parent e495f07 commit 2291322
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nixos/modules/services/web-apps/nextcloud-notify_push.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,22 @@ in
dbType = if cfg.dbtype == "pgsql" then "postgresql" else cfg.dbtype;
dbUser = lib.optionalString (cfg.dbuser != null) cfg.dbuser;
dbPass = lib.optionalString (cfg.dbpassFile != null) ":$DATABASE_PASSWORD";
isSocket = lib.hasPrefix "/" (toString cfg.dbhost);
dbHostHasPrefix = prefix: lib.hasPrefix prefix (toString cfg.dbhost);
isPostgresql = dbType == "postgresql";
isMysql = dbType == "mysql";
isSocket = (isPostgresql && dbHostHasPrefix "/") || (isMysql && dbHostHasPrefix "localhost:/");
dbHost = lib.optionalString (cfg.dbhost != null) (if
isSocket then
if dbType == "postgresql" then "?host=${cfg.dbhost}" else
if dbType == "mysql" then "?socket=${cfg.dbhost}" else throw "unsupported dbtype"
if isPostgresql then "" else
if isMysql then "@localhost" else throw "unsupported dbtype"
else
"@${cfg.dbhost}");
dbOpts = lib.optionalString (cfg.dbhost != null && isSocket) (
if isPostgresql then "?host=${cfg.dbhost}" else
if isMysql then "?socket=${lib.removePrefix "localhost:" cfg.dbhost}" else throw "unsupported dbtype"
);
dbName = lib.optionalString (cfg.dbname != null) "/${cfg.dbname}";
dbUrl = "${dbType}://${dbUser}${dbPass}${lib.optionalString (!isSocket) dbHost}${dbName}${lib.optionalString isSocket dbHost}";
dbUrl = "${dbType}://${dbUser}${dbPass}${dbHost}${dbName}${dbOpts}";
in lib.optionalString (dbPass != "") ''
export DATABASE_PASSWORD="$(<"${cfg.dbpassFile}")"
'' + ''
Expand Down

0 comments on commit 2291322

Please sign in to comment.