feat(flake): Add unit testing
Change-Id: Idc9bbca0e752b21a5293e2ad4819da9af42ca8ca
Reviewed-on: https://git.clicks.codes/c/Infra/NixFiles/+/782
Tested-by: Skyler Grey <minion@clicks.codes>
Reviewed-by: Samuel Shuert <coded@clicks.codes>
diff --git a/lib/checks/default.nix b/lib/checks/default.nix
new file mode 100644
index 0000000..0340be1
--- /dev/null
+++ b/lib/checks/default.nix
@@ -0,0 +1,38 @@
+# SPDX-FileCopyrightText: 2024 Clicks Codes
+#
+# SPDX-License-Identifier: GPL-3.0-only
+
+{
+ lib,
+ inputs,
+ ...
+}: {
+ checks = pkgs: {
+ nix-unit = pkgs.stdenv.mkDerivation {
+ name = "run nix-unit";
+ src = ./../..;
+ buildPhase = let
+ getSubInputs = prefix: inputs: lib.trivial.pipe inputs [
+ (lib.attrsets.mapAttrsToList (name: value: [
+ "--override-input ${prefix}${name} ${value.outPath}"
+ (if value ? inputs
+ then getSubInputs "${prefix}${name}/" value.inputs
+ else [])
+ ]))
+ lib.lists.flatten
+ (builtins.concatStringsSep " ")
+ ];
+ inputPathArgs = getSubInputs "" inputs;
+ in ''
+ export HOME="$(realpath .)"
+ ${pkgs.lib.getExe pkgs.nix-unit} \
+ --eval-store $HOME \
+ --flake \
+ --option extra-experimental-features flakes \
+ ${inputPathArgs} \
+ .#specs.${pkgs.system}
+ touch $out
+ '';
+ };
+ };
+}