From 616dbd67f7a903d2a57ef4b8d0d9bcc4f567eab3 Mon Sep 17 00:00:00 2001 From: Alistair Potts Date: Thu, 1 Feb 2018 13:33:24 +0000 Subject: [PATCH] mercurial: add module Very simple module for hg based on programs.git, and is intended to have compatible options. For simple setups, a user should be able to write something like: {...}: let vcsconfig = { enable = true; userName = "John Smith"; userEmail = "js@example.com"; ignores = [ "*.swp" "*~" ]; }; in { programs.git = vcsconfig // {...extra git config...}; programs.mercurial = vcsconfig // {...extra hg confg...}; } For this reason, the ignore options are `ignores` for `syntax: glob` and `ignoresRegexp` for `syntax: regexp` so that simple glob ignores can (very likely) be shared with a git config, despite regular expressions being the default for mercurial. --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/mercurial.nix | 102 +++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 modules/programs/mercurial.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 202ab915e..1dab10ae4 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -543,6 +543,13 @@ in The old module will be removed on February 25, 2018. ''; } + + { + time = "2018-02-02T11:15:00+00:00"; + message = '' + A new program configuration is available: 'programs.mercurial' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 7fd76147b..8c000d2f6 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -34,6 +34,7 @@ let ./programs/info.nix ./programs/lesspipe.nix ./programs/man.nix + ./programs/mercurial.nix ./programs/neovim.nix ./programs/rofi.nix ./programs/ssh.nix diff --git a/modules/programs/mercurial.nix b/modules/programs/mercurial.nix new file mode 100644 index 000000000..5daee39f1 --- /dev/null +++ b/modules/programs/mercurial.nix @@ -0,0 +1,102 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.mercurial; + +in + +{ + + options = { + programs.mercurial = { + enable = mkEnableOption "Mercurial"; + + package = mkOption { + type = types.package; + default = pkgs.mercurial; + defaultText = "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; + default = {}; + description = "Mercurial aliases to define."; + }; + + extraConfig = mkOption { + type = types.either types.attrs types.lines; + default = {}; + description = "Additional configuration to add."; + }; + + iniContent = mkOption { + type = types.attrsOf types.attrs; + internal = true; + }; + + ignores = mkOption { + type = types.listOf types.str; + default = []; + example = [ "*~" "*.swp" ]; + description = "List of globs for files to be globally ignored."; + }; + + ignoresRegexp = mkOption { + type = types.listOf types.str; + default = []; + example = [ "^.*~$" "^.*\\.swp$" ]; + description = + "List of regular expressions for files to be globally ignored."; + }; + }; + }; + + config = mkIf cfg.enable ( + mkMerge [ + { + home.packages = [ cfg.package ]; + + programs.mercurial.iniContent.ui = { + username = cfg.userName + " <" + cfg.userEmail + ">"; + }; + + xdg.configFile."hg/hgrc".text = generators.toINI {} cfg.iniContent; + } + + (mkIf (cfg.ignores != [] || cfg.ignoresRegexp != []) { + programs.mercurial.iniContent.ui.ignore = + "${config.xdg.configHome}/hg/hgignore_global"; + + xdg.configFile."hg/hgignore_global".text = + "syntax: glob\n" + concatStringsSep "\n" cfg.ignores + "\n" + + "syntax: regexp\n" + concatStringsSep "\n" cfg.ignoresRegexp + "\n"; + }) + + (mkIf (cfg.aliases != {}) { + programs.mercurial.iniContent.alias = cfg.aliases; + }) + + (mkIf (lib.isAttrs cfg.extraConfig) { + programs.mercurial.iniContent = cfg.extraConfig; + }) + + (mkIf (lib.isString cfg.extraConfig) { + xdg.configFile."hg/hgrc".text = cfg.extraConfig; + }) + ] + ); +}