From 134d6a3556675c98aec3062c71432e5ba4ca3ca1 Mon Sep 17 00:00:00 2001 From: Felix Tenley Date: Sat, 15 Aug 2020 03:06:37 +0200 Subject: [PATCH] feat(git): move git module --- home/git.nix | 97 ++++++++------------------------------------ home/modules/git.nix | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 80 deletions(-) create mode 100644 home/modules/git.nix diff --git a/home/git.nix b/home/git.nix index c43b38d..81ce9ef 100644 --- a/home/git.nix +++ b/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"; }; } diff --git a/home/modules/git.nix b/home/modules/git.nix new file mode 100644 index 0000000..fa65ef4 --- /dev/null +++ b/home/modules/git.nix @@ -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); + }; + }; +}