|
1 | 1 | { |
2 | 2 | pkgs, |
3 | | - flake, |
| 3 | + inputs, |
4 | 4 | system, |
| 5 | + perSystem, |
5 | 6 | ... |
6 | 7 | }: let |
7 | | - inherit (flake.packages.${system}) nixos-facter; |
| 8 | + # we have to import diskoLib like this because there are some impure default imports e.g. <nixpkgs> |
| 9 | + diskoLib = import "${inputs.disko}/lib" { |
| 10 | + inherit (pkgs) lib; |
| 11 | + makeTest = import "${inputs.nixpkgs}/nixos/tests/make-test-python.nix"; |
| 12 | + eval-config = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix"; |
| 13 | + }; |
8 | 14 | in |
9 | 15 | # for now we only run the tests in x86_64-linux since we don't have access to a bare-metal ARM box or a VM that supports nested |
10 | 16 | # virtualization which makes the test take forever and ultimately fail |
11 | 17 | pkgs.lib.optionalAttrs pkgs.stdenv.isx86_64 { |
12 | | - basic = pkgs.nixosTest { |
| 18 | + basic = diskoLib.testLib.makeDiskoTest { |
| 19 | + inherit pkgs; |
13 | 20 | name = "basic"; |
14 | | - nodes.machine = { |
15 | | - environment.systemPackages = [nixos-facter]; |
| 21 | + disko-config = ./disko.nix; |
| 22 | + extraSystemConfig = { |
| 23 | + environment.systemPackages = [ |
| 24 | + perSystem.self.nixos-facter |
| 25 | + ]; |
| 26 | + |
| 27 | + systemd.services = { |
| 28 | + create-swap-files = { |
| 29 | + serviceConfig.Type = "oneshot"; |
| 30 | + wantedBy = ["multi-user.target"]; |
| 31 | + path = with pkgs; [ |
| 32 | + coreutils |
| 33 | + util-linux |
| 34 | + ]; |
| 35 | + script = '' |
| 36 | + # create some swap files |
| 37 | + mkdir -p /swap |
| 38 | + for (( i=1; i<=3; i++ )); do |
| 39 | + out="/swap/swapfile-$i" |
| 40 | + dd if=/dev/zero of="$out" bs=1MB count=10 |
| 41 | + chmod 600 "$out" |
| 42 | + mkswap "$out" |
| 43 | + swapon "$out" |
| 44 | + done |
| 45 | + ''; |
| 46 | + }; |
| 47 | + }; |
16 | 48 | }; |
17 | | - testScript = '' |
18 | | - machine.succeed("nixos-facter generate report -o /report.json") |
| 49 | + |
| 50 | + extraTestScript = '' |
| 51 | + import json |
| 52 | +
|
| 53 | + report = json.loads(machine.succeed("nixos-facter -e")) |
| 54 | +
|
| 55 | + with subtest("Capture system"): |
| 56 | + assert report['system'] == '${system}' |
| 57 | +
|
| 58 | + with subtest("Capture virtualisation"): |
| 59 | + virt = report['virtualisation'] |
| 60 | + # kvm for systems that support it, otherwise the vm test should present itself as qemu |
| 61 | + # todo double-check this is the same for intel |
| 62 | + assert virt in ("kvm", "qemu"), f"expected virtualisation to be either kvm or qemu, got {virt}" |
| 63 | +
|
| 64 | + with subtest("Capture swap entries"): |
| 65 | + assert 'swap' in report, "'swap' not found in the report" |
| 66 | + assert report['swap'] == [ |
| 67 | + { 'path': '/dev/vda4', 'type': 'partition', 'size': 1048572, 'used': 0, 'priority': -2 }, |
| 68 | + { 'path': '/dev/dm-0', 'type': 'partition', 'size': 10236, 'used': 0, 'priority': 100 }, |
| 69 | + { 'path': '/swap/swapfile-1', 'type': 'file', 'size': 9760, 'used': 0, 'priority': -3 }, |
| 70 | + { 'path': '/swap/swapfile-2', 'type': 'file', 'size': 9760, 'used': 0, 'priority': -4 }, |
| 71 | + { 'path': '/swap/swapfile-3', 'type': 'file', 'size': 9760, 'used': 0, 'priority': -5 } |
| 72 | + ], "swap entries did not match what we expected" |
| 73 | + # todo is there a nice way of showing a diff? |
19 | 74 | ''; |
20 | 75 | }; |
21 | 76 | } |
0 commit comments