From 0bb3d001365a5d75947a7a713dfd06307b3934d4 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Thu, 16 Feb 2023 14:01:27 -0700 Subject: [PATCH] nixos: Don't fail if PWD cannot be changed into Fixes #26. --- nixos/atticd.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nixos/atticd.nix b/nixos/atticd.nix index 9a32a75..24ddc69 100644 --- a/nixos/atticd.nix +++ b/nixos/atticd.nix @@ -22,6 +22,17 @@ let cat <$configFile >$out ''; + atticadmShim = pkgs.writeShellScript "atticadm" '' + if [ -n "$ATTICADM_PWD" ]; then + cd "$ATTICADM_PWD" + if [ "$?" != "0" ]; then + >&2 echo "Warning: Failed to change directory to $ATTICADM_PWD" + fi + fi + + exec ${cfg.package}/bin/atticadm -f ${checkedConfigFile} "$@" + ''; + atticadmWrapper = pkgs.writeShellScriptBin "atticd-atticadm" '' exec systemd-run \ --pty \ @@ -32,8 +43,10 @@ let --property=EnvironmentFile=${cfg.credentialsFile} \ --property=DynamicUser=yes \ --property=User=atticd \ + --property=Environment=ATTICADM_PWD=$(pwd) \ + --working-directory / \ -- \ - ${cfg.package}/bin/atticadm -f ${checkedConfigFile} "$@" + ${atticadmShim} "$@" ''; hasLocalPostgresDB = let