nixos-rebuild-ng: reduce build closure by moving checks to passthru.tests

This commit is contained in:
Thiago Kenji Okada 2024-11-16 10:49:48 +00:00
parent 0ceb3a735b
commit d55f8c84a5
2 changed files with 41 additions and 13 deletions

View File

@ -96,4 +96,10 @@ And use `nixos-rebuild-ng` instead of `nixos-rebuild`.
- [ ] Improve documentation
- [ ] `nixos-rebuild repl` (calling old `nixos-rebuild` for now)
- [ ] `nix` build/bootstrap
- [ ] Reduce build closure
- [ ] Generate tab completion via [`shtab`](https://docs.iterative.ai/shtab/)
- [x] Reduce build closure
## TODON'T
- Reimplement `systemd-run` logic (will be moved to the new
[`apply`](https://github.com/NixOS/nixpkgs/pull/344407) script)

View File

@ -3,10 +3,12 @@
installShellFiles,
nix,
nixos-rebuild,
nixos-rebuild-ng,
python3,
runCommand,
withNgSuffix ? true,
}:
python3.pkgs.buildPythonApplication {
python3.pkgs.buildPythonApplication rec {
pname = "nixos-rebuild-ng";
version = "0.0.0";
src = ./src;
@ -18,7 +20,6 @@ python3.pkgs.buildPythonApplication {
dependencies = with python3.pkgs; [
tabulate
types-tabulate
];
nativeBuildInputs = [
@ -55,20 +56,41 @@ python3.pkgs.buildPythonApplication {
nativeCheckInputs = with python3.pkgs; [
pytestCheckHook
mypy
ruff
];
pytestFlagsArray = [ "-vv" ];
postCheck = ''
echo -e "\x1b[32m## run mypy\x1b[0m"
mypy nixos_rebuild tests
echo -e "\x1b[32m## run ruff\x1b[0m"
ruff check nixos_rebuild tests
echo -e "\x1b[32m## run ruff format\x1b[0m"
ruff format --check nixos_rebuild tests
'';
# NOTE: this is a CI test rather than a build-time test because we want to
# keep the build closures small
passthru.tests = {
ci =
runCommand "${pname}-ci"
{
nativeBuildInputs = [
nixos-rebuild-ng # to trigger build
(python3.withPackages (
ps: with ps; [
mypy
pytest
ruff
types-tabulate
]
))
];
}
''
export RUFF_CACHE_DIR="$(mktemp -d)"
echo -e "\x1b[32m## run mypy\x1b[0m"
mypy ${src}
echo -e "\x1b[32m## run ruff\x1b[0m"
ruff check ${src}
echo -e "\x1b[32m## run ruff format\x1b[0m"
ruff format --check ${src}
touch $out
'';
};
meta = {
description = "Rebuild your NixOS configuration and switch to it, on local hosts and remote";