{ stdenv
, fetchhg
, modules ? []
}:

let
  copyModule = name: "cp -rv $src/${name} $out/;";
  concat = a: b: a + b;
  head = ''
    source $stdenv/setup
    mkdir -p $out
  '';
in stdenv.mkDerivation {
  name = "prosody-modules";
  src = fetchhg {
    url = "http://hg.prosody.im/prosody-modules";
    sha256 = "0nsf1j2prc6ggajn7zz9h300msf6aajqqxhy396g7j834knj5fb2";
  };
  builder = builtins.toFile "builder.sh" (head + (builtins.foldl' concat "" (map copyModule modules)));
}