168 lines
6.8 KiB
Nix
168 lines
6.8 KiB
Nix
{
|
|
description = "Camino app-instance object graph runtime";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, ... }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = import nixpkgs { inherit system; };
|
|
lib = pkgs.lib;
|
|
nodeRequireBanner = "import { createRequire } from 'module';const require = createRequire(import.meta.url);";
|
|
entrypoints = {
|
|
server = "dist/src/server.js";
|
|
cli = "dist/src/cli.js";
|
|
schema-compile = "dist/src/schema-compile.js";
|
|
codegen-ts-runtime = "dist/src/codegen-ts-runtime.js";
|
|
};
|
|
bundleEntrypoint = name: source: ''
|
|
esbuild ${source} \
|
|
--bundle \
|
|
--platform=node \
|
|
--target=node24 \
|
|
--format=esm \
|
|
--banner:js=${lib.escapeShellArg nodeRequireBanner} \
|
|
--outfile=${name}.mjs
|
|
'';
|
|
installEntrypoint = name: _source: ''
|
|
install -Dm755 ${name}.mjs "$out/libexec/camino/${name}.mjs"
|
|
'';
|
|
camino = pkgs.stdenvNoCC.mkDerivation {
|
|
pname = "quixos-camino";
|
|
version = "0.1.0";
|
|
src = ../..;
|
|
setSourceRoot = ''
|
|
sourceRoot=$(echo */quixos-instance/camino)
|
|
'';
|
|
npmDeps = pkgs.importNpmLock { npmRoot = ./.; };
|
|
npmConfigHook = pkgs.importNpmLock.npmConfigHook;
|
|
nativeBuildInputs = [
|
|
pkgs.esbuild
|
|
pkgs.importNpmLock.npmConfigHook
|
|
pkgs.nodejs_24
|
|
pkgs.protobuf
|
|
];
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
export QUIXOS_PROTO_PATH="${pkgs.protobuf}/include:$PWD/../../quixos-protocol/proto''${QUIXOS_PROTO_PATH:+:$QUIXOS_PROTO_PATH}"
|
|
npm run build
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList bundleEntrypoint entrypoints)}
|
|
runHook postBuild
|
|
'';
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p "$out"
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList installEntrypoint entrypoints)}
|
|
cp --reflink=auto --recursive ../../quixos-protocol/proto "$out/proto"
|
|
cp package.json "$out/package.json"
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
mkNodeLauncher = name: entrypoint: extraEnv: pkgs.writeShellApplication {
|
|
inherit name;
|
|
runtimeInputs = [ pkgs.nodejs_24 pkgs.protobuf ];
|
|
text = ''
|
|
export QUIXOS_PROTO_PATH="${pkgs.protobuf}/include:${camino}/proto''${QUIXOS_PROTO_PATH:+:$QUIXOS_PROTO_PATH}"
|
|
export CAMINO_PROTO_PATH="$QUIXOS_PROTO_PATH''${CAMINO_PROTO_PATH:+:$CAMINO_PROTO_PATH}"
|
|
${extraEnv}
|
|
exec ${pkgs.nodejs_24}/bin/node ${camino}/libexec/camino/${entrypoint}.mjs "$@"
|
|
'';
|
|
};
|
|
camino-server = mkNodeLauncher "camino-server" "server" "";
|
|
camino-cli = mkNodeLauncher "camino" "cli" "";
|
|
camino-schema-compile = mkNodeLauncher "camino-schema-compile" "schema-compile" ''
|
|
'';
|
|
camino-codegen-ts-runtime = mkNodeLauncher "camino-codegen-ts-runtime" "codegen-ts-runtime" ''
|
|
'';
|
|
camino-db-start = pkgs.writeShellApplication {
|
|
name = "camino-db-start";
|
|
runtimeInputs = [ pkgs.coreutils pkgs.postgresql_17 ];
|
|
text = builtins.readFile ./nix/camino-db-start.sh;
|
|
};
|
|
camino-db-stop = pkgs.writeShellApplication {
|
|
name = "camino-db-stop";
|
|
runtimeInputs = [ pkgs.coreutils pkgs.postgresql_17 ];
|
|
text = builtins.readFile ./nix/camino-db-stop.sh;
|
|
};
|
|
camino-db-url = pkgs.writeShellApplication {
|
|
name = "camino-db-url";
|
|
runtimeInputs = [ pkgs.coreutils ];
|
|
text = builtins.readFile ./nix/camino-db-url.sh;
|
|
};
|
|
camino-db-reset = pkgs.writeShellApplication {
|
|
name = "camino-db-reset";
|
|
runtimeInputs = [ pkgs.coreutils pkgs.postgresql_17 ];
|
|
text = builtins.readFile ./nix/camino-db-reset.sh;
|
|
};
|
|
camino-server-start = pkgs.writeShellApplication {
|
|
name = "camino-server-start";
|
|
runtimeInputs = [ pkgs.coreutils pkgs.procps pkgs.util-linux camino-server ];
|
|
text = builtins.readFile ./nix/camino-server-start.sh;
|
|
};
|
|
camino-server-status = pkgs.writeShellApplication {
|
|
name = "camino-server-status";
|
|
runtimeInputs = [ pkgs.coreutils pkgs.procps ];
|
|
text = builtins.readFile ./nix/camino-server-status.sh;
|
|
};
|
|
camino-server-stop = pkgs.writeShellApplication {
|
|
name = "camino-server-stop";
|
|
runtimeInputs = [ pkgs.coreutils pkgs.procps ];
|
|
text = builtins.readFile ./nix/camino-server-stop.sh;
|
|
};
|
|
in {
|
|
packages.default = camino-server;
|
|
packages.camino = camino-cli;
|
|
packages.camino-codegen-ts-runtime = camino-codegen-ts-runtime;
|
|
packages.camino-schema-compile = camino-schema-compile;
|
|
packages.camino-db-start = camino-db-start;
|
|
packages.camino-db-stop = camino-db-stop;
|
|
packages.camino-db-url = camino-db-url;
|
|
packages.camino-db-reset = camino-db-reset;
|
|
packages.camino-server-start = camino-server-start;
|
|
packages.camino-server-status = camino-server-status;
|
|
packages.camino-server-stop = camino-server-stop;
|
|
apps.default = {
|
|
type = "app";
|
|
program = "${camino-server}/bin/camino-server";
|
|
};
|
|
apps.schema-compile = {
|
|
type = "app";
|
|
program = "${camino-schema-compile}/bin/camino-schema-compile";
|
|
};
|
|
devShells.default = pkgs.mkShell {
|
|
packages = [
|
|
pkgs.nodejs_24
|
|
pkgs.postgresql_17
|
|
pkgs.protobuf
|
|
pkgs.typescript
|
|
camino-cli
|
|
camino-codegen-ts-runtime
|
|
camino-server
|
|
camino-server-start
|
|
camino-server-status
|
|
camino-server-stop
|
|
camino-db-start
|
|
camino-db-stop
|
|
camino-db-url
|
|
camino-db-reset
|
|
];
|
|
shellHook = ''
|
|
if [ -n "''${PS1-}" ]; then
|
|
if [ -n "''${QX_DEV_SHELL_PROMPT-}" ]; then
|
|
PS1="''${PS1#\[qx:''${QX_DEV_SHELL_PROMPT}\] }"
|
|
fi
|
|
export QX_DEV_SHELL_PROMPT="camino"
|
|
PS1="[qx:camino] $PS1"
|
|
fi
|
|
export CAMINO_DEV_ROOT="$PWD/.var"
|
|
export QUIXOS_PROTO_PATH="${pkgs.protobuf}/include:$PWD/../../quixos-protocol/proto''${QUIXOS_PROTO_PATH:+:$QUIXOS_PROTO_PATH}"
|
|
export CAMINO_PROTO_PATH="$QUIXOS_PROTO_PATH''${CAMINO_PROTO_PATH:+:$CAMINO_PROTO_PATH}"
|
|
export CAMINO_DATABASE_URL="$(${camino-db-url}/bin/camino-db-url)"
|
|
'';
|
|
};
|
|
});
|
|
}
|