nix-builder-autoscaler/flake.nix

208 lines
6.1 KiB
Nix
Raw Normal View History

2026-02-27 10:25:17 +01:00
{
2026-02-27 11:59:16 +01:00
description = "nix-builder-autoscaler - autoscaler daemon for Nix remote builders on EC2 Spot";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
2026-02-27 10:25:17 +01:00
outputs =
2026-02-27 11:59:16 +01:00
{
self,
nixpkgs,
treefmt-nix,
pyproject-nix,
uv2nix,
pyproject-build-systems,
...
}:
2026-02-27 10:25:17 +01:00
let
2026-02-27 11:59:16 +01:00
systems = [ "x86_64-linux" ];
2026-02-27 10:25:17 +01:00
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
2026-02-27 11:59:16 +01:00
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./agent; };
overlay = workspace.mkPyprojectOverlay { sourcePreference = "wheel"; };
2026-02-27 10:25:17 +01:00
in
{
2026-02-27 11:59:16 +01:00
formatter = forAllSystems (
pkgs: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
);
packages = forAllSystems (
pkgs:
let
pythonSet =
(pkgs.callPackage pyproject-nix.build.packages {
python = pkgs.python312;
}).overrideScope
(
pkgs.lib.composeManyExtensions [
pyproject-build-systems.overlays.default
overlay
]
);
venv = pythonSet.mkVirtualEnv "nix-builder-autoscaler-env" workspace.deps.default;
in
{
nix-builder-autoscaler = venv;
default = venv;
}
);
apps = forAllSystems (
pkgs:
let
venv = self.packages.${pkgs.stdenv.hostPlatform.system}.nix-builder-autoscaler;
in
{
nix-builder-autoscaler = {
type = "app";
program = "${venv}/bin/python";
meta.description = "Nix builder autoscaler daemon";
};
autoscalerctl = {
type = "app";
program = "${venv}/bin/autoscalerctl";
meta.description = "Autoscaler CLI";
};
default = {
type = "app";
program = "${venv}/bin/autoscalerctl";
meta.description = "Autoscaler CLI";
};
}
);
checks = forAllSystems (
pkgs:
let
pythonSet =
(pkgs.callPackage pyproject-nix.build.packages {
python = pkgs.python312;
}).overrideScope
(
pkgs.lib.composeManyExtensions [
pyproject-build-systems.overlays.default
overlay
]
);
testVenv = pythonSet.mkVirtualEnv "nix-builder-autoscaler-test-env" {
nix-builder-autoscaler = [ "dev" ];
};
src = ./agent;
in
{
devShell = self.devShells.${pkgs.stdenv.hostPlatform.system}.default;
nix-builder-autoscaler-unit-tests = pkgs.stdenv.mkDerivation {
name = "nix-builder-autoscaler-unit-tests";
inherit src;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ testVenv ];
checkPhase = ''
runHook preCheck
export HOME=$(mktemp -d)
pytest nix_builder_autoscaler/tests/ --ignore=nix_builder_autoscaler/tests/integration/ -v
runHook postCheck
'';
doCheck = true;
installPhase = ''
mkdir -p $out
touch $out/passed
'';
};
nix-builder-autoscaler-integration-tests = pkgs.stdenv.mkDerivation {
name = "nix-builder-autoscaler-integration-tests";
inherit src;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ testVenv ];
checkPhase = ''
runHook preCheck
export HOME=$(mktemp -d)
# Exit code 5 means no tests collected — tolerate until integration tests are written
pytest nix_builder_autoscaler/tests/integration/ -v || test $? -eq 5
runHook postCheck
'';
doCheck = true;
installPhase = ''
mkdir -p $out
touch $out/passed
'';
};
nix-builder-autoscaler-ruff = pkgs.stdenv.mkDerivation {
name = "nix-builder-autoscaler-ruff";
inherit src;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ testVenv ];
checkPhase = ''
runHook preCheck
ruff check nix_builder_autoscaler/
ruff format --check nix_builder_autoscaler/
runHook postCheck
'';
doCheck = true;
installPhase = ''
mkdir -p $out
touch $out/passed
'';
};
nix-builder-autoscaler-pyright = pkgs.stdenv.mkDerivation {
name = "nix-builder-autoscaler-pyright";
inherit src;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [
testVenv
pkgs.nodejs
];
checkPhase = ''
runHook preCheck
export HOME=$(mktemp -d)
pyright nix_builder_autoscaler/
runHook postCheck
'';
doCheck = true;
installPhase = ''
mkdir -p $out
touch $out/passed
'';
};
}
2026-02-27 10:25:17 +01:00
);
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
2026-02-27 11:59:16 +01:00
uv
ruff
pyright
2026-02-27 10:25:17 +01:00
];
};
});
};
}