lol

Merge pull request #207063 from figsoda/gitconfig

nixos/git: allow lists for config to keep things in order

authored by

figsoda and committed by
GitHub
522bf206 d23edec3

+32 -6
+32 -6
nixos/modules/programs/git.nix
··· 20 20 }; 21 21 22 22 config = mkOption { 23 - type = with types; attrsOf (attrsOf anything); 24 - default = { }; 23 + type = 24 + with types; 25 + let 26 + gitini = attrsOf (attrsOf anything); 27 + in 28 + either gitini (listOf gitini) // { 29 + merge = loc: defs: 30 + let 31 + config = foldl' 32 + (acc: { value, ... }@x: acc // (if isList value then { 33 + ordered = acc.ordered ++ value; 34 + } else { 35 + unordered = acc.unordered ++ [ x ]; 36 + })) 37 + { 38 + ordered = [ ]; 39 + unordered = [ ]; 40 + } 41 + defs; 42 + in 43 + [ (gitini.merge loc config.unordered) ] ++ config.ordered; 44 + }; 45 + default = [ ]; 25 46 example = { 26 47 init.defaultBranch = "main"; 27 48 url."https://github.com/".insteadOf = [ "gh:" "github:" ]; 28 49 }; 29 50 description = lib.mdDoc '' 30 - Configuration to write to /etc/gitconfig. See the CONFIGURATION FILE 31 - section of git-config(1) for more information. 51 + Configuration to write to /etc/gitconfig. A list can also be 52 + specified to keep the configuration in order. For example, setting 53 + `config` to `[ { foo.x = 42; } { bar.y = 42; }]` will put the `foo` 54 + section before the `bar` section unlike the default alphabetical 55 + order, which can be helpful for sections such as `include` and 56 + `includeIf`. See the CONFIGURATION FILE section of git-config(1) for 57 + more information. 32 58 ''; 33 59 }; 34 60 ··· 48 74 config = mkMerge [ 49 75 (mkIf cfg.enable { 50 76 environment.systemPackages = [ cfg.package ]; 51 - environment.etc.gitconfig = mkIf (cfg.config != {}) { 52 - text = generators.toGitINI cfg.config; 77 + environment.etc.gitconfig = mkIf (cfg.config != [ ]) { 78 + text = concatMapStringsSep "\n" generators.toGitINI cfg.config; 53 79 }; 54 80 }) 55 81 (mkIf (cfg.enable && cfg.lfs.enable) {