nixpkgs/pkgs/applications/editors/emacs-modes/libgenerated.nix
Servilio Afre Puentes b2c8626d61 emacs-modes: build MELPA package sets without null packages
The current algorithm creates attributes with null values for packages
with no source in a variant of MELPA. Though will satify dependencies
they produce no files, and though a build that transitively depends on
one them will be successful, Emacs won't find them and any code
depending on them won't work.

The solution with minimal code change would have been filtering the
list of results from melpaDerivation by comparing the value against
null, but that leads to an infinite recursion.

This commit also moves legacy renames from the shared to the unstable
set, as the corresponding null value elements won't exist in the
stable set anymore.

The test used for the problem was:

  $ nix-build --show-trace ./default.nix -A emacs26Packages.melpaStablePackages.findr
  error: expression does not evaluate to a derivation (or a set or list of those)

The expected output, obtained with this commit is:

  $ nix-build --show-trace ./default.nix -A emacs26Packages.melpaStablePackages.findr
  error: attribute 'findr' in selection path 'emacs26Packages.melpaStablePackages.findr' not found
2020-03-26 16:32:11 -04:00

94 lines
2.8 KiB
Nix

lib: self:
let
fetcherGenerators = { repo ? null
, url ? null
, ... }:
{ sha256
, commit
, ...}: {
github = self.callPackage ({ fetchFromGitHub }:
fetchFromGitHub {
owner = lib.head (lib.splitString "/" repo);
repo = lib.head (lib.tail (lib.splitString "/" repo));
rev = commit;
inherit sha256;
}
) {};
gitlab = self.callPackage ({ fetchFromGitLab }:
fetchFromGitLab {
owner = lib.head (lib.splitString "/" repo);
repo = lib.head (lib.tail (lib.splitString "/" repo));
rev = commit;
inherit sha256;
}
) {};
git = self.callPackage ({ fetchgit }:
fetchgit {
rev = commit;
inherit sha256 url;
}
) {};
bitbucket = self.callPackage ({ fetchhg }:
fetchhg {
rev = commit;
url = "https://bitbucket.com/${repo}";
inherit sha256;
}
) {};
hg = self.callPackage ({ fetchhg }:
fetchhg {
rev = commit;
inherit sha256 url;
}
) {};
};
in {
melpaDerivation = variant:
{ ename, fetcher
, commit ? null
, sha256 ? null
, ... }@args:
let
sourceArgs = args.${variant};
version = sourceArgs.version or null;
deps = sourceArgs.deps or null;
error = sourceArgs.error or args.error or null;
hasSource = lib.hasAttr variant args;
pname = builtins.replaceStrings [ "@" ] [ "at" ] ename;
broken = ! isNull error;
in
if hasSource then
lib.nameValuePair ename (
self.callPackage ({ melpaBuild, fetchurl, ... }@pkgargs:
melpaBuild {
inherit pname;
ename = ename;
version = if isNull version then "" else
lib.concatStringsSep "." (map toString version);
# TODO: Broken should not result in src being null (hack to avoid eval errors)
src = if (isNull sha256 || broken) then null else
lib.getAttr fetcher (fetcherGenerators args sourceArgs);
recipe = if isNull commit then null else
fetchurl {
name = pname + "-recipe";
url = "https://raw.githubusercontent.com/melpa/melpa/${commit}/recipes/${ename}";
inherit sha256;
};
packageRequires = lib.optionals (! isNull deps)
(map (dep: pkgargs.${dep} or self.${dep} or null)
deps);
meta = (sourceArgs.meta or {}) // {
inherit broken;
};
}
) {}
)
else
null;
}