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
+ '';
+ };
+ };
+}
diff --git a/lib/strings/default.nix b/lib/strings/default.nix
index dccb09f..ca056e0 100644
--- a/lib/strings/default.nix
+++ b/lib/strings/default.nix
@@ -11,5 +11,14 @@
prefixLength = lib.strings.commonPrefixLength a b;
in
builtins.substring 0 prefixLength a;
+
+ endsWith = suffix: str: let
+ suffixLength = builtins.stringLength suffix;
+ strLength = builtins.stringLength str;
+
+ suffixStart = strLength - suffixLength;
+
+ maybeSuffix = builtins.substring suffixStart strLength str;
+ in suffixStart >= 0 && maybeSuffix == suffix;
};
}