mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
Add Glab
This commit is contained in:
parent
e1aec543f5
commit
7f82387121
5 changed files with 117 additions and 0 deletions
64
modules/programs/glab.nix
Normal file
64
modules/programs/glab.nix
Normal file
|
@ -0,0 +1,64 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.programs.glab;
|
||||
yamlFormat = pkgs.formats.yaml { };
|
||||
|
||||
in {
|
||||
meta.maintainers = [ maintainers.shikanime ];
|
||||
|
||||
options.programs.glab = {
|
||||
enable = mkEnableOption "GitLab CLI";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.glab;
|
||||
defaultText = literalExpression "pkgs.glab";
|
||||
description = "Package providing {command}`glab`.";
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = yamlFormat.type;
|
||||
default = { };
|
||||
description =
|
||||
"Configuration written to {file}`$XDG_CONFIG_HOME/glab-cli/config.yml`.";
|
||||
example = literalExpression ''
|
||||
{
|
||||
git_protocol = "ssh";
|
||||
};
|
||||
'';
|
||||
};
|
||||
|
||||
gitCredentialHelper = {
|
||||
enable = mkEnableOption "the glab git credential helper" // {
|
||||
default = true;
|
||||
};
|
||||
|
||||
hosts = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "https://gitlab.com" ];
|
||||
description =
|
||||
"GitLab hosts to enable the glab git credential helper for";
|
||||
example = literalExpression ''
|
||||
["https://gitlab.com"]
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
xdg.configFile."glab-cli/config.yml".source =
|
||||
yamlFormat.generate "glab-cli-config.yml" cfg.settings;
|
||||
|
||||
programs.git.extraConfig.credential = mkIf cfg.gitCredentialHelper.enable
|
||||
(builtins.listToAttrs (map (host:
|
||||
lib.nameValuePair host {
|
||||
helper = "${cfg.package}/bin/glab auth git-credential";
|
||||
}) cfg.gitCredentialHelper.hosts));
|
||||
};
|
||||
}
|
23
tests/modules/programs/glab/config-file.nix
Normal file
23
tests/modules/programs/glab/config-file.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
programs.glab = {
|
||||
enable = true;
|
||||
settings.git_protocol = "ssh";
|
||||
settings.editor = "vim";
|
||||
};
|
||||
|
||||
test.stubs.glab = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/glab-cli/config.yml
|
||||
assertFileContent home-files/.config/glab-cli/config.yml ${
|
||||
builtins.toFile "config-file.yml" ''
|
||||
git_protocol: ssh
|
||||
editor: vim
|
||||
''
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
5
tests/modules/programs/glab/credential-helper.git.conf
Normal file
5
tests/modules/programs/glab/credential-helper.git.conf
Normal file
|
@ -0,0 +1,5 @@
|
|||
[credential "https://gitlab.com"]
|
||||
helper = "@glab@/bin/glab auth git-credential"
|
||||
|
||||
[credential "https://gitlab.example.com"]
|
||||
helper = "@glab@/bin/glab auth git-credential"
|
21
tests/modules/programs/glab/credential-helper.nix
Normal file
21
tests/modules/programs/glab/credential-helper.nix
Normal file
|
@ -0,0 +1,21 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
programs.glab = {
|
||||
enable = true;
|
||||
gitCredentialHelper = {
|
||||
enable = true;
|
||||
hosts = [ "https://gitlab.com" "https://gitlab.example.com" ];
|
||||
};
|
||||
};
|
||||
|
||||
programs.git.enable = true;
|
||||
|
||||
test.stubs.glab = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/git/config
|
||||
assertFileContent home-files/.config/git/config \
|
||||
${./credential-helper.git.conf}
|
||||
'';
|
||||
}
|
4
tests/modules/programs/glab/default.nix
Normal file
4
tests/modules/programs/glab/default.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
glab-config-file = ./config-file.nix;
|
||||
glab-credential-helper = ./credential-helper.nix;
|
||||
}
|
Loading…
Reference in a new issue