1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

gh: idempotently consider existing symlinks

> -e file
>        True if file exists.
> -f file
>        True if file exists and is a regular file.
> [...]
> -L file
>        True if file exists and is a symbolic link.
>
> (Source: bash(1))
This commit is contained in:
NAHO 2023-12-27 15:42:41 +01:00 committed by Robert Helgesson
parent 6e2afa5c3b
commit f8a4a5c18f
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED

View file

@ -135,15 +135,16 @@ in {
# #
# See https://github.com/nix-community/home-manager/issues/4744 for details. # See https://github.com/nix-community/home-manager/issues/4744 for details.
home.activation.migrateGhAccounts = home.activation.migrateGhAccounts =
hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' let ghHosts = "${config.xdg.configHome}/gh/hosts.yml";
if [[ -e "${config.xdg.configHome}/gh/hosts.yml" ]]; then in hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] ''
if [[ ! -L "${ghHosts}" && -f "${ghHosts}" ]]; then
( (
TMP_DIR=$(mktemp -d) TMP_DIR=$(mktemp -d)
trap "rm --force --recursive $TMP_DIR" EXIT trap "rm --force --recursive $TMP_DIR" EXIT
cp "${config.xdg.configHome}/gh/hosts.yml" $TMP_DIR/ cp "${ghHosts}" $TMP_DIR/
export GH_CONFIG_DIR=$TMP_DIR export GH_CONFIG_DIR=$TMP_DIR
$DRY_RUN_CMD ${getExe cfg.package} help 2>&1 > $DRY_RUN_NULL $DRY_RUN_CMD ${getExe cfg.package} help 2>&1 > $DRY_RUN_NULL
cp $TMP_DIR/hosts.yml "${config.xdg.configHome}/gh/hosts.yml" cp $TMP_DIR/hosts.yml "${ghHosts}"
) )
fi fi
''; '';