modules/test: move test derivation to an option

Introduced the `test.derivation` read-only option.
This commit is contained in:
Matt Sturgeon 2024-08-05 12:21:24 +01:00
parent 851edc8df1
commit cbd1003d9d
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
7 changed files with 114 additions and 91 deletions

View file

@ -1,10 +1,64 @@
{ lib, ... }:
{
pkgs,
config,
lib,
...
}:
let
cfg = config.test;
in
{
options.test = {
name = lib.mkOption {
type = lib.types.str;
default = "nixvim-check";
description = "The test derivation's name.";
};
runNvim = lib.mkOption {
type = lib.types.bool;
description = "Whether to run `nvim` in the test.";
default = true;
};
# 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;
nativeBuildInputs = [
config.finalPackage
pkgs.docker-client
];
# 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
'';
};
};
}