diff --git a/dots/.gitconfig b/dots/.gitconfig deleted file mode 100644 index 1c02057..0000000 --- a/dots/.gitconfig +++ /dev/null @@ -1,104 +0,0 @@ -[include] - path = ~/.gitconfig.email - -[core] - editor = nvim - excludesfile = ~/.gitignore - -[user] - name = Hektor Misplon - username = hektor - signingKey = AEB98353B8D72E465C4236435151AF79E723F21C - -[alias] - d = diff - ds = diff --staged - a = add - ap = add -p - c = commit - cm = commit -m - cam = commit --amend - l = log --pretty=format:"(%an)\\ \\ %h\\ \\ %ad\\ \\ %s" --date=short - s = status --short - sv = status --verbose - co = checkout - cob = checkout -b - pullr = "pull --rebase --autostash" - pushf = "push --force-with-lease" - # Note these follow the naming convention of my `.bash_aliases` - al = "!git config -l | grep alias | cut -c 7-" - alf = "!git config -l | grep alias | cut -c 7- | fzf" - al- = "!git config --local --unset $(git config -l | grep alias | cut --delimiter="=" --fields=1 | fzf)" - rs = "restore --staged" - rb = "rebase" - rbi = "rebase -i" - wt = "worktree" - wtc = "config remote.origin.fetch \"+refs/heads/*:refs/remotes/origin/*\"" - -[color] - ui = auto - -[color "diff"] - meta = yellow bold - commit = green bold - frag = magenta bold - old = red bold - new = green bold - whitespace = red reverse - -[color "diff-highlight"] - oldNormal = red bold - oldHighlight = "red bold 52" - newNormal = "green bold" - newHighlight = "green bold 22" - -[color "branch"] - current = normal bold - local = normal - remote = normal italic - -[color "status"] - added = green - changed = yellow - untracked = normal italic - -[credential] - helper = cache --timeout=3600 - -[init] - defaultBranch = main - -[log] - date = relative - abbrevCommit = true - -[credential "https://github.com"] - helper = !gh auth git-credential - -[merge] - tool = nvimdiff - conflictstyle = diff3 -[diff] - colorMoved = zebra - tool = nvimdiff -[difftool] - prompt = false -[mergetool] - prompt = false - keepBackup = false -[commit] - gpgsign = false - -[interactive] - singleKey = true - -[pull] - rebase = true -[rerere] - enabled = true - -[includeIf "gitdir:~/work/"] - path = ~/.gitconfig.work - -[includeIf "gitdir:~/nix-dev-shells/"] - path = ~/.gitconfig.work diff --git a/dots/.gitconfig.email.example b/dots/.gitconfig.email.example deleted file mode 100644 index acd2388..0000000 --- a/dots/.gitconfig.email.example +++ /dev/null @@ -1,2 +0,0 @@ -[user] - email = your.email@example.com diff --git a/dots/.gitconfig.work b/dots/.gitconfig.work deleted file mode 100644 index 4878c22..0000000 --- a/dots/.gitconfig.work +++ /dev/null @@ -1,13 +0,0 @@ -[include] - path = ~/.gitconfig.work.email - -[core] - longpaths = true - -[user] - name = Hektor Misplon - username = hektor.misplon - signingKey = 1C88BE828184CEE6 - -[commit] - gpgsign = false diff --git a/dots/.gitconfig.work.email.example b/dots/.gitconfig.work.email.example deleted file mode 100644 index d6c0105..0000000 --- a/dots/.gitconfig.work.email.example +++ /dev/null @@ -1,2 +0,0 @@ -[user] - email = your.work.email@example.com diff --git a/home/modules/git/default.nix b/home/modules/git/default.nix index 7d39537..9ebf5ed 100644 --- a/home/modules/git/default.nix +++ b/home/modules/git/default.nix @@ -1,10 +1,31 @@ { config, + inputs, lib, - dotsPath, + myUtils, + osConfig ? null, ... }: +let + cfg = config.git; + sops = myUtils.sopsAvailability config osConfig; + standalone = osConfig == null; + + personalEmail = sops.templates.".gitconfig.email".path; + workEmail = sops.templates.".gitconfig.work.email".path; + + workSettings = { + include.path = workEmail; + core.longpaths = true; + user = { + name = "Hektor Misplon"; + username = "hektor.misplon"; + signingKey = "1C88BE828184CEE6"; + }; + commit.gpgSign = false; + }; +in { options.git = { enable = lib.mkEnableOption "git"; @@ -26,18 +47,138 @@ ./gitlab.nix ]; - config = lib.mkIf config.git.enable { - assertions = [ - { - assertion = config.nvim.enable; - message = "git module requires 'nvim' module (`nvimdiff`)"; - } - ]; - programs.git.enable = true; - home.file = { - ".gitconfig".source = dotsPath + "/.gitconfig"; - ".gitconfig.work".source = dotsPath + "/.gitconfig.work"; - ".gitignore".source = dotsPath + "/.gitignore"; - }; - }; + config = lib.mkIf cfg.enable ( + lib.optionalAttrs standalone { + sops = { + secrets = myUtils.mkSopsSecrets "${toString inputs.nix-secrets}/secrets" { + email = [ + "personal" + "work" + ]; + }; + + templates = { + ".gitconfig.email".content = '' + [user] + email = ${config.sops.placeholder."email/personal"} + ''; + ".gitconfig.work.email".content = '' + [user] + email = ${config.sops.placeholder."email/work"} + ''; + }; + }; + } + // { + assertions = [ + { + assertion = config.nvim.enable; + message = "git module requires 'nvim' module (`nvimdiff`)"; + } + ]; + + xdg.configFile."git/ignore".source = ./global.gitignore; + + programs.git = { + enable = true; + settings = { + core.editor = "nvim"; + user = { + name = "Hektor Misplon"; + username = "hektor"; + signingKey = "AEB98353B8D72E465C4236435151AF79E723F21C"; + }; + alias = { + d = "diff"; + ds = "diff --staged"; + a = "add"; + ap = "add -p"; + c = "commit"; + cm = "commit -m"; + cam = "commit --amend"; + l = ''log --pretty=format:(%an)\ \ %h\ \ %ad\ \ %s --date=short''; + s = "status --short"; + sv = "status --verbose"; + co = "checkout"; + cob = "checkout -b"; + pullr = "pull --rebase --autostash"; + pushf = "push --force-with-lease"; + al = "!git config -l | grep alias | cut -c 7-"; + alf = "!git config -l | grep alias | cut -c 7- | fzf"; + "al-" = + ''!git config --local --unset $(git config -l | grep alias | cut --delimiter="=" --fields=1 | fzf)''; + rs = "restore --staged"; + rb = "rebase"; + rbi = "rebase -i"; + wt = "worktree"; + wtc = ''config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"''; + }; + color = { + ui = "auto"; + diff = { + meta = "yellow bold"; + commit = "green bold"; + frag = "magenta bold"; + old = "red bold"; + new = "green bold"; + whitespace = "red reverse"; + }; + "diff-highlight" = { + oldNormal = "red bold"; + oldHighlight = "red bold 52"; + newNormal = "green bold"; + newHighlight = "green bold 22"; + }; + branch = { + current = "normal bold"; + local = "normal"; + remote = "normal italic"; + }; + status = { + added = "green"; + changed = "yellow"; + untracked = "normal italic"; + }; + }; + credential.helper = "cache --timeout=3600"; + init.defaultBranch = "main"; + log = { + date = "relative"; + abbrevCommit = true; + }; + merge = { + tool = "nvimdiff"; + conflictStyle = "diff3"; + }; + diff = { + colorMoved = "zebra"; + tool = "nvimdiff"; + }; + difftool.prompt = false; + mergetool = { + prompt = false; + keepBackup = false; + }; + commit.gpgSign = false; + interactive.singleKey = true; + pull.rebase = true; + rerere.enabled = true; + }; + + includes = [ + { path = personalEmail; } + { + condition = "gitdir:~/work/"; + contents = workSettings; + contentSuffix = "gitconfig-work"; + } + { + condition = "gitdir:~/nix-dev-shells/"; + contents = workSettings; + contentSuffix = "gitconfig-work"; + } + ]; + }; + } + ); } diff --git a/dots/.gitignore b/home/modules/git/global.gitignore similarity index 100% rename from dots/.gitignore rename to home/modules/git/global.gitignore diff --git a/modules/git/default.nix b/modules/git/default.nix index 692da91..67556f9 100644 --- a/modules/git/default.nix +++ b/modules/git/default.nix @@ -12,7 +12,6 @@ in sops.templates = { ".gitconfig.email" = { inherit owner; - path = "/home/${username}/.gitconfig.email"; content = '' [user] email = ${config.sops.placeholder."email/personal"} @@ -20,7 +19,6 @@ in }; ".gitconfig.work.email" = { inherit owner; - path = "/home/${username}/.gitconfig.work.email"; content = '' [user] email = ${config.sops.placeholder."email/work"}