1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-08 10:01:05 +01:00

gh: add hosts option (#6925)

Add a programs.gh.hosts option that -- similar to programs.gh.settings -- gives structured access to $XDG_CONFIG_HOME/gh/hosts.yml.
This commit is contained in:
Benedikt M. Rips 2025-04-28 17:12:47 +02:00 committed by GitHub
parent 69c60b035e
commit 6f974faa19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 3 deletions

View file

@ -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 = "<your_username>";
};
};
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

View file

@ -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;
}

View file

@ -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
''}
'';
}