1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

gh: use structural settings (#2339)

This commit is contained in:
Nicolas Berbiche 2021-10-08 23:29:25 +02:00 committed by GitHub
parent fd2f746016
commit 82c92a18ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 35 deletions

4
.github/CODEOWNERS vendored
View file

@ -81,8 +81,8 @@
/modules/programs/foot.nix @plabadens /modules/programs/foot.nix @plabadens
/tests/modules/programs/foot @plabadens /tests/modules/programs/foot @plabadens
/modules/programs/gh.nix @Gerschtli /modules/programs/gh.nix @Gerschtli @berbiche
/tests/modules/programs/gh @Gerschtli /tests/modules/programs/gh @Gerschtli @berbiche
/modules/programs/git.nix @rycee /modules/programs/git.nix @rycee

View file

@ -6,50 +6,96 @@ let
cfg = config.programs.gh; cfg = config.programs.gh;
yamlFormat = pkgs.formats.yaml { };
settingsType = types.submodule {
freeformType = yamlFormat.type;
# These options are only here for the mkRenamedOptionModule support
options = {
aliases = mkOption {
type = with types; attrsOf str;
default = { };
example = literalExample ''
{
co = "pr checkout";
pv = "pr view";
}
'';
description = ''
Aliases that allow you to create nicknames for gh commands.
'';
};
editor = mkOption {
type = types.str;
default = "";
description = ''
The editor that gh should run when creating issues, pull requests, etc.
If blank, will refer to environment.
'';
};
git_protocol = mkOption {
type = types.str;
default = "https";
example = "ssh";
description = ''
The protocol to use when performing Git operations.
'';
};
};
};
in { in {
meta.maintainers = [ maintainers.gerschtli ]; meta.maintainers = [ maintainers.gerschtli maintainers.berbiche ];
imports = (map (x:
mkRenamedOptionModule [ "programs" "gh" x ] [
"programs"
"gh"
"settings"
x
]) [ "aliases" "editor" ]) ++ [
(mkRenamedOptionModule [ "programs" "gh" "gitProtocol" ] [
"programs"
"gh"
"settings"
"git_protocol"
])
];
options.programs.gh = { options.programs.gh = {
enable = mkEnableOption "GitHub CLI tool"; enable = mkEnableOption "GitHub CLI tool";
aliases = mkOption { package = mkOption {
type = with types; attrsOf str; type = types.package;
default = pkgs.gh;
defaultText = literalExample "pkgs.gh";
description = "Package providing <command>gh</command>.";
};
settings = mkOption {
type = settingsType;
default = { }; default = { };
description =
"Configuration written to <filename>$XDG_CONFIG_HOME/gh/config.yml</filename>.";
example = literalExample '' example = literalExample ''
{ {
co = "pr checkout"; git_protocol = "ssh";
pv = "pr view";
}
'';
description = ''
Aliases that allow you to create nicknames for gh commands.
'';
};
editor = mkOption { prompt = "enabled";
type = types.str;
default = "";
description = ''
The editor that gh should run when creating issues, pull requests, etc.
If blank, will refer to environment.
'';
};
gitProtocol = mkOption { aliases = {
type = types.enum [ "https" "ssh" ]; co = "pr checkout";
default = "https"; pv = "pr view";
description = '' };
The protocol to use when performing Git operations. };
''; '';
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ pkgs.gh ]; home.packages = [ cfg.package ];
xdg.configFile."gh/config.yml".text = builtins.toJSON { xdg.configFile."gh/config.yml".source =
inherit (cfg) aliases editor; yamlFormat.generate "gh-config.yml" cfg.settings;
git_protocol = cfg.gitProtocol;
};
}; };
} }

View file

@ -4,8 +4,8 @@
config = { config = {
programs.gh = { programs.gh = {
enable = true; enable = true;
aliases = { co = "pr checkout"; }; settings.aliases = { co = "pr checkout"; };
editor = "vim"; settings.editor = "vim";
}; };
test.stubs.gh = { }; test.stubs.gh = { };
@ -14,7 +14,11 @@
assertFileExists home-files/.config/gh/config.yml assertFileExists home-files/.config/gh/config.yml
assertFileContent home-files/.config/gh/config.yml ${ assertFileContent home-files/.config/gh/config.yml ${
builtins.toFile "config-file.yml" '' builtins.toFile "config-file.yml" ''
{"aliases":{"co":"pr checkout"},"editor":"vim","git_protocol":"https"}'' aliases:
co: pr checkout
editor: vim
git_protocol: https
''
} }
''; '';
}; };

View file

@ -1 +1,4 @@
{ gh-config-file = ./config-file.nix; } {
gh-config-file = ./config-file.nix;
gh-warnings = ./warnings.nix;
}

View file

@ -0,0 +1,35 @@
{ config, options, lib, pkgs, ... }:
{
config = {
programs.gh = {
enable = true;
aliases = { co = "pr checkout"; };
editor = "vim";
};
test.stubs.gh = { };
test.asserts.warnings.expected = [
"The option `programs.gh.editor' defined in ${
lib.showFiles options.programs.gh.editor.files
} has been renamed to `programs.gh.settings.editor'."
"The option `programs.gh.aliases' defined in ${
lib.showFiles options.programs.gh.aliases.files
} has been renamed to `programs.gh.settings.aliases'."
];
test.asserts.warnings.enable = true;
nmt.script = ''
assertFileExists home-files/.config/gh/config.yml
assertFileContent home-files/.config/gh/config.yml ${
builtins.toFile "config-file.yml" ''
aliases:
co: pr checkout
editor: vim
git_protocol: https
''
}
'';
};
}