19 src = fetchFromGitHub {
23 hash = "sha256-6z5QoJk81NEP115uW+2ah7vxpDz8XQUmMLESPsZT9uU=";
26 makeCacheWritable = true; # sharp tries to build stuff in node_modules
27 ELECTRON_SKIP_BINARY_DOWNLOAD = true;
29 npmDepsHash = "sha256-jvGvhgNhY+wz/DFS7NDtmzKXbhHbNF3i0qVQoFFeB0M=";
31 dontNpmBuild = true; # missing script: build
37 ] ++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook; # for onnx libs
40 (lib.getLib stdenv.cc.cc) # for libstdc++.so, required by onnxruntime
41 vips # or it will try to download from the Internet
46 mkdir -p $out/{bin,share}
47 cp -r . $out/share/chatd
49 for bin in ollama-darwin ollama-linux; do
50 makeWrapper ${lib.getExe ollama} $out/share/chatd/src/service/ollama/runners/$bin
53 makeWrapper ${lib.getExe electron} $out/bin/chatd \
54 --add-flags $out/share/chatd/src/index.js \
55 --chdir $out/share/chatd \
56 --set-default ELECTRON_FORCE_IS_PACKAGED 1
61 substituteInPlace $out/share/chatd/node_modules/@xenova/transformers/src/env.js \
62 --replace-fail "import fs from 'fs';" "import fs from 'fs';import os from 'os';" \
63 --replace-fail 'path.dirname(path.dirname(url.fileURLToPath(import.meta.url)))' 'path.join(os.homedir(), ".cache", "chatd")'
65 rm -rf $out/share/electron{,-winstaller} $(find $out -name 'win32')
66 find $out/share/chatd/node_modules -name '*.exe' -or -name '*.dll' -or -name '*.pdb' -delete
68 lib.concatStringsSep " " (
70 !stdenv.hostPlatform.isx86_64
71 ) "$out/share/chatd/node_modules/onnxruntime-node/bin/napi-v3/*/x64")
73 !stdenv.hostPlatform.isAarch64
74 ) "$out/share/chatd/node_modules/onnxruntime-node/bin/napi-v3/*/arm64")
76 !stdenv.hostPlatform.isDarwin
77 ) "$out/share/chatd/node_modules/onnxruntime-node/bin/napi-v3/darwin")
79 !stdenv.hostPlatform.isLinux
80 ) "$out/share/chatd/node_modules/onnxruntime-node/bin/napi-v3/linux")
85 passthru.updateScript = gitUpdater { rev-prefix = "v"; };
88 description = "Chat with your documents using local AI";
89 homepage = "https://github.com/BruceMacD/chatd";
90 changelog = "https://github.com/BruceMacD/chatd/releases/tag/v${version}";
91 license = lib.licenses.mit;
92 maintainers = [ lib.maintainers.lucasew ];
93 mainProgram = "chatd";
94 platforms = electron.meta.platforms;