python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / nixos / tests / btrbk.nix
blob9f34f7dfbe38fb0f718aa952990c2f7ad7af94e4
1 import ./make-test-python.nix ({ pkgs, ... }:
3   let
4     privateKey = ''
5       -----BEGIN OPENSSH PRIVATE KEY-----
6       b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
7       QyNTUxOQAAACBx8UB04Q6Q/fwDFjakHq904PYFzG9pU2TJ9KXpaPMcrwAAAJB+cF5HfnBe
8       RwAAAAtzc2gtZWQyNTUxOQAAACBx8UB04Q6Q/fwDFjakHq904PYFzG9pU2TJ9KXpaPMcrw
9       AAAEBN75NsJZSpt63faCuaD75Unko0JjlSDxMhYHAPJk2/xXHxQHThDpD9/AMWNqQer3Tg
10       9gXMb2lTZMn0pelo8xyvAAAADXJzY2h1ZXR6QGt1cnQ=
11       -----END OPENSSH PRIVATE KEY-----
12     '';
13     publicKey = ''
14       ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHHxQHThDpD9/AMWNqQer3Tg9gXMb2lTZMn0pelo8xyv
15     '';
16   in
17   {
18     name = "btrbk";
19     meta = with pkgs.lib; {
20       maintainers = with maintainers; [ symphorien ];
21     };
23     nodes = {
24       archive = { ... }: {
25         environment.systemPackages = with pkgs; [ btrfs-progs ];
26         # note: this makes the privateKey world readable.
27         # don't do it with real ssh keys.
28         environment.etc."btrbk_key".text = privateKey;
29         services.btrbk = {
30           extraPackages = [ pkgs.lz4 ];
31           instances = {
32             remote = {
33               onCalendar = "minutely";
34               settings = {
35                 ssh_identity = "/etc/btrbk_key";
36                 ssh_user = "btrbk";
37                 stream_compress = "lz4";
38                 volume = {
39                   "ssh://main/mnt" = {
40                     target = "/mnt";
41                     snapshot_dir = "btrbk/remote";
42                     subvolume = "to_backup";
43                   };
44                 };
45               };
46             };
47           };
48         };
49       };
51       main = { ... }: {
52         environment.systemPackages = with pkgs; [ btrfs-progs ];
53         services.openssh = {
54           enable = true;
55           passwordAuthentication = false;
56           kbdInteractiveAuthentication = false;
57         };
58         services.btrbk = {
59           extraPackages = [ pkgs.lz4 ];
60           sshAccess = [
61             {
62               key = publicKey;
63               roles = [ "source" "send" "info" "delete" ];
64             }
65           ];
66           instances = {
67             local = {
68               onCalendar = "minutely";
69               settings = {
70                 volume = {
71                   "/mnt" = {
72                     snapshot_dir = "btrbk/local";
73                     subvolume = "to_backup";
74                   };
75                 };
76               };
77             };
78           };
79         };
80       };
81     };
83     testScript = ''
84       start_all()
86       # create btrfs partition at /mnt
87       for machine in (archive, main):
88         machine.succeed("dd if=/dev/zero of=/data_fs bs=120M count=1")
89         machine.succeed("mkfs.btrfs /data_fs")
90         machine.succeed("mkdir /mnt")
91         machine.succeed("mount /data_fs /mnt")
93       # what to backup and where
94       main.succeed("btrfs subvolume create /mnt/to_backup")
95       main.succeed("mkdir -p /mnt/btrbk/{local,remote}")
97       # check that local snapshots work
98       with subtest("local"):
99           main.succeed("echo foo > /mnt/to_backup/bar")
100           main.wait_until_succeeds("cat /mnt/btrbk/local/*/bar | grep foo")
101           main.succeed("echo bar > /mnt/to_backup/bar")
102           main.succeed("cat /mnt/btrbk/local/*/bar | grep foo")
104       # check that btrfs send/receive works and ssh access works
105       with subtest("remote"):
106           archive.wait_until_succeeds("cat /mnt/*/bar | grep bar")
107           main.succeed("echo baz > /mnt/to_backup/bar")
108           archive.succeed("cat /mnt/*/bar | grep bar")
109     '';
110   })