Installing mercurial extensions

The official Nix package for mercurial describes the process of adding extensions is to use the provided withExtensions as shown here: https://github.com/NixOS/nixpkgs/blob/c55537aa04e2d5b8de4614b79782d3e5430c3ea7/pkgs/applications/version-management/mercurial/default.nix#L170

In my configuration.nix file I’ve added mercurial using the format specified:

let
  mercurial_e = pkgs.mercurial.withExtensions (pm: [ pm.hg-evolve ]);
in
{
  ...
  environment.systemPackages = with pkgs; [
    mercurial_e
  ];
  ...
}

This installs fine, but it still fails to import the extension.

❯ hg
*** failed to import extension "evolve": No module named 'evolve'
*** failed to import extension "topic": No module named 'topic'

Following symlinks and inspecting the Python interpreter used by the installation shows that the hg-evolve module isn’t installed. I’ve tried forgoing withExtensions and adding it manually:

let
  mercurial_e = pkgs.mercurial.overridePythonAttrs (oldAttrs: rec {
    buildInputs = oldAttrs.buildInputs or [] ++ [ pkgs.python3Packages.hg-evolve ];
  });

but unfortunately the outcome is the same.

My question: how can I install the hg-evolve extension into the provided mercurial package, which should be as simple as making the hg-evolve Python package available during runtime?

Note that the extensions are loaded by adding

[extensions]
evolve=
topic=

into one’s hgrc file.

Hmm, that’s odd.

Does

nix-shell --pure -p 'let nixpkgs = (import <nixpkgs> {}); in (nixpkgs.pkgs.mercurial.withExtensions (pm: [ pm.hg-evolve ]))'

yield a working hg that has the evolve extension loaded? It does for me:

[nix-shell:~]$ hg debugextensions
absorb
amend
evolve (6.5!)
git
histedit
purge
rebase
remotenames
strip
topic (6.5!)

[nix-shell:~]$ hg version
Mercurial Distributed SCM (version 6.5.2)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2023 Olivia Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1 Like

Starting the pure shell with that command works for me. It turned out that I was still using the default version of the package due to my home-manager configuration. Dumb mistake, thanks for the help! Wouldn’t have realized it otherwise.

1 Like