2020-08-15 03:06:37 +02:00
|
|
|
{ lib, pkgs, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2022-01-01 02:13:02 +01:00
|
|
|
let cfg = config.programs.git;
|
|
|
|
in {
|
2020-08-15 03:18:48 +02:00
|
|
|
options.programs.git = {
|
2020-08-15 03:06:37 +02:00
|
|
|
profiles = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
|
|
|
options = {
|
2022-01-01 02:13:02 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2022-01-01 02:13:02 +01:00
|
|
|
config = let profiles = cfg.profiles;
|
2020-08-15 03:06:37 +02:00
|
|
|
in {
|
|
|
|
programs.git = {
|
|
|
|
userName = profiles."${cfg.defaultProfile}".name;
|
|
|
|
userEmail = profiles."${cfg.defaultProfile}".email;
|
2022-01-01 02:13:02 +01:00
|
|
|
signing = { key = profiles."${cfg.defaultProfile}".signingKey; };
|
|
|
|
includes = flatten (mapAttrsToList (name: profile:
|
|
|
|
map (dir: {
|
|
|
|
condition = "gitdir:${dir}";
|
|
|
|
contents = {
|
|
|
|
user = {
|
|
|
|
name = profile.name;
|
|
|
|
email = profile.email;
|
|
|
|
signingKey = profile.signingKey;
|
|
|
|
};
|
2020-08-15 03:06:37 +02:00
|
|
|
};
|
2022-01-01 02:13:02 +01:00
|
|
|
}) profile.dirs) profiles);
|
2020-08-15 03:06:37 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|