flake.nix: Dynamically import tests

Makes it possible to add new test files to the tests directory and have
everything instantly working.
This commit is contained in:
Donovan Glover 2024-04-08 10:33:06 -04:00
parent cc0213be48
commit 30e0239cf7
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65
4 changed files with 13 additions and 19 deletions

View File

@ -27,15 +27,8 @@
inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage;
inherit (builtins) attrNames listToAttrs map replaceStrings readDir;
checkArgs = {
inherit self;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
};
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" ];
flakeDirectories = [ "overlays" "modules" "home" "packages" ];
packageDirectory = "packages";
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" "checks" ];
flakeDirectories = [ "overlays" "modules" "home" "packages" "tests" ];
in
{
formatter.x86_64-linux = nixpkgs-fmt;
@ -47,11 +40,6 @@
modules = [ ./. ];
};
};
checks.x86_64-linux = {
hyprland = import ./tests/hyprland.nix checkArgs;
neovim = import ./tests/neovim.nix checkArgs;
};
} //
(listToAttrs
(map
@ -66,14 +54,20 @@
(file: {
name = replaceStrings [ ".nix" ] [ "" ] file;
value =
if directory == packageDirectory
if directory == "packages"
then callPackage ./${directory}/${file} { }
else import ./${directory}/${file};
else
if directory == "tests"
then import ./${directory}/${file} {
inherit self;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
}
else import ./${directory}/${file};
})
(attrNames (readDir ./${directory}))));
attributeSet =
if directory == packageDirectory
if directory == "packages" || directory == "tests"
then { x86_64-linux = attributeValue; }
else attributeValue;
in

View File

@ -2,7 +2,7 @@
let
inherit (builtins) attrValues;
in
(import ./lib.nix) {
(import ../lib.nix) {
name = "hyprland";
nodes.machine = { nix-config, ... }: {

View File

@ -2,7 +2,7 @@
let
inherit (builtins) attrValues;
in
(import ./lib.nix) {
(import ../lib.nix) {
name = "neovim";
nodes.machine = { nix-config, ... }: {