nixos-config/home/modules/git.nix

60 lines
1.3 KiB
Nix
Raw Normal View History

2024-05-26 16:45:38 +02:00
{
lib,
pkgs,
config,
...
}:
2020-08-15 03:06:37 +02:00
with lib;
2024-05-26 16:45:38 +02:00
let
cfg = config.programs.git;
in
{
options.programs.git = {
2020-08-15 03:06:37 +02:00
profiles = mkOption {
2024-05-26 16:45:38 +02:00
type = types.attrsOf (
types.submodule (
{ name, config, ... }:
{
options = {
name = mkOption { type = types.str; };
email = mkOption { type = types.str; };
signingKey = mkOption { type = types.str; };
dirs = mkOption { type = types.listOf types.str; };
};
}
)
);
2020-08-15 03:06:37 +02:00
};
2022-01-01 02:13:02 +01:00
defaultProfile = mkOption { type = types.str; };
2020-08-15 03:06:37 +02:00
};
2024-05-26 16:45:38 +02:00
config =
let
inherit (cfg) profiles;
in
{
programs.git = {
# fix/workaround for https://github.com/NixOS/nixpkgs/issues/169193
extraConfig.safe.directory = "/etc/nixos";
2024-05-26 16:45:38 +02:00
userName = profiles."${cfg.defaultProfile}".name;
userEmail = profiles."${cfg.defaultProfile}".email;
signing = {
key = profiles."${cfg.defaultProfile}".signingKey;
};
includes = flatten (
mapAttrsToList (
name: profile:
map (dir: {
condition = "gitdir:${dir}";
contents.user = {
inherit (profile) name email signingKey;
};
}) profile.dirs
) profiles
);
};
2020-08-15 03:06:37 +02:00
};
}