blob: b4c1d9a4a7e7f24fa2570f9d5e091e1b8060c2fb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
{ config, lib, pkgs, ... }:
let
inherit (lib) types;
cfg = config.vuizvui.user.aszlig.programs.git;
gitPatched = pkgs.gitFull.overrideAttrs (git: {
makeFlags = let
oldFlags = git.makeFlags or [];
newVal = "ETC_GITCONFIG=${cfg.configFile}";
in if lib.isList oldFlags
then oldFlags ++ [ newVal ]
else "${oldFlags} ${newVal}";
});
in {
options.vuizvui.user.aszlig.programs.git = {
enable = lib.mkEnableOption "Git";
configFile = lib.mkOption {
type = types.path;
readOnly = true;
description = ''
The path to the system-wide configuration file.
'';
};
settings = lib.mkOption {
type = let
scalar = types.oneOf [ types.bool types.int types.str ];
section = types.either (types.attrsOf scalar) scalar;
in types.attrsOf (types.attrsOf section);
default = {};
example = {
color.ui = "auto";
merge.tool = "vimdiff";
guitool.foobar.noconsole = true;
};
description = ''
System-wide Git options as described in <citerefentry>
<refentrytitle>git-config</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>.
'';
};
};
config = lib.mkIf cfg.enable {
vuizvui.user.aszlig.programs.git.configFile = let
escStr = s: "\"${lib.escape [ "\"" "\\" ] s}\"";
mkVal = v: if lib.isBool v && v then "true"
else if lib.isBool v && !v then "false"
else escStr (toString v);
mkLine = key: val: "${key} = ${mkVal val}";
joinLines = lib.concatStringsSep "\n";
filterNull = lib.filterAttrs (lib.const (v: !(isNull v)));
mkSection = sect: subsect: vals: ''
[${sect}${lib.optionalString (subsect != null) " ${escStr subsect}"}]
${joinLines (lib.mapAttrsToList mkLine (filterNull vals))}
'';
mkConf = sect: content: let
subs = lib.filterAttrs (lib.const lib.isAttrs) content;
nonSubs = lib.filterAttrs (lib.const (s: !lib.isAttrs s)) content;
maybePlain = lib.optional (nonSubs != {});
plainSects = lib.singleton (mkSection sect null nonSubs);
in lib.mapAttrsToList (mkSection sect) subs ++ maybePlain plainSects;
lines = lib.flatten (lib.mapAttrsToList mkConf cfg.settings);
in pkgs.writeText "gitconfig" (joinLines lines);
environment.systemPackages = [
gitPatched
pkgs.gitAndTools.git-remote-hg
pkgs.gitAndTools.hub
];
};
}
|