jgm / djot

A light markup language
https://djot.net
MIT License
1.67k stars 43 forks source link

Document how to run djot without installing #57

Closed matklad closed 1 year ago

matklad commented 1 year ago

make install wants to write to / which isn't possible without sudo (and, on something like NixOS, isn't possible at all). Luckily, luarocks supports --local flag for installing into ~/.luarocks. Add a make target for that.

Note that I am not really comfortable with neither make nor lua, but that's the magic spell which worked for me on NixOS!

matklad commented 1 year ago

Hm, or maybe this doesn't work? After the local install ~/.luarocks/bin/djot -h works for me, but ~/.luarocks/bin/djot example.djot fails with

/nix/store/yp7zmdrj8lv3qsgq98h1q3lgvf2gsr2j-lua-5.2.4/bin/lua: /home/matklad/.luarocks/share/lua/5.2/djot/inline.lua:579: attempt to call upvalue 'unpack_match' (a nil value)
matklad commented 1 year ago

So, yeah, I wasn't able to get neithe global, nor local install to work for me. lua ./bin/main.lua did the trick though!

jgm commented 1 year ago

luarocks --local make works fine for me. But maybe the problem would reveal itself if I had your example.djot? Also, what version of lua are you running?

matklad commented 1 year ago

Here's some extra debug output:

[matklad@Ishmael:~/p/djot]$ lua -v
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio

[matklad@Ishmael:~/p/djot]$ luarocks --version
/nix/store/5da3vmaf17hvbcy27fdydf4lib0zifaa-luarocks-3.9.1/bin/.luarocks-wrapped 3.9.1
LuaRocks main command-line interface

[matklad@Ishmael:~/p/djot]$ echo $LUA_PATH 
/nix/store/5da3vmaf17hvbcy27fdydf4lib0zifaa-luarocks-3.9.1/share/lua/5.2/?.lua;/nix/store/5da3vmaf17hvbcy27fdydf4lib0zifaa-luarocks-3.9.1/share/lua/5.2/?/init.lua;/home/matklad/.luarocks/share/lua/5.2/?.lua;/home/matklad/.luarocks/share/lua/5.2/?/init.lua

[matklad@Ishmael:~/p/djot]$ luarocks --local test

djot 0.1.0-1 depends on lua >= 5.1 (5.2-1 provided by VM)
djot 0.1.0-1 depends on luafilesystem >= 1.8 (1.8.0-1 installed)
Error running test task_lists.test line 13:
./djot/inline.lua:579: attempt to call upvalue 'unpack_match' (a nil value)
Error running test task_lists.test line 31:
./djot/inline.lua:579: attempt to call upvalue 'unpack_match' (a nil value)
Error running test definition-lists.test line 24:
./djot/inline.lua:579: attempt to call upvalue 'unpack_match' (a nil value)
Error running test definition-lists.test line 47:
./djot/inline.lua:579: attempt to call upvalue 'unpack_match' (a nil value)
Error running test definition-lists.test line 79:

Given that this is NixOS, it's highly likely that something's wrong on my end.

I think even local install from luarocks doesnt' work?

λ luarocks install --local djot
Installing https://luarocks.org/djot-0.1.0-1.src.rock

djot 0.1.0-1 depends on lua >= 5.1 (5.2-1 provided by VM)
No existing manifest. Attempting to rebuild...
djot 0.1.0-1 is now installed in /home/matklad/.luarocks (license: MIT)

15:27:30|~/p
λ ~/.luarocks/bin/djot  -h
djot [opts] [file*]

Options:
-m        Show matches.
-a        Show AST.
-r        Show references.
-p        Include source positions in AST.
-M        Show memory usage.
-v        Verbose (show warnings).
-h        Help.

15:27:46|~/p
λ ~/.luarocks/bin/djot /dev/null
/nix/store/yp7zmdrj8lv3qsgq98h1q3lgvf2gsr2j-lua-5.2.4/bin/lua: /home/matklad/.luarocks/share/lua/5.2/djot/match.lua:18: attempt to call field 'pack' (a nil value)
stack traceback:
    /home/matklad/.luarocks/share/lua/5.2/djot/match.lua:18: in function 'make_match'
    /home/matklad/.luarocks/share/lua/5.2/djot/block.lua:621: in function 'add_match'
    /home/matklad/.luarocks/share/lua/5.2/djot/block.lua:738: in function 'parse'
    ...d/.luarocks/lib/luarocks/rocks-5.2/djot/0.1.0-1/bin/djot:75: in main chunk
    [C]: in ?
matklad commented 1 year ago

(I also notice that CI wasn't kicking in here without your approval, it's possible to change this (or rather, revert to how it was a couple of years ago) if you want to https://matklad.github.io/2022/10/24/actions-permissions.html)

jgm commented 1 year ago
/nix/store/yp7zmdrj8lv3qsgq98h1q3lgvf2gsr2j-lua-5.2.4/bin/lua: /home/matklad/.luarocks/share/lua/5.2/djot/match.lua:18: attempt to call field 'pack' (a nil value)

This is hard to understand. If you look at match.lua, it should not be able to get to line 18 if string.pack is a nil value, because of the conditional on line 3.

jgm commented 1 year ago

However, I can reproduce the issue using nix-shell.

jgm commented 1 year ago

OK, I think I see the problem.

jgm commented 1 year ago

I think this commit fixes things (try luarocks install --local again). But I don't yet understand why it would work locally but not in luarocks.

matklad commented 1 year ago

Yup, that commit fixed luarocks test --local for me:

λ luarocks test --local

djot 0.1.0-1 depends on lua >= 5.1 (5.2-1 provided by VM)
djot 0.1.0-1 depends on luafilesystem >= 1.8 (1.8.0-1 installed)
224 tests completed in 0.021 s
PASSED:  224
FAILED:    0
ERRORS:    0

The install still doesn't work though:

λ ~/.luarocks/bin/djot ./test/emoji.test
/nix/store/yp7zmdrj8lv3qsgq98h1q3lgvf2gsr2j-lua-5.2.4/bin/lua: /home/matklad/.luarocks/share/lua/5.2/djot/match.lua:18: attempt to call field 'pack' (a nil value)
stack traceback:
    /home/matklad/.luarocks/share/lua/5.2/djot/match.lua:18: in function 'make_match'
    /home/matklad/.luarocks/share/lua/5.2/djot/block.lua:621: in function 'add_match'
    /home/matklad/.luarocks/share/lua/5.2/djot/block.lua:453: in function 'open'
    /home/matklad/.luarocks/share/lua/5.2/djot/block.lua:700: in function 'parse'
    ...d/.luarocks/lib/luarocks/rocks-5.2/djot/0.1.0-1/bin/djot:75: in main chunk
    [C]: in ?
jgm commented 1 year ago

Did you try it after the follow-up commit 55f2a12ddeaed46a8e8ed82e2e818d1141915661 ?

matklad commented 1 year ago

yup, that was as of 55f2a12ddeaed46a8e8ed82e2e818d1141915661