claude-desktop/nix/default.nix
Eddy d315f421ec
All checks were successful
Build AppImage / build (push) Successful in 7m11s
[appimage] Bridge-Deploy: Scripts-Bundle + npm ci im Nix-Wrapper-Modus
Problem: Beim Nix-Wrapper lag nur das Binary unter ~/.local/share/claude-desktop/bin,
aber claude-bridge.js + node_modules waren nirgends deployt → "Bridge nicht gefunden"
beim ersten Chat-Versuch.

Loesung:
- claude.rs: Bridge-Such-Pfad um bin/../scripts erweitert (exe_dir.parent / scripts).
- update.rs: UpdateManifest + UpdateStatus um bundle_filename/bundle_sha256 erweitert.
  Neues Tauri-Command apply_bundle_update: laedt tar.gz, pruefte SHA256, entpackt
  nach ~/.local/share/claude-desktop, ruft npm ci --omit=dev auf. Im AppImage-Modus
  no-op (Bundle ist im AppImage enthalten).
- lib.rs: apply_bundle_update registriert.
- CI: packt scripts/claude-bridge.js + package.json + package-lock.json als
  claude-desktop-bundle_VERSION.tar.gz und laedt neben Binary in die Package Registry.
  update.json v3 enthaelt bundle_filename + bundle_sha256.
- install.sh: Erst-Installer laedt das Bundle, verifiziert SHA, entpackt, fuehrt
  npm ci --omit=dev aus. Holt nodejs bei Bedarf ueber nix-build (analog zu jq).
- UpdateDialog.svelte: ruft im Nix-Modus apply_bundle_update vor apply_update auf,
  damit nach dem Neustart Scripts + node_modules aktuell sind.
- nix/default.nix: nodejs_22 + tar + gzip im Wrapper-PATH, damit die App aus dem
  Binary heraus npm ci aufrufen kann.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 13:50:56 +02:00

135 lines
4.3 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Claude Desktop — Nix-Wrapper-Paket
#
# Liefert:
# $out/bin/claude-desktop — Launcher mit LD_LIBRARY_PATH
# $out/bin/claude-desktop-install — Installer (kopiert Binary nach ~/.local/share)
# $out/share/applications/… — Desktop-Entry
# $out/share/icons/… — Icon
#
# Das eigentliche Binary lebt unter ~/.local/share/claude-desktop/bin/claude-desktop
# (writable), damit der Auto-Updater es ersetzen kann. Nix-Store ist read-only und
# waere deshalb inkompatibel mit dem Rename-Trick in apply_update().
#
# Einbinden in /etc/nixos/configuration.nix:
#
# environment.systemPackages = [
# (import /pfad/zum/claude-desktop/nix/default.nix { inherit pkgs; })
# ];
#
# Oder per home-manager:
# home.packages = [ (import ./claude-desktop/nix/default.nix { inherit pkgs; }) ];
{ pkgs ? import <nixpkgs> {} }:
let
# Alle Laufzeit-Libs, die das Tauri-Binary braucht (parallel zu shell.nix).
runtimeLibs = with pkgs; [
webkitgtk_4_1
libappindicator-gtk3
librsvg
gtk3
glib
cairo
pango
gdk-pixbuf
libsoup_3
at-spi2-atk
openssl
];
# Laufzeit-Binaries die die App spawnen muss (node fuer claude-bridge.js,
# npm fuer apply_bundle_update, tar fuer Bundle-Extract)
runtimeBins = [ pkgs.nodejs_22 pkgs.gnutar pkgs.gzip ];
in
pkgs.stdenv.mkDerivation {
pname = "claude-desktop";
version = "0.1.0";
# Keine Quelldateien — Wir packen nur Wrapper + Desktop-Entry
dontUnpack = true;
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/share/applications $out/share/icons/hicolor/256x256/apps
# 1) Launcher: startet das User-Binary mit Nix-LD_LIBRARY_PATH
cat > $out/bin/claude-desktop <<'LAUNCHER'
#!${pkgs.bash}/bin/bash
# Claude Desktop NixOS-Launcher
set -e
APP_DIR="$HOME/.local/share/claude-desktop"
BIN="$APP_DIR/bin/claude-desktop"
if [ ! -x "$BIN" ]; then
echo " Claude-Desktop-Binary nicht gefunden: $BIN" >&2
echo "" >&2
echo "Erst installieren (aus fertigem Build in /tmp/claude-target):" >&2
echo " claude-desktop-install" >&2
echo "" >&2
echo "Oder neu bauen im Repo:" >&2
echo " CARGO_TARGET_DIR=/tmp/claude-target \\" >&2
echo " nix-shell shell.nix --run 'npm ci && npm run tauri build'" >&2
echo " claude-desktop-install" >&2
exit 1
fi
# Marker fuer update.rs: wir laufen unter Nix-Wrapper
export CLAUDE_DESKTOP_NIX_WRAPPER=1
export CLAUDE_DESKTOP_BIN="$BIN"
exec "$BIN" "$@"
LAUNCHER
chmod +x $out/bin/claude-desktop
# LD_LIBRARY_PATH + PATH dauerhaft ans Launcher-Script binden
# PATH: node/npm/tar muessen fuer die Bridge und apply_bundle_update verfuegbar sein
wrapProgram $out/bin/claude-desktop \
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath runtimeLibs} \
--prefix PATH : ${pkgs.lib.makeBinPath runtimeBins}
# 2) Installer: kopiert ein frisch gebautes Binary an den Ziel-Ort
cat > $out/bin/claude-desktop-install <<'INSTALLER'
#!${pkgs.bash}/bin/bash
set -e
SRC="''${1:-/tmp/claude-target/release/claude-desktop}"
DEST_DIR="$HOME/.local/share/claude-desktop/bin"
DEST="$DEST_DIR/claude-desktop"
if [ ! -x "$SRC" ]; then
echo " Quelle nicht gefunden oder nicht ausfuehrbar: $SRC" >&2
echo "" >&2
echo "Erst bauen:" >&2
echo " cd <repo>; CARGO_TARGET_DIR=/tmp/claude-target \\" >&2
echo " nix-shell shell.nix --run 'npm ci && npm run tauri build'" >&2
exit 1
fi
mkdir -p "$DEST_DIR"
cp "$SRC" "$DEST"
chmod +x "$DEST"
echo " Claude Desktop installiert nach $DEST"
echo " Starten mit: claude-desktop (oder aus KDE-Menue)"
INSTALLER
chmod +x $out/bin/claude-desktop-install
# 3) Desktop-Entry
cp ${./claude-desktop.desktop} $out/share/applications/claude-desktop.desktop
# 4) Icon
cp ${../src-tauri/icons/icon.png} $out/share/icons/hicolor/256x256/apps/claude-desktop.png
runHook postInstall
'';
meta = with pkgs.lib; {
description = "Native Desktop-App fuer Claude Code (Wrapper-Paket, Binary in ~/.local/share)";
homepage = "https://git.data-it-solution.de/data/claude-desktop";
license = licenses.mit;
platforms = platforms.linux;
mainProgram = "claude-desktop";
};
}