2021-03-22 05:19:48 -07:00
|
|
|
pkgs:
|
2021-03-22 05:19:47 -07:00
|
|
|
let
|
|
|
|
makeVM = import ./make-test-vm.nix pkgs;
|
2021-03-22 05:19:48 -07:00
|
|
|
inherit (pkgs) lib;
|
2021-03-22 05:19:47 -07:00
|
|
|
in
|
2021-03-22 05:19:48 -07:00
|
|
|
|
2021-03-22 05:19:47 -07:00
|
|
|
name: testConfig:
|
2020-09-27 03:43:20 -07:00
|
|
|
{
|
2021-03-22 05:19:47 -07:00
|
|
|
vm = makeVM {
|
|
|
|
name = "nix-bitcoin-${name}";
|
2020-09-27 03:43:20 -07:00
|
|
|
|
2022-09-05 09:12:09 -07:00
|
|
|
nodes.machine = { config, ... }: {
|
2020-09-27 03:43:20 -07:00
|
|
|
imports = [ testConfig ];
|
2022-09-05 09:12:09 -07:00
|
|
|
|
2021-03-22 05:19:48 -07:00
|
|
|
virtualisation = {
|
|
|
|
# Needed because duplicity requires 270 MB of free temp space, regardless of backup size
|
|
|
|
diskSize = 1024;
|
|
|
|
|
|
|
|
# Min. 800 MiB needed to avoid 'out of memory' errors
|
|
|
|
memorySize = lib.mkDefault 2048;
|
|
|
|
|
|
|
|
cores = lib.mkDefault 2;
|
|
|
|
};
|
2022-09-05 09:12:09 -07:00
|
|
|
|
2022-10-22 10:37:44 -07:00
|
|
|
test.shellcheckServices.enable = true;
|
2020-09-27 03:43:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = nodes: let
|
|
|
|
cfg = nodes.nodes.machine.config;
|
|
|
|
data = {
|
|
|
|
data = cfg.test.data;
|
|
|
|
tests = cfg.tests;
|
|
|
|
};
|
2020-11-18 18:01:44 -08:00
|
|
|
dataFile = pkgs.writeText "test-data" (builtins.toJSON data);
|
2020-09-27 03:43:20 -07:00
|
|
|
initData = ''
|
|
|
|
import json
|
|
|
|
|
|
|
|
with open("${dataFile}") as f:
|
|
|
|
data = json.load(f)
|
|
|
|
|
|
|
|
enabled_tests = set(test for (test, enabled) in data["tests"].items() if enabled)
|
|
|
|
test_data = data["data"]
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
builtins.concatStringsSep "\n\n" [
|
|
|
|
initData
|
|
|
|
(builtins.readFile ./../tests.py)
|
2021-10-01 02:52:05 -07:00
|
|
|
cfg.test.extraTestScript
|
2020-09-27 03:43:20 -07:00
|
|
|
# Don't run tests in interactive mode.
|
|
|
|
# is_interactive is set in ../run-tests.sh
|
|
|
|
''
|
|
|
|
if not "is_interactive" in vars():
|
|
|
|
run_tests()
|
|
|
|
''
|
|
|
|
];
|
2021-03-22 05:19:47 -07:00
|
|
|
};
|
2020-09-27 03:43:28 -07:00
|
|
|
|
|
|
|
container = {
|
|
|
|
# The container name has a 11 char length limit
|
2020-12-11 04:26:05 -08:00
|
|
|
containers.nb-test = { config, ... }: {
|
2022-01-06 04:40:52 -08:00
|
|
|
imports = [
|
|
|
|
{
|
|
|
|
config = {
|
|
|
|
extra = config.config.test.container;
|
|
|
|
config = testConfig;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
# Enable FUSE inside the container when clightning replication
|
|
|
|
# is enabled.
|
|
|
|
# TODO-EXTERNAL: Remove this when
|
|
|
|
# https://github.com/systemd/systemd/issues/17607
|
|
|
|
# has been resolved. This will also improve security.
|
|
|
|
(
|
|
|
|
let
|
2022-10-22 10:37:52 -07:00
|
|
|
s = config.config.services;
|
2022-01-06 04:40:52 -08:00
|
|
|
in
|
2022-10-22 10:37:52 -07:00
|
|
|
lib.mkIf (s ? clightning && s.clightning.enable && s.clightning.replication.enable) {
|
2022-01-06 04:40:52 -08:00
|
|
|
bindMounts."/dev/fuse" = { hostPath = "/dev/fuse"; };
|
|
|
|
allowedDevices = [ { node = "/dev/fuse"; modifier = "rw"; } ];
|
|
|
|
}
|
|
|
|
)
|
|
|
|
];
|
2020-09-27 03:43:28 -07:00
|
|
|
};
|
|
|
|
};
|
2020-12-11 04:26:05 -08:00
|
|
|
|
2021-03-26 15:23:22 -07:00
|
|
|
# This allows running a test scenario in a regular NixOS VM.
|
|
|
|
# No tests are executed.
|
2022-07-05 01:12:54 -07:00
|
|
|
vmWithoutTests = (pkgs.nixos ({ config, ... }: {
|
2021-03-26 15:23:22 -07:00
|
|
|
imports = [
|
|
|
|
testConfig
|
2022-10-22 10:37:47 -07:00
|
|
|
(pkgs.path + "/nixos/modules/virtualisation/qemu-vm.nix")
|
2021-03-26 15:23:22 -07:00
|
|
|
];
|
|
|
|
virtualisation.graphics = false;
|
2021-08-04 15:48:58 -07:00
|
|
|
services.getty.autologinUser = "root";
|
2021-03-26 15:23:22 -07:00
|
|
|
|
2022-10-22 10:37:45 -07:00
|
|
|
# Avoid lengthy build of the nixos manual
|
|
|
|
documentation.nixos.enable = false;
|
|
|
|
|
2022-10-22 10:37:46 -07:00
|
|
|
# Power off VM when the user exits the shell
|
|
|
|
systemd.services."serial-getty@".preStop = ''
|
|
|
|
echo o >/proc/sysrq-trigger
|
|
|
|
'';
|
2022-07-05 01:12:54 -07:00
|
|
|
|
2022-07-05 03:19:01 -07:00
|
|
|
system.stateVersion = lib.mkDefault config.system.nixos.release;
|
2022-07-05 01:12:54 -07:00
|
|
|
})).config.system.build.vm;
|
2021-03-26 15:23:22 -07:00
|
|
|
|
2020-12-11 04:26:05 -08:00
|
|
|
config = testConfig;
|
2020-09-27 03:43:20 -07:00
|
|
|
}
|