From f89522362fd3f0e9487eebe32acafb0fc11d2504 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Fri, 1 Feb 2019 01:06:18 +0100 Subject: [PATCH] git: use `attrsOf` instead of `attrs` This makes sure that values added to programs.git.aliases or programs.git.extraConfig are merged as expected. Also add a few option examples. (cherry picked from commit 445c0b1482c38172a9f8294ee16a7ca7462388e5) --- modules/programs/git.nix | 16 +++++-- tests/modules/programs/git-expected.conf | 4 +- tests/modules/programs/git.nix | 60 ++++++++++++++---------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 4c962e99..001d02b2 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -6,6 +6,12 @@ let cfg = config.programs.git; + gitIniType = with types; + let + primitiveType = either bool (either int str); + in + attrsOf (attrsOf primitiveType); + signModule = types.submodule { options = { key = mkOption { @@ -80,8 +86,9 @@ in }; aliases = mkOption { - type = types.attrs; + type = types.attrsOf types.str; default = {}; + example = { co = "checkout"; }; description = "Git aliases to define."; }; @@ -92,13 +99,16 @@ in }; extraConfig = mkOption { - type = types.either types.attrs types.lines; + type = types.either types.lines gitIniType; default = {}; + example = { + core = { whitespace = "trailing-space,space-before-tab"; }; + }; description = "Additional configuration to add."; }; iniContent = mkOption { - type = types.attrsOf types.attrs; + type = gitIniType; internal = true; }; diff --git a/tests/modules/programs/git-expected.conf b/tests/modules/programs/git-expected.conf index d2c48f76..2b0f3caf 100644 --- a/tests/modules/programs/git-expected.conf +++ b/tests/modules/programs/git-expected.conf @@ -1,11 +1,13 @@ [alias] a1=foo -a2=bar +a2=baz [commit] gpgSign=true [extra] +boolean=true +integer=38 name=value [gpg] diff --git a/tests/modules/programs/git.nix b/tests/modules/programs/git.nix index 29f3d17e..f642bede 100644 --- a/tests/modules/programs/git.nix +++ b/tests/modules/programs/git.nix @@ -4,33 +4,41 @@ with lib; { config = { - programs.git = { - enable = true; - aliases = { - a1 = "foo"; - a2 = "bar"; - }; - extraConfig = { - extra = { - name = "value"; + programs.git = mkMerge [ + { + enable = true; + aliases = { + a1 = "foo"; + a2 = "bar"; }; - }; - ignores = [ "*~" "*.swp" ]; - includes = [ - { path = "~/path/to/config.inc"; } - { - path = "~/path/to/conditional.inc"; - condition = "gitdir:~/src/dir"; - } - ]; - signing = { - gpgPath = "path-to-gpg"; - key = "00112233445566778899AABBCCDDEEFF"; - signByDefault = true; - }; - userEmail = "user@example.org"; - userName = "John Doe"; - }; + extraConfig = { + extra = { + name = "value"; + }; + }; + ignores = [ "*~" "*.swp" ]; + includes = [ + { path = "~/path/to/config.inc"; } + { + path = "~/path/to/conditional.inc"; + condition = "gitdir:~/src/dir"; + } + ]; + signing = { + gpgPath = "path-to-gpg"; + key = "00112233445566778899AABBCCDDEEFF"; + signByDefault = true; + }; + userEmail = "user@example.org"; + userName = "John Doe"; + } + + { + aliases.a2 = mkForce "baz"; + extraConfig.extra.boolean = true; + extraConfig.extra.integer = 38; + } + ]; nmt.script = '' assertFileExists home-files/.config/git/config