add nixos module

This commit is contained in:
Joshua Bell 2026-01-26 10:16:33 -06:00
parent 601b4ab15e
commit e28d1fa14f

View file

@ -6,87 +6,108 @@
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils }: outputs =
flake-utils.lib.eachDefaultSystem (system: {
self,
nixpkgs,
flake-utils,
}:
{
nixosModules.default =
{
pkgs,
...
}:
{
config = {
environment.systemPackages = [ self.packages.${pkgs.system}.qvm ];
};
};
}
// flake-utils.lib.eachDefaultSystem (
system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
qvm = pkgs.stdenv.mkDerivation { qvm = pkgs.stdenv.mkDerivation {
pname = "qvm"; pname = "qvm";
version = "0.1.0"; version = "0.1.0";
src = ./.; src = ./.;
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
makeWrapper makeWrapper
installShellFiles installShellFiles
]; ];
buildInputs = with pkgs; [ buildInputs = with pkgs; [
bash bash
]; ];
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
# Create output directories # Create output directories
mkdir -p $out/bin mkdir -p $out/bin
mkdir -p $out/lib/qvm mkdir -p $out/lib/qvm
mkdir -p $out/share/qvm mkdir -p $out/share/qvm
# Install library files # Install library files
install -Dm755 lib/common.sh $out/lib/qvm/common.sh install -Dm755 lib/common.sh $out/lib/qvm/common.sh
# Install default VM flake template # Install default VM flake template
if [ -d "flake/default-vm" ]; then if [ -d "flake/default-vm" ]; then
cp -r flake/default-vm $out/share/qvm/default-vm cp -r flake/default-vm $out/share/qvm/default-vm
fi fi
# Install all scripts from bin/ # Install all scripts from bin/
for script in bin/*; do for script in bin/*; do
if [ -f "$script" ]; then if [ -f "$script" ]; then
install -Dm755 "$script" "$out/bin/$(basename "$script")" install -Dm755 "$script" "$out/bin/$(basename "$script")"
fi fi
done done
# Wrap all scripts with PATH containing required dependencies # Wrap all scripts with PATH containing required dependencies
for script in $out/bin/*; do for script in $out/bin/*; do
wrapProgram "$script" \ wrapProgram "$script" \
--prefix PATH : ${pkgs.lib.makeBinPath [ --prefix PATH : ${
pkgs.qemu pkgs.lib.makeBinPath [
pkgs.openssh pkgs.qemu
pkgs.jq pkgs.openssh
pkgs.coreutils pkgs.jq
pkgs.gnused pkgs.coreutils
pkgs.gnugrep pkgs.gnused
pkgs.nix pkgs.gnugrep
pkgs.netcat-gnu pkgs.nix
pkgs.bc pkgs.netcat-gnu
pkgs.procps pkgs.bc
pkgs.sshpass pkgs.procps
]} \ pkgs.sshpass
]
} \
--set QVM_LIB_DIR "$out/lib/qvm" --set QVM_LIB_DIR "$out/lib/qvm"
done done
runHook postInstall runHook postInstall
''; '';
meta = with pkgs.lib; { meta = with pkgs.lib; {
description = "Quick development VMs for AI-assisted workflows"; description = "Quick development VMs for AI-assisted workflows";
homepage = "https://github.com/josh/qvm"; homepage = "https://github.com/josh/qvm";
license = licenses.mit; license = licenses.mit;
maintainers = []; maintainers = [ ];
platforms = platforms.linux; platforms = platforms.linux;
mainProgram = "qvm"; mainProgram = "qvm";
}; };
}; };
in { in
{
packages = { packages = {
inherit qvm; inherit qvm;
default = qvm; default = qvm;
}; };
apps = { apps = {
qvm = { qvm = {
type = "app"; type = "app";
@ -97,7 +118,7 @@
program = "${qvm}/bin/qvm"; program = "${qvm}/bin/qvm";
}; };
}; };
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
# Runtime dependencies for development # Runtime dependencies for development
@ -112,12 +133,12 @@
bc bc
procps procps
sshpass sshpass
# Development tools # Development tools
shellcheck shellcheck
shfmt shfmt
]; ];
shellHook = '' shellHook = ''
export QVM_LIB_DIR="$(pwd)/lib" export QVM_LIB_DIR="$(pwd)/lib"
echo "QVM development environment" echo "QVM development environment"