From d1d950841d230490f308f5fcf8c0d4f2bd3f24a7 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 8 Dec 2023 19:33:19 +0530 Subject: [PATCH] gh: include version in settings Also add an activation script block for allowing gh version 2.40.0 and later to perform account migration. --- modules/programs/gh.nix | 22 +++++++++++++++++++++- tests/modules/programs/gh/config-file.nix | 1 + tests/modules/programs/gh/warnings.nix | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/programs/gh.nix b/modules/programs/gh.nix index 526010a5..b56e8cfc 100644 --- a/modules/programs/gh.nix +++ b/modules/programs/gh.nix @@ -126,7 +126,27 @@ in { home.packages = [ cfg.package ]; xdg.configFile."gh/config.yml".source = - yamlFormat.generate "gh-config.yml" cfg.settings; + yamlFormat.generate "gh-config.yml" ({ version = "1"; } // cfg.settings); + + # Version 2.40.0+ of gh needs to migrate account formats, this needs to + # happen before the version = 1 is placed in the configuration file. Running + # `gh help` is sufficient to perform the migration. If the migration already + # has occurred, then this is a no-op. + # + # 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/config.yml" ]]; then + ( + TMP_DIR=$(mktemp -d) + trap "rm --force --recursive $TMP_DIR" EXIT + cp "${config.xdg.configHome}/gh/hosts.yml" $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" + ) + fi + ''; programs.git.extraConfig.credential = mkIf cfg.gitCredentialHelper.enable (builtins.listToAttrs (map (host: diff --git a/tests/modules/programs/gh/config-file.nix b/tests/modules/programs/gh/config-file.nix index 58600e7f..e7c17d5d 100644 --- a/tests/modules/programs/gh/config-file.nix +++ b/tests/modules/programs/gh/config-file.nix @@ -18,6 +18,7 @@ co: pr checkout editor: vim git_protocol: https + version: '1' '' } ''; diff --git a/tests/modules/programs/gh/warnings.nix b/tests/modules/programs/gh/warnings.nix index 53937a7c..bf7e5df8 100644 --- a/tests/modules/programs/gh/warnings.nix +++ b/tests/modules/programs/gh/warnings.nix @@ -28,6 +28,7 @@ co: pr checkout editor: vim git_protocol: https + version: '1' '' } '';