Compare commits

..

4 Commits

Author SHA1 Message Date
Timothy J. Aveni 8dde1f6b82 Add Camino TypeScript package helper 2026-07-12 12:21:21 -07:00
Timothy J. Aveni e0874093f2 Drop perl from package prepare shell 2026-06-27 20:33:06 -07:00
Timothy J. Aveni 0b159fcb81 Add perl to package prepare shell 2026-06-27 20:31:20 -07:00
Timothy J. Aveni f33eee054f Initial commit
germanium cutoff
2026-05-24 15:25:38 -07:00
4 changed files with 318 additions and 613 deletions
-8
View File
@@ -1,8 +0,0 @@
{
"version": 1,
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos",
"sourceCommit": "1de28b236de076d239752b77553f833dfbdb5b43",
"sourcePath": "quixos-instance/quixos-nix-helpers",
"exportName": "quixos-nix-helpers",
"mirrorRemote": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos-nix-helpers.git"
}
-69
View File
@@ -1,69 +0,0 @@
import { createRequire } from "node:module";
import path from "node:path";
// Resolve build dependencies from the package's locked node_modules, not from
// the helper's own Nix-store location. This program runs only during the build.
const require = createRequire(path.join(process.cwd(), "package.json"));
const { build } = require("esbuild");
const options = JSON.parse(process.argv[2]);
const platform = new Map([
["react", "/__quixos/platform/react/v18.mjs"],
["react/jsx-runtime", "/__quixos/platform/react-jsx-runtime/v18.mjs"],
["react/jsx-dev-runtime", "/__quixos/platform/react-jsx-dev-runtime/v18.mjs"],
["@quixos/web-studio-react-runtime", "/__quixos/platform/web-studio-react-runtime/v1.mjs"],
]);
await build({
...options,
plugins: [
{
name: "quixos-browser-source",
setup(api) {
api.onResolve({ filter: /\?browser-source$/ }, async ({ path: specifier, resolveDir }) => {
if (!specifier.startsWith("./") && !specifier.startsWith("../"))
throw new Error("Browser source imports must name a relative compiled module");
const resolved = await api.resolve(specifier.slice(0, -"?browser-source".length), {
resolveDir,
kind: "import-statement",
});
if (resolved.errors.length) return { errors: resolved.errors };
return { path: resolved.path, namespace: "browser-source" };
});
api.onLoad({ filter: /.*/, namespace: "browser-source" }, async ({ path: entry }) => {
const browser = await build({
entryPoints: [entry],
bundle: true,
write: false,
outfile: "component.mjs",
format: "esm",
platform: "browser",
target: "es2022",
metafile: true,
plugins: [
{
name: "quixos-platform",
setup(browserApi) {
browserApi.onResolve({ filter: /.*/ }, ({ path: name }) =>
platform.has(name) ? { path: platform.get(name), external: true } : undefined,
);
},
},
],
});
const js = browser.outputFiles.find((file) => file.path.endsWith(".mjs"));
if (!js) throw new Error("Browser source build produced no JavaScript");
const css = browser.outputFiles.find((file) => file.path.endsWith(".css"));
if (css && Object.values(browser.metafile.outputs).some((output) => output.exports?.includes("styles")))
throw new Error("Use either imported CSS or an explicit styles export, not both");
if (browser.outputFiles.some((file) => !file.path.endsWith(".mjs") && !file.path.endsWith(".css")))
throw new Error("Browser assets must be embedded, not emitted as unserved files");
const source = js.text + (css ? `\nexport const styles = ${JSON.stringify(css.text)};\n` : "");
return {
contents: `export default ${JSON.stringify(source)};`,
loader: "js",
watchFiles: Object.keys(browser.metafile.inputs),
};
});
},
},
],
});
-40
View File
@@ -1,40 +0,0 @@
import fs from "node:fs";
import crypto from "node:crypto";
const [schemaPath, packageRevisionId, bindingOutput, generatorPath, output] = process.argv.slice(2);
if (!schemaPath || !packageRevisionId || !bindingOutput || !generatorPath || !output)
throw new Error("Missing candidate check receipt inputs");
const canonical = (value) =>
Array.isArray(value)
? value.map(canonical)
: value && typeof value === "object"
? Object.fromEntries(
Object.entries(value)
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
.map(([key, entry]) => [key, canonical(entry)]),
)
: value;
const hash = (value) =>
`sha256:${crypto
.createHash("sha256")
.update(JSON.stringify(canonical(value)))
.digest("hex")}`;
const schema = JSON.parse(fs.readFileSync(schemaPath, "utf8"));
if (!schema.packages.some((entry) => entry.revisionId === packageRevisionId))
throw new Error("Checked binding schema lacks the package");
const generated = fs.readFileSync(bindingOutput, "utf8");
if (generated !== fs.readFileSync(".qx-checked-bindings", "utf8"))
throw new Error("Build replaced candidate-generated bindings; its check is not evidence for this candidate");
const receipt = {
schemaVersion: 1,
packageRevisionId,
success: true,
bindingSchema: schema,
bindingSchemaDigest: hash(schema),
generatedDigest: hash(generated),
checkerDigest: hash({
generatorPath,
compiler: JSON.parse(fs.readFileSync("node_modules/typescript/package.json", "utf8")),
lock: fs.readFileSync("yarn.lock", "utf8"),
}),
};
fs.writeFileSync(output, `${JSON.stringify(receipt, null, 2)}\n`, { flag: "wx" });
+125 -303
View File
@@ -19,25 +19,23 @@ let
schemaMainPathDefault = "dist/quixos-package-schema.js"; schemaMainPathDefault = "dist/quixos-package-schema.js";
schemaPackageName = schemaPackageJson.name or "schema"; schemaPackageName = schemaPackageJson.name or "schema";
selfSchemaName = selfSchemaName =
if pkgs.lib.hasInfix "/" schemaPackageName then if pkgs.lib.hasInfix "/" schemaPackageName
pkgs.lib.last (pkgs.lib.splitString "/" schemaPackageName) then pkgs.lib.last (pkgs.lib.splitString "/" schemaPackageName)
else else schemaPackageName;
schemaPackageName;
flakeText = builtins.replaceStrings [ "\n" "\r" "\t" ] [ " " " " " " ] ( flakeText =
builtins.readFile "${flakeRoot}/flake.nix" builtins.replaceStrings
); [ "\n" "\r" "\t" ]
[ " " " " " " ]
(builtins.readFile "${flakeRoot}/flake.nix");
getInputUrl = getInputUrl = inputName:
inputName:
let let
pattern1 = ".*" + inputName + "[[:space:]]*\\.url[[:space:]]*=[[:space:]]*\"([^\"]+)\".*"; pattern1 = ".*" + inputName + "[[:space:]]*\\.url[[:space:]]*=[[:space:]]*\"([^\"]+)\".*";
pattern2 = pattern2 = ".*" + inputName + "[[:space:]]*=[[:space:]]*\\{[^}]*url[[:space:]]*=[[:space:]]*\"([^\"]+)\".*";
".*" + inputName + "[[:space:]]*=[[:space:]]*\\{[^}]*url[[:space:]]*=[[:space:]]*\"([^\"]+)\".*";
match1 = builtins.match pattern1 flakeText; match1 = builtins.match pattern1 flakeText;
match2 = if match1 != null then match1 else builtins.match pattern2 flakeText; match2 = if match1 != null then match1 else builtins.match pattern2 flakeText;
in in if match2 == null then null else builtins.elemAt match2 0;
if match2 == null then null else builtins.elemAt match2 0;
schemaBase = schemaBase =
(pkgs.callPackage "${schemaDir}/yarn-project.nix" { (pkgs.callPackage "${schemaDir}/yarn-project.nix" {
@@ -67,44 +65,51 @@ let
''; '';
}); });
schemaInputs = pkgs.lib.filterAttrs (name: _: pkgs.lib.hasPrefix schemaPrefix name) inputs; schemaInputs =
pkgs.lib.filterAttrs (name: _: pkgs.lib.hasPrefix schemaPrefix name) inputs;
decodeSchemaInputName = encodedName: builtins.replaceStrings [ "__" ] [ "." ] encodedName; decodeSchemaInputName = encodedName:
builtins.replaceStrings [ "__" ] [ "." ] encodedName;
schemaPackagesFromInputs = pkgs.lib.mapAttrs' ( schemaPackagesFromInputs =
name: flake: pkgs.lib.mapAttrs'
(name: flake:
let let
schemaName = decodeSchemaInputName (pkgs.lib.removePrefix schemaPrefix name); schemaName =
decodeSchemaInputName (pkgs.lib.removePrefix schemaPrefix name);
in in
{ {
name = schemaName; name = schemaName;
value = flake.packages.${system}.schema; value = flake.packages.${system}.schema;
} })
) schemaInputs; schemaInputs;
schemaPackages = schemaPackagesFromInputs // { schemaPackages = schemaPackagesFromInputs // { "${selfSchemaName}" = schema; };
"${selfSchemaName}" = schema;
};
schemaMetaByName = pkgs.lib.mapAttrs' ( schemaMetaByName =
name: flake: pkgs.lib.mapAttrs'
(name: flake:
let let
schemaName = decodeSchemaInputName (pkgs.lib.removePrefix schemaPrefix name); schemaName =
decodeSchemaInputName (pkgs.lib.removePrefix schemaPrefix name);
sourceInfo = if flake ? sourceInfo then flake.sourceInfo else { }; sourceInfo = if flake ? sourceInfo then flake.sourceInfo else { };
sourceRev = sourceInfo.rev or null; sourceRev = sourceInfo.rev or null;
inputUrl = getInputUrl name; inputUrl = getInputUrl name;
urlBase = if inputUrl == null then null else builtins.head (pkgs.lib.splitString "?" inputUrl); urlBase =
if inputUrl == null
then null
else builtins.head (pkgs.lib.splitString "?" inputUrl);
isDisallowed = isDisallowed =
inputUrl == null inputUrl == null
|| pkgs.lib.hasPrefix "path:" inputUrl || pkgs.lib.hasPrefix "path:" inputUrl
|| pkgs.lib.hasPrefix "file:" inputUrl || pkgs.lib.hasPrefix "file:" inputUrl
|| pkgs.lib.hasPrefix "git+file:" inputUrl; || pkgs.lib.hasPrefix "git+file:" inputUrl;
flakeRef = flakeRef =
if isDisallowed || sourceRev == null || urlBase == null then if isDisallowed || sourceRev == null || urlBase == null
null then null
else else urlBase + "?rev=" + sourceRev;
urlBase + "?rev=" + sourceRev; meta =
meta = { {
name = "@quixos-package-schemas/${schemaName}"; name = "@quixos-package-schemas/${schemaName}";
type = sourceInfo.type or null; type = sourceInfo.type or null;
url = inputUrl; url = inputUrl;
@@ -112,16 +117,16 @@ let
flakeRef = flakeRef; flakeRef = flakeRef;
}; };
in in
if flakeRef == null then if flakeRef == null
throw "Schema input ${schemaName} must be a git flake with url+rev" then throw "Schema input ${schemaName} must be a git flake with url+rev"
else else {
{
name = schemaName; name = schemaName;
value = meta; value = meta;
} })
) schemaInputs; schemaInputs;
schemaMetaJsonByName = pkgs.lib.mapAttrs (_: meta: builtins.toJSON meta) schemaMetaByName; schemaMetaJsonByName =
pkgs.lib.mapAttrs (_: meta: builtins.toJSON meta) schemaMetaByName;
schemaExtensionsBlock = pkgs.lib.concatStringsSep "\n" ( schemaExtensionsBlock = pkgs.lib.concatStringsSep "\n" (
[ [
@@ -146,11 +151,12 @@ let
); );
schemaInstallCommands = pkgs.lib.concatStringsSep "\n" ( schemaInstallCommands = pkgs.lib.concatStringsSep "\n" (
pkgs.lib.mapAttrsToList ( pkgs.lib.mapAttrsToList (name: drv:
name: drv:
let let
metaJson = metaJson =
if pkgs.lib.hasAttr name schemaMetaJsonByName then schemaMetaJsonByName.${name} else null; if pkgs.lib.hasAttr name schemaMetaJsonByName
then schemaMetaJsonByName.${name}
else null;
in in
'' ''
schema_pkg="$(ls -d ${drv}/libexec/* | head -n1)" schema_pkg="$(ls -d ${drv}/libexec/* | head -n1)"
@@ -160,8 +166,8 @@ let
chmod -R u+w "$dest" chmod -R u+w "$dest"
'' ''
+ ( + (
if metaJson != null then if metaJson != null
'' then ''
schema_main="${schemaMainPathDefault}" schema_main="${schemaMainPathDefault}"
if [ -f "$dest/$schema_main" ]; then if [ -f "$dest/$schema_main" ]; then
block_tmp="$(mktemp -p "$dest")" block_tmp="$(mktemp -p "$dest")"
@@ -199,8 +205,7 @@ let
rm -f "$block_tmp" "$tmp_out" rm -f "$block_tmp" "$tmp_out"
fi fi
'' ''
else else ""
""
) )
) schemaPackages ) schemaPackages
); );
@@ -235,8 +240,7 @@ let
schemaInstallCommands schemaInstallCommands
updateYarnrcScript updateYarnrcScript
schemaExtensionsBlockEscaped schemaExtensionsBlockEscaped
selfSchemaName selfSchemaName;
;
}; };
mkTsPackageServer = mkTsPackageServer =
@@ -261,10 +265,9 @@ let
nodejs' = if nodejs != null then nodejs else pkgs.nodejs_24; nodejs' = if nodejs != null then nodejs else pkgs.nodejs_24;
git' = if git != null then git else pkgs.git; git' = if git != null then git else pkgs.git;
templatePreparePackages' = templatePreparePackages' =
if templatePreparePackages != null then if templatePreparePackages != null
templatePreparePackages then templatePreparePackages
else else [
[
pkgs.findutils pkgs.findutils
git' git'
pkgs.gnused pkgs.gnused
@@ -288,33 +291,28 @@ let
runtimeBinPath = pkgs.lib.makeBinPath extraRuntimePackages; runtimeBinPath = pkgs.lib.makeBinPath extraRuntimePackages;
runtimeLibPath = pkgs.lib.makeLibraryPath extraRuntimePackages; runtimeLibPath = pkgs.lib.makeLibraryPath extraRuntimePackages;
runtimeWrap = runtimeWrap =
if extraRuntimePackages == [ ] then if extraRuntimePackages == [ ]
"" then ""
else else ''
''
wrapProgram "$out/bin/${serverBin}" \ wrapProgram "$out/bin/${serverBin}" \
--prefix PATH : ${runtimeBinPath} \ --prefix PATH : ${runtimeBinPath} \
--prefix LD_LIBRARY_PATH : ${runtimeLibPath} --prefix LD_LIBRARY_PATH : ${runtimeLibPath}
''; '';
server = base.overrideAttrs ( server = base.overrideAttrs (old:
old:
let let
extraAttrs = serverOverrides old; extraAttrs = serverOverrides old;
in in
{ {
buildInputs = (old.buildInputs or [ ]) ++ extraBuildInputs; buildInputs = (old.buildInputs or [ ]) ++ extraBuildInputs;
nativeBuildInputs = nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
(old.nativeBuildInputs or [ ])
++ [
pkgs.python3 pkgs.python3
pkgs.gnumake pkgs.gnumake
pkgs.gcc pkgs.gcc
pkgs.pkg-config pkgs.pkg-config
pkgs.makeWrapper pkgs.makeWrapper
] ] ++ extraNativeBuildInputs;
++ extraNativeBuildInputs;
# node-gyp will look at these # node-gyp will look at these
PYTHON = "${pkgs.python3}/bin/python3"; PYTHON = "${pkgs.python3}/bin/python3";
@@ -328,14 +326,13 @@ let
buildPhase = buildPhase =
(old.buildPhase or "") (old.buildPhase or "")
+ ( + (
if buildCommand != null then if buildCommand != null
'' then ''
runHook preBuildQuixos runHook preBuildQuixos
${buildCommand} ${buildCommand}
runHook postBuildQuixos runHook postBuildQuixos
'' ''
else else ""
""
); );
postFixup = (old.postFixup or "") + runtimeWrap; postFixup = (old.postFixup or "") + runtimeWrap;
@@ -345,8 +342,7 @@ let
mkdir -p "$pkg_root/quixos-package-schemas" mkdir -p "$pkg_root/quixos-package-schemas"
(cd "$pkg_root" && ${schemaSupport.schemaInstallCommands}) (cd "$pkg_root" && ${schemaSupport.schemaInstallCommands})
''; '';
} } // extraAttrs
// extraAttrs
); );
check = server.overrideAttrs (old: { check = server.overrideAttrs (old: {
@@ -364,12 +360,7 @@ let
}; };
in in
{ {
inherit inherit server check packageName serverBin;
server
check
packageName
serverBin
;
devShells = { devShells = {
"quixos-prepare" = prepareShell; "quixos-prepare" = prepareShell;
@@ -401,18 +392,13 @@ let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
schemaSupport = mkSchemaSupport { schemaSupport = mkSchemaSupport {
inherit inherit pkgs inputs system schemaDir schemaPrefix self flakeRoot;
pkgs
inputs
system
schemaDir
schemaPrefix
self
flakeRoot
;
}; };
normalizeList = value: if builtins.isFunction value then value pkgs else value; normalizeList = value:
if builtins.isFunction value
then value pkgs
else value;
serverResult = serverBuilder { serverResult = serverBuilder {
inherit pkgs schemaSupport; inherit pkgs schemaSupport;
@@ -422,28 +408,26 @@ let
}; };
combinedName = pkgs.lib.strings.sanitizeDerivationName ( combinedName = pkgs.lib.strings.sanitizeDerivationName (
if packageName != null then if packageName != null
packageName then packageName
else if serverResult ? packageName then else if serverResult ? packageName
serverResult.packageName then serverResult.packageName
else else "quixos-package"
"quixos-package"
); );
packageServer = serverResult.server; packageServer = serverResult.server;
packageServerCheck = if serverResult ? check then serverResult.check else null; packageServerCheck = if serverResult ? check then serverResult.check else null;
appProgramFinal = appProgramFinal =
if appProgram != null then if appProgram != null
appProgram then appProgram
else if serverResult ? appProgram then else if serverResult ? appProgram
serverResult.appProgram then serverResult.appProgram
else else "${packageServer}/bin/${serverResult.serverBin or "server"}";
"${packageServer}/bin/${serverResult.serverBin or "server"}";
devShellHookBase = devShellHookBase =
if enableYarnrcHook then if enableYarnrcHook
'' then ''
find_schema_root() { find_schema_root() {
dir="$PWD" dir="$PWD"
while [ "$dir" != "/" ]; do while [ "$dir" != "/" ]; do
@@ -471,26 +455,21 @@ let
fi fi
fi fi
'' ''
else else "";
"";
devShellHook = devShellHookBase + extraDevShellHook; devShellHook = devShellHookBase + extraDevShellHook;
devShellPackages = normalizeList extraDevShellPackages; devShellPackages = normalizeList extraDevShellPackages;
checks = { checks =
schema = schemaSupport.schemaCheck; { schema = schemaSupport.schemaCheck; }
}
// (if packageServerCheck != null then { default = packageServerCheck; } else { }); // (if packageServerCheck != null then { default = packageServerCheck; } else { });
extraDevShells = if serverResult ? devShells then serverResult.devShells else { }; extraDevShells = if serverResult ? devShells then serverResult.devShells else { };
in in
{ {
packages.default = pkgs.symlinkJoin { packages.default = pkgs.symlinkJoin {
name = combinedName; name = combinedName;
paths = [ paths = [ packageServer schemaSupport.schema ];
packageServer
schemaSupport.schema
];
}; };
packages.server = packageServer; packages.server = packageServer;
packages.schema = schemaSupport.schema; packages.schema = schemaSupport.schema;
@@ -531,29 +510,6 @@ let
''; '';
}; };
# Language-neutral, offline schema compilation. Snapshot directories must be
# fixed Nix inputs matching the resource lock's complete dependency closure.
mkQxBindingSchema =
{
pkgs,
protocol,
src,
repository,
commit,
resources ? [ ],
}:
let
snapshots = pkgs.writeText "qx-binding-snapshots.json" (builtins.toJSON { inherit resources; });
in
pkgs.runCommand "qx-binding-schema.json" { } ''
${protocol}/bin/quixos-resource-compile \
--root ${src} --kind package \
--repository ${pkgs.lib.escapeShellArg repository} \
--commit ${pkgs.lib.escapeShellArg commit} \
--checkout-root "$TMPDIR/checkouts" \
--snapshot-map ${snapshots} --snapshot-only true --schema-out "$out" > /dev/null
'';
mkCaminoTsYarnNixifyFlake = mkCaminoTsYarnNixifyFlake =
{ {
inputs, inputs,
@@ -565,13 +521,8 @@ let
promptName ? null, promptName ? null,
nodejsAttr ? "nodejs_24", nodejsAttr ? "nodejs_24",
buildCommand ? "yarn build", buildCommand ? "yarn build",
sourcePortals ? { },
buildEnv ? { }, buildEnv ? { },
# An exact, compiler-produced BindingSchema JSON artifact and a backend.
# Other language helpers can consume the same schema with their own generator/runtime.
bindings ? null,
# A dedicated entrypoint calling SDK serveMigration; never start the
# normal package server in the isolated migration execution boundary.
migrationEntrypoint ? null,
nativeBuildInputs ? [ ], nativeBuildInputs ? [ ],
devShellPackages ? [ ], devShellPackages ? [ ],
devShellHook ? "", devShellHook ? "",
@@ -580,22 +531,22 @@ let
}: }:
flake-utils.lib.eachDefaultSystem ( flake-utils.lib.eachDefaultSystem (
system: system:
let
outputsFor =
candidateBindings:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
lib = pkgs.lib; lib = pkgs.lib;
nodejs = pkgs.${nodejsAttr}; nodejs = pkgs.${nodejsAttr};
callOption = callOption = value:
value: if builtins.isFunction value then value { inherit inputs pkgs system; } else value; if builtins.isFunction value
then value { inherit inputs pkgs system; }
else value;
packageJson = builtins.fromJSON (builtins.readFile "${packageRoot}/package.json"); packageJson = builtins.fromJSON (builtins.readFile "${packageRoot}/package.json");
packageNameFinal = packageNameFinal = if packageName != null then packageName else packageJson.name or "quixos-package";
if packageName != null then packageName else packageJson.name or "quixos-package";
promptNameFinal = promptNameFinal =
if promptName != null then promptName else lib.strings.sanitizeDerivationName packageNameFinal; if promptName != null
then promptName
else lib.strings.sanitizeDerivationName packageNameFinal;
sourcePackage = mkCaminoSourcePackage { sourcePackage = mkCaminoSourcePackage {
inherit pkgs; inherit pkgs;
@@ -603,57 +554,19 @@ let
name = sourceName; name = sourceName;
}; };
exportsFor = exportsFor = attrs:
attrs:
lib.concatStringsSep "\n" ( lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: value: "export ${name}=${lib.escapeShellArg (toString value)}") attrs lib.mapAttrsToList
(name: value: "export ${name}=${lib.escapeShellArg (toString value)}")
attrs
); );
bindingConfig = portalLinksFor = attrs:
if candidateBindings != null then lib.concatStringsSep "\n" (
candidateBindings lib.mapAttrsToList
else if bindings == null then (target: source: "ln -sfn ${source} ${lib.escapeShellArg target}")
null attrs
else );
callOption bindings;
bindingSchema =
if bindingConfig == null then
null
else
bindingConfig.schema or (mkQxBindingSchema {
inherit pkgs;
protocol = bindingConfig.generator;
src = packageRoot;
inherit (bindingConfig) repository commit;
resources = bindingConfig.resources or [ ];
});
bindingOutput =
if bindingConfig == null then "src/gen/qx.ts" else bindingConfig.output or "src/gen/qx.ts";
authoringCheck = builtins.fromJSON (builtins.readFile "${packageRoot}/quixos.check.json");
bindingOptionsFile =
if bindingConfig == null then
null
else
pkgs.writeText "qx-typescript-options.json" (builtins.toJSON (authoringCheck.options or { }));
bindingCommand =
if bindingConfig == null then
""
else
''
mkdir -p ${lib.escapeShellArg (dirOf bindingOutput)}
${bindingConfig.generator}/bin/quixos-codegen-ts \
${lib.escapeShellArg (toString bindingSchema)} \
${lib.escapeShellArg bindingConfig.packageRevisionId} \
${lib.escapeShellArg bindingOutput} ${bindingOptionsFile}
${lib.optionalString (installServer != null && descriptorPath != null) ''
${bindingConfig.generator}/bin/quixos-qx package-descriptor ${lib.escapeShellArg (toString bindingSchema)} \
${lib.escapeShellArg bindingConfig.packageRevisionId} > ${lib.escapeShellArg descriptorPath}
''}
'';
generateBindings = pkgs.writeShellApplication {
name = "qx-generate-bindings";
text = bindingCommand;
};
bundleConfig = if bundle == null then { } else bundle; bundleConfig = if bundle == null then { } else bundle;
bundleOutfile = bundleConfig.outfile or "server.mjs"; bundleOutfile = bundleConfig.outfile or "server.mjs";
@@ -661,44 +574,16 @@ let
bundleTarget = bundleConfig.target or "node24"; bundleTarget = bundleConfig.target or "node24";
bundleFormat = bundleConfig.format or "esm"; bundleFormat = bundleConfig.format or "esm";
bundleBanner = bundleConfig.banner or nodeRequireBanner; bundleBanner = bundleConfig.banner or nodeRequireBanner;
bundleAliases =
bundleConfig.aliases or {
"@automerge/automerge" =
"./node_modules/@automerge/automerge/dist/mjs/entrypoints/fullfat_base64.js";
};
bundleAliasArgs = lib.concatStringsSep " " (
lib.mapAttrsToList (from: to: "--alias:${from}=${lib.escapeShellArg to}") bundleAliases
);
nodeRequireBanner = "import { createRequire } from 'module';const require = createRequire(import.meta.url);"; nodeRequireBanner = "import { createRequire } from 'module';const require = createRequire(import.meta.url);";
bundleCommand = bundleCommand =
if bundle == null then if bundle == null
"" then ""
else if bundleConfig.browserSources or false then else ''
''
${nodejs}/bin/node ${./browser-source.mjs} ${
lib.escapeShellArg (
builtins.toJSON {
entryPoints = [ bundleConfig.entry ];
bundle = true;
platform = bundlePlatform;
target = bundleTarget;
format = bundleFormat;
alias = bundleAliases;
preserveSymlinks = bundleConfig.preserveSymlinks or true;
banner.js = bundleBanner;
outfile = bundleOutfile;
}
)
}
''
else
''
esbuild ${lib.escapeShellArg bundleConfig.entry} \ esbuild ${lib.escapeShellArg bundleConfig.entry} \
--bundle \ --bundle \
--platform=${bundlePlatform} \ --platform=${bundlePlatform} \
--target=${bundleTarget} \ --target=${bundleTarget} \
--format=${bundleFormat} \ --format=${bundleFormat} \
${bundleAliasArgs} \
${lib.optionalString (bundleConfig.preserveSymlinks or true) "--preserve-symlinks \\"} ${lib.optionalString (bundleConfig.preserveSymlinks or true) "--preserve-symlinks \\"}
--banner:js=${lib.escapeShellArg bundleBanner} \ --banner:js=${lib.escapeShellArg bundleBanner} \
--outfile=${lib.escapeShellArg bundleOutfile} --outfile=${lib.escapeShellArg bundleOutfile}
@@ -710,25 +595,12 @@ let
installConfig.libexecName or (lib.strings.sanitizeDerivationName packageNameFinal); installConfig.libexecName or (lib.strings.sanitizeDerivationName packageNameFinal);
serverFile = installConfig.serverFile or bundleOutfile; serverFile = installConfig.serverFile or bundleOutfile;
descriptorPath = installConfig.descriptorPath or "descriptor.quixos-package.txtpb"; descriptorPath = installConfig.descriptorPath or "descriptor.quixos-package.txtpb";
extraFiles = installConfig.extraFiles or [ ];
installExtraFile =
file:
let
source = toString file.source;
target = file.target or (baseNameOf source);
mode = file.mode or "0644";
in
''
install -Dm${toString mode} ${lib.escapeShellArg source} "$out/libexec/${serverLibexecName}/${target}"
'';
installServerPhase = installServerPhase =
if installServer == null then if installServer == null
null then null
else else ''
''
runHook preInstall runHook preInstall
install -Dm755 ${lib.escapeShellArg serverFile} "$out/libexec/${serverLibexecName}/${serverFile}" install -Dm755 ${lib.escapeShellArg serverFile} "$out/libexec/${serverLibexecName}/${serverFile}"
${lib.concatMapStringsSep "\n" installExtraFile extraFiles}
mkdir -p "$out/bin" mkdir -p "$out/bin"
cat > "$out/bin/${serverBin}" <<EOF cat > "$out/bin/${serverBin}" <<EOF
#!${pkgs.runtimeShell} #!${pkgs.runtimeShell}
@@ -738,56 +610,27 @@ let
${lib.optionalString (installConfig ? descriptorPath && descriptorPath != null) '' ${lib.optionalString (installConfig ? descriptorPath && descriptorPath != null) ''
cp ${lib.escapeShellArg descriptorPath} "$out/${descriptorPath}" cp ${lib.escapeShellArg descriptorPath} "$out/${descriptorPath}"
''} ''}
${lib.optionalString (bindingConfig != null) ''
install -m 0444 quixos-check.json "$out/quixos-check.json"
''}
${lib.optionalString (migrationEntrypoint != null) ''
install -Dm444 migration.mjs "$out/libexec/${serverLibexecName}/migration.mjs"
cat > "$out/bin/migrate" <<EOF
#!${pkgs.runtimeShell}
exec ${nodejs}/bin/node --max-old-space-size=256 "$out/libexec/${serverLibexecName}/migration.mjs" "\$@"
EOF
chmod +x "$out/bin/migrate"
''}
runHook postInstall runHook postInstall
''; '';
project = (pkgs.callPackage "${packageRoot}/yarn-project.nix" { inherit nodejs; }) { project = (pkgs.callPackage "${packageRoot}/yarn-project.nix" { inherit nodejs; }) {
src = packageRoot; src = packageRoot;
overrideAttrs = overrideAttrs = old: {
old:
{
nativeBuildInputs = nativeBuildInputs =
(old.nativeBuildInputs or [ ]) (old.nativeBuildInputs or [ ])
++ lib.optional (bundle != null || migrationEntrypoint != null) pkgs.esbuild ++ lib.optional (bundle != null) pkgs.esbuild
++ callOption nativeBuildInputs; ++ callOption nativeBuildInputs;
preConfigure = (old.preConfigure or "") + ''
${portalLinksFor (callOption sourcePortals)}
'';
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
${exportsFor (callOption buildEnv)} ${exportsFor (callOption buildEnv)}
${bindingCommand}
${lib.optionalString (
bindingConfig != null && bundle != null
) "${bindingConfig.generator}/bin/quixos-qx bundle-policy src"}
${lib.optionalString (bindingConfig != null) "yarn exec tsc --noEmit"}
${lib.optionalString (
bindingConfig != null
) "cp ${lib.escapeShellArg bindingOutput} .qx-checked-bindings"}
${buildCommand} ${buildCommand}
${lib.optionalString (bindingConfig != null) ''
yarn exec tsc --noEmit
node ${./check-receipt.mjs} ${lib.escapeShellArg (toString bindingSchema)} \
${lib.escapeShellArg bindingConfig.packageRevisionId} ${lib.escapeShellArg bindingOutput} \
${lib.escapeShellArg (toString bindingConfig.generator)} quixos-check.json
''}
${bundleCommand} ${bundleCommand}
${lib.optionalString (migrationEntrypoint != null) ''
esbuild ${lib.escapeShellArg migrationEntrypoint} --bundle --platform=node --target=node24 --format=esm \
${bundleAliasArgs} --preserve-symlinks --banner:js=${lib.escapeShellArg nodeRequireBanner} --outfile=migration.mjs
''}
runHook postBuild runHook postBuild
''; '';
} } // lib.optionalAttrs (installServerPhase != null) {
// lib.optionalAttrs (installServerPhase != null) {
installPhase = installServerPhase; installPhase = installServerPhase;
}; };
}; };
@@ -803,10 +646,9 @@ let
''; '';
maybeServerOutputs = maybeServerOutputs =
if installServer == null then if installServer == null
{ } then { }
else else {
{
packages.server = project; packages.server = project;
apps.default = { apps.default = {
type = "app"; type = "app";
@@ -820,29 +662,11 @@ let
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
packages = [ packages = [
nodejs nodejs
project.yarn-freestanding pkgs.yarn-berry_4
] ] ++ callOption devShellPackages;
++ lib.optional (bindingConfig != null) generateBindings
++ callOption devShellPackages;
# Explicit command keeps shell entry free of source mutations.
shellHook = devShellHookBase + callOption devShellHook; shellHook = devShellHookBase + callOption devShellHook;
}; };
} } // maybeServerOutputs
// maybeServerOutputs;
in
(outputsFor null)
// {
# The workspace supplies a compiler-produced schema for the exact
# candidate graph. Standalone builds may use checked-in authoring types,
# but only this build path regenerates and witnesses candidate contracts.
quixosPackages.checkedServer =
{
schema,
generator,
packageRevisionId,
}:
(outputsFor { inherit schema generator packageRevisionId; }).packages.server;
}
); );
in in
{ {
@@ -851,7 +675,5 @@ in
mkTsPackageServer mkTsPackageServer
mkSchemaSupport mkSchemaSupport
mkCaminoSourcePackage mkCaminoSourcePackage
mkQxBindingSchema mkCaminoTsYarnNixifyFlake;
mkCaminoTsYarnNixifyFlake
;
} }