#!/usr/bin/env bash
set -e
if [[ ! -d "/persist/dots/scripts/ldap-nginx-plumber" ]]; then
  echo "Cannot find source directory; Did you move it?"
  echo "(Looking for "/persist/dots/scripts/ldap-nginx-plumber")"
  echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
  exit 1
fi

# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/persist/dots/scripts/ldap-nginx-plumber" true

# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/persist/dots/scripts/ldap-nginx-plumber/.envrc"

# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/persist/dots/scripts/ldap-nginx-plumber/.envrc" "/persist/dots/scripts/ldap-nginx-plumber/.direnv"/*.rc
