99 lines
4.0 KiB
Nix
99 lines
4.0 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.esbuild
|
|
pkgs.protobuf
|
|
];
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
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
|
|
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/resource-lock/cli.js \
|
|
--bundle --platform=node --target=node24 --format=esm \
|
|
--outfile=quixos-lock-check.mjs
|
|
runHook postBuild
|
|
'';
|
|
doCheck = true;
|
|
checkPhase = ''
|
|
runHook preCheck
|
|
yarn test
|
|
runHook postCheck
|
|
'';
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p "$out"
|
|
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"
|
|
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-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-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-lock-check.mjs "$out/libexec/quixos-protocol/quixos-lock-check.mjs"
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
};
|
|
in {
|
|
packages.default = quixos-protocol;
|
|
checks.default = quixos-protocol;
|
|
devShells.default = pkgs.mkShell {
|
|
packages = [
|
|
nodejs
|
|
pkgs.protobuf
|
|
quixos-protocol.yarn
|
|
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}"
|
|
'';
|
|
};
|
|
});
|
|
}
|