@github/copilot-language-serverをNixで扱う時のメモ

Table of Contents

Introduction

@github/copilot-language-servertakeokunn/nixos-configuration 上で扱えるようにしたのでメモしておく。

Background

  • copilot.el のバージョンが上がった
  • @github/copilot-language-server をnpmでインストールして使う必要があった
  • 以下の要件を満たしたい
    • Nixでパッケージングしたい
    • Neovimなどのエディタでも汎用的に使えるようにしたい

対応手順

1. node2nixでパッケージングする

node2nix/node-packages.json に以下のような記述をした。

["@github/copilot-language-server"]

以下のshell scriptを実行するとファイルが生成された。

  • node2nix/default.nix
  • node2nix/node-env.nix
  • node2nix/node-packages.nix
$ nix-shell -p nodePackages.node2nix --command "node2nix -i ./node-packages.json -o node-packages.nix"

2. 実行ファイルを取得する

node2nix/default.nix をimportするとpackageが読み込めるようになった。

nodePkgs = pkgs.callPackage ../node2nix { inherit pkgs; };

copilot-language-server は以下のようなディレクトリ構造になっている。

$ dust native/

 65M ├─┬ native/darwin-x64
 65M │ └── native/darwin-x64/copilot-language-server
 60M ├─┬ native/darwin-arm64
 60M │ └── native/darwin-arm64/copilot-language-server
 59M ├─┬ native/linux-x64
 59M │ └── native/linux-x64/copilot-language-server
 50M └─┬ native/win32-x64
 50M   └── native/win32-x64/copilot-language-server.exe

そこで、platformごとに対応表を作って COPILOT_LANGUAGE_SERVER_PATH にPATHを通してあげた。

{ pkgs, nodePkgs }:
let
  platforms = {
    "x86_64-linux" = "linux-amd64";
    "aarch64-linux" = "linux-aarch64";
    "x86_64-darwin" = "darwin-amd64";
    "aarch64-darwin" = "darwin-arm64";
  };
  platform = builtins.getAttr pkgs.system platforms;
in
{
  home.packages = [ nodePkgs."@github/copilot-language-server" ];

  programs.fish = {
    interactiveShellInit = ''
      set -gx COPILOT_LANGUAGE_SERVER_PATH ${
        nodePkgs."@github/copilot-language-server"
      }/lib/node_modules/@github/copilot-language-server/native/${platform}/copilot-language-server
    '';
  };
}

2025/03/27(Mon) 現在、以下のような環境変数が定義されている。

$ echo $COPILOT_LANGUAGE_SERVER_PATH
/nix/store/314dbj3vqb5s0f37gszm948arm37layx-_at_github_slash_copilot-language-server-1.291.0/lib/node_modules/@github/copilot-language-server/native/darwin-arm64/copilot-language-server

3. copilot.elにPATHを通す

exec-path-from-shell:

(setopt exec-path-from-shell-variables '("PATH" "TERM" "SSH_AUTH_SOCK" "COPILOT_LANGUAGE_SERVER_PATH"))

copilot.el:

(setopt copilot-server-executable (getenv "COPILOT_LANGUAGE_SERVER_PATH"))

終わりに

問題なく使えるようになってうれしい。今後ともcopilotを使い倒していきたい。