From 50db96001e026178d4db8f6d186ed02090ed2424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Sun, 2 Nov 2025 16:43:48 +0800 Subject: [PATCH] tree-wide: deduplicate git identity --- nix/configurations/hydrogen/home/dev.nix | 62 --------------------- nix/configurations/vanadium/home/dev.nix | 71 ++---------------------- nix/git-identities/git-compat.nix | 14 +++++ nix/git-identities/list.nix | 53 ++++++++++++++++++ 4 files changed, 73 insertions(+), 127 deletions(-) create mode 100644 nix/git-identities/git-compat.nix create mode 100644 nix/git-identities/list.nix diff --git a/nix/configurations/hydrogen/home/dev.nix b/nix/configurations/hydrogen/home/dev.nix index d10f4926..93d1e440 100644 --- a/nix/configurations/hydrogen/home/dev.nix +++ b/nix/configurations/hydrogen/home/dev.nix @@ -7,68 +7,6 @@ programs.git = { enable = true; signing.signByDefault = false; # no need to setup the key - includes = let - hasconfigRemoteCondition = cfg: let - cfg' = builtins.removeAttrs cfg ["url" "path"]; - path = cfg.path or "*/**"; - in [ - (cfg' // {condition = "hasconfig:remote.*.url:git@${cfg.url}:${path}";}) - (cfg' // {condition = "hasconfig:remote.*.url:https://${cfg.url}/${path}";}) - ]; - - haskellIdentity = { - init.defaultBranch = "main"; - user.name = "Léana Jiang"; - }; - - universityIdentity = { - init.defaultBranch = "main"; - user = { - name = "Léana CHIANG"; - email = "leana.chiang@etudiant.univ-rennes1.fr"; - signingKey = "0x32035DB97E777EEB"; - }; - }; - - blameIgnore = { - blame.ignoreRevsFile = ".git-blame-ignore-revs"; - }; - in - builtins.concatMap hasconfigRemoteCondition [ - # Univ stuff - { - url = "gitlab.istic.univ-rennes1.fr"; - contents = universityIdentity; - } - { - url = "gitlab2.istic.univ-rennes1.fr"; - contents = universityIdentity; - } - - # Haskell - { - url = "gitlab.haskell.org"; - contents = haskellIdentity; - } - - # Blame - # Turning this on globally will fail if the file doesn't exist - { - url = "github.com"; - path = "nixos/nixpkgs.git"; - contents = blameIgnore; - } - { - url = "gitlab.haskell.org"; - path = "ghc/ghc.git"; - contents = blameIgnore; - } - { - url = "github.com"; - path = "haskell/cabal.git"; - contents = blameIgnore; - } - ]; }; programs.gpg.enable = true; diff --git a/nix/configurations/vanadium/home/dev.nix b/nix/configurations/vanadium/home/dev.nix index 5d3b2068..8fbe473b 100644 --- a/nix/configurations/vanadium/home/dev.nix +++ b/nix/configurations/vanadium/home/dev.nix @@ -35,74 +35,15 @@ signing.signByDefault = true; maintenance = { enable = true; - repositories = - lib.map (path: config.home.homeDirectory + "/${path}") - [ - "r/nixos/nixpkgs" - ]; + repositories = lib.map (path: config.home.homeDirectory + "/${path}") [ + "r/nixos/nixpkgs" + ]; }; includes = let - hasconfigRemoteCondition = cfg: let - cfg' = builtins.removeAttrs cfg ["url" "path"]; - path = cfg.path or "*/**"; - in [ - (cfg' // {condition = "hasconfig:remote.*.url:git@${cfg.url}:${path}";}) - (cfg' // {condition = "hasconfig:remote.*.url:https://${cfg.url}/${path}";}) - ]; - - haskellIdentity = { - init.defaultBranch = "main"; - user.name = "Léana Jiang"; - }; - - universityIdentity = { - init.defaultBranch = "main"; - user = { - name = "Léana CHIANG"; - email = "leana.chiang@etudiant.univ-rennes1.fr"; - signingKey = "0x32035DB97E777EEB"; - }; - }; - - blameIgnore = { - blame.ignoreRevsFile = ".git-blame-ignore-revs"; - }; + fromList = import ../../../git-identities/git-compat.nix; + identities = import ../../../git-identities/list.nix; in - builtins.concatMap hasconfigRemoteCondition [ - # Univ stuff - { - url = "gitlab.istic.univ-rennes1.fr"; - contents = universityIdentity; - } - { - url = "gitlab2.istic.univ-rennes1.fr"; - contents = universityIdentity; - } - - # Haskell - { - url = "gitlab.haskell.org"; - contents = haskellIdentity; - } - - # Blame - # Turning this on globally will fail if the file doesn't exist - { - url = "github.com"; - path = "nixos/nixpkgs.git"; - contents = blameIgnore; - } - { - url = "gitlab.haskell.org"; - path = "ghc/ghc.git"; - contents = blameIgnore; - } - { - url = "github.com"; - path = "haskell/cabal.git"; - contents = blameIgnore; - } - ]; + fromList identities; }; programs.gpg.enable = true; diff --git a/nix/git-identities/git-compat.nix b/nix/git-identities/git-compat.nix new file mode 100644 index 00000000..28bc74a6 --- /dev/null +++ b/nix/git-identities/git-compat.nix @@ -0,0 +1,14 @@ +let + hasconfigRemoteCondition = { + # Custom arguments + url, + path ? "*/**", + ... + } @ cfg: let + cfg' = builtins.removeAttrs cfg ["url" "path"]; + in [ + (cfg' // {condition = "hasconfig:remote.*.url:git@${url}:${path}";}) + (cfg' // {condition = "hasconfig:remote.*.url:https://${url}/${path}";}) + ]; +in + builtins.concatMap hasconfigRemoteCondition diff --git a/nix/git-identities/list.nix b/nix/git-identities/list.nix new file mode 100644 index 00000000..9568c0c1 --- /dev/null +++ b/nix/git-identities/list.nix @@ -0,0 +1,53 @@ +let + haskellIdentity = { + init.defaultBranch = "main"; + user.name = "Léana Jiang"; + }; + + universityIdentity = { + init.defaultBranch = "main"; + user = { + name = "Léana CHIANG"; + email = "leana.chiang@etudiant.univ-rennes1.fr"; + signingKey = "0x32035DB97E777EEB"; + }; + }; + + blameIgnore = { + blame.ignoreRevsFile = ".git-blame-ignore-revs"; + }; +in [ + # Univ stuff + { + url = "gitlab.istic.univ-rennes1.fr"; + contents = universityIdentity; + } + { + url = "gitlab2.istic.univ-rennes1.fr"; + contents = universityIdentity; + } + + # Haskell + { + url = "gitlab.haskell.org"; + contents = haskellIdentity; + } + + # Blame + # Turning this on globally will fail if the file doesn't exist + { + url = "github.com"; + path = "nixos/nixpkgs.git"; + contents = blameIgnore; + } + { + url = "gitlab.haskell.org"; + path = "ghc/ghc.git"; + contents = blameIgnore; + } + { + url = "github.com"; + path = "haskell/cabal.git"; + contents = blameIgnore; + } +]