diff options
-rw-r--r-- | flake.nix | 40 | ||||
-rw-r--r-- | tests.nix | 28 | ||||
-rw-r--r-- | tests/README.md | 6 |
3 files changed, 61 insertions, 13 deletions
diff --git a/flake.nix b/flake.nix index f28d40b..cf39e80 100644 --- a/flake.nix +++ b/flake.nix @@ -86,24 +86,38 @@ } @ attrs: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; + nixos-lib = import (nixpkgs + "/nixos/lib") {}; pkgsUnstable = nixpkgs-unstable.legacyPackages.${system}; + + specialArgs = + attrs + // { + inherit pkgsUnstable nixpkgs-unstable nixos-lib extraModules; + }; + + extraModules = [ + simple-nixos-mailserver.nixosModule + disko.nixosModules.default + impermanence.nixosModules.impermanence + agenix.nixosModules.default + ]; + + inherit (pkgs) lib; + tests = import ./tests.nix {inherit lib pkgs specialArgs;}; in { nixosConfigurations."server1" = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; - specialArgs = - attrs - // { - inherit pkgsUnstable; - }; - modules = [ - ./modules/nixos - ./hosts/server1/configuration.nix - simple-nixos-mailserver.nixosModule - disko.nixosModules.default - impermanence.nixosModules.impermanence - agenix.nixosModules.default - ]; + inherit specialArgs; + modules = + extraModules + ++ [ + ./modules/nixos + ./hosts/server1/configuration.nix + ]; }; + + checks."${system}" = tests; + devShells."${system}" = { default = pkgs.mkShell { packages = with pkgs; [ diff --git a/tests.nix b/tests.nix new file mode 100644 index 0000000..d91a9c9 --- /dev/null +++ b/tests.nix @@ -0,0 +1,28 @@ +{ + pkgs, + lib, + specialArgs, +}: let + # for `nix eval --file` (as it does not support args) use: + # ``` + # specialArgs = {}; + # pkgs = (builtins.getFlake "nixpkgs").legacyPackages."x86_64-linux"; + # inherit (pkgs) lib; + # ``` + # instead of the function arguments above. + importTests' = test: let + basename = builtins.baseNameOf test; + testName = builtins.baseNameOf (lib.strings.removeSuffix "/${basename}" "${builtins.toString test}"); + in { + name = "${testName}"; + value = pkgs.callPackage test specialArgs; + }; + + importTests = dir: + builtins.listToAttrs (builtins.map importTests' ( + lib.fileset.toList (lib.fileset.fileFilter (file: file.name == "test.nix") dir) + )); + + tests = importTests ./tests; +in + tests diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..2613f4a --- /dev/null +++ b/tests/README.md @@ -0,0 +1,6 @@ +# Tests + +This directory tree mirrors the modules defined in the +[modules](`../modules/`) directory. Each module should have at least +one test in the mirrored directory, effectively replacing the module's +`default.nix` file. |