nixos-config/home/modules/git.nix

43 lines
1.2 KiB
Nix
Raw Normal View History

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 {
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 = {
# 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}";
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
};
};
}