From 5cd56ddcf330c93a437205c96c899fd8bd34ffb5 Mon Sep 17 00:00:00 2001 From: Yadunand Prem Date: Mon, 18 Aug 2025 13:38:40 +0800 Subject: [PATCH] Migrate git configuration --- .../yadunut@yadunut-mbp/default.nix | 22 +--- modules/home/git/default.nix | 114 ++++++++++++++++++ 2 files changed, 119 insertions(+), 17 deletions(-) create mode 100644 modules/home/git/default.nix diff --git a/homes/aarch64-darwin/yadunut@yadunut-mbp/default.nix b/homes/aarch64-darwin/yadunut@yadunut-mbp/default.nix index 7a2d718..d2124d9 100644 --- a/homes/aarch64-darwin/yadunut@yadunut-mbp/default.nix +++ b/homes/aarch64-darwin/yadunut@yadunut-mbp/default.nix @@ -17,14 +17,11 @@ home.packages = [ # pkgs.dive pkgs.entr - pkgs.lazygit pkgs.jq pkgs.just pkgs.rsync - pkgs.gh pkgs.claude-code pkgs.devenv - pkgs.jujutsu pkgs.dive ]; @@ -39,25 +36,16 @@ "/opt/homebrew/bin" ]; - programs.zsh.shellAliases = { - lg = "lazygit"; - }; - zsh.enable = true; + git = { + enable = true; + gpgProgram = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"; + signingKey = "~/.ssh/yadunut_ed25519.pub"; + }; # Let Home Manager install and manage itself. programs.home-manager.enable = true; - programs.git.extraConfig = { - gpg.ssh.program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"; - user.signingkey = "~/.ssh/yadunut_ed25519.pub"; - core.excludesFile = "~/.gitignore_global"; - }; - - programs.gh = { - enable = true; - }; - targets.darwin = { defaults."com.apple.dock".autohide = true; defaults."com.apple.finder".AppleShowAllFiles = true; diff --git a/modules/home/git/default.nix b/modules/home/git/default.nix new file mode 100644 index 0000000..37d3f54 --- /dev/null +++ b/modules/home/git/default.nix @@ -0,0 +1,114 @@ +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.git; + inherit (lib) mkEnableOption mkIf mkOption; + types = lib.types; + name = "Yadunand Prem"; + email = "yadunand@yadunut.com"; +in +{ + options.git = { + enable = mkEnableOption "Git"; + gpgProgram = mkOption { + default = null; + type = types.nullOr types.str; + }; + signingKey = mkOption { + type = types.nullOr types.str; + default = null; + }; + }; + + config = mkIf cfg.enable { + + home.packages = with pkgs; [ + git + lazygit + jujutsu + delta + ]; + + programs.zsh.shellAliases = { + lg = "lazygit"; + }; + programs.git = { + ignores = [ + ".DS_Store" + ".direnv/" + ".envrc" + "**/.claude/settings.local.json" + ]; + enable = true; + userEmail = email; + userName = name; + delta.enable = true; + lfs.enable = true; + + extraConfig = lib.mkMerge [ + { + init.defaultBranch = "main"; + + pull.rebase = true; + pull.autostash = true; + + rebase.autostash = true; + rebase.autosquash = true; + + push.autoSetupRemote = true; + + commit.gpgsign = true; + commit.verbose = true; + + # merge.conflictstyle = "zdiff2"; + diff.colorMoved = true; + diff.algorithm = "histogram"; + feature.experimental = true; + branch.sort = "committerdate"; + diff.mnemonicPrefix = true; + fetch.all = true; + column.ui = "auto"; + tags.sort = "version:refname"; + push.followTags = true; + + rerere.enabled = true; + rerere.autoupdate = true; + + rebase.updateRefs = true; + + credential.helper = [ + "${pkgs.git-credential-oauth}/bin/git-credential-oauth" + ]; + gpg.format = "ssh"; + credential = { + "https://git.yadunut.dev" = { + oauthClientId = "a4792ccc-144e-407e-86c9-5e7d8d9c3269"; + oauthScopes = "read:repository write:repository"; + oauthAuthURL = "/login/oauth/authorize"; + oauthTokenURL = "/login/oauth/access_token"; + }; + }; + } + (mkIf (cfg.gpgProgram != null) { gpg.ssh.program = cfg.gpgProgram; }) + (mkIf (cfg.signingKey != null) { user.signingkey = cfg.signingKey; }) + ]; + }; + + programs.jujutsu = { + enable = true; + settings = { + user = { + name = name; + email = email; + }; + ui.default-command = "log"; + }; + }; + programs.gh.enable = true; + }; + +}