diff --git a/home/config/ssh/other.nix b/home/config/ssh/other.nix index d0e81a1..f661748 100644 --- a/home/config/ssh/other.nix +++ b/home/config/ssh/other.nix @@ -9,6 +9,18 @@ "github" = { user = "git"; 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" = { user = "git"; diff --git a/home/programs/git/default.nix b/home/programs/git/default.nix index ac5efe9..2b331a7 100644 --- a/home/programs/git/default.nix +++ b/home/programs/git/default.nix @@ -1,130 +1,163 @@ { config, pkgs, lib, ... }: let cfg = config.programs.git; + + github-uri-prefixes = [ + # Preferred + "github:" + + # Alternative + "https://github.com/" + "ssh://git@github.com:" + "git@github.com:" + "github.com:" + ]; in { - programs.git = { - enable = true; - package = pkgs.gitFull; + # TODO: convert to template once nix-sops supports it in hm module + sops.secrets."git/nordicsemi-config" = { }; - userName = "h7x4"; - userEmail = "h7x4@nani.wtf"; - - signing = { - key = "46B9228E814A2AAC"; - signByDefault = true; - }; - - lfs.enable = true; - - delta = { + programs.git = lib.mkMerge [ + { enable = true; - options = { - line-numbers = true; - side-by-side = true; - theme = "Monokai Extended Origin"; - }; - }; + package = pkgs.gitFull; - aliases = { - aliases = "!git config --get-regexp alias | sed -re 's/alias\\.(\\S*)\\s(.*)$/\\1 = \\2/g'"; - 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\""; - }; + userName = "h7x4"; + userEmail = "h7x4@nani.wtf"; - extraConfig = { - core = { - whitespace = "space-before-tab,-indent-with-non-tab,trailing-space"; - untrackedCache = true; - editor = "nvim"; + signing = { + key = "46B9228E814A2AAC"; + signByDefault = true; }; - safe.directory = "*"; + lfs.enable = true; - rerere.enabled = true; - - branch.sort = "-committerdate"; - - "color \"branch\"".upstream = "cyan"; - color.ui = "auto"; - - init.defaultBranch = "main"; - - fetch = { - prune = true; - fsckObjects = true; + delta = { + enable = true; + options = { + line-numbers = true; + side-by-side = true; + theme = "Monokai Extended Origin"; + }; }; - transfer.fsckObjects = true; - - receive.fsckObjects = true; - - pull.rebase = true; - - rebase = { - autoStash = true; - autoSquash = true; - abbreviateCommands = true; - updateRefs = true; + aliases = { + aliases = "!git config --get-regexp alias | sed -re 's/alias\\.(\\S*)\\s(.*)$/\\1 = \\2/g'"; + 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\""; }; - push = { - default = "current"; - autoSetupRemote = true; - followTags = true; + extraConfig = { + core = { + whitespace = "space-before-tab,-indent-with-non-tab,trailing-space"; + 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 = { - 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 \"github:\"".insteadOf = [ - "https://github.com/" - "ssh://git@github.com:" - "git@github.com:" - "github.com:" + ignores = [ + ".vscode" + ".direnv" + ".envrc" + "shell.nix" ]; + } - "url \"pvv-git:\"".insteadOf = [ + (let + uri-prefixes = [ + # Preferred + "pvv-git:" + + # Alternative "https://git.pvv.org/" "ssh://gitea@git.pvv.ntnu.no:2222/" "gitea@git.pvv.ntnu.no:2222/" @@ -132,23 +165,62 @@ in "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\"" = { - required = true; - smudge = "git-lfs smudge -- %f"; - process = "git-lfs filter-process"; - clean = "git-lfs clean -- %f"; - }; - }; + includes = map (x: { + contentSuffix = "pvv.gitconfig"; + condition = "hasconfig:remote.*.url:${x}**"; + contents = { + user = { + email = "oysteikt@pvv.ntnu.no"; + name = "Øystein Tveit"; + }; + }; + }) (lib.flatten (lib.attrValues prefixes-per-org)); + }) - ignores = [ - ".vscode" - ".direnv" - ".envrc" - "shell.nix" - ]; - }; + (let + bitbucket-uri-prefixes = [ + # Preferred + "bitbucket-nordicsemi:" + + # 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 = [ (pkgs.writeShellApplication { diff --git a/secrets/home.yaml b/secrets/home.yaml index 33abc7a..039167e 100644 --- a/secrets/home.yaml +++ b/secrets/home.yaml @@ -1,5 +1,7 @@ +git: + nordicsemi-config: ENC[AES256_GCM,data:ziuM41RTsxkiutxjj8Pl5YuoETkxQNWEbGKd2Y99E0kTV9fL67g+YeGjeVFXErraeB/+jBVpjitK3lSHxlpxZLWckZ0G6A7NAFNagY9cORCFlLb+egyKb44xu8vBt4V5eA==,iv:yG06oluENc038cm5A9tpmSQtaGjd6nYDi/FnBd3A8Rk=,tag:ky6bCsYLOZmWObHnJ816Zw==,type:str] ssh: - secret-config: ENC[AES256_GCM,data:HFrGyBiqNJJOzWhoDBosh7Kub7zz2cJvE6FphapqFeZ3ZNqG27nVu6G9JsLiIZBtsSgBcne0WEV+vNY07d6QBHX/IHryNczhrIEkiI9yNBORBvIOVLS9J4bP/ueUBn4EmLVBQ5tW5/s+0RNSTw==,iv:6bhpPR5QjnnO44p0NCjXl9P/TVP+Tdi61gU3RddNCIU=,tag:QAWcPbwAW1Fmue7CzFWF8w==,type:str] + secret-config: "" sops: kms: [] gcp_kms: [] @@ -15,8 +17,8 @@ sops: QllyaVlIVEVrSlJDZzlwdFpoRlg3bmsKYBGLYmsfFu6GuRUPGsS0+vkUv1QzJXZl D9CFcRQw0Xzti0DvDj7cWrCJ32F1eYRp/9LWyG1CEjfoNEKyUJZ2qQ== -----END AGE ENCRYPTED FILE----- - lastmodified: "2024-07-08T12:56:35Z" - mac: ENC[AES256_GCM,data:NOs6g8PKDBwbimZLumnde2ohhxRKxajORZMI1kraLgbow8uFUO9CreEMz5epRFMqesClFuWQXJfpki9dxONYs4zsIaPjuZWi9a1d3eUf+AGw5Ey6GKEh5z/oSQkfK3CCYH9g9E+iOeK8eCHPMYAwAPSyxCBumEoIuwOrUlgdGlQ=,iv:vXWOqw4ZPZkMktuKU5WmA8AAsBniyxbjfVaI+9TpH9M=,tag:MmHBM527T8egbIvpUNPiuQ==,type:str] + lastmodified: "2024-07-08T13:25:35Z" + mac: ENC[AES256_GCM,data:JUYECqv5+wtAhDWr+2pNSh/EXhh/gjjUFCjC6oH+3cXpZHacg23S/D5ol6nIXKH1+XUFaIX10YQOC0WaciZUcfgCP4t01MJRB3OE1iYcGllyeP+9gEIKfoeEajHVQdYWZHUql7T4EnQWs74uHiF7nt6jALnp98Wc4Pny6xvvZds=,iv:gDr7O566etB9oYAJB1RIK1PQJIc1NVcIlhZISidVmlA=,tag:bQ1iC1Xi5A+VbBgunHt02w==,type:str] pgp: - created_at: "2024-07-08T12:27:24Z" enc: |-