Open jaidetree opened 2 years ago
Thank you for tackling this. Our most untenable moment is when a user attempts to use it for the first time. And if something doesn't work off the bat - many would lose confidence and interest right away. And even advocated by someone else later, they most likely would not even try again.
I just switched to nix as my package manager after doing a fresh re-install to macOS 12.4, and indeed I've run into some issues re: fennel.
/Users/<user>/.nix-profile/bin/fennel
is where fennel ends up.
Being a fairly green dev, spacehammer is my first introduction to hammerspoon Lua/fennel/emacs etc. (note: I haven't actually used spacehammer yet, due to this plan going awry)
I've tried
symlinking /opt/homebrew/
(not installed) to ~/.nix-profile/
installing luarockt via nix, and then trying to install fennel via luarocks
luarocks install fennel --local
which does install it to ~/luarocks/rocks-5.1/fennel/
both in hopes that whatever is going on with the fennel lookup would find the required files. Not sure what I can do to help but looking to learn nix and would love to get this working.
@eccentric-j were you able to hack together any solutions?
Thanks for that insight. Unfortunately I have not had a chance to set nix up on my personal yet.
Based on what you describe editing spacehammer's init.lua to point to your fennel installation might be a quick way to get unblocked.
From there can discuss options for making that smarter.
Some options off the top of my head...
Open to more ideas too.
After a bunch of messing around, I've got the following line added to the init.lua
package.cpath = package.cpath .. ";" .. os.getenv("HOME") .. "/.nix-profile/bin/?"
and am getting the following
2022-06-09 18:25:27: -- Loading ~/.hammerspoon/init.lua
2022-06-09 18:25:27: -- Loading extension: alert
2022-06-09 18:25:27: 18:25:27 ** Warning: LuaSkin: hs.canvas:delete - explicit delete is no longer required for canvas objects; garbage collection occurs automatically
2022-06-09 18:25:27: *** ERROR: error loading module 'fennel' from file '/Users/ar4s/.nix-profile/bin/fennel':
dlopen(/Users/ar4s/.nix-profile/bin/fennel, 0x0006): tried: '/Users/ar4s/.nix-profile/bin/fennel' (not a mach-o file), '/nix/store/3xfyx8a9g9mza5n87ppfbbdl2qa90gkw-fennel-1.1.0/bin/fennel' (not a mach-o file)
stack traceback:
[C]: in ?
[C]: in function 'rawrequire'
...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:662: in function 'require'
/Users/ar4s/.hammerspoon/init.lua:10: in main chunk
[C]: in function 'xpcall'
...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:723: in function 'hs._coresetup.setup'
(...tail calls...)
It seems like it's able to find the correct path but I'm unfamiliar with mach-o, lua and fennel and what might be going wrong here.
mach-o is basically just ELF (a binary format) but for OSX. So basically, it looks like it's trying to import fennel as a binary.
The problem is that you're setting CPATH, which is for binary libraries, not lua files. What type of file in your bin/fennel?
The problem is that you're setting CPATH, which is for binary libraries, not lua files. What type of file in your bin/fennel?
Upon some investigation it looks like the imported fennel from $HOME/.nix-profile/bin/fennel
is an alias to /nix/store/3xfyx8a9g9mza5n87ppfbbdl2qa90gkw-fennel-1.1.0/bin/fennel
which has the following lua code (and no file extension on either), and it's about 6000 more lines after the following:
#!/nix/store/88izv24drz57506g5lfvdzgrwf9s0csn-lua-5.2.4/bin/lua
package.preload["fennel.binary"] = package.preload["fennel.binary"] or function(...)
local fennel = require("fennel")
local _local_712_ = require("fennel.utils")
local warn = _local_712_["warn"]
local copy = _local_712_["copy"]
local function shellout(command)
local f = io.popen(command)
local stdout = f:read("*all")
return (f:close() and stdout)
end
...
Noted about the CPATH, thank you.
Trying package.path = package.path .. ";" .. os.getenv("HOME") .. "/.nix-profile/bin/?"
Gets me the following output from the hs console.
2022-06-10 13:37:55: -- Lazy extension loading enabled
2022-06-10 13:37:55: -- Loading ~/.hammerspoon/init.lua
2022-06-10 13:37:55: -- Loading extension: alert
2022-06-10 13:37:55: 13:37:55 ** Warning: LuaSkin: hs.canvas:delete - explicit delete is no longer required for canvas objects; garbage collection occurs automatically
2022-06-10 13:37:56: *** ERROR: /Users/ar4s/.nix-profile/bin/fennel:5767: attempt to get length of a nil value (global 'arg')
stack traceback:
/Users/ar4s/.nix-profile/bin/fennel:5767: in main chunk
[C]: in function 'rawrequire'
...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:662: in function 'require'
/Users/ar4s/.hammerspoon/init.lua:10: in main chunk
[C]: in function 'xpcall'
...poon.app/Contents/Resources/extensions/hs/_coresetup.lua:723: in function 'hs._coresetup.setup'
(...tail calls...)
Which references the following code block from the /bin/fennel (file?) at line 5767
for i = #arg, 1, -1 do
local _692_ = arg[i]
if (_692_ == "--lua") then
handle_lua(i)
else
end
end
Googling the errors has turned up that this tends to be a fairly common error. One solution was that the path perhaps needed a "/" but besides trying (and failing) with that, I'm not sure where to dig next.
I recently got my Nix config working for Spacehammer. If you are using Home Manager to configure your system this might be useful.
fennel.lua
to ~/.hamerspoon
.FWIW vendoring Fennel as suggested in #169 would greatly improve the ergonomics.
This is my current, "self-contained" setup:
home.file.".hammerspoon" = {
recursive = true;
source = pkgs.applyPatches {
src = pkgs.fetchFromGitHub {
owner = "agzam";
repo = "spacehammer";
rev = "0241428669872d708368ee2d21b909d837a5a851";
sha256 = "18yjcyvsvai378wqf7gw0kmsd71isx1708607x4y29qax8arsp2s";
# date = 2023-04-17T22:50:17-05:00;
};
# Edit-with-emacs workaround
patches = [ ./pkgs/spacehammer/0001-replace-usr-bin-with-nix-path.patch ];
};
};
home.file.".hammerspoon/fennel.lua" = {
source = builtins.fetchTarball
{
url = "https://fennel-lang.org/downloads/fennel-1.3.0.tar.gz";
sha256 = "sha256:0wciqn0ayqjxaz58hxfavwf4j63vv1v2b4ki7qgzxvzx38yhl8jl";
} + "/fennel.lua";
};
home.file.".hammerspoon/fennelview.lua" = {
source = builtins.fetchTarball
{
url = "https://fennel-lang.org/downloads/fennel-1.3.0.tar.gz";
sha256 = "sha256:0wciqn0ayqjxaz58hxfavwf4j63vv1v2b4ki7qgzxvzx38yhl8jl";
} + "/fennelview.lua";
};
Currently, nix is becoming a more common way to manage packages so it’s possible users may have fennel installed through nix instead of luarocks.
Going to install nix again on an older computer and figure out some solutions.