feat(git): add directory-based git config

This commit is contained in:
Felix Schröter 2020-05-22 18:27:31 +02:00
parent edd428ee27
commit 3ef402af9f
No known key found for this signature in database
GPG key ID: A12D7C9D2FD34458
3 changed files with 52 additions and 18 deletions

View file

@ -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;

View file

@ -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; [

View file

@ -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.str; type = types.attrsOf (types.submodule ({ name, config, ... }: {
default = "Felix Tenley"; options = {
name = mkOption {
type = types.str;
};
email = mkOption {
type = types.str;
};
signingKey = mkOption {
type = types.str;
};
dirs = mkOption {
type = types.listOf types.str;
};
};
}));
default = defaultProfiles;
}; };
userEmail = mkOption { defaultProfile = mkOption {
type = types.str; type = types.str;
default = "dev@felschr.com"; default = "private";
};
signingKey = mkOption {
type = types.str;
}; };
}; };
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);
}; };
}; };
} }