From 7cbeaa437565e2154ae68835e244b9164de660f6 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 23 Nov 2024 10:25:54 +0100 Subject: tests({tests,modules}): Couple via a co-import --- lib/by-name-overlay.nix | 13 ++++++++++++- modules/default.nix | 7 +++++++ tests/default.nix | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/by-name-overlay.nix b/lib/by-name-overlay.nix index cc8bcb67..4d700a8f 100644 --- a/lib/by-name-overlay.nix +++ b/lib/by-name-overlay.nix @@ -5,6 +5,8 @@ baseDirectory, fileName, finalizeFunction, + coImportsNameFunction ? null, + coImportsWarnMessageObject ? null, }: let # Takes a list of attrs as input and returns one merged attr set. flattenAttrs = list: @@ -44,9 +46,18 @@ else let mkPath = name: _type: let path = baseDirectory + "/${shard}/${name}" + "/${fileName}"; + coImportPath = + if coImportsNameFunction != null + then + coImportsNameFunction + {inherit shard name;} + else path; in if builtins.pathExists path - then path + then + if builtins.pathExists coImportPath + then path + else warn "'${builtins.toString coImportPath}' does not exist. Should include ${coImportsWarnMessageObject} for '${shard}/${name}'" path else warn "'${builtins.toString path}' does not exist. Skipped" null; in filterAttrs (name: value: value != null) diff --git a/modules/default.nix b/modules/default.nix index 3364c3db..af5ef20f 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -9,6 +9,13 @@ baseDirectory = ./by-name; fileName = "module.nix"; finalizeFunction = name: value: value; + + coImportsNameFunction = { + shard, + name, + }: + ../tests/by-name + "/${shard}" + "/${name}" + "/test.nix"; + coImportsWarnMessageObject = "test"; }); in { imports = files; diff --git a/tests/default.nix b/tests/default.nix index 9803c99c..a5ca5deb 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -28,6 +28,13 @@ mkTest ; }; + + coImportsNameFunction = { + shard, + name, + }: + ../modules/by-name + "/${shard}" + "/${name}" + "/module.nix"; + coImportsWarnMessageObject = "modules"; }; in tests -- cgit 1.4.1