feat(git): move git module
This commit is contained in:
parent
1354334545
commit
134d6a3556
83
home/git.nix
83
home/git.nix
|
@ -1,9 +1,14 @@
|
|||
{ lib, pkgs, config, ... }:
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
cfg = config.programs.git.custom;
|
||||
defaultProfiles = {
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./modules/git.nix
|
||||
];
|
||||
|
||||
programs.git.custom = {
|
||||
profiles = {
|
||||
private = {
|
||||
name = "Felix Tenley";
|
||||
email = "dev@felschr.com";
|
||||
|
@ -17,74 +22,6 @@ let
|
|||
dirs = [ "~/dev/" ];
|
||||
};
|
||||
};
|
||||
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;
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = defaultProfiles;
|
||||
};
|
||||
defaultProfile = mkOption {
|
||||
type = types.str;
|
||||
default = "private";
|
||||
};
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
defaultProfile = "private";
|
||||
};
|
||||
}
|
||||
|
|
74
home/modules/git.nix
Normal file
74
home/modules/git.nix
Normal 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);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue