tests: merge both flakes

we used to have a flake in tests/flake.nix on top of the top-level one.
This results in 2 lockfiles for the same purpose and is not practical.
Instead this moves tests to legacyPackages:

- so they dont appear in "nix flake show" as it can be inconvenient
- legacyPackages supported nested attribute sets of derivations which
  could let us regroup tests under a same set and build that instead.
  For instance, one could `nix build .#tests.neovim` and build all of
  neovim packages. One could still pick a single `nix build
  .#tests.neovim.plugin-config`

dont expose tests into devShells to limit

fix python test runner to find the tests where appropriate
This commit is contained in:
teto 2026-01-03 22:48:19 +01:00 committed by Austin Horstman
parent f1ebddedab
commit 8e0f4cdeee
3 changed files with 137 additions and 171 deletions

136
flake.nix
View file

@ -48,6 +48,113 @@
forAllPkgs =
f:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: f nixpkgs.legacyPackages.${system});
forCI = nixpkgs.lib.genAttrs [
"aarch64-darwin"
"x86_64-linux"
];
testChunks =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
# Create chunked test packages for better CI parallelization
tests = import ./tests {
inherit pkgs;
# Disable big tests since this is only used for CI
enableBig = false;
};
allTests = lib.attrNames tests.build;
# Remove 'all' from the test list as it's a meta-package
filteredTests = lib.filter (name: name != "all") allTests;
# NOTE: Just a starting value, we can tweak this to find a good value.
targetTestsPerChunk = 50;
numChunks = lib.max 1 (
builtins.ceil ((builtins.length filteredTests) / (targetTestsPerChunk * 1.0))
);
chunkSize = builtins.ceil ((builtins.length filteredTests) / (numChunks * 1.0));
makeChunk =
chunkNum: testList:
let
start = (chunkNum - 1) * chunkSize;
end = lib.min (start + chunkSize) (builtins.length testList);
chunkTests = lib.sublist start (end - start) testList;
chunkAttrs = lib.genAttrs chunkTests (name: tests.build.${name});
in
pkgs.symlinkJoin {
name = "test-chunk-${toString chunkNum}";
paths = lib.attrValues chunkAttrs;
passthru.tests = chunkTests;
};
in
lib.listToAttrs (
lib.genList (
i: lib.nameValuePair "test-chunk-${toString (i + 1)}" (makeChunk (i + 1) filteredTests)
) numChunks
);
integrationTests =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
in
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux (
let
tests = import ./tests/integration { inherit pkgs lib; };
renameTestPkg = n: v: lib.nameValuePair "integration-${n}" v;
in
lib.mapAttrs' renameTestPkg (lib.removeAttrs tests [ "all" ])
);
buildTests =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./tests { inherit pkgs; };
renameTestPkg = n: nixpkgs.lib.nameValuePair "test-${n}";
in
nixpkgs.lib.mapAttrs' renameTestPkg tests.build;
buildTestsNoBig =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./tests {
inherit pkgs;
enableBig = false;
};
in
{
test-all-enableBig-false-enableLegacyIfd-false = tests.build.all;
};
buildTestsNoBigIfd =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./tests {
inherit pkgs;
enableBig = false;
enableLegacyIfd = true;
};
in
{
test-all-enableBig-false-enableLegacyIfd-true = tests.build.all;
};
integrationTestPackages =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
tests = import ./tests/integration { inherit pkgs lib; };
renameTestPkg = n: lib.nameValuePair "integration-test-${n}";
in
lib.mapAttrs' renameTestPkg tests;
in
{
formatter = forAllPkgs (
@ -63,6 +170,22 @@
}
);
# TODO: increase buildbot testing scope
buildbot = forCI (
system:
let
allIntegrationTests = integrationTests system;
workingIntegrationTests = nixpkgs.lib.filterAttrs (
name: _:
nixpkgs.lib.elem name [
"integration-nixos-basics"
"integration-nixos-legacy-profile-management"
]
) allIntegrationTests;
in
(testChunks system) // workingIntegrationTests
);
packages = forAllPkgs (
pkgs:
let
@ -90,6 +213,19 @@
docs-manpages = docs.manPages;
}
);
legacyPackages = forAllPkgs (
pkgs:
let
system = pkgs.stdenv.hostPlatform.system;
in
(buildTests system)
// (integrationTestPackages system)
// (buildTestsNoBig system)
// (buildTestsNoBigIfd system)
// (testChunks system)
// (integrationTests system)
);
}
);
}

View file

@ -1,169 +0,0 @@
# This is an internal Nix Flake intended for use when running tests.
#
# You can build all tests or specific tests by running
#
# nix build --reference-lock-file flake.lock ./tests#test-all
# nix build --reference-lock-file flake.lock ./tests#test-alacritty-empty-settings
#
# in the Home Manager project root directory.
#
# Similarly for integration tests
#
# nix build --reference-lock-file flake.lock ./tests#integration-test-all
# nix build --reference-lock-file flake.lock ./tests#integration-test-standalone-standard-basics
{
description = "Tests of Home Manager for Nix";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{ nixpkgs, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
forCI = nixpkgs.lib.genAttrs [
"aarch64-darwin"
"x86_64-linux"
];
testChunks =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
# Create chunked test packages for better CI parallelization
tests = import ./. {
inherit pkgs;
# Disable big tests since this is only used for CI
enableBig = false;
};
allTests = lib.attrNames tests.build;
# Remove 'all' from the test list as it's a meta-package
filteredTests = lib.filter (name: name != "all") allTests;
# NOTE: Just a starting value, we can tweak this to find a good value.
targetTestsPerChunk = 50;
numChunks = lib.max 1 (
builtins.ceil ((builtins.length filteredTests) / (targetTestsPerChunk * 1.0))
);
chunkSize = builtins.ceil ((builtins.length filteredTests) / (numChunks * 1.0));
makeChunk =
chunkNum: testList:
let
start = (chunkNum - 1) * chunkSize;
end = lib.min (start + chunkSize) (builtins.length testList);
chunkTests = lib.sublist start (end - start) testList;
chunkAttrs = lib.genAttrs chunkTests (name: tests.build.${name});
in
pkgs.symlinkJoin {
name = "test-chunk-${toString chunkNum}";
paths = lib.attrValues chunkAttrs;
passthru.tests = chunkTests;
};
in
lib.listToAttrs (
lib.genList (
i: lib.nameValuePair "test-chunk-${toString (i + 1)}" (makeChunk (i + 1) filteredTests)
) numChunks
);
integrationTests =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
in
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux (
let
tests = import ./integration { inherit pkgs lib; };
renameTestPkg = n: v: lib.nameValuePair "integration-${n}" v;
in
lib.mapAttrs' renameTestPkg (lib.removeAttrs tests [ "all" ])
);
# Test group definitions
buildTests =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./. { inherit pkgs; };
renameTestPkg = n: nixpkgs.lib.nameValuePair "test-${n}";
in
nixpkgs.lib.mapAttrs' renameTestPkg tests.build;
buildTestsNoBig =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./. {
inherit pkgs;
enableBig = false;
};
in
{
test-all-enableBig-false-enableLegacyIfd-false = tests.build.all;
};
buildTestsNoBigIfd =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./. {
inherit pkgs;
enableBig = false;
enableLegacyIfd = true;
};
in
{
test-all-enableBig-false-enableLegacyIfd-true = tests.build.all;
};
integrationTestPackages =
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
tests = import ./integration { inherit pkgs lib; };
renameTestPkg = n: lib.nameValuePair "integration-test-${n}";
in
lib.mapAttrs' renameTestPkg tests;
in
{
# TODO: increase buildbot testing scope
buildbot = forCI (
system:
let
allIntegrationTests = integrationTests system;
workingIntegrationTests = nixpkgs.lib.filterAttrs (
name: _:
nixpkgs.lib.elem name [
"integration-nixos-basics"
"integration-nixos-legacy-profile-management"
]
) allIntegrationTests;
in
(testChunks system) // workingIntegrationTests
);
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
tests = import ./. { inherit pkgs; };
in
tests.run
);
packages = forAllSystems (
system:
(buildTests system)
// (integrationTestPackages system)
// (buildTestsNoBig system)
// (buildTestsNoBigIfd system)
// (testChunks system)
// (integrationTests system)
);
};
}

View file

@ -64,8 +64,7 @@ class TestRunner:
)
cmd = [
"nix", "eval", "--raw", "--reference-lock-file", "flake.lock",
f"./tests#packages.{system}", "--apply", nix_apply_expr
"nix", "eval", "--raw", f".#legacyPackages.{system}", "--apply", nix_apply_expr
]
result = _run_command(cmd, cwd=self.repo_root)