1# Almost 1:1 copy of idris2's nix/package.nix. Some work done in their flake.nix
2# we do here instead.
3{
4 stdenv,
5 lib,
6 chez,
7 chez-racket,
8 clang,
9 gmp,
10 fetchFromGitHub,
11 makeWrapper,
12 gambit,
13 nodejs,
14 zsh,
15 callPackage,
16}:
17
18# NOTICE: An `idris2WithPackages` is available at: https://github.com/claymager/idris2-pkgs
19
20let
21 platformChez =
22 if (stdenv.system == "x86_64-linux") || (lib.versionAtLeast chez.version "10.0.0") then
23 chez
24 else
25 chez-racket;
26in
27stdenv.mkDerivation rec {
28 pname = "idris2";
29 version = "0.7.0";
30
31 src = fetchFromGitHub {
32 owner = "idris-lang";
33 repo = "Idris2";
34 rev = "v${version}";
35 sha256 = "sha256-VwveX3fZfrxEsytpbOc5Tm6rySpLFhTt5132J6rmrmM=";
36 };
37
38 strictDeps = true;
39 nativeBuildInputs = [
40 makeWrapper
41 clang
42 platformChez
43 ]
44 ++ lib.optionals stdenv.hostPlatform.isDarwin [ zsh ];
45 buildInputs = [
46 platformChez
47 gmp
48 ];
49
50 prePatch = ''
51 patchShebangs --build tests
52 '';
53
54 makeFlags = [ "PREFIX=$(out)" ] ++ lib.optional stdenv.hostPlatform.isDarwin "OS=";
55
56 # The name of the main executable of pkgs.chez is `scheme`
57 buildFlags = [
58 "bootstrap"
59 "SCHEME=scheme"
60 ];
61
62 checkTarget = "test";
63 nativeCheckInputs = [
64 gambit
65 nodejs
66 ]; # racket ];
67 checkFlags = [ "INTERACTIVE=" ];
68
69 # TODO: Move this into its own derivation, such that this can be changed
70 # without having to recompile idris2 every time.
71 postInstall =
72 let
73 name = "${pname}-${version}";
74 globalLibraries = [
75 "\\$HOME/.nix-profile/lib/${name}"
76 "/run/current-system/sw/lib/${name}"
77 "$out/${name}"
78 ];
79 globalLibrariesPath = builtins.concatStringsSep ":" globalLibraries;
80 in
81 ''
82 # Remove existing idris2 wrapper that sets incorrect LD_LIBRARY_PATH
83 rm $out/bin/idris2
84 # The only thing we need from idris2_app is the actual binary
85 mv $out/bin/idris2_app/idris2.so $out/bin/idris2
86 rm $out/bin/idris2_app/*
87 rmdir $out/bin/idris2_app
88 # idris2 needs to find scheme at runtime to compile
89 # idris2 installs packages with --install into the path given by
90 # IDRIS2_PREFIX. We set that to a default of ~/.idris2, to mirror the
91 # behaviour of the standard Makefile install.
92 # TODO: Make support libraries their own derivation such that
93 # overriding LD_LIBRARY_PATH is unnecessary
94 wrapProgram "$out/bin/idris2" \
95 --set-default CHEZ "${platformChez}/bin/scheme" \
96 --run 'export IDRIS2_PREFIX=''${IDRIS2_PREFIX-"$HOME/.idris2"}' \
97 --suffix IDRIS2_LIBS ':' "$out/${name}/lib" \
98 --suffix IDRIS2_DATA ':' "$out/${name}/support" \
99 --suffix IDRIS2_PACKAGE_PATH ':' "${globalLibrariesPath}" \
100 --suffix DYLD_LIBRARY_PATH ':' "$out/${name}/lib" \
101 --suffix LD_LIBRARY_PATH ':' "$out/${name}/lib"
102 '';
103
104 # Run package tests
105 passthru.tests = callPackage ./tests.nix { inherit pname; };
106
107 meta = {
108 description = "Purely functional programming language with first class types";
109 mainProgram = "idris2";
110 homepage = "https://github.com/idris-lang/Idris2";
111 license = lib.licenses.bsd3;
112 maintainers = with lib.maintainers; [
113 fabianhjr
114 wchresta
115 mattpolzin
116 ];
117 inherit (chez.meta) platforms;
118 };
119}