nixos/healthchecks: automatically invoke sudo in the wrapper

much like nextcloud-occ does
This commit is contained in:
Sandro Jäckel 2022-10-27 21:21:53 +02:00
parent a3c39df9e8
commit 897044e435
No known key found for this signature in database
GPG Key ID: 3AF5A43A3EECC2E5

View File

@ -15,14 +15,14 @@ let
environmentFile = pkgs.writeText "healthchecks-environment" (lib.generators.toKeyValue { } environment);
healthchecksManageScript = with pkgs; (writeShellScriptBin "healthchecks-manage" ''
healthchecksManageScript = pkgs.writeShellScriptBin "healthchecks-manage" ''
sudo=exec
if [[ "$USER" != "${cfg.user}" ]]; then
echo "please run as user 'healtchecks'." >/dev/stderr
exit 1
sudo='exec /run/wrappers/bin/sudo -u ${cfg.user} --preserve-env --preserve-env=PYTHONPATH'
fi
export $(cat ${environmentFile} | xargs);
exec ${pkg}/opt/healthchecks/manage.py "$@"
'');
export $(cat ${environmentFile} | xargs)
$sudo ${pkg}/opt/healthchecks/manage.py "$@"
'';
in
{
options.services.healthchecks = {