-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Ryan Lahfa
committed
Aug 26, 2024
1 parent
eea4716
commit 2978bcc
Showing
2 changed files
with
40 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; | ||
} |