diff --git a/flake.lock b/flake.lock index f31b889..d130367 100644 --- a/flake.lock +++ b/flake.lock @@ -101,9 +101,7 @@ "blueprint": "blueprint", "bun2nix": "bun2nix", "flake-parts": "flake-parts", - "nixpkgs": [ - "nixpkgs" - ], + "nixpkgs": "nixpkgs", "systems": "systems", "treefmt-nix": "treefmt-nix" }, @@ -122,6 +120,22 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1776949667, + "narHash": "sha256-GMSVw35Q+294GlrTUKlx087E31z7KurReQ1YHSKp5iw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01fbdeef22b76df85ea168fbfe1bfd9e63681b30", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1776734388, "narHash": "sha256-vl3dkhlE5gzsItuHoEMVe+DlonsK+0836LIRDnm6MXQ=", @@ -140,7 +154,7 @@ "root": { "inputs": { "llm-agents": "llm-agents", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_2", "t3code": "t3code" } }, diff --git a/flake.nix b/flake.nix index ae546f9..56cfb7b 100644 --- a/flake.nix +++ b/flake.nix @@ -3,10 +3,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; - llm-agents = { - url = "github:numtide/llm-agents.nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + llm-agents.url = "github:numtide/llm-agents.nix"; t3code.url = "github:pingdotgg/t3code"; t3code.flake = false; }; diff --git a/packages/common.nix b/packages/common.nix index 380f846..ddca124 100644 --- a/packages/common.nix +++ b/packages/common.nix @@ -60,25 +60,25 @@ in { ''; buildPhase = '' - runHook preBuild + runHook preBuild - export HOME="$TMPDIR" - export BUN_INSTALL_CACHE_DIR="$(mktemp -d)" - ${extraEnv} + export HOME="$TMPDIR" + export BUN_INSTALL_CACHE_DIR="$(mktemp -d)" + ${extraEnv} - bun install \ - --frozen-lockfile \ - --ignore-scripts \ - --backend=copyfile \ - --linker=hoisted \ - --no-progress \ -${renderBunInstallFlags installFlags} -${renderBunFilters filters} + bun install \ + --frozen-lockfile \ + --ignore-scripts \ + --backend=copyfile \ + --linker=hoisted \ + --no-progress \ + ${renderBunInstallFlags installFlags} + ${renderBunFilters filters} - bun --bun ${./scripts/canonicalize-node-modules.ts} - bun --bun ${./scripts/normalize-bun-binaries.ts} + bun --bun ${./scripts/canonicalize-node-modules.ts} + bun --bun ${./scripts/normalize-bun-binaries.ts} - runHook postBuild + runHook postBuild ''; installPhase = '' @@ -109,7 +109,11 @@ ${renderBunFilters filters} mkdir -p ./node_modules cp -R ${nodeModules}/. ./node_modules/ chmod -R u+rwX node_modules - if [ ${if chmodBins then "true" else "false"} = true ] && [ -d node_modules/.bin ]; then + if [ ${ + if chmodBins + then "true" + else "false" + } = true ] && [ -d node_modules/.bin ]; then chmod -R u+x node_modules/.bin fi patchShebangs node_modules diff --git a/packages/node-modules-layers.nix b/packages/node-modules-layers.nix index b243c3d..5f07d61 100644 --- a/packages/node-modules-layers.nix +++ b/packages/node-modules-layers.nix @@ -49,7 +49,6 @@ export npm_config_build_from_source=true ''; }; - in { inherit t3codeNodeModulesBase diff --git a/packages/t3code-desktop/default.nix b/packages/t3code-desktop/default.nix index a5a344a..6e1feb3 100644 --- a/packages/t3code-desktop/default.nix +++ b/packages/t3code-desktop/default.nix @@ -3,6 +3,7 @@ src, asar, stdenv, + symlinkJoin, bun, codex ? null, claudeCode ? null, @@ -35,11 +36,7 @@ pname = "t3code-desktop"; version = desktopPackageJson.version; -in - assert lib.assertMsg (!withCodex || codex != null) "withCodex requires a codex package"; - assert lib.assertMsg (!withClaudeCode || claudeCode != null) "withClaudeCode requires a claudeCode package"; - assert lib.assertMsg (!withOpencode || opencode != null) "withOpencode requires an opencode package"; - stdenv.mkDerivation (finalAttrs: { + basePackage = stdenv.mkDerivation (finalAttrs: { inherit pname version; inherit src; @@ -178,16 +175,9 @@ in --set-default ELECTRON_FORCE_IS_PACKAGED 1 \ --set-default ELECTRON_IS_DEV 0 \ --prefix PATH : ${lib.makeBinPath [ - git - xdg-utils - ]} \ - ${lib.optionalString withCodex '' - --prefix PATH : "${lib.makeBinPath [ codex ]}" \ - ''}${lib.optionalString withClaudeCode '' - --prefix PATH : "${lib.makeBinPath [ claudeCode ]}" \ - ''}${lib.optionalString withOpencode '' - --prefix PATH : "${lib.makeBinPath [ opencode ]}" \ - ''} \ + git + xdg-utils + ]} \ --add-flags "$out/share/${pname}/resources/app.asar" export out @@ -205,4 +195,34 @@ in platforms = ["x86_64-linux"]; sourceProvenance = with lib.sourceTypes; [fromSource]; }; - }) + }); + withAgentPath = withCodex || withClaudeCode || withOpencode; + agentPath = lib.makeBinPath ( + lib.optionals withCodex [codex] + ++ lib.optionals withClaudeCode [claudeCode] + ++ lib.optionals withOpencode [opencode] + ); +in + assert lib.assertMsg (!withCodex || codex != null) "withCodex requires a codex package"; + assert lib.assertMsg (!withClaudeCode || claudeCode != null) "withClaudeCode requires a claudeCode package"; + assert lib.assertMsg (!withOpencode || opencode != null) "withOpencode requires an opencode package"; + if withAgentPath + then + symlinkJoin { + inherit pname version; + name = "${pname}-${version}"; + paths = [basePackage]; + nativeBuildInputs = [makeWrapper]; + postBuild = '' + wrapProgram "$out/bin/t3code" \ + --prefix PATH : "${agentPath}" + + rm -f "$out/share/applications/t3code.desktop" + install -Dm644 ${basePackage}/share/applications/t3code.desktop \ + "$out/share/applications/t3code.desktop" + substituteInPlace "$out/share/applications/t3code.desktop" \ + --replace-fail "${basePackage}/bin/t3code" "$out/bin/t3code" + ''; + meta = basePackage.meta; + } + else basePackage diff --git a/packages/t3code-server/default.nix b/packages/t3code-server/default.nix index 5dc891b..4af0a7c 100644 --- a/packages/t3code-server/default.nix +++ b/packages/t3code-server/default.nix @@ -2,6 +2,7 @@ lib, src, stdenv, + symlinkJoin, bun, codex ? null, claudeCode ? null, @@ -28,11 +29,7 @@ pname = "t3code-server"; version = serverPackageJson.version; -in - assert lib.assertMsg (!withCodex || codex != null) "withCodex requires a codex package"; - assert lib.assertMsg (!withClaudeCode || claudeCode != null) "withClaudeCode requires a claudeCode package"; - assert lib.assertMsg (!withOpencode || opencode != null) "withOpencode requires an opencode package"; - stdenv.mkDerivation (finalAttrs: { + basePackage = stdenv.mkDerivation (finalAttrs: { inherit pname version; inherit src; @@ -116,13 +113,6 @@ in cp -R --no-preserve=mode packages/shared "$out/libexec/t3code/packages/" makeWrapper ${lib.getExe nodejs} "$out/bin/t3" \ - ${lib.optionalString withCodex '' - --prefix PATH : "${lib.makeBinPath [ codex ]}" \ - ''}${lib.optionalString withClaudeCode '' - --prefix PATH : "${lib.makeBinPath [ claudeCode ]}" \ - ''}${lib.optionalString withOpencode '' - --prefix PATH : "${lib.makeBinPath [ opencode ]}" \ - ''} \ --add-flags "$out/libexec/t3code/apps/server/dist/bin.mjs" runHook postInstall @@ -136,4 +126,28 @@ in platforms = lib.platforms.unix; sourceProvenance = with lib.sourceTypes; [fromSource]; }; - }) + }); + withAgentPath = withCodex || withClaudeCode || withOpencode; + agentPath = lib.makeBinPath ( + lib.optionals withCodex [codex] + ++ lib.optionals withClaudeCode [claudeCode] + ++ lib.optionals withOpencode [opencode] + ); +in + assert lib.assertMsg (!withCodex || codex != null) "withCodex requires a codex package"; + assert lib.assertMsg (!withClaudeCode || claudeCode != null) "withClaudeCode requires a claudeCode package"; + assert lib.assertMsg (!withOpencode || opencode != null) "withOpencode requires an opencode package"; + if withAgentPath + then + symlinkJoin { + inherit pname version; + name = "${pname}-${version}"; + paths = [basePackage]; + nativeBuildInputs = [makeBinaryWrapper]; + postBuild = '' + wrapProgram "$out/bin/t3" \ + --prefix PATH : "${agentPath}" + ''; + meta = basePackage.meta; + } + else basePackage