2024-08-05 12:21:24 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.test;
|
|
|
|
in
|
2024-08-20 00:30:16 +01:00
|
|
|
{
|
|
|
|
options.test = {
|
2024-08-05 12:21:24 +01:00
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "nixvim-check";
|
|
|
|
description = "The test derivation's name.";
|
|
|
|
};
|
|
|
|
|
2024-08-20 00:30:16 +01:00
|
|
|
runNvim = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
description = "Whether to run `nvim` in the test.";
|
|
|
|
default = true;
|
|
|
|
};
|
2024-08-05 12:21:24 +01:00
|
|
|
|
|
|
|
# Output
|
|
|
|
derivation = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
description = ''
|
|
|
|
A derivation that tests the config by running neovim.
|
|
|
|
'';
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
test.derivation = pkgs.stdenv.mkDerivation {
|
|
|
|
inherit (cfg) name;
|
|
|
|
dontUnpack = true;
|
|
|
|
|
2024-08-21 02:35:38 +01:00
|
|
|
nativeBuildInputs = [ config.finalPackage ];
|
2024-08-05 12:21:24 +01:00
|
|
|
|
|
|
|
# We need to set HOME because neovim will try to create some files
|
|
|
|
#
|
|
|
|
# Because neovim does not return an exitcode when quitting we need to check if there are
|
|
|
|
# errors on stderr
|
|
|
|
buildPhase = lib.optionalString cfg.runNvim ''
|
|
|
|
mkdir -p .cache/nvim
|
|
|
|
|
|
|
|
output=$(HOME=$(realpath .) nvim -mn --headless "+q" 2>&1 >/dev/null)
|
|
|
|
if [[ -n $output ]]; then
|
|
|
|
echo "ERROR: $output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
# If we don't do this nix is not happy
|
|
|
|
installPhase = ''
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
};
|
2024-08-20 00:30:16 +01:00
|
|
|
};
|
|
|
|
}
|