diff --git a/modules/programs/gh.nix b/modules/programs/gh.nix index 88de89d14..ba08da430 100644 --- a/modules/programs/gh.nix +++ b/modules/programs/gh.nix @@ -146,14 +146,24 @@ in ''; example = literalExpression "[ pkgs.gh-eco ]"; }; + + hosts = mkOption { + inherit (yamlFormat) type; + default = { }; + description = "Host-specific configuration written to {file}`$XDG_CONFIG_HOME/gh/hosts.yml`."; + example."github.com".user = ""; + }; }; config = mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."gh/config.yml".source = yamlFormat.generate "gh-config.yml" ( - { version = "1"; } // cfg.settings - ); + xdg.configFile = { + "gh/config.yml".source = yamlFormat.generate "gh-config.yml" ({ version = "1"; } // cfg.settings); + "gh/hosts.yml" = mkIf (cfg.hosts != { }) { + source = yamlFormat.generate "gh-hosts.yml" cfg.hosts; + }; + }; # 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 diff --git a/tests/modules/programs/gh/default.nix b/tests/modules/programs/gh/default.nix index d033ae22c..334fc0c92 100644 --- a/tests/modules/programs/gh/default.nix +++ b/tests/modules/programs/gh/default.nix @@ -2,5 +2,6 @@ gh-config-file = ./config-file.nix; gh-credential-helper = ./credential-helper.nix; gh-extensions = ./extensions.nix; + gh-hosts-file = ./hosts-file.nix; gh-warnings = ./warnings.nix; } diff --git a/tests/modules/programs/gh/hosts-file.nix b/tests/modules/programs/gh/hosts-file.nix new file mode 100644 index 000000000..afd6dd402 --- /dev/null +++ b/tests/modules/programs/gh/hosts-file.nix @@ -0,0 +1,18 @@ +{ + programs.gh = { + enable = true; + hosts."github.com" = { + git_protocol = "ssh"; + user = "my_username"; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/gh/hosts.yml + assertFileContent home-files/.config/gh/hosts.yml ${builtins.toFile "hosts.yml" '' + github.com: + git_protocol: ssh + user: my_username + ''} + ''; +}