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
|
|
|
};
|
|
|
|
|
2023-01-07 17:24:59 +01:00
|
|
|
config = let inherit (cfg) profiles;
|
2020-08-15 03:06:37 +02:00
|
|
|
in {
|
|
|
|
programs.git = {
|
2022-05-09 12:58:57 +02:00
|
|
|
# fix/workaround for https://github.com/NixOS/nixpkgs/issues/169193
|
|
|
|
extraConfig.safe.directory = "/etc/nixos";
|
|
|
|
|
2020-08-15 03:06:37 +02:00
|
|
|
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}";
|
2023-01-07 17:24:59 +01:00
|
|
|
contents.user = { inherit (profile) name email signingKey; };
|
2022-01-01 02:13:02 +01:00
|
|
|
}) profile.dirs) profiles);
|
2020-08-15 03:06:37 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|