Skip to content

Commit 7e3555c

Browse files
author
Ryan Lahfa
committed
chore(docs/user): vendor various lean-nix code
As upstream is moving to a non-user-facing Nix library, we are vendoring some of the useful code such as `buildLeanPackage`. Signed-off-by: Ryan Lahfa <[email protected]>
1 parent 877a758 commit 7e3555c

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

docs/user/flake.nix

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
with inputs.lean.packages.${system}; with nixpkgs;
2222
let
2323
doc-src = ./.; # lib.sourceByRegex ../. ["doc.*" "tests(/lean(/beginEndAsMacro.lean)?)?"];
24+
leanLib = callPackage ./nix { };
2425
in {
2526
packages = rec {
2627
lean-mdbook = mdbook.overrideAttrs (drv: rec {
@@ -87,36 +88,8 @@
8788
aeneas-base =
8889
let
8990
manifest = builtins.fromJSON (builtins.readFile ./lake-manifest.json);
90-
fetchFromLakeManifest = { name, hash, ... }:
91-
let
92-
dep = lib.findFirst (pkg: pkg.name == name) null manifest.packages;
93-
in
94-
assert dep != null;
95-
assert dep.type == "git"; fetchGit {
96-
inherit (dep) url rev;
97-
narHash = hash;
98-
} // (if dep.inputRev != null then { ref = dep.inputRev; } else {});
99-
100-
# Inspired from Loogle scaffolding.
101-
# addFakeFile can plug into buildLeanPackage’s overrideBuildModAttrs
102-
# it takes a lean module name and a filename, and makes that file available
103-
# (as an empty file) in the build tree, e.g. for include_str.
104-
addFakeFiles = m: self: super:
105-
if m ? ${super.name}
106-
then let
107-
paths = m.${super.name};
108-
in {
109-
src = pkgs.runCommandCC "${super.name}-patched" {
110-
inherit (super) leanPath src relpath;
111-
} (''
112-
dir=$(dirname $relpath)
113-
mkdir -p $out/$dir
114-
if [ -d $src ]; then cp -r $src/. $out/$dir/; else cp $src $out/$leanPath; fi
115-
'' + pkgs.lib.concatMapStringsSep "\n" (p : ''
116-
install -D -m 644 ${pkgs.emptyFile} $out/${p}
117-
'') paths);
118-
}
119-
else {};
91+
fetchFromLakeManifest = leanLib.fetchFromLakeManifest manifest;
92+
inherit (leanLib) addFakeFiles;
12093

12194
batteries = buildLeanPackage {
12295
name = "Batteries";

docs/user/nix/default.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{ emptyFile, runCommandCC, lib, callPackage, ... }: {
2+
/* Given a parsed Lake manifest in Nix,
3+
this will fetch a specific Lake dependency of the manifest.
4+
5+
This currently only supports Git inputs.
6+
*/
7+
fetchFromLakeManifest = manifest: { name, hash, ... }:
8+
let
9+
dep = lib.findFirst (pkg: pkg.name == name) null manifest.packages;
10+
in
11+
assert dep != null;
12+
assert dep.type == "git"; fetchGit {
13+
inherit (dep) url rev;
14+
narHash = hash;
15+
} // (if dep.inputRev != null then { ref = dep.inputRev; } else {});
16+
17+
# Inspired from Loogle scaffolding.
18+
# addFakeFile can plug into buildLeanPackage’s overrideBuildModAttrs
19+
# it takes a lean module name and a filename, and makes that file available
20+
# (as an empty file) in the build tree, e.g. for include_str.
21+
addFakeFiles = m: self: super:
22+
if m ? ${super.name}
23+
then let
24+
paths = m.${super.name};
25+
in {
26+
src = runCommandCC "${super.name}-patched" {
27+
inherit (super) leanPath src relpath;
28+
} (''
29+
dir=$(dirname $relpath)
30+
mkdir -p $out/$dir
31+
if [ -d $src ]; then cp -r $src/. $out/$dir/; else cp $src $out/$leanPath; fi
32+
'' + lib.concatMapStringsSep "\n" (p : ''
33+
install -D -m 644 ${emptyFile} $out/${p}
34+
'') paths);
35+
}
36+
else {};
37+
}

0 commit comments

Comments
 (0)