/
sapling.nix
83 lines (65 loc) · 1.95 KB
/
sapling.nix
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
83
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.sapling;
iniFormat = pkgs.formats.ini { };
in {
meta.maintainers = [ maintainers.pbar ];
options = {
programs.sapling = {
enable = mkEnableOption "Sapling";
package = mkPackageOption pkgs "sapling" { };
userName = mkOption {
type = types.str;
description = "Default user name to use.";
};
userEmail = mkOption {
type = types.str;
description = "Default user email to use.";
};
aliases = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Sapling aliases to define.";
};
extraConfig = mkOption {
type = types.attrsOf types.anything;
default = { };
description = "Additional configuration to add.";
};
iniContent = mkOption {
type = iniFormat.type;
internal = true;
};
};
};
config = mkIf cfg.enable (mkMerge [
{
home.packages = [ cfg.package ];
programs.sapling.iniContent.ui = {
username = cfg.userName + " <" + cfg.userEmail + ">";
};
}
(mkIf (!pkgs.stdenv.isDarwin) {
xdg.configFile."sapling/sapling.conf".source =
iniFormat.generate "sapling.conf" cfg.iniContent;
})
(mkIf (pkgs.stdenv.isDarwin) {
home.file."Library/Preferences/sapling/sapling.conf".source =
iniFormat.generate "sapling.conf" cfg.iniContent;
})
(mkIf (cfg.aliases != { }) {
programs.sapling.iniContent.alias = cfg.aliases;
})
(mkIf (lib.isAttrs cfg.extraConfig) {
programs.sapling.iniContent = cfg.extraConfig;
})
(mkIf (lib.isString cfg.extraConfig && !pkgs.stdenv.isDarwin) {
xdg.configFile."sapling/sapling.conf".text = cfg.extraConfig;
})
(mkIf (lib.isString cfg.extraConfig && pkgs.stdenv.isDarwin) {
home.file."Library/Preferences/sapling/sapling.conf".text =
cfg.extraConfig;
})
]);
}