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 (
|
||||
system: let
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
t3 = pkgs.callPackage ./packages/server-package.nix {src = t3code;};
|
||||
t3code-server = pkgs.callPackage ./packages/server {src = t3code;};
|
||||
in
|
||||
{
|
||||
inherit t3;
|
||||
t3code = t3;
|
||||
default = t3;
|
||||
inherit t3code-server;
|
||||
default = t3code-server;
|
||||
}
|
||||
// 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: {
|
||||
default = {
|
||||
type = "app";
|
||||
program = "${self.packages.${system}.t3}/bin/t3";
|
||||
program = "${self.packages.${system}.t3code-server}/bin/t3";
|
||||
};
|
||||
t3 = {
|
||||
t3code-server = {
|
||||
type = "app";
|
||||
program = "${self.packages.${system}.t3}/bin/t3";
|
||||
program = "${self.packages.${system}.t3code-server}/bin/t3";
|
||||
};
|
||||
});
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
{
|
||||
t3 = self.packages.${system}.t3;
|
||||
t3code-server = self.packages.${system}.t3code-server;
|
||||
}
|
||||
// lib.optionalAttrs (system == "x86_64-linux") {
|
||||
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,
|
||||
xdg-utils,
|
||||
}: let
|
||||
common = import ../common.nix {
|
||||
inherit
|
||||
lib
|
||||
stdenv
|
||||
bun
|
||||
nodejs
|
||||
writableTmpDirAsHomeHook
|
||||
;
|
||||
};
|
||||
desktopPackageJson = lib.importJSON "${src}/apps/desktop/package.json";
|
||||
|
||||
pname = "t3code-desktop";
|
||||
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 {
|
||||
name = "t3code";
|
||||
desktopName = "T3 Code";
|
||||
@@ -47,76 +46,38 @@ in
|
||||
inherit src;
|
||||
|
||||
strictDeps = true;
|
||||
patches = [./patches/desktop-nix-autoupdate.patch];
|
||||
|
||||
nodeModules = stdenv.mkDerivation {
|
||||
pname = "${pname}-node-modules";
|
||||
inherit (finalAttrs) version src;
|
||||
patches = [./desktop-nix-autoupdate.patch];
|
||||
|
||||
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 =
|
||||
lib.fetchers.proxyImpureEnvVars
|
||||
++ [
|
||||
"GIT_PROXY_COMMAND"
|
||||
"SOCKS_SERVER"
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
bun
|
||||
extraNativeBuildInputs = [
|
||||
gcc
|
||||
gnumake
|
||||
nodejs
|
||||
pkg-config
|
||||
python3
|
||||
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)"
|
||||
extraEnv = ''
|
||||
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
||||
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
||||
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 = [
|
||||
@@ -142,24 +103,10 @@ in
|
||||
npm_config_nodedir = "${nodejs}";
|
||||
};
|
||||
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
|
||||
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
|
||||
'';
|
||||
configurePhase = common.mkNodePtyConfigurePhase {
|
||||
nodeModules = finalAttrs.nodeModules;
|
||||
chmodBins = true;
|
||||
};
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
@@ -168,7 +115,7 @@ in
|
||||
export BUN_INSTALL_CACHE_DIR="$(mktemp -d)"
|
||||
|
||||
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
|
||||
chmod -R u+rwX packaged-app/node_modules
|
||||
patchShebangs packaged-app/node_modules
|
||||
@@ -197,9 +144,9 @@ in
|
||||
--set-default ELECTRON_FORCE_IS_PACKAGED 1 \
|
||||
--set-default ELECTRON_IS_DEV 0 \
|
||||
--prefix PATH : ${lib.makeBinPath [
|
||||
git
|
||||
xdg-utils
|
||||
]} \
|
||||
git
|
||||
xdg-utils
|
||||
]} \
|
||||
--add-flags "$out/share/${pname}/resources/app.asar"
|
||||
|
||||
runHook postInstall
|
||||
@@ -9,20 +9,19 @@
|
||||
python3,
|
||||
writableTmpDirAsHomeHook,
|
||||
}: let
|
||||
common = import ../common.nix {
|
||||
inherit
|
||||
lib
|
||||
stdenv
|
||||
bun
|
||||
nodejs
|
||||
writableTmpDirAsHomeHook
|
||||
;
|
||||
};
|
||||
serverPackageJson = lib.importJSON "${src}/apps/server/package.json";
|
||||
|
||||
pname = "t3code-server";
|
||||
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
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
inherit pname version;
|
||||
@@ -30,59 +29,18 @@ in
|
||||
|
||||
strictDeps = true;
|
||||
|
||||
nodeModules = stdenv.mkDerivation {
|
||||
pname = "${pname}-node-modules";
|
||||
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
|
||||
'';
|
||||
|
||||
nodeModules = common.mkNodeModules {
|
||||
inherit (finalAttrs) pname version src;
|
||||
outputHash = "sha256-l0BXsHRRFPyWjdxWedAdS8K7VdXSzAfw5c+0caqzT6M=";
|
||||
outputHashAlgo = "sha256";
|
||||
outputHashMode = "recursive";
|
||||
filters = [
|
||||
"./apps/server"
|
||||
"./apps/web"
|
||||
"./packages/client-runtime"
|
||||
"./packages/contracts"
|
||||
"./packages/effect-acp"
|
||||
"./packages/effect-codex-app-server"
|
||||
"./packages/shared"
|
||||
];
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
@@ -94,22 +52,9 @@ in
|
||||
writableTmpDirAsHomeHook
|
||||
];
|
||||
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
|
||||
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
|
||||
'';
|
||||
configurePhase = common.mkNodePtyConfigurePhase {
|
||||
nodeModules = finalAttrs.nodeModules;
|
||||
};
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
Reference in New Issue
Block a user