Visual Studio Code Insiders is a version of VS Code that includes the latest features and updates. It is ideal for developers who want to try out new features before they are released in the stable version. However, there is no prebuilt version of VS Code Insiders in nixpkgs, so the package needs to be installed with an overlay.

There is an example of how to do this on the NixOS Wiki, but I encountered several issues when using it. I made this work using a different approach:

Step 1: Define the Overlay

First, define the overlay to override the default VS Code package with the Insiders version:

{
  pkgs,
  variables,
  # osConfig,
  ...
}: let
  inherit (variables) fullName email;

  vscode-insiders = (pkgs.vscode.override { isInsiders = true; }).overrideAttrs (oldAttrs: rec {
    version = "latest";
    name = "vscode-insiders-${version}";

    src = pkgs.fetchurl {
      url = "https://code.visualstudio.com/sha/download?build=insider&os=darwin-arm64";
      name = "VSCode-darwin-arm64.zip";
      sha256 = ""; # Updated by just update-vscode-insiders
    };

    buildInputs = oldAttrs.buildInputs ++ [ pkgs.krb5 pkgs.darwin.apple_sdk.frameworks.Security ];
    
    installPhase = ''
      mkdir -p $out/Applications
      unzip -q -o ${src}
      mv "Visual Studio Code - Insiders.app" "$out/Applications/"
      chmod -R +x "$out/Applications/Visual Studio Code - Insiders.app/Contents/MacOS"
      chmod -R +x "$out/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks"
    '';
  });
in {
  ...
};

Step 2: Enable VS Code

Next, enable VS Code in your configuration:

programs.vscode.enable = true;

Step 3: Add a justfile job to update the hash

update-vscode-insiders:
    #!/usr/bin/env bash
    set -euo pipefail
    echo "Fetching latest VSCode Insiders build..."
    URL='https://code.visualstudio.com/sha/download?build=insider&os=darwin-arm64'
    HASH=$(nix-prefetch-url --quiet "$URL" --name vscode-insider.zip)
    if [ -z "$HASH" ]; then
        echo "Error: Failed to fetch hash" >&2
        exit 1
    fi
    echo "Updating hash in programs.nix..."
    sed -i '' 's/sha256 = "[^"]*"/sha256 = "'"$HASH"'"/' modules/darwin/programs.nix

With these steps, you can now install Visual Studio Code Insiders on macOS using nix. This approach ensures that you have the latest version of VS Code Insiders with the necessary dependencies.