feat(git): move git module

This commit is contained in:
Felix Schröter 2020-08-15 03:06:37 +02:00
parent 1354334545
commit 134d6a3556
No known key found for this signature in database
GPG key ID: 910ACB9F6BD26F58
2 changed files with 91 additions and 80 deletions

View file

@ -1,90 +1,27 @@
{ lib, pkgs, config, ... }: { config, pkgs, ... }:
with lib;
let let
cfg = config.programs.git.custom;
defaultProfiles = {
private = {
name = "Felix Tenley";
email = "dev@felschr.com";
signingKey = "6AB3 7A28 5420 9A41 82D9 0068 910A CB9F 6BD2 6F58";
dirs = [ "/etc/nixos/" ];
};
work = {
name = "Felix Schröter";
email = "fs@upsquared.com";
signingKey = "F28B FB74 4421 7580 5A49 2930 BE85 F0D9 987F A014";
dirs = [ "~/dev/" ];
};
};
in in
{ {
options.programs.git.custom = { imports = [
profiles = mkOption { ./modules/git.nix
type = types.attrsOf (types.submodule ({ name, config, ... }: { ];
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;
};
defaultProfile = mkOption {
type = types.str;
default = "private";
};
};
config = let programs.git.custom = {
profiles = cfg.profiles; profiles = {
in { private = {
programs.git = { name = "Felix Tenley";
enable = true; email = "dev@felschr.com";
userName = profiles."${cfg.defaultProfile}".name; signingKey = "6AB3 7A28 5420 9A41 82D9 0068 910A CB9F 6BD2 6F58";
userEmail = profiles."${cfg.defaultProfile}".email; dirs = [ "/etc/nixos/" ];
ignores = [".direnv"];
signing = {
key = profiles."${cfg.defaultProfile}".signingKey;
signByDefault = true;
}; };
extraConfig = { work = {
init = { name = "Felix Schröter";
defaultBranch = "main"; email = "fs@upsquared.com";
}; signingKey = "F28B FB74 4421 7580 5A49 2930 BE85 F0D9 987F A014";
pull = { dirs = [ "~/dev/" ];
rebase = true;
};
rebase = {
autoStash = true;
autoSquash = true;
abbreviateCommands = true;
missingCommitsCheck = "warn";
};
}; };
aliases = {
mr = "!sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' -";
pr = "!sh -c 'git fetch $1 refs/pull/$2/head:pr/$1 && git checkout pr/$2'";
};
includes = flatten (mapAttrsToList (name: profile: map (dir: {
condition = "gitdir:${dir}";
contents = {
user = {
name = profile.name;
email = profile.email;
signingkey = profile.signingKey;
};
};
}) profile.dirs) profiles);
}; };
defaultProfile = "private";
}; };
} }

74
home/modules/git.nix Normal file
View file

@ -0,0 +1,74 @@
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.programs.git.custom;
in
{
options.programs.git.custom = {
profiles = mkOption {
type = types.attrsOf (types.submodule ({ name, config, ... }: {
options = {
name = mkOption {
type = types.str;
};
email = mkOption {
type = types.str;
};
signingKey = mkOption {
type = types.str;
};
dirs = mkOption {
type = types.listOf types.str;
};
};
}));
};
defaultProfile = mkOption {
type = types.str;
};
};
config = let
profiles = cfg.profiles;
in {
programs.git = {
enable = true;
userName = profiles."${cfg.defaultProfile}".name;
userEmail = profiles."${cfg.defaultProfile}".email;
ignores = [".direnv"];
signing = {
key = profiles."${cfg.defaultProfile}".signingKey;
signByDefault = true;
};
extraConfig = {
init = {
defaultBranch = "main";
};
pull = {
rebase = true;
};
rebase = {
autoStash = true;
autoSquash = true;
abbreviateCommands = true;
missingCommitsCheck = "warn";
};
};
aliases = {
mr = "!sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' -";
pr = "!sh -c 'git fetch $1 refs/pull/$2/head:pr/$1 && git checkout pr/$2'";
};
includes = flatten (mapAttrsToList (name: profile: map (dir: {
condition = "gitdir:${dir}";
contents = {
user = {
name = profile.name;
email = profile.email;
signingKey = profile.signingKey;
};
};
}) profile.dirs) profiles);
};
};
}