diff --git a/CHANGELOG.md b/CHANGELOG.md index b8507d4..5f02d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- ... +- Add `testScript` option for adding flake checks based on nixosTest library. ## 0.1.0 (Jun 12, 2023) diff --git a/nix/flake-module.nix b/nix/flake-module.nix index 790a7bc..d4b4857 100644 --- a/nix/flake-module.nix +++ b/nix/flake-module.nix @@ -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; + }; }); } diff --git a/nix/process-compose/default.nix b/nix/process-compose/default.nix index fc7256d..aad3330 100644 --- a/nix/process-compose/default.nix +++ b/nix/process-compose/default.nix @@ -7,6 +7,7 @@ in imports = [ ./cli.nix ./settings + ./test.nix ]; options = { diff --git a/nix/process-compose/test.nix b/nix/process-compose/test.nix new file mode 100644 index 0000000..088a0e4 --- /dev/null +++ b/nix/process-compose/test.nix @@ -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 + ''; + }); + }; + }; + }; + }; + }; + }; +} \ No newline at end of file