mirror of
https://github.com/nix-community/nixvim.git
synced 2025-08-01 16:45:07 +02:00
modules/test: move test derivation to an option
Introduced the `test.derivation` read-only option.
This commit is contained in:
parent
851edc8df1
commit
cbd1003d9d
7 changed files with 114 additions and 91 deletions
|
@ -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
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue