Skip to content

Instantly share code, notes, and snippets.

@lqdev
Created March 18, 2026 02:04
Show Gist options
  • Select an option

  • Save lqdev/7f4b59c2edcd73e676dc83e9c7b0966b to your computer and use it in GitHub Desktop.

Select an option

Save lqdev/7f4b59c2edcd73e676dc83e9c7b0966b to your computer and use it in GitHub Desktop.
Install GitHub Copilot CLI on NixOS

NixOS Copilot CLI Declarative Install Guide

Overview

This document describes a **declarative installation of the GitHub Copilot CLI** on NixOS (25.11).

This method creates a small local Nix package that:

  • installs the Copilot CLI via npm
  • works with NixOS’s dynamic linking model using nix-ld
  • integrates with the system configuration

Prerequisites

  • A machine running **NixOS 25.11**
  • A **GitHub Copilot subscription** (required for login)
  • Familiarity with editing /etc/nixos/configuration.nix

Directory Layout

You will create:

PathDescription
etc/nixos/pkgslocal package definitions
copilot-cli.nixwrapper package for Copilot CLI

Step 1 — Create the Local Package

sudo mkdir -p /etc/nixos/pkgs
sudo nano /etc/nixos/pkgs/copilot-cli.nix

Paste this content into copilot-cli.nix:

{ pkgs }:

pkgs.writeShellScriptBin "copilot" ''
  #!/usr/bin/env bash
  set -euo pipefail

  # Local installation directory
  export PREFIX="$HOME/.local/share/copilot-cli"
  export NPM_CONFIG_PREFIX="$PREFIX"

  # Ensure Node from Nixpkgs
  export PATH="${pkgs.nodejs_22}/bin:$PREFIX/bin:$PATH"

  if ! command -v copilot >/dev/null; then
    echo "Installing GitHub Copilot CLI..."
    mkdir -p "$PREFIX"
    npm install -g @github/copilot@latest
  fi

  exec "$PREFIX/bin/copilot" "$@"
''

Step 2 — Edit system configuration

Open your system config:

sudo nano /etc/nixos/configuration.nix

Add this inside the top‑level config block:

{ config, pkgs, ... }:

let
  copilot-cli = pkgs.callPackage ./pkgs/copilot-cli.nix {};
in {
  ;; Enable nix-ld for dynamic binaries
  programs.nix-ld.enable = true;

  ;; Install the Copilot package
  environment.systemPackages = [
    copilot-cli
  ];

  ;; (Optional) Add extra libs if needed
  ;; programs.nix-ld.libraries = with pkgs; [ openssl zlib ];
}

Step 3 — Rebuild NixOS

Run the rebuild:

sudo nixos-rebuild switch

This step:

  • Enables nix-ld (to support Copilot’s prebuilt native executable)
  • Adds the `copilot` wrapper to your system path

Step 4 — First Run

Run Copilot:

copilot --help

On first run it will:

  • install the real Copilot CLI into ~/.local/share/copilot-cli
  • then launch with –help output

Step 5 — Authenticate

To login:

copilot auth login

Follow the interactive GitHub authentication flow.

Updating Copilot

To update to the latest Copilot CLI:

rm -rf ~/.local/share/copilot-cli
copilot --help

This re‑installs the latest version.

Optional: Dual Alias

If you want both `copilot` and `copilot-cli`:

let
  copilot = pkgs.callPackage ./pkgs/copilot-cli.nix {};
  copilot-cli = pkgs.writeShellScriptBin "copilot-cli" ''
    exec ${copilot}/bin/copilot "$@"
  '';
in {
  environment.systemPackages = [ copilot copilot-cli ];
}

Notes

Org Mode Syntax

Org Mode is plain‑text markup for outlining and documenting. Headings start with `*`, lists are defined with `-` or `+`, and code blocks use `#+BEGIN_SRC … #+END_SRC`. :contentReference[oaicite:1]{index=1}

nix-ld Context

NixOS normally lacks a traditional dynamic loader path (e.g., `/lib64/ld-linux-x86-64.so.2`). Tools like Copilot CLI ship native binaries expecting that path, so we enable nix-ld to allow them to run on NixOS. The nix-ld integration is explicitly supported for just this purpose.

Summary

This process gives you:

  • a **declarative NixOS configuration** for Copilot CLI
  • the ability to run the upstream CLI without polluting global npm installs
  • an easily maintainable, Nix‑friendly workflow

Happy coding!

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