fork/home-manager
git clone https://git.julia.blue/fork/home-manager
4fd794d3
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . gh ; 8 9yamlFormat = pkgs . formats . yaml { }; 10 11settingsType = types . submodule { 12freeformType = yamlFormat . type ; 13# These options are only here for the mkRenamedOptionModule support 14options = { 15aliases = mkOption { 16type = with types ; attrsOf str ; 17default = { }; 18example = literalExpression '' 19{ 20co = "pr checkout"; 21pv = "pr view"; 22} 23'' ; 24description = '' 25Aliases that allow you to create nicknames for gh commands. 26'' ; 27}; 28editor = mkOption { 29type = types . str ; 30default = "" ; 31description = '' 32The editor that gh should run when creating issues, pull requests, etc. 33If blank, will refer to environment. 34'' ; 35}; 36git_protocol = mkOption { 37type = types . str ; 38default = "https" ; 39example = "ssh" ; 40description = '' 41The protocol to use when performing Git operations. 42'' ; 43}; 44}; 45}; 46 47in { 48meta . maintainers = [ maintainers . gerschtli maintainers . berbiche ]; 49 50imports = ( map ( x : 51mkRenamedOptionModule [ "programs" "gh" x ] [ 52"programs" 53"gh" 54"settings" 55x 56]) [ "aliases" "editor" ]) ++ [ 57( mkRenamedOptionModule [ "programs" "gh" "gitProtocol" ] [ 58"programs" 59"gh" 60"settings" 61"git_protocol" 62]) 63( mkRenamedOptionModule [ "programs" "gh" "enableGitCredentialHelper" ] [ 64"programs" 65"gh" 66"gitCredentialHelper" 67"enable" 68]) 69]; 70 71options . programs . gh = { 72enable = mkEnableOption "GitHub CLI tool" ; 73 74package = mkOption { 75type = types . package ; 76default = pkgs . gh ; 77defaultText = literalExpression "pkgs.gh" ; 78description = "Package providing {command}`gh`." ; 79}; 80 81settings = mkOption { 82type = settingsType ; 83default = { }; 84description = 85"Configuration written to {file}`$XDG_CONFIG_HOME/gh/config.yml`." ; 86example = literalExpression '' 87{ 88git_protocol = "ssh"; 89 90prompt = "enabled"; 91 92aliases = { 93co = "pr checkout"; 94pv = "pr view"; 95}; 96}; 97'' ; 98}; 99 100gitCredentialHelper = { 101enable = mkEnableOption "the gh git credential helper" // { 102default = true ; 103}; 104 105hosts = mkOption { 106type = types . listOf types . str ; 107default = [ "https://github.com" ]; 108description = "GitHub hosts to enable the gh git credential helper for" ; 109example = literalExpression '' 110[ "https://github.com" "https://github.example.com" ] 111'' ; 112}; 113}; 114 115extensions = mkOption { 116type = types . listOf types . package ; 117default = [ ]; 118description = '' 119gh extensions, see <https://cli.github.com/manual/gh_extension>. 120'' ; 121example = literalExpression "[ pkgs.gh-eco ]" ; 122}; 123}; 124 125config = mkIf cfg . enable { 126home . packages = [ cfg . package ]; 127 128xdg . configFile . "gh/config.yml" . source = 129yamlFormat . generate "gh-config.yml" cfg . settings ; 130 131programs . git . extraConfig . credential = mkIf cfg . gitCredentialHelper . enable 132( builtins . listToAttrs ( map ( host : 133lib . nameValuePair host { 134helper = " ${ cfg . package } /bin/gh auth git-credential" ; 135}) cfg . gitCredentialHelper . hosts )); 136 137xdg . dataFile . "gh/extensions" = mkIf ( cfg . extensions != [ ]) { 138source = pkgs . linkFarm "gh-extensions" ( builtins . map ( p :{ 139name = p . pname ; 140path = " ${ p } /bin" ; 141}) cfg . extensions ); 142}; 143}; 144}