Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
feat: add a Nix flakes build setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderssorby authored Sep 30, 2021
1 parent 9aa3ab1 commit 1d32b08
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use_flake() {
watch_file flake.nix
watch_file flake.lock
eval "$(nix print-dev-env)"
}
use flake
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/build
result*
# Do not lock flake to avoid having to maintain it
flake.lock
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ $ ./build.sh -j4

After building, the `lake` binary will be located at `build/bin/lake` and the library's `.olean` files will be located directly in `build`.

### Building with nix flakes

It is also possible to build lake with the nix setup `buildLeanPackage` from lean4. To do this you need to have nix installed with flakes enabled. It is recommended to have set up the lean4 binary cache as described in the lean4 repo.
It is then possible to build lake with `nix build .` or run it from anywhere with `nix run github:leanprover/lake`.

A development environment with lean installed can be loaded automatically by running `nix develop` or automatically on `cd` with direnv by running `direnv allow`.

The versions of nixpkgs and lean4 are fixed to specific hashes. They can be updated by running `nix flake update`.

### Augmenting Lake's Search Path

The `lake` executable needs to know where to find the `.olean` files for the modules used in the package configuration file. Lake will intelligently setup an initial search path based on the location of its own executable and `lean`.
Expand Down
52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
description = "Lake (Lean Make) is a new build system and package manager for Lean 4.";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.05";
lean = {
url = "github:leanprover/lean4";
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{ self
, flake-utils
, nixpkgs
, lean
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
packageName = "Lake";
src = ./.;
leanPkgs = lean.packages.${system};
project = leanPkgs.buildLeanPackage {
name = packageName;
inherit src;
};
in
{
packages.${packageName} = project.lean-package;
packages.lakeProject = project;

defaultPackage = self.packages.${system}.${packageName};

apps.lake = flake-utils.lib.mkApp {
name = "lake";
drv = project.executable;
};

defaultApp = self.apps.${system}.lake;

# `nix develop`
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
leanPkgs.lean
];
};
});
}

0 comments on commit 1d32b08

Please sign in to comment.