From 0f096f9ad40f2fb055f4b696f16450d7487cd895 Mon Sep 17 00:00:00 2001 From: Nikita Uvarov Date: Thu, 21 Sep 2017 14:45:20 +0200 Subject: [PATCH] git: change extraConfig from lines to attrs --- modules/misc/news.nix | 28 +++++++++++++++++++++ modules/programs/git.nix | 53 ++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 17747fb7..eef664b6 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -192,6 +192,34 @@ in A new service is available: 'services.screen-locker'. ''; } + + { + time = "2017-09-22T12:09:01+00:00"; + condition = isString config.programs.git.extraConfig; + message = '' + The 'programs.git.extraConfig' parameter now accepts + attributes instead of strings which allows more flexible + configuration. + + The string parameter type will be deprecated in the future, + please change your configuration file accordingly. + + For example, if your configuration includes + + programs.git.extraConfig = ''' + [core] + editor = vim + '''; + + then you can now change it to + + programs.git.extraConfig = { + core = { + editor = "vim"; + }; + }; + ''; + } ]; }; } diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 28d1168d..1616dcb4 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -65,34 +65,51 @@ in }; extraConfig = mkOption { - type = types.lines; - default = ""; + type = types.either types.attrs types.lines; + default = {}; description = "Additional configuration to add."; }; + + iniContent = mkOption { + type = types.attrsOf types.attrs; + internal = true; + }; }; }; config = mkIf cfg.enable ( - let - ini = { - user = { - name = cfg.userName; - email = cfg.userEmail; - } // optionalAttrs (cfg.signing != null) { - signingKey = cfg.signing.key; - }; - } // optionalAttrs (cfg.signing != null) { - commit.gpgSign = cfg.signing.signByDefault; - gpg.program = cfg.signing.gpgPath; - } // optionalAttrs (cfg.aliases != {}) { - alias = cfg.aliases; - }; - in + mkMerge [ { home.packages = [ cfg.package ]; + programs.git.iniContent.user = { + name = cfg.userName; + email = cfg.userEmail; + }; + home.file.".gitconfig".text = - generators.toINI {} ini + "\n" + cfg.extraConfig; + generators.toINI {} cfg.iniContent; } + + (mkIf (cfg.signing != null) { + programs.git.iniContent = { + user.signingKey = cfg.signing.key; + commit.gpgSign = cfg.signing.signByDefault; + gpg.program = cfg.signing.gpgPath; + }; + }) + + (mkIf (cfg.aliases != {}) { + programs.git.iniContent.alias = cfg.aliases; + }) + + (mkIf (lib.isAttrs cfg.extraConfig) { + programs.git.iniContent = cfg.extraConfig; + }) + + (mkIf (lib.isString cfg.extraConfig) { + home.file.".gitconfig".text = cfg.extraConfig; + }) + ] ); }