WIP: test: Set up service tests
This commit is contained in:
parent
82e9a58bb1
commit
30a5843fdf
6 changed files with 121 additions and 11 deletions
|
|
@ -6,6 +6,8 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
x86_64-linux = lib.mergeAttrsList [
|
x86_64-linux = lib.mergeAttrsList [
|
||||||
|
flake-inputs.self.nixosConfigurations.hetzner-1.config.serviceTests
|
||||||
|
|
||||||
{
|
{
|
||||||
nix = checkLib.mkLint {
|
nix = checkLib.mkLint {
|
||||||
name = "nix-lints";
|
name = "nix-lints";
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
flake-inputs.tlaternet-webserver.nixosModules.default
|
flake-inputs.tlaternet-webserver.nixosModules.default
|
||||||
|
|
||||||
"${modulesPath}/profiles/minimal.nix"
|
"${modulesPath}/profiles/minimal.nix"
|
||||||
(import ../modules)
|
../modules
|
||||||
|
|
||||||
./services/backups.nix
|
./services/backups.nix
|
||||||
./services/battery-manager.nix
|
./services/battery-manager.nix
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
{ lib, ... }:
|
{
|
||||||
|
flake-inputs,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./logging.nix
|
./logging.nix
|
||||||
|
|
@ -10,7 +15,8 @@
|
||||||
description = "The base domain name to append to virtual domain names";
|
description = "The base domain name to append to virtual domain names";
|
||||||
};
|
};
|
||||||
|
|
||||||
config.services.nginx = {
|
config = {
|
||||||
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
recommendedTlsSettings = true;
|
recommendedTlsSettings = true;
|
||||||
recommendedOptimisation = true;
|
recommendedOptimisation = true;
|
||||||
|
|
@ -19,4 +25,54 @@
|
||||||
clientMaxBodySize = "10G";
|
clientMaxBodySize = "10G";
|
||||||
statusPage = true; # For metrics, should be accessible only from localhost
|
statusPage = true; # For metrics, should be accessible only from localhost
|
||||||
};
|
};
|
||||||
|
|
||||||
|
serviceTests =
|
||||||
|
let
|
||||||
|
testHostConfig =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
_module.args = { inherit flake-inputs; };
|
||||||
|
imports = [
|
||||||
|
./.
|
||||||
|
../../modules/serviceTests/mocks.nix
|
||||||
|
flake-inputs.sops-nix.nixosModules.sops
|
||||||
|
];
|
||||||
|
|
||||||
|
services.nginx = {
|
||||||
|
domain = "testHost";
|
||||||
|
|
||||||
|
virtualHosts."${config.services.nginx.domain}" = {
|
||||||
|
useACMEHost = "tlater.net";
|
||||||
|
forceSSL = true;
|
||||||
|
enableHSTS = true;
|
||||||
|
locations."/".return = "200 ok";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
hstsIsSet = pkgs.testers.runNixOSTest {
|
||||||
|
name = "assert-hsts";
|
||||||
|
nodes = {
|
||||||
|
testHost = testHostConfig;
|
||||||
|
|
||||||
|
client =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
environment.systemPackages = [ pkgs.curl ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
testHost.wait_for_unit("nginx")
|
||||||
|
testHost.succeed("systemctl start network-online.target")
|
||||||
|
testHost.wait_for_unit("network-online.target")
|
||||||
|
|
||||||
|
client.succeed("curl http://testHost")
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,6 @@
|
||||||
{ imports = [ ./crowdsec ]; }
|
{
|
||||||
|
imports = [
|
||||||
|
./crowdsec
|
||||||
|
./serviceTests/stub.nix
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
|
||||||
27
modules/serviceTests/mocks.nix
Normal file
27
modules/serviceTests/mocks.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/**
|
||||||
|
Module containing mock definitions for service test runners.
|
||||||
|
*/
|
||||||
|
{ lib, ... }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
../.
|
||||||
|
../../configuration/services/backups.nix
|
||||||
|
];
|
||||||
|
# imports = [ flake-inputs.sops-nix.nixosModules.sops ];
|
||||||
|
|
||||||
|
sops.defaultSopsFile = ../../keys/staging.yaml;
|
||||||
|
environment.etc."staging.key" = {
|
||||||
|
mode = "0400";
|
||||||
|
source = ../../keys/hosts/staging.key;
|
||||||
|
};
|
||||||
|
services.openssh = {
|
||||||
|
enable = true;
|
||||||
|
hostKeys = lib.mkForce [
|
||||||
|
{
|
||||||
|
type = "rsa";
|
||||||
|
bits = 4096;
|
||||||
|
path = "/etc/staging.key";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
20
modules/serviceTests/stub.nix
Normal file
20
modules/serviceTests/stub.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
Module to make writing service-specific tests easy.
|
||||||
|
*/
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
serviceTests = mkOption {
|
||||||
|
type = types.attrsOf types.package;
|
||||||
|
|
||||||
|
description = ''
|
||||||
|
NixOS tests to run.
|
||||||
|
'';
|
||||||
|
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue