aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/nixos/tests/sanoid.nix
blob: 284b38932ccebf65c501b0bd639292cafc856eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import ./make-test-python.nix ({ pkgs, ... }: let
  inherit (import ./ssh-keys.nix pkgs)
    snakeOilPrivateKey snakeOilPublicKey;

  commonConfig = { pkgs, ... }: {
    virtualisation.emptyDiskImages = [ 2048 ];
    boot.supportedFilesystems = [ "zfs" ];
    environment.systemPackages = [ pkgs.parted ];
  };
in {
  name = "sanoid";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ lopsided98 ];
  };

  nodes = {
    source = { ... }: {
      imports = [ commonConfig ];
      networking.hostId = "daa82e91";

      programs.ssh.extraConfig = ''
        UserKnownHostsFile=/dev/null
        StrictHostKeyChecking=no
      '';

      services.sanoid = {
        enable = true;
        templates.test = {
          hourly = 12;
          daily = 1;
          monthly = 1;
          yearly = 1;

          autosnap = true;
        };
        datasets."pool/test".useTemplate = [ "test" ];
      };

      services.syncoid = {
        enable = true;
        sshKey = "/root/.ssh/id_ecdsa";
        commonArgs = [ "--no-sync-snap" ];
        commands."pool/test".target = "root@target:pool/test";
      };
    };
    target = { ... }: {
      imports = [ commonConfig ];
      networking.hostId = "dcf39d36";

      services.openssh.enable = true;
      users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ];
    };
  };

  testScript = ''
    source.succeed(
        "mkdir /tmp/mnt",
        "parted --script /dev/vdb -- mklabel msdos mkpart primary 1024M -1s",
        "udevadm settle",
        "zpool create pool /dev/vdb1",
        "zfs create -o mountpoint=legacy pool/test",
        "mount -t zfs pool/test /tmp/mnt",
        "udevadm settle",
    )
    target.succeed(
        "parted --script /dev/vdb -- mklabel msdos mkpart primary 1024M -1s",
        "udevadm settle",
        "zpool create pool /dev/vdb1",
        "udevadm settle",
    )

    source.succeed("mkdir -m 700 /root/.ssh")
    source.succeed(
        "cat '${snakeOilPrivateKey}' > /root/.ssh/id_ecdsa"
    )
    source.succeed("chmod 600 /root/.ssh/id_ecdsa")

    source.succeed("touch /tmp/mnt/test.txt")
    source.systemctl("start --wait sanoid.service")

    target.wait_for_open_port(22)
    source.systemctl("start --wait syncoid.service")
    target.succeed(
        "mkdir /tmp/mnt",
        "zfs set mountpoint=legacy pool/test",
        "mount -t zfs pool/test /tmp/mnt",
    )
    target.succeed("cat /tmp/mnt/test.txt")
  '';
})