155 lines
7.3 KiB
Nix
155 lines
7.3 KiB
Nix
{
|
|
description = "Shared Quixos protobuf protocol definitions";
|
|
|
|
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; };
|
|
nodejs = pkgs.nodejs_24;
|
|
quixos-protocol = (pkgs.callPackage ./yarn-project.nix { inherit nodejs; }) {
|
|
src = pkgs.lib.cleanSource ./.;
|
|
overrideAttrs = old: {
|
|
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
|
|
pkgs.diffutils
|
|
pkgs.esbuild
|
|
pkgs.protobuf
|
|
pkgs.git
|
|
pkgs.jujutsu
|
|
pkgs.gnutar
|
|
];
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
mkdir -p "$TMPDIR/generated-before"
|
|
cp --recursive src/gen "$TMPDIR/generated-before/proto"
|
|
cp --recursive src/capability-language/generated "$TMPDIR/generated-before/capability"
|
|
cp --recursive src/resource-lock/generated "$TMPDIR/generated-before/lock"
|
|
export QUIXOS_PROTO_PATH="${pkgs.protobuf}/include:$PWD/proto''${QUIXOS_PROTO_PATH:+:$QUIXOS_PROTO_PATH}"
|
|
patchShebangs node_modules/.bin node_modules/@bufbuild/protoc-gen-es/bin
|
|
yarn build
|
|
diff --recursive --unified "$TMPDIR/generated-before/proto" src/gen
|
|
diff --recursive --unified "$TMPDIR/generated-before/capability" src/capability-language/generated
|
|
diff --recursive --unified "$TMPDIR/generated-before/lock" src/resource-lock/generated
|
|
esbuild dist/src/descriptor-check.js \
|
|
--bundle --platform=node --target=node24 --format=esm \
|
|
--outfile=quixos-descriptor-check.mjs
|
|
esbuild dist/src/capability-language/cli.js \
|
|
--bundle --platform=node --target=node24 --format=esm \
|
|
--outfile=quixos-capability-compile.mjs
|
|
esbuild dist/src/capability-language/workspace-cli.js \
|
|
--bundle --platform=node --target=node24 --format=esm \
|
|
--outfile=quixos-workspace-compile.mjs
|
|
esbuild dist/src/capability-language/resource-cli.js \
|
|
--bundle --platform=node --target=node24 --format=esm \
|
|
--outfile=quixos-resource-compile.mjs
|
|
esbuild dist/src/resource-lock/cli.js \
|
|
--bundle --platform=node --target=node24 --format=esm \
|
|
--outfile=quixos-lock-check.mjs
|
|
esbuild dist/src/bindings/cli.js --bundle --platform=node --target=node24 --format=esm --outfile=quixos-codegen-ts.mjs
|
|
esbuild dist/src/capability-language/tool-cli.js --bundle --platform=node --target=node24 --format=esm --outfile=quixos-qx.mjs
|
|
runHook postBuild
|
|
'';
|
|
doCheck = true;
|
|
checkPhase = ''
|
|
runHook preCheck
|
|
yarn test
|
|
runHook postCheck
|
|
'';
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p "$out"
|
|
install -Dm644 nix/checked-package.nix "$out/share/checked-package.nix"
|
|
cp --reflink=auto --recursive grammar "$out/grammar"
|
|
cp --reflink=auto --recursive proto "$out/proto"
|
|
cp --reflink=auto --recursive dist "$out/dist"
|
|
cp package.json "$out/package.json"
|
|
mkdir -p "$out/bin"
|
|
for tool in quixos-codegen-ts quixos-qx; do
|
|
printf '#!/bin/sh\nexec ${pkgs.nodejs_24}/bin/node "%s/libexec/quixos-protocol/%s.mjs" "$@"\n' "$out" "$tool" > "$out/bin/$tool"
|
|
chmod +x "$out/bin/$tool"
|
|
done
|
|
cat > "$out/bin/quixos-descriptor-check" <<EOF
|
|
#!/bin/sh
|
|
export PATH="${pkgs.protobuf}/bin:\$PATH"
|
|
export QUIXOS_PROTO_PATH="${pkgs.protobuf}/include:$out/proto\''${QUIXOS_PROTO_PATH:+:$QUIXOS_PROTO_PATH}"
|
|
exec ${pkgs.nodejs_24}/bin/node "$out/libexec/quixos-protocol/quixos-descriptor-check.mjs" "\$@"
|
|
EOF
|
|
chmod +x "$out/bin/quixos-descriptor-check"
|
|
cat > "$out/bin/quixos-capability-compile" <<EOF
|
|
#!/bin/sh
|
|
exec ${pkgs.nodejs_24}/bin/node "$out/libexec/quixos-protocol/quixos-capability-compile.mjs" "\$@"
|
|
EOF
|
|
chmod +x "$out/bin/quixos-capability-compile"
|
|
cat > "$out/bin/quixos-workspace-compile" <<EOF
|
|
#!/bin/sh
|
|
exec ${pkgs.nodejs_24}/bin/node "$out/libexec/quixos-protocol/quixos-workspace-compile.mjs" "\$@"
|
|
EOF
|
|
chmod +x "$out/bin/quixos-workspace-compile"
|
|
cat > "$out/bin/quixos-resource-compile" <<EOF
|
|
#!/bin/sh
|
|
exec ${pkgs.nodejs_24}/bin/node "$out/libexec/quixos-protocol/quixos-resource-compile.mjs" "\$@"
|
|
EOF
|
|
chmod +x "$out/bin/quixos-resource-compile"
|
|
cat > "$out/bin/quixos-lock-check" <<EOF
|
|
#!/bin/sh
|
|
exec ${pkgs.nodejs_24}/bin/node "$out/libexec/quixos-protocol/quixos-lock-check.mjs" "\$@"
|
|
EOF
|
|
chmod +x "$out/bin/quixos-lock-check"
|
|
mkdir -p "$out/libexec/quixos-protocol"
|
|
install -m644 quixos-codegen-ts.mjs quixos-qx.mjs "$out/libexec/quixos-protocol/"
|
|
install -m644 quixos-descriptor-check.mjs "$out/libexec/quixos-protocol/quixos-descriptor-check.mjs"
|
|
install -m644 quixos-capability-compile.mjs "$out/libexec/quixos-protocol/quixos-capability-compile.mjs"
|
|
install -m644 quixos-workspace-compile.mjs "$out/libexec/quixos-protocol/quixos-workspace-compile.mjs"
|
|
install -m644 quixos-resource-compile.mjs "$out/libexec/quixos-protocol/quixos-resource-compile.mjs"
|
|
install -m644 quixos-lock-check.mjs "$out/libexec/quixos-protocol/quixos-lock-check.mjs"
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
};
|
|
in {
|
|
packages.default = quixos-protocol;
|
|
packages.inspector = (pkgs.callPackage ./yarn-project.nix { inherit nodejs; }) {
|
|
src = pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = pkgs.lib.fileset.unions [ ./package.json ./yarn.lock ./.yarnrc.yml ./.yarn/plugins ./src ];
|
|
};
|
|
overrideAttrs = old: {
|
|
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkgs.esbuild ];
|
|
doCheck = false;
|
|
buildPhase = ''
|
|
esbuild src/capability-language/inspect-cli.ts --bundle --platform=node --target=node24 --format=esm --outfile=inspect.mjs
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p "$out/bin" "$out/lib"
|
|
cp inspect.mjs "$out/lib/inspect.mjs"
|
|
printf '#!${pkgs.runtimeShell}\nexec ${nodejs}/bin/node --max-old-space-size=128 %s/lib/inspect.mjs\n' "$out" > "$out/bin/quixos-qx-inspect"
|
|
chmod +x "$out/bin/quixos-qx-inspect"
|
|
'';
|
|
};
|
|
};
|
|
checks.default = quixos-protocol;
|
|
devShells.default = pkgs.mkShell {
|
|
packages = [
|
|
nodejs
|
|
pkgs.protobuf
|
|
quixos-protocol.yarn-freestanding
|
|
quixos-protocol
|
|
];
|
|
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="quixos-protocol"
|
|
PS1="[qx:quixos-protocol] $PS1"
|
|
fi
|
|
export QUIXOS_PROTO_PATH="${pkgs.protobuf}/include:$PWD/proto''${QUIXOS_PROTO_PATH:+:$QUIXOS_PROTO_PATH}"
|
|
'';
|
|
};
|
|
});
|
|
}
|