|
4 | 4 | inputs = { |
5 | 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
6 | 6 | flake-parts.url = "github:hercules-ci/flake-parts"; |
| 7 | + # Keep lean4-nix as an input in case we restore Nix builds later, |
| 8 | + # but do not depend on its toolchain overlay for dev shells. |
7 | 9 | lean4-nix.url = "github:lenianiva/lean4-nix"; |
8 | 10 | }; |
9 | 11 |
|
10 | 12 | outputs = inputs @ { |
11 | 13 | nixpkgs, |
12 | 14 | flake-parts, |
13 | 15 | lean4-nix, |
| 16 | + # lean4-nix is intentionally unused in devShell to avoid pinning Lean |
| 17 | + # in Nix. We rely on `elan` + `lean-toolchain` instead. |
| 18 | + # It remains available in `inputs` for future use. |
14 | 19 | ... |
15 | 20 | }: |
16 | 21 | flake-parts.lib.mkFlake { inherit inputs; } { |
|
23 | 28 |
|
24 | 29 | perSystem = { system, ... }: |
25 | 30 | let |
26 | | - pkgs = import nixpkgs { |
27 | | - inherit system; |
28 | | - overlays = [ (lean4-nix.readToolchainFile ./lean-toolchain) ]; |
29 | | - }; |
30 | | - lake = (lean4-nix.lake { inherit pkgs; }); |
31 | | - # Build the test executable via lake-manifest integration |
32 | | - sdqlTests = (lake.mkPackage { |
33 | | - src = ./.; |
34 | | - # Explicit roots to avoid auto-capitalization from manifest name |
35 | | - roots = [ "Tests" ]; |
36 | | - }).executable; |
| 31 | + # Use plain nixpkgs for the dev shell; do not pin Lean here. |
| 32 | + # Lean/Lake will come from `elan` according to `lean-toolchain`. |
| 33 | + pkgs = import nixpkgs { inherit system; }; |
37 | 34 | in |
38 | 35 | { |
39 | | - packages = { |
40 | | - default = sdqlTests; |
41 | | - sdql-tests = sdqlTests; |
42 | | - }; |
43 | | - |
44 | | - # The executable name defaults to the lowercased manifest name |
45 | | - # (see lean4-nix buildLeanPackage), which for this repo is |
46 | | - # "part_ii_project". |
47 | | - apps = let exePath = "${sdqlTests}/bin/part_ii_project"; in { |
48 | | - default = { |
49 | | - type = "app"; |
50 | | - program = exePath; |
51 | | - }; |
52 | | - sdql-tests = { |
53 | | - type = "app"; |
54 | | - program = exePath; |
55 | | - }; |
56 | | - }; |
57 | | - |
58 | 36 | devShells.default = pkgs.mkShell { |
59 | | - # Provide Lean + Lake matching ./lean-toolchain, plus essential tools. |
60 | | - # Keep this minimal to avoid attr or non-derivation issues on some channels. |
61 | | - packages = |
62 | | - (with pkgs.lean; [ lean-all ]) |
63 | | - ++ (with pkgs; [ git unzip rustc cargo codex uv ]); |
| 37 | + # Keep the shell minimal and reproducible. We rely on `elan` |
| 38 | + # to supply Lean/Lake that match `./lean-toolchain`. |
| 39 | + packages = with pkgs; [ git unzip rustc cargo codex uv elan ]; |
| 40 | + |
| 41 | + # Ensure the desired toolchain is available and preferred. |
| 42 | + # This avoids depending on a Lean version packaged in nixpkgs |
| 43 | + # or an overlay that may lag behind the toolchain file. |
| 44 | + shellHook = '' |
| 45 | + if command -v elan >/dev/null 2>&1; then |
| 46 | + TOOLCHAIN=$(cat lean-toolchain) |
| 47 | + echo "Using Lean toolchain $TOOLCHAIN via elan" |
| 48 | + # Try to install silently if missing (ignore failures offline) |
| 49 | + elan toolchain install "$TOOLCHAIN" >/dev/null 2>&1 || true |
| 50 | + # Derive the toolchain path used by elan without shell parameter expansion |
| 51 | + ELAN_TC=$(printf "%s" "$TOOLCHAIN" | sed -e 's#/#--#g' -e 's#:#---#g') |
| 52 | + ELAN_BIN="$HOME/.elan/toolchains/$ELAN_TC/bin" |
| 53 | + if [ -d "$ELAN_BIN" ]; then |
| 54 | + export PATH="$ELAN_BIN:$PATH" |
| 55 | + fi |
| 56 | + else |
| 57 | + echo "Warning: elan not found; system Lean/Lake (if any) will be used." |
| 58 | + fi |
| 59 | + ''; |
64 | 60 | }; |
65 | 61 | }; |
66 | 62 | }; |
|
0 commit comments