From 472d7731d64d8db89ea8bbbe5fbf6194fd6a1af8 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Tue, 12 Mar 2019 01:35:55 -0700 Subject: [PATCH] git: support multiple values Closes #614 --- modules/programs/git.nix | 19 +++++++++++++++---- tests/modules/programs/git-expected.conf | 2 ++ tests/modules/programs/git.nix | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index a71169ce..2ab84b5a 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -6,11 +6,22 @@ let cfg = config.programs.git; + # generation for multiple ini values + mkKeyValue = k: v: + let + mkKeyValue = generators.mkKeyValueDefault {} "=" k; + in + concatStringsSep "\n" (map mkKeyValue (toList v)); + + gitToIni = generators.toINI { inherit mkKeyValue; }; + gitIniType = with types; let - primitiveType = either bool (either int str); + primitiveType = either str (either bool int); + multipleType = either primitiveType (listOf primitiveType); + sectionType = attrsOf multipleType; in - attrsOf (attrsOf primitiveType); + attrsOf sectionType; signModule = types.submodule { options = { @@ -64,7 +75,7 @@ let }; config.path = mkIf (config.contents != {}) ( - mkDefault (pkgs.writeText "contents" (generators.toINI {} config.contents)) + mkDefault (pkgs.writeText "contents" (gitToIni config.contents)) ); }); @@ -175,7 +186,7 @@ in }; xdg.configFile = { - "git/config".text = generators.toINI {} cfg.iniContent; + "git/config".text = gitToIni cfg.iniContent; "git/ignore" = mkIf (cfg.ignores != []) { text = concatStringsSep "\n" cfg.ignores + "\n"; diff --git a/tests/modules/programs/git-expected.conf b/tests/modules/programs/git-expected.conf index e6d23d11..ba4a362e 100644 --- a/tests/modules/programs/git-expected.conf +++ b/tests/modules/programs/git-expected.conf @@ -8,6 +8,8 @@ gpgSign=true [extra] boolean=true integer=38 +multiple=1 +multiple=2 name=value [filter "lfs"] diff --git a/tests/modules/programs/git.nix b/tests/modules/programs/git.nix index 71573c38..771c909a 100644 --- a/tests/modules/programs/git.nix +++ b/tests/modules/programs/git.nix @@ -31,6 +31,7 @@ in extraConfig = { extra = { name = "value"; + multiple = [1]; }; }; ignores = [ "*~" "*.swp" ]; @@ -59,6 +60,7 @@ in aliases.a2 = mkForce "baz"; extraConfig.extra.boolean = true; extraConfig.extra.integer = 38; + extraConfig.extra.multiple = [2]; } ];