1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +01:00
This commit is contained in:
William Phetsinorath 2024-10-14 14:23:13 +02:00
parent e1aec543f5
commit 7f82387121
No known key found for this signature in database
GPG key ID: C3CA52462F1C3B79
5 changed files with 117 additions and 0 deletions

64
modules/programs/glab.nix Normal file
View 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));
};
}

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

View 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"

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

View file

@ -0,0 +1,4 @@
{
glab-config-file = ./config-file.nix;
glab-credential-helper = ./credential-helper.nix;
}