Refactor server and desktop Nix packaging
- Move shared Node module setup into `packages/common.nix` - Rename package entrypoints under `packages/server` and `packages/desktop` - Update flake outputs to expose `t3code-server` as the default
This commit is contained in:
@@ -27,33 +27,32 @@
|
|||||||
packages = forAllSystems (
|
packages = forAllSystems (
|
||||||
system: let
|
system: let
|
||||||
pkgs = import nixpkgs {inherit system;};
|
pkgs = import nixpkgs {inherit system;};
|
||||||
t3 = pkgs.callPackage ./packages/server-package.nix {src = t3code;};
|
t3code-server = pkgs.callPackage ./packages/server {src = t3code;};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit t3;
|
inherit t3code-server;
|
||||||
t3code = t3;
|
default = t3code-server;
|
||||||
default = t3;
|
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs (system == "x86_64-linux") {
|
// lib.optionalAttrs (system == "x86_64-linux") {
|
||||||
t3code-desktop = pkgs.callPackage ./packages/desktop-package.nix {src = t3code;};
|
t3code-desktop = pkgs.callPackage ./packages/desktop {src = t3code;};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
apps = forAllSystems (system: {
|
apps = forAllSystems (system: {
|
||||||
default = {
|
default = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${self.packages.${system}.t3}/bin/t3";
|
program = "${self.packages.${system}.t3code-server}/bin/t3";
|
||||||
};
|
};
|
||||||
t3 = {
|
t3code-server = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${self.packages.${system}.t3}/bin/t3";
|
program = "${self.packages.${system}.t3code-server}/bin/t3";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
checks = forAllSystems (
|
checks = forAllSystems (
|
||||||
system:
|
system:
|
||||||
{
|
{
|
||||||
t3 = self.packages.${system}.t3;
|
t3code-server = self.packages.${system}.t3code-server;
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs (system == "x86_64-linux") {
|
// lib.optionalAttrs (system == "x86_64-linux") {
|
||||||
t3code-desktop = self.packages.${system}.t3code-desktop;
|
t3code-desktop = self.packages.${system}.t3code-desktop;
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
stdenv,
|
||||||
|
bun,
|
||||||
|
nodejs,
|
||||||
|
writableTmpDirAsHomeHook,
|
||||||
|
}: let
|
||||||
|
workspacePreparePatched = [
|
||||||
|
"apps/server/package.json"
|
||||||
|
"apps/web/package.json"
|
||||||
|
"packages/client-runtime/package.json"
|
||||||
|
"packages/contracts/package.json"
|
||||||
|
"packages/effect-acp/package.json"
|
||||||
|
"packages/effect-codex-app-server/package.json"
|
||||||
|
"packages/shared/package.json"
|
||||||
|
];
|
||||||
|
|
||||||
|
renderBunFilters = filters:
|
||||||
|
lib.concatMapStringsSep "\n" (filter: " --filter ${filter} \\") filters;
|
||||||
|
in {
|
||||||
|
inherit workspacePreparePatched;
|
||||||
|
|
||||||
|
mkNodeModules = {
|
||||||
|
pname,
|
||||||
|
version,
|
||||||
|
src,
|
||||||
|
outputHash,
|
||||||
|
filters,
|
||||||
|
extraNativeBuildInputs ? [],
|
||||||
|
impureEnvVars ? [],
|
||||||
|
extraEnv ? "",
|
||||||
|
}:
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "${pname}-node-modules";
|
||||||
|
inherit version src impureEnvVars;
|
||||||
|
|
||||||
|
nativeBuildInputs =
|
||||||
|
[
|
||||||
|
bun
|
||||||
|
nodejs
|
||||||
|
writableTmpDirAsHomeHook
|
||||||
|
]
|
||||||
|
++ extraNativeBuildInputs;
|
||||||
|
|
||||||
|
dontConfigure = true;
|
||||||
|
dontFixup = true;
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
for packageJson in ${lib.concatStringsSep " " workspacePreparePatched}; do
|
||||||
|
substituteInPlace "$packageJson" \
|
||||||
|
--replace-fail '"prepare": "effect-language-service patch"' '"prepare": "true"'
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
|
||||||
|
export HOME="$TMPDIR"
|
||||||
|
export BUN_INSTALL_CACHE_DIR="$(mktemp -d)"
|
||||||
|
${extraEnv}
|
||||||
|
|
||||||
|
bun install \
|
||||||
|
--frozen-lockfile \
|
||||||
|
--ignore-scripts \
|
||||||
|
--linker=hoisted \
|
||||||
|
--no-progress \
|
||||||
|
${renderBunFilters filters}
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
|
cp -R ./node_modules $out
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
|
inherit outputHash;
|
||||||
|
outputHashAlgo = "sha256";
|
||||||
|
outputHashMode = "recursive";
|
||||||
|
};
|
||||||
|
|
||||||
|
mkNodePtyConfigurePhase = {
|
||||||
|
nodeModules,
|
||||||
|
chmodBins ? false,
|
||||||
|
}: ''
|
||||||
|
runHook preConfigure
|
||||||
|
|
||||||
|
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
|
||||||
|
chmod -R u+x node_modules/.bin
|
||||||
|
fi
|
||||||
|
patchShebangs node_modules
|
||||||
|
|
||||||
|
cd node_modules/node-pty
|
||||||
|
node-gyp rebuild
|
||||||
|
node scripts/post-install.js
|
||||||
|
cd "$NIX_BUILD_TOP/$sourceRoot"
|
||||||
|
|
||||||
|
runHook postConfigure
|
||||||
|
'';
|
||||||
|
}
|
||||||
@@ -18,21 +18,20 @@
|
|||||||
writableTmpDirAsHomeHook,
|
writableTmpDirAsHomeHook,
|
||||||
xdg-utils,
|
xdg-utils,
|
||||||
}: let
|
}: let
|
||||||
|
common = import ../common.nix {
|
||||||
|
inherit
|
||||||
|
lib
|
||||||
|
stdenv
|
||||||
|
bun
|
||||||
|
nodejs
|
||||||
|
writableTmpDirAsHomeHook
|
||||||
|
;
|
||||||
|
};
|
||||||
desktopPackageJson = lib.importJSON "${src}/apps/desktop/package.json";
|
desktopPackageJson = lib.importJSON "${src}/apps/desktop/package.json";
|
||||||
|
|
||||||
pname = "t3code-desktop";
|
pname = "t3code-desktop";
|
||||||
version = desktopPackageJson.version;
|
version = desktopPackageJson.version;
|
||||||
|
|
||||||
workspacePreparePatched = [
|
|
||||||
"apps/server/package.json"
|
|
||||||
"apps/web/package.json"
|
|
||||||
"packages/client-runtime/package.json"
|
|
||||||
"packages/contracts/package.json"
|
|
||||||
"packages/effect-acp/package.json"
|
|
||||||
"packages/effect-codex-app-server/package.json"
|
|
||||||
"packages/shared/package.json"
|
|
||||||
];
|
|
||||||
|
|
||||||
desktopItem = makeDesktopItem {
|
desktopItem = makeDesktopItem {
|
||||||
name = "t3code";
|
name = "t3code";
|
||||||
desktopName = "T3 Code";
|
desktopName = "T3 Code";
|
||||||
@@ -47,76 +46,38 @@ in
|
|||||||
inherit src;
|
inherit src;
|
||||||
|
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
patches = [./patches/desktop-nix-autoupdate.patch];
|
patches = [./desktop-nix-autoupdate.patch];
|
||||||
|
|
||||||
nodeModules = stdenv.mkDerivation {
|
|
||||||
pname = "${pname}-node-modules";
|
|
||||||
inherit (finalAttrs) version src;
|
|
||||||
|
|
||||||
|
nodeModules = common.mkNodeModules {
|
||||||
|
inherit (finalAttrs) pname version src;
|
||||||
|
outputHash = "sha256-mzcaRKIymMQb934wrto/mBuKt0KzncbzUQ0rzkCLlC4=";
|
||||||
|
filters = [
|
||||||
|
"./apps/desktop"
|
||||||
|
"./apps/server"
|
||||||
|
"./apps/web"
|
||||||
|
"./packages/client-runtime"
|
||||||
|
"./packages/contracts"
|
||||||
|
"./packages/effect-acp"
|
||||||
|
"./packages/effect-codex-app-server"
|
||||||
|
"./packages/shared"
|
||||||
|
];
|
||||||
impureEnvVars =
|
impureEnvVars =
|
||||||
lib.fetchers.proxyImpureEnvVars
|
lib.fetchers.proxyImpureEnvVars
|
||||||
++ [
|
++ [
|
||||||
"GIT_PROXY_COMMAND"
|
"GIT_PROXY_COMMAND"
|
||||||
"SOCKS_SERVER"
|
"SOCKS_SERVER"
|
||||||
];
|
];
|
||||||
|
extraNativeBuildInputs = [
|
||||||
nativeBuildInputs = [
|
|
||||||
bun
|
|
||||||
gcc
|
gcc
|
||||||
gnumake
|
gnumake
|
||||||
nodejs
|
|
||||||
pkg-config
|
pkg-config
|
||||||
python3
|
python3
|
||||||
writableTmpDirAsHomeHook
|
|
||||||
];
|
];
|
||||||
|
extraEnv = ''
|
||||||
dontConfigure = true;
|
|
||||||
dontFixup = true;
|
|
||||||
|
|
||||||
postPatch = ''
|
|
||||||
for packageJson in ${lib.concatStringsSep " " workspacePreparePatched}; do
|
|
||||||
substituteInPlace "$packageJson" \
|
|
||||||
--replace-fail '"prepare": "effect-language-service patch"' '"prepare": "true"'
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
runHook preBuild
|
|
||||||
|
|
||||||
export HOME="$TMPDIR"
|
|
||||||
export BUN_INSTALL_CACHE_DIR="$(mktemp -d)"
|
|
||||||
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
||||||
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||||||
export npm_config_build_from_source=true
|
export npm_config_build_from_source=true
|
||||||
|
|
||||||
bun install \
|
|
||||||
--frozen-lockfile \
|
|
||||||
--ignore-scripts \
|
|
||||||
--linker=hoisted \
|
|
||||||
--no-progress \
|
|
||||||
--filter ./apps/desktop \
|
|
||||||
--filter ./apps/server \
|
|
||||||
--filter ./apps/web \
|
|
||||||
--filter ./packages/client-runtime \
|
|
||||||
--filter ./packages/contracts \
|
|
||||||
--filter ./packages/effect-acp \
|
|
||||||
--filter ./packages/effect-codex-app-server \
|
|
||||||
--filter ./packages/shared
|
|
||||||
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
runHook preInstall
|
|
||||||
|
|
||||||
cp -R ./node_modules $out
|
|
||||||
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
|
|
||||||
outputHash = "sha256-mzcaRKIymMQb934wrto/mBuKt0KzncbzUQ0rzkCLlC4=";
|
|
||||||
outputHashAlgo = "sha256";
|
|
||||||
outputHashMode = "recursive";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
@@ -142,24 +103,10 @@ in
|
|||||||
npm_config_nodedir = "${nodejs}";
|
npm_config_nodedir = "${nodejs}";
|
||||||
};
|
};
|
||||||
|
|
||||||
configurePhase = ''
|
configurePhase = common.mkNodePtyConfigurePhase {
|
||||||
runHook preConfigure
|
nodeModules = finalAttrs.nodeModules;
|
||||||
|
chmodBins = true;
|
||||||
mkdir -p ./node_modules
|
};
|
||||||
cp -R ${finalAttrs.nodeModules}/. ./node_modules/
|
|
||||||
chmod -R u+rw node_modules
|
|
||||||
if [ -d node_modules/.bin ]; then
|
|
||||||
chmod -R u+x node_modules/.bin
|
|
||||||
fi
|
|
||||||
patchShebangs node_modules
|
|
||||||
|
|
||||||
cd node_modules/node-pty
|
|
||||||
node-gyp rebuild
|
|
||||||
node scripts/post-install.js
|
|
||||||
cd "$NIX_BUILD_TOP/$sourceRoot"
|
|
||||||
|
|
||||||
runHook postConfigure
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
@@ -168,7 +115,7 @@ in
|
|||||||
export BUN_INSTALL_CACHE_DIR="$(mktemp -d)"
|
export BUN_INSTALL_CACHE_DIR="$(mktemp -d)"
|
||||||
|
|
||||||
bun run build:desktop
|
bun run build:desktop
|
||||||
node ${./patches/build-nix-desktop-package.mjs} --output-dir packaged-app
|
node ${./build-nix-desktop-package.mjs} --output-dir packaged-app
|
||||||
cp -R node_modules packaged-app/node_modules
|
cp -R node_modules packaged-app/node_modules
|
||||||
chmod -R u+rwX packaged-app/node_modules
|
chmod -R u+rwX packaged-app/node_modules
|
||||||
patchShebangs packaged-app/node_modules
|
patchShebangs packaged-app/node_modules
|
||||||
@@ -197,9 +144,9 @@ in
|
|||||||
--set-default ELECTRON_FORCE_IS_PACKAGED 1 \
|
--set-default ELECTRON_FORCE_IS_PACKAGED 1 \
|
||||||
--set-default ELECTRON_IS_DEV 0 \
|
--set-default ELECTRON_IS_DEV 0 \
|
||||||
--prefix PATH : ${lib.makeBinPath [
|
--prefix PATH : ${lib.makeBinPath [
|
||||||
git
|
git
|
||||||
xdg-utils
|
xdg-utils
|
||||||
]} \
|
]} \
|
||||||
--add-flags "$out/share/${pname}/resources/app.asar"
|
--add-flags "$out/share/${pname}/resources/app.asar"
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
@@ -9,20 +9,19 @@
|
|||||||
python3,
|
python3,
|
||||||
writableTmpDirAsHomeHook,
|
writableTmpDirAsHomeHook,
|
||||||
}: let
|
}: let
|
||||||
|
common = import ../common.nix {
|
||||||
|
inherit
|
||||||
|
lib
|
||||||
|
stdenv
|
||||||
|
bun
|
||||||
|
nodejs
|
||||||
|
writableTmpDirAsHomeHook
|
||||||
|
;
|
||||||
|
};
|
||||||
serverPackageJson = lib.importJSON "${src}/apps/server/package.json";
|
serverPackageJson = lib.importJSON "${src}/apps/server/package.json";
|
||||||
|
|
||||||
pname = "t3code-server";
|
pname = "t3code-server";
|
||||||
version = serverPackageJson.version;
|
version = serverPackageJson.version;
|
||||||
|
|
||||||
workspacePreparePatched = [
|
|
||||||
"apps/server/package.json"
|
|
||||||
"apps/web/package.json"
|
|
||||||
"packages/client-runtime/package.json"
|
|
||||||
"packages/contracts/package.json"
|
|
||||||
"packages/effect-acp/package.json"
|
|
||||||
"packages/effect-codex-app-server/package.json"
|
|
||||||
"packages/shared/package.json"
|
|
||||||
];
|
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation (finalAttrs: {
|
stdenv.mkDerivation (finalAttrs: {
|
||||||
inherit pname version;
|
inherit pname version;
|
||||||
@@ -30,59 +29,18 @@ in
|
|||||||
|
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
|
|
||||||
nodeModules = stdenv.mkDerivation {
|
nodeModules = common.mkNodeModules {
|
||||||
pname = "${pname}-node-modules";
|
inherit (finalAttrs) pname version src;
|
||||||
inherit (finalAttrs) version src;
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
bun
|
|
||||||
nodejs
|
|
||||||
writableTmpDirAsHomeHook
|
|
||||||
];
|
|
||||||
|
|
||||||
dontConfigure = true;
|
|
||||||
dontFixup = true;
|
|
||||||
|
|
||||||
postPatch = ''
|
|
||||||
for packageJson in ${lib.concatStringsSep " " workspacePreparePatched}; do
|
|
||||||
substituteInPlace "$packageJson" \
|
|
||||||
--replace-fail '"prepare": "effect-language-service patch"' '"prepare": "true"'
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
runHook preBuild
|
|
||||||
|
|
||||||
export HOME="$TMPDIR"
|
|
||||||
export BUN_INSTALL_CACHE_DIR="$(mktemp -d)"
|
|
||||||
|
|
||||||
bun install \
|
|
||||||
--frozen-lockfile \
|
|
||||||
--ignore-scripts \
|
|
||||||
--linker=hoisted \
|
|
||||||
--no-progress \
|
|
||||||
--filter ./apps/server \
|
|
||||||
--filter ./apps/web \
|
|
||||||
--filter ./packages/client-runtime \
|
|
||||||
--filter ./packages/contracts \
|
|
||||||
--filter ./packages/effect-acp \
|
|
||||||
--filter ./packages/effect-codex-app-server \
|
|
||||||
--filter ./packages/shared
|
|
||||||
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
runHook preInstall
|
|
||||||
|
|
||||||
cp -R ./node_modules $out
|
|
||||||
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
|
|
||||||
outputHash = "sha256-l0BXsHRRFPyWjdxWedAdS8K7VdXSzAfw5c+0caqzT6M=";
|
outputHash = "sha256-l0BXsHRRFPyWjdxWedAdS8K7VdXSzAfw5c+0caqzT6M=";
|
||||||
outputHashAlgo = "sha256";
|
filters = [
|
||||||
outputHashMode = "recursive";
|
"./apps/server"
|
||||||
|
"./apps/web"
|
||||||
|
"./packages/client-runtime"
|
||||||
|
"./packages/contracts"
|
||||||
|
"./packages/effect-acp"
|
||||||
|
"./packages/effect-codex-app-server"
|
||||||
|
"./packages/shared"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
@@ -94,22 +52,9 @@ in
|
|||||||
writableTmpDirAsHomeHook
|
writableTmpDirAsHomeHook
|
||||||
];
|
];
|
||||||
|
|
||||||
configurePhase = ''
|
configurePhase = common.mkNodePtyConfigurePhase {
|
||||||
runHook preConfigure
|
nodeModules = finalAttrs.nodeModules;
|
||||||
|
};
|
||||||
mkdir -p ./node_modules
|
|
||||||
cp -R ${finalAttrs.nodeModules}/. ./node_modules/
|
|
||||||
|
|
||||||
chmod -R u+rwX node_modules
|
|
||||||
patchShebangs node_modules
|
|
||||||
|
|
||||||
cd node_modules/node-pty
|
|
||||||
node-gyp rebuild
|
|
||||||
node scripts/post-install.js
|
|
||||||
cd "$NIX_BUILD_TOP/$sourceRoot"
|
|
||||||
|
|
||||||
runHook postConfigure
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
Reference in New Issue
Block a user