home-manager/modules/programs/mercurial.nix

101 lines
2.4 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.mercurial;
2020-02-01 23:39:17 +00:00
in {
options = {
programs.mercurial = {
enable = mkEnableOption "Mercurial";
package = mkOption {
type = types.package;
default = pkgs.mercurial;
defaultText = literalExample "pkgs.mercurial";
description = "Mercurial package to install.";
};
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.attrs;
2020-02-01 23:39:17 +00:00
default = { };
description = "Mercurial aliases to define.";
};
extraConfig = mkOption {
type = types.either types.attrs types.lines;
2020-02-01 23:39:17 +00:00
default = { };
description = "Additional configuration to add.";
};
iniContent = mkOption {
type = types.attrsOf types.attrs;
internal = true;
};
ignores = mkOption {
type = types.listOf types.str;
2020-02-01 23:39:17 +00:00
default = [ ];
example = [ "*~" "*.swp" ];
description = "List of globs for files to be globally ignored.";
};
ignoresRegexp = mkOption {
type = types.listOf types.str;
2020-02-01 23:39:17 +00:00
default = [ ];
example = [ "^.*~$" "^.*\\.swp$" ];
description =
2020-02-01 23:39:17 +00:00
"List of regular expressions for files to be globally ignored.";
};
};
};
2020-02-01 23:39:17 +00:00
config = mkIf cfg.enable (mkMerge [
{
home.packages = [ cfg.package ];
2020-02-01 23:39:17 +00:00
programs.mercurial.iniContent.ui = {
username = cfg.userName + " <" + cfg.userEmail + ">";
};
2020-02-01 23:39:17 +00:00
xdg.configFile."hg/hgrc".text = generators.toINI { } cfg.iniContent;
}
2020-02-01 23:39:17 +00:00
(mkIf (cfg.ignores != [ ] || cfg.ignoresRegexp != [ ]) {
programs.mercurial.iniContent.ui.ignore =
"${config.xdg.configHome}/hg/hgignore_global";
2020-02-01 23:39:17 +00:00
xdg.configFile."hg/hgignore_global".text = ''
syntax: glob
'' + concatStringsSep "\n" cfg.ignores + "\n" + ''
syntax: regexp
'' + concatStringsSep "\n" cfg.ignoresRegexp + "\n";
})
2020-02-01 23:39:17 +00:00
(mkIf (cfg.aliases != { }) {
programs.mercurial.iniContent.alias = cfg.aliases;
})
2020-02-01 23:39:17 +00:00
(mkIf (lib.isAttrs cfg.extraConfig) {
programs.mercurial.iniContent = cfg.extraConfig;
})
2020-02-01 23:39:17 +00:00
(mkIf (lib.isString cfg.extraConfig) {
xdg.configFile."hg/hgrc".text = cfg.extraConfig;
})
]);
}