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

View File

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

View File

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