Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copilot-language-server: fix dynamically linked error in copilot-language-server derivation #391748

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tanya1866
Copy link
Contributor

Fixes the "dynamically linked executable" error by using autoPatchelfHook

Remaining Issue: The binary still fails with a Node.js pkg error (SyntaxError: Invalid or unexpected token). This appears to be a problem with the prebuilt binary expecting a traditional FHS structure, which may require additional work (e.g., buildFHSUserEnv).

Testing Steps:
nix-build -A copilot-language-server
./result/bin/copilot-language-server --version # Still errors, but no "dynamically linked" issue.

Closes #391730 (partially)
Maintainers: @arunoruto @wattmto

@arunoruto
Copy link
Contributor

arunoruto commented Mar 21, 2025

Thanks for the PR!
The content of the PR looks good, but there are a few things to be tweaked:

  • If stdenv is being needed, maybe the stdenvNoCC should be replaced with it
  • The formatting is not right (see PR checker complaining how to solve it)
  • Commits which are not related to this PR have been pushed
  • The commit name should have the format: copilot-language-server: <name of the fix>

I am trying to replicate this issue on my machine, but the binary behaves normally, both from nixpkgs and building it myself...

@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch from 776825f to 7b3433a Compare March 21, 2025 10:42
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` and removed 10.rebuild-linux: 1 labels Mar 21, 2025
@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch from 7b3433a to ab84243 Compare March 21, 2025 10:56
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux and removed 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 labels Mar 21, 2025
@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch 2 times, most recently from 4841009 to 80caa40 Compare March 21, 2025 11:10
@github-actions github-actions bot added 10.rebuild-darwin: 1 10.rebuild-darwin: 1-10 10.rebuild-linux: 1 10.rebuild-linux: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Mar 21, 2025
@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch 3 times, most recently from 7642304 to 1250a76 Compare March 21, 2025 11:28
@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch 2 times, most recently from 6c90dee to 779c961 Compare March 22, 2025 10:12
@tanya1866
Copy link
Contributor Author

okiee

@tanya1866 tanya1866 requested a review from drupol March 23, 2025 12:02
@drupol
Copy link
Contributor

drupol commented Mar 23, 2025

Here's the diff to fix everything. Please make it in 2 commits as I updated the version too.

diff --git a/pkgs/by-name/co/copilot-language-server/package.nix b/pkgs/by-name/co/copilot-language-server/package.nix
index da30bc7e2f..8ee4136f07 100644
--- a/pkgs/by-name/co/copilot-language-server/package.nix
+++ b/pkgs/by-name/co/copilot-language-server/package.nix
@@ -4,7 +4,6 @@
   fetchzip,
   autoPatchelfHook,
   nix-update-script,
-  versionCheckHook,
 }:
 
 let
@@ -28,25 +27,21 @@
 
 stdenv.mkDerivation (finalAttrs: {
   pname = "copilot-language-server";
-  version = "1.280.0";
+  version = "1.290.0";
 
   src = fetchzip {
     url = "https://github.com/github/copilot-language-server-release/releases/download/${finalAttrs.version}/copilot-language-server-native-${finalAttrs.version}.zip";
-    hash = "sha256-s47WaWH0ov/UazQCOFBUAO6ZYgCmCpQ1o79KjAVJFh4=";
+    hash = "sha256-ELOSeb3Z7AI8pjDhtUIRoaf+4UXjXKEu/OJ2CLQno6A=";
     stripRoot = false;
   };
 
-  npmDepsHash = "sha256-PLX/mN7xu8gMh2BkkyTncP3+rJ3nBmX+pHxl0ONXbe4=";
-
   nativeBuildInputs = [
     autoPatchelfHook
-    versionCheckHook
   ];
+
   buildInputs = [ stdenv.cc.cc.lib ];
 
-  doCheck = true;
-  checkFlags = "--version";
-  versionExe = "./${os}-${arch}/copilot-language-server";
+  dontStrip = true;
 
   installPhase = ''
     runHook preInstall
@@ -56,8 +51,6 @@
     runHook postInstall
   '';
 
-  dontStrip = true;
-
   passthru.updateScript = nix-update-script { };
 
   meta = {

@tanya1866
Copy link
Contributor Author

sure!!

@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch from f33a00a to 1dd03e7 Compare March 23, 2025 16:25
Copy link
Contributor

@drupol drupol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please make sure this PR only has 2 commits:

  • The first one for fixing the original issue
  • The second one to update to 1.290.0

Make sure you know how to write proper commit log messages.

@arunoruto
Copy link
Contributor

For commit messages visit the following two links:

Resolved dynamically linked error by replacing stdenvNoCC with stdenv and adding autoPatchelfHook.
Updated copilot-language-server to 1.290.0
@drupol drupol marked this pull request as draft March 23, 2025 18:08
@tanya1866 tanya1866 force-pushed the copilot-language-server-fix branch from 1dd03e7 to b4915b8 Compare March 23, 2025 18:08
@tanya1866
Copy link
Contributor Author

does it look alright?

@drupol drupol marked this pull request as ready for review March 23, 2025 18:11
Copy link
Contributor

@drupol drupol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect now!

@tanya1866
Copy link
Contributor Author

thank you :)

@arunoruto
Copy link
Contributor

I guess we won't merge this PR as long as the syntax error is present?
I am currently trying to fix it using FHS envs. Maybe someone can run nix run github:arunoruto/flake#copilot-language-server -L -- --version and tell me if the output is as expected?

@drupol
Copy link
Contributor

drupol commented Mar 23, 2025

I guess we won't merge this PR as long as the syntax error is present?

Which syntax error are you talking about?

@arunoruto
Copy link
Contributor

I guess we won't merge this PR as long as the syntax error is present?

Which syntax error are you talking about?

This one: #391748 (comment)

@drupol
Copy link
Contributor

drupol commented Mar 23, 2025

Oooh right ! So this PR doesn't fix anything then?

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Mar 23, 2025
@arunoruto
Copy link
Contributor

Oooh right ! So this PR doesn't fix anything then?

It's not for me, but please test it yourself and correct me if I'm wrong. It seems like the autopatch script breaks the binary. Maybe it is something specific to node binaries.

While I approve the state of the code, I will only improve the PR if it solves the problem. I am not even sure how, where, or when it happens; the environment when it happens isn't clear.

@drupol drupol marked this pull request as draft March 25, 2025 06:57
@arunoruto
Copy link
Contributor

It seems like using an FHS solves the issue (the issue author tested it himself). I can either create a PR myself or my config can be implemented here, I am fine with both approaches.

I am not sure on how to treat the problem.. either have one package which is build using fhs or have two packages, one without and one with fhs. I implemented the solution using a flag, but it can be split into two files if needed:

{
  lib,
  stdenv,
  buildFHSEnv,
  fetchzip,
  nix-update-script,
  withFHS ? true,
}:

let
  arch =
    {
      aarch64-darwin = "arm64";
      aarch64-linux = "arm64";
      x86_64-darwin = "x64";
      x86_64-linux = "x64";
    }
    ."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
  os =
    {
      aarch64-darwin = "darwin";
      aarch64-linux = "linux";
      x86_64-darwin = "darwin";
      x86_64-linux = "linux";
    }
    ."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
  copilot-language-server = stdenv.mkDerivation (finalAttrs: {
    pname = "copilot-language-server";
    version = "1.280.0";
    # version = "1.286.0";
    # version = "1.290.0";

    src = fetchzip {
      url = "https://github.com/github/copilot-language-server-release/releases/download/${finalAttrs.version}/copilot-language-server-native-${finalAttrs.version}.zip";
      hash = "sha256-s47WaWH0ov/UazQCOFBUAO6ZYgCmCpQ1o79KjAVJFh4=";
      # hash = "sha256-yYsfp3Hdph8zOTkycjjV8nnWe0bT1QYgVSzSHVJ6HzM=";
      # hash = "sha256-ELOSeb3Z7AI8pjDhtUIRoaf+4UXjXKEu/OJ2CLQno6A=";
      stripRoot = false;
    };

    installPhase = ''
      runHook preInstall

      install -Dt "$out"/bin "${os}-${arch}"/copilot-language-server

      runHook postInstall
    '';

    dontStrip = true;

    passthru.updateScript = nix-update-script { };

    meta = {
      description = "Use GitHub Copilot with any editor or IDE via the Language Server Protocol";
      homepage = "https://github.com/features/copilot";
      # license = {
      #   deprecated = false;
      #   free = false;
      #   fullName = "GitHub Copilot Product Specific Terms";
      #   redistributable = false;
      #   shortName = "GitHub Copilot License";
      #   url = "https://github.com/customer-terms/github-copilot-product-specific-terms";
      # };
      mainProgram = "copilot-language-server";
      platforms = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];
      maintainers = with lib.maintainers; [
        arunoruto
        wattmto
      ];
    };
  });

  copilot-language-server-fhs = buildFHSEnv {
    name = "copilot-language-server";
    targetPkgs = pkgs: [
      pkgs.stdenv.cc.cc.lib # libstdc++.so.6
      # pkgs.zlib # libz.so.1
      # pkgs.openssl # libssl.so.3/libcrypto.so.3
    ];
    runScript = "${copilot-language-server}/bin/copilot-language-server";

    meta = copilot-language-server.meta // {
      description = copilot-language-server.meta.description + " (FHS-wrapped)";
    };
  };
in
if withFHS then copilot-language-server-fhs else copilot-language-server

(The licence was commented out, since it complained that it was unfree during local building)

@drupol
Copy link
Contributor

drupol commented Mar 25, 2025

Thanks ! I don't have the solution to your question, but have you checked how similar packages are made in nixpkgs ?

@arunoruto
Copy link
Contributor

arunoruto commented Mar 25, 2025

Thanks ! I don't have the solution to your question, but have you checked how similar packages are made in nixpkgs ?

Editors have sometimes a normal version and a -fhs version. Both are available. But I haven't seen such a situation with LSPs...
I guess having both versions would be fine with a small hint in the description to use the FHS version if dependency errors happen.

I am starting to believe, that the problem is related to the users nixpkgs version. Folks on stable releases don't have that problem and those using unstable face the issue... Not sure what change unstable introduced that created this problem...
But if this issue is consistent with 25.05, we can just drop the non FHS version and make the FHS version the default one.

@drupol
Copy link
Contributor

drupol commented Mar 25, 2025

Let's move on then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

copilot-language-server: copilot-language-server fails to lauch
4 participants