feat(git): move git module
This commit is contained in:
parent
1354334545
commit
134d6a3556
97
home/git.nix
97
home/git.nix
|
@ -1,90 +1,27 @@
|
|||
{ lib, pkgs, config, ... }:
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
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
|
||||
{
|
||||
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";
|
||||
};
|
||||
};
|
||||
imports = [
|
||||
./modules/git.nix
|
||||
];
|
||||
|
||||
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;
|
||||
programs.git.custom = {
|
||||
profiles = {
|
||||
private = {
|
||||
name = "Felix Tenley";
|
||||
email = "dev@felschr.com";
|
||||
signingKey = "6AB3 7A28 5420 9A41 82D9 0068 910A CB9F 6BD2 6F58";
|
||||
dirs = [ "/etc/nixos/" ];
|
||||
};
|
||||
extraConfig = {
|
||||
init = {
|
||||
defaultBranch = "main";
|
||||
};
|
||||
pull = {
|
||||
rebase = true;
|
||||
};
|
||||
rebase = {
|
||||
autoStash = true;
|
||||
autoSquash = true;
|
||||
abbreviateCommands = true;
|
||||
missingCommitsCheck = "warn";
|
||||
};
|
||||
work = {
|
||||
name = "Felix Schröter";
|
||||
email = "fs@upsquared.com";
|
||||
signingKey = "F28B FB74 4421 7580 5A49 2930 BE85 F0D9 987F A014";
|
||||
dirs = [ "~/dev/" ];
|
||||
};
|
||||
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