From b2af81413ffbfd349d37ea48389953e749775e99 Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:42:41 +0100 Subject: [PATCH] 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)) --- modules/programs/gh.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/programs/gh.nix b/modules/programs/gh.nix index b419791e6..bdd939dee 100644 --- a/modules/programs/gh.nix +++ b/modules/programs/gh.nix @@ -135,15 +135,16 @@ in { # # See https://github.com/nix-community/home-manager/issues/4744 for details. home.activation.migrateGhAccounts = - hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' - if [[ -e "${config.xdg.configHome}/gh/hosts.yml" ]]; then + let ghHosts = "${config.xdg.configHome}/gh/hosts.yml"; + in hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' + if [[ ! -L "${ghHosts}" && -f "${ghHosts}" ]]; then ( TMP_DIR=$(mktemp -d) 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 $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 '';