summary refs log tree commit diff
path: root/pkgs/applications/editors/emacs/elisp-packages/libgenerated.nix
blob: 1b131750c69c96f05a4eada3cf4990dde47bfd84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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;
        }).overrideAttrs(_: {
          GIT_SSL_NO_VERIFY = true;
        })
      ) {};
      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 commit;
            version = if isNull version then "" else
              lib.concatStringsSep "." (map toString
                # Hack: Melpa archives contains versions with parse errors such as [ 4 4 -4 413 ] which should be 4.4-413
                # This filter method is still technically wrong, but it's computationally cheap enough and tapers over the issue
                (builtins.filter (n: n >= 0) 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;

}