Hello,
I have a lua seutp with a flake.nix
that looks like this:
{
description = "A very basic flake";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs;
utils.url = github:numtide/flake-utils;
};
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem(system:
let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
lua = pkgs.lua5_3.withPackages(ps: with ps; [
cjson
http
]);
in {
devShells.default = pkgs.mkShell rec {
buildInputs = [
lua
];
};
});
}
I assumed that both the lua-http as well as the cjson would be available to call from within lua code. Trying to verify this in a REPL however throws an error (the example is copied from the lua-http docs):
Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio
> local http_request = require "http.request"
> local headers, stream = assert(http_request.new_from_uri("http://example.com"):go())
stdin:1: attempt to index a nil value (global 'http_request')
stack traceback:
stdin:1: in main chunk
[C]: in ?
> local body = assert(stream:get_body_as_string())
stdin:1: attempt to index a nil value (global 'stream')
stack traceback:
stdin:1: in main chunk
[C]: in ?
> if headers:get ":status" ~= "200" then
>> error(body)
>> end
stdin:1: attempt to index a nil value (global 'headers')
stack traceback:
stdin:1: in main chunk
[C]: in ?
> print(body)
nil
The behavior when requiring cjson
is the same, and the same thing happens across different versions of the lua package as well as the luajit packages. The modules seem to be installed fine:
which lua
# /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/bin/lua
fd http /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/
# /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/http-0.3-0-rocks
# /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/share/lua/5.3/http
fd cjson /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/
# /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/lib/lua/5.3/cjson.so
# /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/lua-cjson-2.1.0.6-1-rocks
# /nix/store/f392f68bh95j6mz8hz2lx91jd6sf6cfh-lua-5.3.6-env/share/lua/5.3/cjson
What am I missing?