Skip to content

Commit

Permalink
chore(docs/user): vendor various lean-nix code
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ryan Lahfa committed Aug 26, 2024
1 parent eea4716 commit 2978bcc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
33 changes: 3 additions & 30 deletions docs/user/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
with inputs.lean.packages.${system}; with nixpkgs;
let
doc-src = ./.; # lib.sourceByRegex ../. ["doc.*" "tests(/lean(/beginEndAsMacro.lean)?)?"];
leanLib = callPackage ./nix { };
in {
packages = rec {
lean-mdbook = mdbook.overrideAttrs (drv: rec {
Expand Down Expand Up @@ -87,36 +88,8 @@
aeneas-base =
let
manifest = builtins.fromJSON (builtins.readFile ./lake-manifest.json);
fetchFromLakeManifest = { name, hash, ... }:
let
dep = lib.findFirst (pkg: pkg.name == name) null manifest.packages;
in
assert dep != null;
assert dep.type == "git"; fetchGit {
inherit (dep) url rev;
narHash = hash;
} // (if dep.inputRev != null then { ref = dep.inputRev; } else {});

# Inspired from Loogle scaffolding.
# addFakeFile can plug into buildLeanPackage’s overrideBuildModAttrs
# it takes a lean module name and a filename, and makes that file available
# (as an empty file) in the build tree, e.g. for include_str.
addFakeFiles = m: self: super:
if m ? ${super.name}
then let
paths = m.${super.name};
in {
src = pkgs.runCommandCC "${super.name}-patched" {
inherit (super) leanPath src relpath;
} (''
dir=$(dirname $relpath)
mkdir -p $out/$dir
if [ -d $src ]; then cp -r $src/. $out/$dir/; else cp $src $out/$leanPath; fi
'' + pkgs.lib.concatMapStringsSep "\n" (p : ''
install -D -m 644 ${pkgs.emptyFile} $out/${p}
'') paths);
}
else {};
fetchFromLakeManifest = leanLib.fetchFromLakeManifest manifest;
inherit (leanLib) addFakeFiles;

batteries = buildLeanPackage {
name = "Batteries";
Expand Down
37 changes: 37 additions & 0 deletions docs/user/nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ emptyFile, runCommandCC, lib, callPackage, ... }: {
/* Given a parsed Lake manifest in Nix,
this will fetch a specific Lake dependency of the manifest.
This currently only supports Git inputs.
*/
fetchFromLakeManifest = manifest: { name, hash, ... }:
let
dep = lib.findFirst (pkg: pkg.name == name) null manifest.packages;
in
assert dep != null;
assert dep.type == "git"; fetchGit {
inherit (dep) url rev;
narHash = hash;
} // (if dep.inputRev != null then { ref = dep.inputRev; } else {});

# Inspired from Loogle scaffolding.
# addFakeFile can plug into buildLeanPackage’s overrideBuildModAttrs
# it takes a lean module name and a filename, and makes that file available
# (as an empty file) in the build tree, e.g. for include_str.
addFakeFiles = m: self: super:
if m ? ${super.name}
then let
paths = m.${super.name};
in {
src = runCommandCC "${super.name}-patched" {
inherit (super) leanPath src relpath;
} (''
dir=$(dirname $relpath)
mkdir -p $out/$dir
if [ -d $src ]; then cp -r $src/. $out/$dir/; else cp $src $out/$leanPath; fi
'' + lib.concatMapStringsSep "\n" (p : ''
install -D -m 644 ${emptyFile} $out/${p}
'') paths);
}
else {};
}

0 comments on commit 2978bcc

Please sign in to comment.