From 30e0239cf79adc59589325b5436dfcf6263fe435 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Mon, 8 Apr 2024 10:33:06 -0400 Subject: [PATCH] flake.nix: Dynamically import tests Makes it possible to add new test files to the tests directory and have everything instantly working. --- flake.nix | 28 +++++++++++----------------- tests/lib.nix => lib.nix | 0 tests/hyprland.nix | 2 +- tests/neovim.nix | 2 +- 4 files changed, 13 insertions(+), 19 deletions(-) rename tests/lib.nix => lib.nix (100%) diff --git a/flake.nix b/flake.nix index 9a425b7e..920dc44e 100644 --- a/flake.nix +++ b/flake.nix @@ -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 diff --git a/tests/lib.nix b/lib.nix similarity index 100% rename from tests/lib.nix rename to lib.nix diff --git a/tests/hyprland.nix b/tests/hyprland.nix index ad3c3c9b..8c7366bb 100644 --- a/tests/hyprland.nix +++ b/tests/hyprland.nix @@ -2,7 +2,7 @@ let inherit (builtins) attrValues; in -(import ./lib.nix) { +(import ../lib.nix) { name = "hyprland"; nodes.machine = { nix-config, ... }: { diff --git a/tests/neovim.nix b/tests/neovim.nix index 550cc67d..f7444fca 100644 --- a/tests/neovim.nix +++ b/tests/neovim.nix @@ -2,7 +2,7 @@ let inherit (builtins) attrValues; in -(import ./lib.nix) { +(import ../lib.nix) { name = "neovim"; nodes.machine = { nix-config, ... }: {