dotfiles/hm/git/default.nix

126 lines
4 KiB
Nix
Raw Permalink Normal View History

2024-10-30 16:02:33 +01:00
{ pkgs, lib, config, unixpkgs, ... }:
2024-09-15 00:33:54 +02:00
let
cfg = config.programs.git;
in
{
2024-09-15 00:33:54 +02:00
config = lib.mkIf cfg.enable {
home.packages = [
(pkgs.writeShellApplication {
2024-01-11 22:25:52 +01:00
name = "git-sync";
text = (lib.strings.concatLines
2024-01-11 22:25:52 +01:00
(map
(r: ''
echo "===== ${r.path}"
if [ ! -d "${r.path}" ]
then
${pkgs.git}/bin/git clone "${r.uri}" "${r.path}"
else
(
cd "${r.path}"
2024-10-04 17:48:40 +02:00
if [ -d .jj ]
then
2024-10-30 16:02:33 +01:00
${lib.getExe config.programs.jujutsu.package} git fetch
${lib.getExe config.programs.jujutsu.package} rebase -d main@origin
2024-10-30 16:30:37 +01:00
${lib.getExe config.programs.jujutsu.package} bookmark set main -r @-
2024-10-30 16:02:33 +01:00
${lib.getExe config.programs.jujutsu.package} git push
2024-10-04 17:48:40 +02:00
else
${pkgs.git}/bin/git --no-optional-locks diff --quiet || echo "Repository is dirty!"
${pkgs.git}/bin/git pull || true
# Only push if there's something to push. Also prevents from trying to push on repos where we don't have rights.
(${pkgs.git}/bin/git --no-optional-locks status --porcelain -b --ignore-submodules | grep ' \[ahead [0-9]\+\]' && ${pkgs.git}/bin/git push) || true
fi
2024-01-11 22:25:52 +01:00
)
fi
'')
(lib.attrsets.attrValues config.services.git-sync.repositories)
)
);
})
];
2024-09-15 00:33:54 +02:00
programs = {
git = {
package = pkgs.gitFull;
aliases = {
"git" = "!exec git"; # In case I write one too many git
};
2024-09-15 00:33:54 +02:00
ignores = [
"*.swp"
"*.swo"
"*.ycm_extra_conf.py"
"tags"
".mypy_cache"
];
delta = {
enable = true;
options = {
line-numbers = true;
syntax-theme = "base16";
};
};
2024-09-15 00:33:54 +02:00
# Also tried difftastic, and while I like the default theme it's a bit
# less configurable
lfs.enable = true;
userEmail = lib.mkDefault "geoffrey@frogeye.fr";
userName = lib.mkDefault "Geoffrey Frogeye";
extraConfig = {
core = {
editor = "nvim";
};
push = {
default = "matching";
};
pull = {
ff = "only";
};
} // lib.optionalAttrs config.frogeye.desktop.xorg {
diff.tool = "meld";
difftool.prompt = false;
"difftool \"meld\"".cmd = "${pkgs.meld}/bin/meld \"$LOCAL\" \"$REMOTE\"";
# This escapes quotes, which isn't the case in the original, hoping this isn't an issue.
};
2024-09-15 00:33:54 +02:00
};
jujutsu = {
enable = true;
2024-10-30 16:02:33 +01:00
package = (import unixpkgs {
inherit (pkgs) system;
}).jujutsu;
# Current version doesn't have the "none" signing backend
2024-09-15 00:33:54 +02:00
settings = {
2024-09-15 20:14:47 +02:00
git = {
auto-local-bookmark = true;
auto-local-branch = true;
};
2024-09-15 00:33:54 +02:00
user = {
email = cfg.userEmail;
name = cfg.userName;
};
ui = {
pager = "delta";
diff.format = "git";
diff-editor = "meld-3";
merge-editor = "meld";
};
signing = {
sign-all = true;
backend = "gpg";
inherit (cfg.signing) key;
backends.gpg.allow-expired-keys = false;
};
};
};
};
services = {
git-sync = {
enable = false; # The real thing syncs too quickly and asks for passphrase, which is annoying
# So for now it's just a way to park config which will be reused by git-sync-* commands
repositories = {
dotfiles = {
path = "${config.xdg.configHome}/dotfiles";
uri = lib.mkDefault "https://git.frogeye.fr/geoffrey/dotfiles.git";
};
};
};
};
};
}