home/git: properly set url overrides and includes

This commit is contained in:
Oystein Kristoffer Tveit 2024-07-08 15:32:00 +02:00
parent 2532fef033
commit cd508d5337
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 211 additions and 125 deletions

View File

@ -9,6 +9,18 @@
"github" = { "github" = {
user = "git"; user = "git";
hostname = "github.com"; hostname = "github.com";
identityFile = [ "~/.ssh/id_ed25519" ];
};
"github-nordicsemi" = {
user = "git";
hostname = "github.com";
identityFile = [ "~/.ssh/id_ed25519_nordicsemi" ];
};
"bitbucket-nordicsemi" = {
user = "git";
hostname = "bitbucket.nordicsemi.no";
port = 7999;
identityFile = [ "~/.ssh/id_ed25519_nordicsemi" ];
}; };
"gitlab.stud.idi.ntnu.no" = { "gitlab.stud.idi.ntnu.no" = {
user = "git"; user = "git";

View File

@ -1,130 +1,163 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
cfg = config.programs.git; cfg = config.programs.git;
github-uri-prefixes = [
# Preferred
"github:"
# Alternative
"https://github.com/"
"ssh://git@github.com:"
"git@github.com:"
"github.com:"
];
in in
{ {
programs.git = { # TODO: convert to template once nix-sops supports it in hm module
enable = true; sops.secrets."git/nordicsemi-config" = { };
package = pkgs.gitFull;
userName = "h7x4"; programs.git = lib.mkMerge [
userEmail = "h7x4@nani.wtf"; {
signing = {
key = "46B9228E814A2AAC";
signByDefault = true;
};
lfs.enable = true;
delta = {
enable = true; enable = true;
options = { package = pkgs.gitFull;
line-numbers = true;
side-by-side = true;
theme = "Monokai Extended Origin";
};
};
aliases = { userName = "h7x4";
aliases = "!git config --get-regexp alias | sed -re 's/alias\\.(\\S*)\\s(.*)$/\\1 = \\2/g'"; userEmail = "h7x4@nani.wtf";
delete-merged = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d";
graph = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all";
graphv = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all";
forcepush = "push --force-with-lease --force-if-includes";
authors = "shortlog --summary --numbered --email";
si = "switch-interactive";
rebase-author = "rebase -i -x \"git commit --amend --reset-author -CHEAD\"";
};
extraConfig = { signing = {
core = { key = "46B9228E814A2AAC";
whitespace = "space-before-tab,-indent-with-non-tab,trailing-space"; signByDefault = true;
untrackedCache = true;
editor = "nvim";
}; };
safe.directory = "*"; lfs.enable = true;
rerere.enabled = true; delta = {
enable = true;
branch.sort = "-committerdate"; options = {
line-numbers = true;
"color \"branch\"".upstream = "cyan"; side-by-side = true;
color.ui = "auto"; theme = "Monokai Extended Origin";
};
init.defaultBranch = "main";
fetch = {
prune = true;
fsckObjects = true;
}; };
transfer.fsckObjects = true; aliases = {
aliases = "!git config --get-regexp alias | sed -re 's/alias\\.(\\S*)\\s(.*)$/\\1 = \\2/g'";
receive.fsckObjects = true; delete-merged = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d";
graph = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all";
pull.rebase = true; graphv = "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all";
forcepush = "push --force-with-lease --force-if-includes";
rebase = { authors = "shortlog --summary --numbered --email";
autoStash = true; si = "switch-interactive";
autoSquash = true; rebase-author = "rebase -i -x \"git commit --amend --reset-author -CHEAD\"";
abbreviateCommands = true;
updateRefs = true;
}; };
push = { extraConfig = {
default = "current"; core = {
autoSetupRemote = true; whitespace = "space-before-tab,-indent-with-non-tab,trailing-space";
followTags = true; untrackedCache = true;
editor = "nvim";
};
safe.directory = "*";
rerere.enabled = true;
branch.sort = "-committerdate";
"color \"branch\"".upstream = "cyan";
color.ui = "auto";
init.defaultBranch = "main";
fetch = {
prune = true;
fsckObjects = true;
};
transfer.fsckObjects = true;
receive.fsckObjects = true;
pull.rebase = true;
rebase = {
autoStash = true;
autoSquash = true;
abbreviateCommands = true;
updateRefs = true;
};
push = {
default = "current";
autoSetupRemote = true;
followTags = true;
};
merge = {
tool = "nvimdiff";
conflictstyle = "diff3";
colorMoved = "zebra";
};
mergetool.keepBackup = false;
"mergetool \"nvimdiff\"".cmd = "nvim -d $BASE $LOCAL $REMOTE $MERGED -c '$wincmd w' -c 'wincmd J'";
diff = {
mnemonicPrefix = true;
renames = true;
tool = "nvimdiff";
submodule = "log";
};
status = {
showUntrackedFiles = "all";
relativePaths = true;
submoduleSummary = true;
};
log.date = "iso";
submodule.recurse = true;
grep = {
break = true;
heading= true;
lineNumber = true;
extendedRegexp = true;
};
# Run autocorrected command after 3 seconds
help.autocorrect = "30";
github.user = "h7x4";
"url \"${lib.head github-uri-prefixes}\"".insteadOf = lib.tail github-uri-prefixes;
web.browser = "google-chrome-stable";
"filter \"lfs\"" = {
required = true;
smudge = "git-lfs smudge -- %f";
process = "git-lfs filter-process";
clean = "git-lfs clean -- %f";
};
}; };
merge = { ignores = [
tool = "nvimdiff"; ".vscode"
conflictstyle = "diff3"; ".direnv"
colorMoved = "zebra"; ".envrc"
}; "shell.nix"
mergetool.keepBackup = false;
"mergetool \"nvimdiff\"".cmd = "nvim -d $BASE $LOCAL $REMOTE $MERGED -c '$wincmd w' -c 'wincmd J'";
diff = {
mnemonicPrefix = true;
renames = true;
tool = "nvimdiff";
submodule = "log";
};
status = {
showUntrackedFiles = "all";
relativePaths = true;
submoduleSummary = true;
};
log.date = "iso";
submodule.recurse = true;
grep = {
break = true;
heading= true;
lineNumber = true;
extendedRegexp = true;
};
# Run autocorrected command after 3 seconds
help.autocorrect = "30";
github.user = "h7x4";
"url \"github:\"".insteadOf = [
"https://github.com/"
"ssh://git@github.com:"
"git@github.com:"
"github.com:"
]; ];
}
"url \"pvv-git:\"".insteadOf = [ (let
uri-prefixes = [
# Preferred
"pvv-git:"
# Alternative
"https://git.pvv.org/" "https://git.pvv.org/"
"ssh://gitea@git.pvv.ntnu.no:2222/" "ssh://gitea@git.pvv.ntnu.no:2222/"
"gitea@git.pvv.ntnu.no:2222/" "gitea@git.pvv.ntnu.no:2222/"
@ -132,23 +165,62 @@ in
"git.pvv.ntnu.no:" "git.pvv.ntnu.no:"
]; ];
web.browser = "google-chrome-stable"; prefixes-per-org = let
organizations = [
"Drift"
"Projects"
];
in lib.genAttrs organizations (org: map (uri-prefix: "${uri-prefix}${org}") uri-prefixes);
in {
extraConfig."url \"${lib.head uri-prefixes}\"".insteadOf = lib.tail uri-prefixes;
"filter \"lfs\"" = { includes = map (x: {
required = true; contentSuffix = "pvv.gitconfig";
smudge = "git-lfs smudge -- %f"; condition = "hasconfig:remote.*.url:${x}**";
process = "git-lfs filter-process"; contents = {
clean = "git-lfs clean -- %f"; user = {
}; email = "oysteikt@pvv.ntnu.no";
}; name = "Øystein Tveit";
};
};
}) (lib.flatten (lib.attrValues prefixes-per-org));
})
ignores = [ (let
".vscode" bitbucket-uri-prefixes = [
".direnv" # Preferred
".envrc" "bitbucket-nordicsemi:"
"shell.nix"
]; # Alternative
}; "ssh://git@bitbucket.nordicsemi.no:7999"
"https://projecttools.nordicsemi.no/bitbucket/scm"
];
prefixes-per-org = let
organizations = [
"NordicSemiconductor"
"NordicPlayground"
"nrfconnect"
];
in lib.genAttrs organizations (org: map (uri-prefix: "${uri-prefix}${org}") github-uri-prefixes);
in {
extraConfig = lib.mergeAttrs
{
"url \"${lib.head bitbucket-uri-prefixes}\"".insteadOf = lib.tail bitbucket-uri-prefixes;
}
(lib.mapAttrs' (org: uri-prefixes: {
name = "url \"github-nordicsemi:${org}\"";
value.insteadOf = uri-prefixes;
}) prefixes-per-org)
;
includes = map (x: {
contentSuffix = "nordicsemi.gitconfig";
condition = "hasconfig:remote.*.url:${x}/**";
path = config.sops.secrets."git/nordicsemi-config".path;
}) (bitbucket-uri-prefixes ++ (lib.flatten (lib.attrValues prefixes-per-org)));
})
];
home.packages = [ home.packages = [
(pkgs.writeShellApplication { (pkgs.writeShellApplication {

View File

@ -1,5 +1,7 @@
git:
nordicsemi-config: ENC[AES256_GCM,data:ziuM41RTsxkiutxjj8Pl5YuoETkxQNWEbGKd2Y99E0kTV9fL67g+YeGjeVFXErraeB/+jBVpjitK3lSHxlpxZLWckZ0G6A7NAFNagY9cORCFlLb+egyKb44xu8vBt4V5eA==,iv:yG06oluENc038cm5A9tpmSQtaGjd6nYDi/FnBd3A8Rk=,tag:ky6bCsYLOZmWObHnJ816Zw==,type:str]
ssh: ssh:
secret-config: ENC[AES256_GCM,data:HFrGyBiqNJJOzWhoDBosh7Kub7zz2cJvE6FphapqFeZ3ZNqG27nVu6G9JsLiIZBtsSgBcne0WEV+vNY07d6QBHX/IHryNczhrIEkiI9yNBORBvIOVLS9J4bP/ueUBn4EmLVBQ5tW5/s+0RNSTw==,iv:6bhpPR5QjnnO44p0NCjXl9P/TVP+Tdi61gU3RddNCIU=,tag:QAWcPbwAW1Fmue7CzFWF8w==,type:str] secret-config: ""
sops: sops:
kms: [] kms: []
gcp_kms: [] gcp_kms: []
@ -15,8 +17,8 @@ sops:
QllyaVlIVEVrSlJDZzlwdFpoRlg3bmsKYBGLYmsfFu6GuRUPGsS0+vkUv1QzJXZl QllyaVlIVEVrSlJDZzlwdFpoRlg3bmsKYBGLYmsfFu6GuRUPGsS0+vkUv1QzJXZl
D9CFcRQw0Xzti0DvDj7cWrCJ32F1eYRp/9LWyG1CEjfoNEKyUJZ2qQ== D9CFcRQw0Xzti0DvDj7cWrCJ32F1eYRp/9LWyG1CEjfoNEKyUJZ2qQ==
-----END AGE ENCRYPTED FILE----- -----END AGE ENCRYPTED FILE-----
lastmodified: "2024-07-08T12:56:35Z" lastmodified: "2024-07-08T13:25:35Z"
mac: ENC[AES256_GCM,data:NOs6g8PKDBwbimZLumnde2ohhxRKxajORZMI1kraLgbow8uFUO9CreEMz5epRFMqesClFuWQXJfpki9dxONYs4zsIaPjuZWi9a1d3eUf+AGw5Ey6GKEh5z/oSQkfK3CCYH9g9E+iOeK8eCHPMYAwAPSyxCBumEoIuwOrUlgdGlQ=,iv:vXWOqw4ZPZkMktuKU5WmA8AAsBniyxbjfVaI+9TpH9M=,tag:MmHBM527T8egbIvpUNPiuQ==,type:str] mac: ENC[AES256_GCM,data:JUYECqv5+wtAhDWr+2pNSh/EXhh/gjjUFCjC6oH+3cXpZHacg23S/D5ol6nIXKH1+XUFaIX10YQOC0WaciZUcfgCP4t01MJRB3OE1iYcGllyeP+9gEIKfoeEajHVQdYWZHUql7T4EnQWs74uHiF7nt6jALnp98Wc4Pny6xvvZds=,iv:gDr7O566etB9oYAJB1RIK1PQJIc1NVcIlhZISidVmlA=,tag:bQ1iC1Xi5A+VbBgunHt02w==,type:str]
pgp: pgp:
- created_at: "2024-07-08T12:27:24Z" - created_at: "2024-07-08T12:27:24Z"
enc: |- enc: |-