From feb70061596134d403e14cc5ef7b01ab114d1dbd Mon Sep 17 00:00:00 2001 From: VwCSXg Date: Mon, 21 Aug 2023 09:35:43 +0200 Subject: [PATCH] git: replace gitToInit with lib function Remove the function gitToInit and underlying functions in favor of using the function lib.generators.toGitINI from nixpkgs. --- modules/programs/git.nix | 52 ++++------------------------------------ 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index b9aca2db3..53728060a 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -6,50 +6,6 @@ let cfg = config.programs.git; - # create [section "subsection"] keys from "section.subsection" attrset names - mkSectionName = name: - let - containsQuote = strings.hasInfix ''"'' name; - sections = splitString "." name; - section = head sections; - subsections = tail sections; - subsection = concatStringsSep "." subsections; - in if containsQuote || subsections == [ ] then - name - else - ''${section} "${subsection}"''; - - mkValueString = v: - let - escapedV = '' - "${ - replaceStrings [ "\n" " " ''"'' "\\" ] [ "\\n" "\\t" ''\"'' "\\\\" ] v - }"''; - in generators.mkValueStringDefault { } (if isString v then escapedV else v); - - # generation for multiple ini values - mkKeyValue = k: v: - let - mkKeyValue = - generators.mkKeyValueDefault { inherit mkValueString; } " = " k; - in concatStringsSep "\n" (map (kv: " " + mkKeyValue kv) (toList v)); - - # converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI - gitFlattenAttrs = let - recurse = path: value: - if isAttrs value then - mapAttrsToList (name: value: recurse ([ name ] ++ path) value) value - else if length path > 1 then { - ${concatStringsSep "." (reverseList (tail path))}.${head path} = value; - } else { - ${head path} = value; - }; - in attrs: foldl recursiveUpdate { } (flatten (recurse [ ] attrs)); - - gitToIni = attrs: - let toIni = generators.toINI { inherit mkKeyValue mkSectionName; }; - in toIni (gitFlattenAttrs attrs); - gitIniType = with types; let primitiveType = either str (either bool int); @@ -137,7 +93,7 @@ let }; config.path = mkIf (config.contents != { }) (mkDefault (pkgs.writeText (hm.strings.storeFileName config.contentSuffix) - (gitToIni config.contents))); + (generators.toGitINI config.contents))); }); in { @@ -415,7 +371,7 @@ in { }; xdg.configFile = { - "git/config".text = gitToIni cfg.iniContent; + "git/config".text = generators.toGitINI cfg.iniContent; "git/ignore" = mkIf (cfg.ignores != [ ]) { text = concatStringsSep "\n" cfg.ignores + "\n"; @@ -502,8 +458,8 @@ in { } else { include.path = "${path}"; }; - in mkAfter - (concatStringsSep "\n" (map gitToIni (map include cfg.includes))); + in mkAfter (concatStringsSep "\n" + (map generators.toGitINI (map include cfg.includes))); }) (mkIf cfg.lfs.enable {