fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge branch 'literalExpression' [#2371]4fa1ba72

master
2.5 KiB103 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.mercurial;
8
9  iniFormat = pkgs.formats.ini { };
10
11in {
12
13  options = {
14    programs.mercurial = {
15      enable = mkEnableOption "Mercurial";
16
17      package = mkOption {
18        type = types.package;
19        default = pkgs.mercurial;
20        defaultText = literalExpression "pkgs.mercurial";
21        description = "Mercurial package to install.";
22      };
23
24      userName = mkOption {
25        type = types.str;
26        description = "Default user name to use.";
27      };
28
29      userEmail = mkOption {
30        type = types.str;
31        description = "Default user email to use.";
32      };
33
34      aliases = mkOption {
35        type = types.attrsOf types.anything;
36        default = { };
37        description = "Mercurial aliases to define.";
38      };
39
40      extraConfig = mkOption {
41        type = types.either (types.attrsOf types.anything) types.lines;
42        default = { };
43        description = "Additional configuration to add.";
44      };
45
46      iniContent = mkOption {
47        type = iniFormat.type;
48        internal = true;
49      };
50
51      ignores = mkOption {
52        type = types.listOf types.str;
53        default = [ ];
54        example = [ "*~" "*.swp" ];
55        description = "List of globs for files to be globally ignored.";
56      };
57
58      ignoresRegexp = mkOption {
59        type = types.listOf types.str;
60        default = [ ];
61        example = [ "^.*~$" "^.*\\.swp$" ];
62        description =
63          "List of regular expressions for files to be globally ignored.";
64      };
65    };
66  };
67
68  config = mkIf cfg.enable (mkMerge [
69    {
70      home.packages = [ cfg.package ];
71
72      programs.mercurial.iniContent.ui = {
73        username = cfg.userName + " <" + cfg.userEmail + ">";
74      };
75
76      xdg.configFile."hg/hgrc".source =
77        iniFormat.generate "hgrc" cfg.iniContent;
78    }
79
80    (mkIf (cfg.ignores != [ ] || cfg.ignoresRegexp != [ ]) {
81      programs.mercurial.iniContent.ui.ignore =
82        "${config.xdg.configHome}/hg/hgignore_global";
83
84      xdg.configFile."hg/hgignore_global".text = ''
85        syntax: glob
86      '' + concatStringsSep "\n" cfg.ignores + "\n" + ''
87        syntax: regexp
88      '' + concatStringsSep "\n" cfg.ignoresRegexp + "\n";
89    })
90
91    (mkIf (cfg.aliases != { }) {
92      programs.mercurial.iniContent.alias = cfg.aliases;
93    })
94
95    (mkIf (lib.isAttrs cfg.extraConfig) {
96      programs.mercurial.iniContent = cfg.extraConfig;
97    })
98
99    (mkIf (lib.isString cfg.extraConfig) {
100      xdg.configFile."hg/hgrc".text = cfg.extraConfig;
101    })
102  ]);
103}