ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.82k stars 450 forks source link

Fix/nixos #1250

Closed misumisumi closed 1 month ago

misumisumi commented 2 months ago

I found two problems with the previous PR. One is with errors in the current release version of NixOS (23.11), another is with luarocks not being set in the path. I will therefore fix these issues. For verification purposes, we have also created a minimal devshell environment that runs the settings of this repository. This will make it possible to verify using a nix environment, even if NixOS or HomeManager are not in place. Since NVIM_APPNAME is used, there is no impact on the existing environment. If there is a slight problem, you may need to put in the effort to keep flake.lock up to date. This can be automated with github actions, just like updating lazy-lock.json. Also, since it doesn't relate to the module part, you may want to update it only when necessary. I would like to add github actions if necessary.

@CharlesChiuGit If possible, could you please confirm if this devshell works in an arm Mac environment? It will start with nix develop.

CharlesChiuGit commented 2 months ago

If possible, could you please confirm if this devshell works in an arm Mac environment?

i think it does? image

but when i'm using your fork:

$ nix develop
trace: true
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'devshell'
         whose name attribute is located at /nix/store/rzkl4xygy3z1glq8cgrv5cc075ylxs0g-source/nix/mkNakedShell.nix:30:11

       … while evaluating attribute 'args' of derivation 'devshell'
         at /nix/store/rzkl4xygy3z1glq8cgrv5cc075ylxs0g-source/nix/mkNakedShell.nix:38:3:
           37|   # Bring in the dependencies on `nix-build`
           38|   args = [ "-ec" "${coreutils}/bin/ln -s ${profile} $out; exit 0" ];
             |   ^
           39|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Package ‘acl-2.3.2’ in /nix/store/qxrwp9qzj2by5vqy4gm6f29njjkw4cna-source/pkgs/development/libraries/acl/default.nix:28 is not available on the requested hostPlatform:
         hostPlatform.config = "aarch64-apple-darwin"
         package.meta.platforms = [
           "aarch64-linux"
           "armv5tel-linux"
           "armv6l-linux"
           "armv7a-linux"
           "armv7l-linux"
           "i686-linux"
           "loongarch64-linux"
           "m68k-linux"
           "microblaze-linux"
           "microblazeel-linux"
           "mips-linux"
           "mips64-linux"
           "mips64el-linux"
           "mipsel-linux"
           "powerpc64-linux"
           "powerpc64le-linux"
           "riscv32-linux"
           "riscv64-linux"
           "s390-linux"
           "s390x-linux"
           "x86_64-linux"
         ]
         package.meta.badPlatforms = [ ]
       , refusing to evaluate.

       a) To temporarily allow packages that are unsupported for this system, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1

          Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnsupportedSystem = true; }
       in configuration.nix to override this.

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnsupportedSystem = true; }
       to ~/.config/nixpkgs/config.nix.

error: Package ‘acl-2.3.2’ in /nix/store/qxrwp9qzj2by5vqy4gm6f29njjkw4cna-source/pkgs/development/libraries/acl/default.nix:28 is not available on the requested hostPlatform:

maybe add this package?

i tried use nix develop --impure, but the error remain the same w/ lacking acl-2.3.2.

CharlesChiuGit commented 2 months ago

This can be automated with github actions, just like updating lazy-lock.json. Also, since it doesn't relate to the module part, you may want to update it only when necessary. I would like to add github actions if necessary.

agree, it would be nice.

misumisumi commented 2 months ago

I tried excluding unsupported packages, will this work?

misumisumi commented 2 months ago

This can be automated with github actions, just like updating lazy-lock.json. Also, since it doesn't relate to the module part, you may want to update it only when necessary. I would like to add github actions if necessary.

I had raised an ambiguous problem., Is this a positive statement, whether it is better to add a workflow or not?

CharlesChiuGit commented 2 months ago

Is this a positive statement, whether it is better to add a workflow or not?

ys, add a github action would be nice.

misumisumi commented 2 months ago

I try not to place lazy-lock.json under $XDG_CONFIG_HOME/nvimdots, but should I place it there? I have been avoiding the lock file because it seems to be updated on the first startup.

misumisumi commented 2 months ago

Before adding the github actions, I'll check them for a bit.

CharlesChiuGit commented 2 months ago

copilot.lua and nvim-nio keeps failing to checkout no matter what i do, but it works fine outside nix devshell. image i tried remove those two plugins in ~/.local/share/nvimdots/site/lazy and let lazy reinstall it, but it just keeps failing. I cant tell what could cause the issue.

CharlesChiuGit commented 2 months ago

I have been avoiding the lock file because it seems to be updated on the first startup.

interesing, this issue doesn't seem to happen on my end.

I try not to place lazy-lock.json under $XDG_CONFIG_HOME/nvimdots, but should I place it there?

i'm fine placing the lock file in or out, as long as it got managed by the user or via our nvim config. Personally i like to place the lock file in $XDG_CONFIG_HOME/nvimdots, so it's faster for me to debug if needed.

Jint-lzxy commented 2 months ago

i tried remove those two plugins in ~/.local/share/nvimdots/site/lazy and let lazy reinstall it, but it just keeps failing. I cant tell what could cause the issue.

@CharlesChiuGit Would verbose logging provide additional insights?

cd ~/.local/share/nvimdots/site/lazy/copilot.lua/
git status && GIT_TRACE=1 GIT_CURL_VERBOSE=1 GIT_TRACE_PACKET=1 GIT_TRACE_SETUP=1 GIT_TRACE_SHALLOW=1 git restore --source=HEAD :/

I once came across this and eventually realized it was a permission issue. Specifically, the default umask got accidentally changed, leaving that git folder wide open for everyone.


By the way can u please help me do a sanity check to ensure that the executables are correctly linked on macOS? I'm just diving into Nix so I might not be much help here. Basically, all u need to do is run otool -L on some of the MachO binaries produced by Nix or Mason and confirm whether they're indeed using packages (libraries) provided by Nix rather than those by the system (this ensures that dyld is doing the right thing and that packages can be located correctly with our config).

misumisumi commented 2 months ago

By the way can u please help me do a sanity check to ensure that the executables are correctly linked on macOS? I'm just diving into Nix so I might not be much help here. Basically, all u need to do is run otool -L on some of the MachO binaries produced by Nix or Mason and confirm whether they're indeed using packages (libraries) provided by Nix rather than those by the system (this ensures that dyld is doing the right thing and that packages can be located correctly with our config).

Maybe I can incorporate a simple test script into flake.nix. However, I have never written a proper test script, so I need to check the home-manager test scripts, etc. I'm busy tomorrow, so I'll work on it again after Thursday.

P.S It seems better to use ldd or patchelf, which are also available on Linux, instead of otool.

CharlesChiuGit commented 2 months ago

copilot.lua and nvim-nio keeps failing to checkout no matter what i do, but it works fine outside nix devshell.

@Jint-lzxy omg, it suddenly works w/o any modification. it's so weird lol image

CharlesChiuGit commented 2 months ago

can u please help me do a sanity check to ensure that the executables are correctly linked on macOS?

sure, let me check. hope i will know how to use those tools soon lol

misumisumi commented 2 months ago

Fixed three things:

  1. Put lazy-lock.json under $XDG_CONFIG_HOME/$NVIM_APPNAME.
  2. Rename test.nix to testEnv.nix.
  3. Adding check-linker script. This is simply script to check whether binary installed by mason link to /nix/store. Print cmd name and target lib if not link.
CharlesChiuGit commented 2 months ago

seems working exactly like we wanted! image

but i think we can add "echo done" at the end of the loop

CharlesChiuGit commented 2 months ago

image

i think this pr lgtm, is there anything still need further modification?

misumisumi commented 2 months ago

I have probrem, loop never ends on linux. Please wait a moment while I fix it.

misumisumi commented 2 months ago

It stopped because set -o pipefail was set when grep did not match. Also, some packages could not find libraries because there was no LIBRARY_PATH and so on set in nvim. Therefore, I have made it so that the environment variables set in nvim are source.

CharlesChiuGit commented 2 months ago

seems like we need to use multiple version of glibc on aarch64-linux? image

misumisumi commented 2 months ago

Can you check node path with readlink -f $(which node)? Maybe use system wide node.

CharlesChiuGit commented 2 months ago

image oh damn, it is using the system node i set.

so devshell or home-manager will inherit OS environment? is there anyway to exclude OS environment?

misumisumi commented 2 months ago

so devshell or home-manager will inherit OS environment?

I don't know if home-manager completely replaces PATH etc. devshell can decide for itself whether to replace it or not (like a shell script). Here, withNodeJs (in programs.neovim.withNodeJs) is set to append to $PATH, so it inherits the current system settings. You can replace paths in the same way as in the shell environment. Currently, this is not possible on the home-manager side. This is to respect the paths in the development environment.

CharlesChiuGit commented 2 months ago

i disable system node temporarily and enter devshell, now all node/npm related installation works properly.

misumisumi commented 2 months ago

Finally, regarding the github actions that update flake.lock, should I update flake.lock when updating lazy-lock.json, or should I update flake.lock separately? Also, is it better to open a PR before updating, like with dependabot?

CharlesChiuGit commented 2 months ago

I prefer update flake.lock separately, since I think update it once a month is enough.

And I prefer to update flake.lock directly w/o opening a PR.

misumisumi commented 2 months ago

I add workflow of auto flake update. This is called at 2:30 (UTC) of 1st of every month

misumisumi commented 2 months ago

I think all the work is completed, what do you think?

CharlesChiuGit commented 2 months ago

Is this error been fixed?

error: Package ‘glibc-nolibgcc-2.39-5’ in /nix/store/qxrwp9qzj2by5vqy4gm6f29njjkw4cna-source/pkgs/development/libraries/glibc/default.nix:184 is not available on the requested hostPlatform:
         hostPlatform.config = "aarch64-apple-darwin"

i cant test it right now since i don't have my mac around at the weekend.

Jint-lzxy commented 1 month ago

can u please help me do a sanity check to ensure that the executables are correctly linked on macOS?

sure, let me check. hope i will know how to use those tools soon lol

@CharlesChiuGit Apple does indeed have a thorough documentation on dynamic library usage tucked away in its documentation archives (way better than what it offers nowadays lol). It's definitely worth a look if u're into this stuff XD

misumisumi commented 1 month ago

@CharlesChiuGit @CharlesChiuGit The wiki needs to be updated. We'll be working on that soon. We'll report back here when it's done.