git: replace gitToInit with lib function

Remove the function gitToInit and underlying functions in favor of using
the function lib.generators.toGitINI from nixpkgs.
This commit is contained in:
VwCSXg 2023-08-21 09:35:43 +02:00 committed by Robert Helgesson
parent f092a92202
commit feb7006159
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -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 {