174 lines
4.2 KiB
Nix
174 lines
4.2 KiB
Nix
{
|
|
description = "QVM - Quick development VMs for AI-assisted workflows";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
flake-utils,
|
|
}:
|
|
{
|
|
nixosModules.default =
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.programs.qvm;
|
|
in
|
|
{
|
|
options.programs.qvm = {
|
|
memory = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "8G";
|
|
description = "Amount of memory to allocate to the VM (e.g., '8G', '16G')";
|
|
};
|
|
|
|
cpus = lib.mkOption {
|
|
type = lib.types.int;
|
|
default = 4;
|
|
description = "Number of CPU cores to allocate to the VM";
|
|
};
|
|
};
|
|
|
|
config = {
|
|
environment.systemPackages = [ self.packages.${pkgs.system}.qvm ];
|
|
|
|
environment.etc."xdg/qvm/qvm.conf".text = ''
|
|
QVM_MEMORY="${cfg.memory}"
|
|
QVM_CPUS="${toString cfg.cpus}"
|
|
'';
|
|
};
|
|
};
|
|
}
|
|
// flake-utils.lib.eachDefaultSystem (
|
|
system:
|
|
let
|
|
pkgs = import nixpkgs { inherit system; };
|
|
|
|
qvm = pkgs.stdenv.mkDerivation {
|
|
pname = "qvm";
|
|
version = "0.1.0";
|
|
|
|
src = ./.;
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
makeWrapper
|
|
installShellFiles
|
|
];
|
|
|
|
buildInputs = with pkgs; [
|
|
bash
|
|
];
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
# Create output directories
|
|
mkdir -p $out/bin
|
|
mkdir -p $out/lib/qvm
|
|
mkdir -p $out/share/qvm
|
|
|
|
# Install library files
|
|
install -Dm755 lib/common.sh $out/lib/qvm/common.sh
|
|
|
|
# Install default VM flake template
|
|
if [ -d "flake/default-vm" ]; then
|
|
cp -r flake/default-vm $out/share/qvm/default-vm
|
|
fi
|
|
|
|
# Install all scripts from bin/
|
|
for script in bin/*; do
|
|
if [ -f "$script" ]; then
|
|
install -Dm755 "$script" "$out/bin/$(basename "$script")"
|
|
fi
|
|
done
|
|
|
|
# Wrap all scripts with PATH containing required dependencies
|
|
for script in $out/bin/*; do
|
|
wrapProgram "$script" \
|
|
--prefix PATH : ${
|
|
pkgs.lib.makeBinPath [
|
|
pkgs.qemu
|
|
pkgs.openssh
|
|
pkgs.jq
|
|
pkgs.coreutils
|
|
pkgs.gnused
|
|
pkgs.gnugrep
|
|
pkgs.nix
|
|
pkgs.netcat-gnu
|
|
pkgs.bc
|
|
pkgs.procps
|
|
pkgs.sshpass
|
|
]
|
|
} \
|
|
--set QVM_LIB_DIR "$out/lib/qvm"
|
|
done
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
meta = with pkgs.lib; {
|
|
description = "Quick development VMs for AI-assisted workflows";
|
|
homepage = "https://github.com/josh/qvm";
|
|
license = licenses.mit;
|
|
maintainers = [ ];
|
|
platforms = platforms.linux;
|
|
mainProgram = "qvm";
|
|
};
|
|
};
|
|
|
|
in
|
|
{
|
|
packages = {
|
|
inherit qvm;
|
|
default = qvm;
|
|
};
|
|
|
|
apps = {
|
|
qvm = {
|
|
type = "app";
|
|
program = "${qvm}/bin/qvm";
|
|
};
|
|
default = {
|
|
type = "app";
|
|
program = "${qvm}/bin/qvm";
|
|
};
|
|
};
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
buildInputs = with pkgs; [
|
|
# Runtime dependencies for development
|
|
qemu
|
|
openssh
|
|
jq
|
|
coreutils
|
|
gnused
|
|
gnugrep
|
|
nix
|
|
netcat-gnu
|
|
bc
|
|
procps
|
|
sshpass
|
|
|
|
# Development tools
|
|
shellcheck
|
|
shfmt
|
|
];
|
|
|
|
shellHook = ''
|
|
export QVM_LIB_DIR="$(pwd)/lib"
|
|
echo "QVM development environment"
|
|
echo "Library directory: $QVM_LIB_DIR"
|
|
'';
|
|
};
|
|
}
|
|
);
|
|
}
|