feat(git): add directory-based git config
This commit is contained in:
parent
edd428ee27
commit
3ef402af9f
|
@ -35,9 +35,7 @@ with pkgs;
|
||||||
programs.gpg.enable = true;
|
programs.gpg.enable = true;
|
||||||
|
|
||||||
programs.git.custom = {
|
programs.git.custom = {
|
||||||
userName = "Felix Schroeter";
|
defaultProfile = "work";
|
||||||
userEmail = "fs@upsquared.com";
|
|
||||||
signingKey = "6DA1 4A05 C6E0 7DBE EB81 BA24 28ED 46BC B881 7B7A";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
programs.firefox.enable = true;
|
programs.firefox.enable = true;
|
||||||
|
|
|
@ -39,9 +39,7 @@ with pkgs;
|
||||||
programs.gpg.enable = true;
|
programs.gpg.enable = true;
|
||||||
|
|
||||||
programs.git.custom = {
|
programs.git.custom = {
|
||||||
userName = "Felix Tenley";
|
defaultProfile = "private";
|
||||||
userEmail = "dev@felschr.com";
|
|
||||||
signingKey = "22A6 DD21 EE66 E73D D4B9 3F20 A12D 7C9D 2FD3 4458";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
|
|
54
home/git.nix
54
home/git.nix
|
@ -3,36 +3,74 @@
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.programs.git.custom;
|
cfg = config.programs.git.custom;
|
||||||
|
defaultProfiles = {
|
||||||
|
private = {
|
||||||
|
name = "Felix Tenley";
|
||||||
|
email = "dev@felschr.com";
|
||||||
|
signingKey = "22A6 DD21 EE66 E73D D4B9 3F20 A12D 7C9D 2FD3 4458";
|
||||||
|
dirs = [ "/etc/nixos/" ];
|
||||||
|
};
|
||||||
|
work = {
|
||||||
|
name = "Felix Schröter";
|
||||||
|
email = "fs@upsquared.com";
|
||||||
|
signingKey = "6DA1 4A05 C6E0 7DBE EB81 BA24 28ED 46BC B881 7B7A";
|
||||||
|
dirs = [ "~/dev/" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.programs.git.custom = {
|
options.programs.git.custom = {
|
||||||
userName = mkOption {
|
profiles = mkOption {
|
||||||
|
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "Felix Tenley";
|
|
||||||
};
|
};
|
||||||
userEmail = mkOption {
|
email = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "dev@felschr.com";
|
|
||||||
};
|
};
|
||||||
signingKey = mkOption {
|
signingKey = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
};
|
};
|
||||||
|
dirs = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
default = defaultProfiles;
|
||||||
|
};
|
||||||
|
defaultProfile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "private";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = let
|
||||||
|
profiles = cfg.profiles;
|
||||||
|
in {
|
||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
userName = cfg.userName;
|
userName = profiles."${cfg.defaultProfile}".name;
|
||||||
userEmail = cfg.userEmail;
|
userEmail = profiles."${cfg.defaultProfile}".email;
|
||||||
ignores = [".direnv"];
|
ignores = [".direnv"];
|
||||||
signing = {
|
signing = {
|
||||||
key = cfg.signingKey;
|
key = profiles."${cfg.defaultProfile}".signingKey;
|
||||||
signByDefault = true;
|
signByDefault = true;
|
||||||
};
|
};
|
||||||
extraConfig = {
|
extraConfig = {
|
||||||
pull = { rebase = true; };
|
pull = { rebase = true; };
|
||||||
rebase = { autoStash = true; };
|
rebase = { autoStash = true; };
|
||||||
};
|
};
|
||||||
|
includes = flatten (mapAttrsToList (name: profile: map (dir: {
|
||||||
|
condition = "gitdir:${dir}";
|
||||||
|
contents = {
|
||||||
|
user = {
|
||||||
|
name = profile.name;
|
||||||
|
email = profile.email;
|
||||||
|
signingkey = profile.signingKey;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}) profile.dirs) profiles);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue