-
Notifications
You must be signed in to change notification settings - Fork 2
/
lake.nix
46 lines (46 loc) · 1.3 KB
/
lake.nix
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
{pkgs}: let
capitalize = s: let
first = pkgs.lib.toUpper (builtins.substring 0 1 s);
rest = builtins.substring 1 (-1) s;
in
first + rest;
importLakeManifest = manifestFile: let
manifest = pkgs.lib.importJSON manifestFile;
in
pkgs.lib.warnIf (manifest.version != "1.1.0") ("Unknown version: " + manifest.version) manifest;
depToPackage = dep: let
src = pkgs.lib.cleanSource (builtins.fetchGit {
inherit (dep) url rev;
shallow = true;
});
in {
inherit src;
manifestFile = "${src}/${dep.manifestFile}";
};
# Builds a Lean package by reading the manifest file.
mkPackage = {
# Path to the source
src,
# Path to the `lake-manifest.json` file
manifestFile ? "${src}/lake-manifest.json",
# Root module
roots ? null,
# Default dependencies
deps ? with pkgs.lean; [Init Std Lean],
}: let
manifest = importLakeManifest manifestFile;
# Build all dependencies using `buildLeanPackage`
manifestDeps = builtins.map (dep: mkPackage (depToPackage dep)) manifest.packages;
in
pkgs.lean.buildLeanPackage {
inherit (manifest) name;
inherit src;
roots =
if builtins.isNull roots
then [(capitalize manifest.name)]
else roots;
deps = deps ++ manifestDeps;
};
in {
inherit mkPackage;
}