Add testScript option

This commit is contained in:
Sridhar Ratnakumar 2023-06-13 12:45:04 -04:00
parent b5e97b110d
commit 3e6a7e4e0f
4 changed files with 57 additions and 4 deletions

View File

@ -2,7 +2,7 @@
## Unreleased
- ...
- Add `testScript` option for adding flake checks based on nixosTest library.
## 0.1.0 (Jun 12, 2023)

View File

@ -29,9 +29,14 @@ in
});
};
config.packages = lib.mapAttrs
(name: cfg: cfg.outputs.package)
config.process-compose;
config = {
packages = lib.mapAttrs
(name: cfg: cfg.outputs.package)
config.process-compose;
checks = lib.mapAttrs
(name: cfg: cfg.outputs.check)
config.process-compose;
};
});
}

View File

@ -7,6 +7,7 @@ in
imports = [
./cli.nix
./settings
./test.nix
];
options = {

View File

@ -0,0 +1,47 @@
{ name, config, pkgs, lib, ... }:
let
inherit (lib) types mkOption;
in
{
options = {
testScript = mkOption {
type = types.nullOr types.str;
description = ''
If set, add a flake check running nixosTest running this process-compose
configuration, followed by the specified testScript.
Useful if you want to test your configuration in CI.
'';
default = null;
};
outputs.check = mkOption {
type = types.nullOr types.package;
default = if config.testScript == null then null else
pkgs.nixosTest {
inherit (config) testScript;
name = "process-compose-${name}-test";
nodes.machine = {
environment.systemPackages = [ pkgs.bash ]; # process-compose requires it.
systemd.services.process-compose = {
enable = true;
wantedBy = [ "default.target" ];
serviceConfig = {
WorkingDirectory = "/tmp";
ExecStart = lib.getExe (pkgs.writeShellApplication {
name = "process-compose-${name}";
text = ''
set -x
echo "Launching procese-compose on ${name} ..."
# make bash available to process-compose
export PATH=/run/current-system/sw/bin:$PATH
${lib.getExe config.outputs.package} -t=false
'';
});
};
};
};
};
};
};
}