I tried to use Nim standard installation on Manjaro and encountered a problem with nimsuggest. When running nimsuggest --v3, I get an exception with the message cannot open '/usr/lib/system.nim'.
Manjaro installs Nim binary in /usr/bin and the library in /usr/lib/nim. Looking at the source, it appears that nimsuggest looks for a directory named “lib” in the parent directory of /usr/bin and, of course, finds /usr/lib. Then it expects the library files to be present here, not in a subdirectory.
Should we consider that Manjaro installation of Nim is broken since it doesn’t follow this requirement or that there is a problem with the way nimsuggest searches the standard library location?
In the first case, how the Manjaro installer should proceed? Installing the binary in /usr/bin is standard and installing the library files in a subdirectory of /usr/lib seems the right thing to do.
Of course, there are other ways to install Nim, but it is reasonable to expect a distribution to provide a standard way to install the compiler and the tools as it is the case for other languages.
Should we consider that Manjaro installation of Nim is broken since it doesn’t follow this requirement
IMHO we should rather consider Nimsuggest broken, since it doesn't follow FHS standards on Linux.
See also:
This also affects other Nim tools:
https://gitlab.archlinux.org/archlinux/packaging/packages/nim/-/issues/3
You are right. If the compiler used the same logic as that of nimsuggest to find the library location, it should not work. This is strange.
To understand what going on, I looked at the compiler source. In the module “options.nim” of the compiler, the procedure getPrefixDir has a special case for Posix platform. If the parent is /usr, then the prefix directory is set to usr/lib/nim.
For some reason, nimsuggest doesn’t call getPrefixDir but uses a simplified rule. And, so, the library path is set to /usr/lib which is wrong. Now, there may be a good reason to not use getPrefixDir in nimsuggest.nim.
So there should be no problem to install Nim on Linux in the standard locations since the case has been foreseen . But, actually, there is a problem with nimsuggest.
For some reason, nimsuggest doesn’t call getPrefixDir but uses a simplified rule.
Aha! Thanks!
I guess this is supposed to be ironic.
Contrary to what you said, the compiler and nimsuggest doesn’t use the same rule. I have no time to find the reason for this, but one thing is sure: if nim binary is in /usr/bin, the compiler does the right thing and expects the library to be in /usr/lib/nim while nimsuggest expects it to be in /usr/lib.
When I have time, I will create an issue for this. At least, I expect that someone will check and give me a better answer that yours.
At least that's how I read it.
Yes, that is what happened. No irony involved.
The problem has been solved.
Thanks to the team for the correction.
2) nimsuggest --stdin --debug Dev/Learn/main.nim Error: cannot open '/usr/lib/system.nim' lineinfos.nim(318) raiseRecoverableError Error: unhandled exception: cannot open '/usr/lib/system.nim' [ERecoverableError]
Also, if add --lib: "/usr/lib/nim" line to '/etc/nim/nim.cfg', then nimsuggest works, but from time to time it freezes and if you close vscode, then nimsuggest remains hanging in memory. I don't know if these problems are related
from time to time it freezes and if you close vscode, then nimsuggest remains hanging in memory.
This rather sounds like the known problem with the wrapper binaries choosenim installs.
Are you sure you don't have a Nim installation from choosenim still in your PATH?
I found out that when using choosenim to install nimsuggest, it suffers from random freezes or crashes, sometimes after high resource usage, which is why I decided to manually install Nim.
Here's a small script that I made (it cleans everything related to the current Nim install either manually or via choosenim, then performs manual installation of 2.0.8):
#!/bin/sh -e
# Copyright (c) 2024, Firas Khalil Khana
# Distributed under the terms of the ISC License
# Don't forget to add `~/.nim/bin` and `~/.nimble/bin` to your `$PATH`
# Don't forget to run `nimble install nimlangserver`
# Don't forget to run `nimble install nph`
ver="2.0.8"
cd ~
rm -fR \
~/choosenim \
~/config.nims \
~/Nim \
~/nim \
~/nimble
rm -fR \
~/.choosenim \
~/.config.nims \
~/.Nim \
~/.nim \
~/.nimble
rm -fR \
~/.cache/choosenim \
~/.cache/config.nims \
~/.cache/Nim \
~/.cache/nim \
~/.cache/nimble
rm -fR \
~/.config/choosenim \
~/.config/config.nims \
~/.config/Nim \
~/.config/nim \
~/.config/nimble
rm -fR \
~/.local/share/choosenim \
~/.local/share/config.nims \
~/.local/share/Nim \
~/.local/share/nim \
~/.local/share/nimble
rm -fR \
~/.local/state/choosenim \
~/.local/state/config.nims \
~/.local/state/Nim \
~/.local/state/nim \
~/.local/state/nimble
rm -fR ~/tmp/Nim
mkdir -pv ~/tmp/Nim
cd ~/tmp/Nim
wget https://nim-lang.org/download/nim-$ver-linux_x64.tar.xz
bsdtar -xmPf nim-$ver-linux_x64.tar.xz -C .
sudo ./nim-$ver/deinstall.sh /usr/bin
sudo rm -f /usr/bin/nim
sudo rm -fR \
/etc/nim \
/usr/lib/nim \
/usr/share/nim \
/opt/nimble
mv nim-$ver ~/.nim
After installation don't forget to add ~/.nim/bin and ~/.nimble/bin to your $PATH then run:
nimble install nimlangserver
nimble install nph
I did not use or install choosenim, installed only nim via pacman and auto installed the nimlangserver in vscode ext. (I think that there is a nimble install nimlangserver under the hood). Just in case, I checked the paths using the script [firasuke] (thanks!), choosenim is missing.
I could try installing via choosenim/init.sh but installing from the distribution's repositories seems more correct.
Yes, of course
Name: nim-lang.org Id: NimLang.nimlang Description: Nim extension maintained by the Nim compiler team. Version: 1.0.2 Publisher: NimLang VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=NimLang.nimlang
from time to time it freezes and if you close vscode, then nimsuggest remains hanging in memory.
I've definitely experienced this problem even with nim installed manually.
I'm currently using my own very hacky replacement for choosenim that's pulling compiler releases from https://nim-lang.org/install.html and using symlinks to switch between versions.
I've tested latest nimlangserver (v1.4.0) in Neovim and after a couple gotoDefinition s it was always starting to create Zombie nimsuggest processes with each taking 100% cpu load which persisted after closing the editor.
I've tested the v1.2.0 version and it doesn't have this problem, you can install 1.2.0 with:
nimble uninstall nimlangserver # remove old version first
nimble install nimlangserver@1.2.0
And recently I tried the development version of langserver. And after noticing that it is a lot more stable than 1.2.0, I've switched to that:
nimble install nimlangserver@\#head
So far, I've had no problems with v1.5.2.
I'm currently using my own very hacky replacement for choosenim that's pulling compiler releases from https://nim-lang.org/install.html and using symlinks to switch between versions.
Feel free to base it on https://github.com/nim-lang/atlas/blob/master/src/nimenv.nim which works for essentially all supported platforms as it builds Nim from source (starting with csources).