1{ lib, stdenv, fetchFromGitLab, buildEnv, makeWrapper, lua, luajit, readline
2, useLuaJit ? false
3, extraLibraries ? []
4}:
5
6let
7 version = "0.7.2";
8 # Build a sort of "union package" with all the native dependencies we
9 # have: Lua (or LuaJIT), readline, etc. Then, we can depend on this
10 # and refer to ${urn-rt} instead of ${lua}, ${readline}, etc.
11 urn-rt = buildEnv {
12 name = "urn-rt-${version}";
13 ignoreCollisions = true;
14 paths = if useLuaJit then
15 [ luajit readline ]
16 else
17 [ lua ];
18 };
19
20 inherit (lib) optionalString concatMapStringsSep;
21in
22
23stdenv.mkDerivation {
24 pname = "urn${optionalString (extraLibraries != []) "-with-libraries"}";
25 inherit version;
26
27 src = fetchFromGitLab {
28 owner = "urn";
29 repo = "urn";
30 rev = "v${version}";
31 sha256 = "0nclr3d8ap0y5cg36i7g4ggdqci6m5q27y9f26b57km8p266kcpy";
32 };
33
34 nativeBuildInputs = [ makeWrapper ];
35 # Any packages that depend on the compiler have a transitive
36 # dependency on the Urn runtime support.
37 propagatedBuildInputs = [ urn-rt ];
38
39 makeFlags = ["-B"];
40
41 installPhase = ''
42 mkdir -p $out/bin $out/lib
43 install -m 0755 bin/urn.lua $out/bin/urn
44 cp -r lib $out/lib/urn
45 wrapProgram $out/bin/urn \
46 --add-flags "-i $out/lib/urn --prelude $out/lib/urn/prelude.lisp" \
47 --add-flags "${concatMapStringsSep " " (x: "-i ${x.libraryPath}") extraLibraries}" \
48 --prefix PATH : ${urn-rt}/bin/ \
49 --prefix LD_LIBRARY_PATH : ${urn-rt}/lib/
50 '';
51
52 meta = with lib; {
53 homepage = "https://urn-lang.com";
54 description = "Yet another Lisp variant which compiles to Lua";
55 license = licenses.bsd3;
56 maintainers = with maintainers; [ CrazedProgrammer ];
57 platforms = platforms.all;
58 };
59
60 passthru = {
61 inherit urn-rt;
62 };
63}