From 9cf7310594b2963e79013c8db9e56eca8ee57149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Thu, 26 Dec 2024 02:21:26 +0100 Subject: [PATCH] nixos/borgmatic: default to the correct user when username is configured --- nixos/modules/services/backup/borgmatic.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/backup/borgmatic.nix b/nixos/modules/services/backup/borgmatic.nix index 82fd8607cea6..ced1383193b0 100644 --- a/nixos/modules/services/backup/borgmatic.nix +++ b/nixos/modules/services/backup/borgmatic.nix @@ -16,11 +16,17 @@ let // { postgresql_databases = map ( d: + let + as_user = if d ? username then "${pkgs.sudo}/bin/sudo -u ${d.username} " else ""; + in { pg_dump_command = - if d.name == "all" then "${postgresql}/bin/pg_dumpall" else "${postgresql}/bin/pg_dump"; - pg_restore_command = "${postgresql}/bin/pg_restore"; - psql_command = "${postgresql}/bin/psql"; + if d.name == "all" then + "${as_user}${postgresql}/bin/pg_dumpall" + else + "${as_user}${postgresql}/bin/pg_dump"; + pg_restore_command = "${as_user}${postgresql}/bin/pg_restore"; + psql_command = "${as_user}${postgresql}/bin/psql"; } // d ) (s.postgresql_databases or [ ]);