default.nix 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. { nixpkgs ? import <nixpkgs> {}
  2. , enableLuaJit ? false
  3. , lua ? nixpkgs.pkgs.lua
  4. , luajit ? nixpkgs.pkgs.luajit
  5. , readline ? nixpkgs.pkgs.readline
  6. , extraLibraries ? []
  7. }:
  8. let
  9. inherit (nixpkgs) stdenv;
  10. ourVersion = "0.7.2";
  11. # Build a sort of "union package" with all the native dependencies we
  12. # have: Lua (or LuaJIT), readline, etc. Then, we can depend on this
  13. # and refer to ${runtime} instead of ${lua}, ${readline}, etc
  14. runtime = nixpkgs.buildEnv {
  15. name = "urn-rt-${ourVersion}";
  16. ignoreCollisions = true;
  17. paths = if enableLuaJit then
  18. [ luajit readline ]
  19. else
  20. [ lua ];
  21. };
  22. dependencies = if extraLibraries == [] then "" else "-with-libraries";
  23. in
  24. stdenv.mkDerivation rec {
  25. name = "urn-${ourVersion}${dependencies}";
  26. version = ourVersion;
  27. src = ./.;
  28. buildInputs = [ runtime nixpkgs.pkgs.makeWrapper ];
  29. # any packages that depend on the compiler have a transitive
  30. # dependency on the runtime support
  31. propagatedBuildInputs = buildInputs;
  32. makeFlags = ["-B"];
  33. installPhase = ''
  34. install -Dm755 bin/urn.lua $out/bin/urn
  35. mkdir -p $out/lib/
  36. cp -r lib $out/lib/urn
  37. wrapProgram $out/bin/urn \
  38. --add-flags "-i $out/lib/urn --prelude $out/lib/urn/prelude.lisp" \
  39. --add-flags "${nixpkgs.lib.concatMapStringsSep " " (x: "-i ${x.libraryPath}") extraLibraries}" \
  40. --prefix PATH : ${runtime}/bin/ \
  41. --prefix LD_LIBRARY_PATH : ${runtime}/lib/
  42. '';
  43. meta = with stdenv.lib; {
  44. homepage = https://squiddev.github.io/urn;
  45. description = "A lean lisp implementation for Lua";
  46. license = licenses.bsd3;
  47. };
  48. passthru = {
  49. # useful for getting a nix-shell
  50. urn-rt = runtime;
  51. };
  52. }