1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 10:49:48 +01:00

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; 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; gitIniType = with types;
let let
primitiveType = either str (either bool int); primitiveType = either str (either bool int);
@ -137,7 +93,7 @@ let
}; };
config.path = mkIf (config.contents != { }) (mkDefault config.path = mkIf (config.contents != { }) (mkDefault
(pkgs.writeText (hm.strings.storeFileName config.contentSuffix) (pkgs.writeText (hm.strings.storeFileName config.contentSuffix)
(gitToIni config.contents))); (generators.toGitINI config.contents)));
}); });
in { in {
@ -415,7 +371,7 @@ in {
}; };
xdg.configFile = { xdg.configFile = {
"git/config".text = gitToIni cfg.iniContent; "git/config".text = generators.toGitINI cfg.iniContent;
"git/ignore" = mkIf (cfg.ignores != [ ]) { "git/ignore" = mkIf (cfg.ignores != [ ]) {
text = concatStringsSep "\n" cfg.ignores + "\n"; text = concatStringsSep "\n" cfg.ignores + "\n";
@ -502,8 +458,8 @@ in {
} else { } else {
include.path = "${path}"; include.path = "${path}";
}; };
in mkAfter in mkAfter (concatStringsSep "\n"
(concatStringsSep "\n" (map gitToIni (map include cfg.includes))); (map generators.toGitINI (map include cfg.includes)));
}) })
(mkIf cfg.lfs.enable { (mkIf cfg.lfs.enable {