0

I'm trying to build for a nix-shell that aren't in the current nixpkgs repository. Specifically: raylua

I've managed to get Raylib itself built as part of a nix-shell using Nim. I'm trying to now modify this to use Lua Raylib and the Lua libraries and am unsure how to procede.

I see people use nix-shell ... commands to bypass a lot of this pain, but I want something I can commit to a repo.

Files I have are:

shell.nix

{ pkgs ? import <nixpkgs> {} }:

let
    unstable = import <unstable> {};
    raylib = pkgs.callPackage ./nix/raylib/default.nix { };
    # toLuaModule
    #raylib-lua = pkgs.callPackage ./nix/raylib-lua/default.nix { raylib };
in
pkgs.mkShell {
    buildInputs = [
        pkgs.bashInteractive
        pkgs.glfw
        pkgs.luajit
        raylib
        #raylua
    ];
}

nix/raylib/default.nix

Same as in https://github.com/adamlwgriffiths/nix-nim/

nix/raylua/default.nix

{ stdenv, lib, fetchFromGitHub, make, luaPackages }: #, raylib }:

with luaPackages;

let
    libs = [];
in
stdenv.mkDerivation rec {
  pname = "raylua";
  version = "3.5.0";

  src = fetchFromGitHub {
    owner = "Rabios";
    repo = pname;
    rev = version;
    sha256 = "0syvd5js1lbx3g4cddwwncqg95l6hb3fdz5nsh5pqy7fr6v84kwj";
  };

  lualibs = [ luaPackages.lua ];
  buildInputs = [ make ] ++ lualibs;

  LUA_PATH = stdenv.lib.concatStringsSep ";" (map luaPackages.getLuaPath lualibs);
  LUA_CPATH = stdenv.lib.concatStringsSep ";" (map luaPackages.getLuaCPath lualibs);

  configureFlags = ''
    LUA_PATH="${LUA_PATH}"
    LUA_CPATH="${LUA_CPATH}"
    INST_LIBDIR="$out/lib/lua/${luaPackages.lua.luaversion}"
    INST_LUADIR="$out/share/lua/${luaPackages.lua.luaversion}"
    LUA_BINDIR="${luaPackages.lua}/bin"
    LUA_INCDIR="-I${luaPackages.lua}/include"
    LUA_LIBDIR="-L${luaPackages.lua}/lib"
  '';

  meta = with stdenv.lib; {
    description = "Lua bindings for raylib, a simple and easy-to-use library to enjoy videogames programming";
    homepage = "https://github.com/Rabios/raylua";
    license = licenses.isc;
    maintainers = with maintainers; [ adamlwgriffiths ];
    platforms = platforms.linux;
  };
}

Rebs
  • 4,169
  • 2
  • 30
  • 34
  • One minor thing is you have `bashInteractive` in your `buildInputs`. I don't suppose you're linking bash into an executable or anything, are you? You could leave it out or add it to `nativeBuildInputs` instead. – Robert Hensing Feb 19 '21 at 13:09
  • Honestly, I don't pretend to grok the vast majority of Nix syntax. I'm just copying other scripts without understanding what they're doing. I'm not sure what "bashInteractive" really does, I saw a post saying if you're using bash in a nix-shell you should use it, so I did. I guess that's not correct? – Rebs Feb 20 '21 at 05:31
  • 1
    `buildInputs = [ bashInteractive ];` configures the build environment so that you can compile and link against bash. It also adds that `bash` to `PATH`, but that's a legacy behavior. `nativeBuildInputs = [ bashInteractive ];` adds it to `PATH` and (in master or 21.05 or newer) adds it to `XDG_DATA_DIRS` which serves as the search path for bash autocompletions among other things. You don't need either, because it already comes with an interactive bash by default. – Robert Hensing Feb 20 '21 at 18:45

0 Answers0