1# This tests validates the order of generated sections that may contain
2# other sections.
3# When a `volume` section has both `subvolume` and `target` children,
4# `target` must go before `subvolume`. Otherwise, `target` will become
5# a child of the last `subvolume` instead of `volume`, due to the
6# order-sensitive config format.
7#
8# Issue: https://github.com/NixOS/nixpkgs/issues/195660
9{ lib, pkgs, ... }:
10{
11 name = "btrbk-section-order";
12 meta.maintainers = with lib.maintainers; [ oxalica ];
13
14 nodes.machine =
15 { ... }:
16 {
17 services.btrbk.instances.local = {
18 onCalendar = null;
19 settings = {
20 timestamp_format = "long";
21 target."ssh://global-target/".ssh_user = "root";
22 volume."/btrfs" = {
23 snapshot_dir = "/volume-snapshots";
24 target."ssh://volume-target/".ssh_user = "root";
25 subvolume."@subvolume" = {
26 snapshot_dir = "/subvolume-snapshots";
27 target."ssh://subvolume-target/".ssh_user = "root";
28 };
29 };
30 };
31 };
32 };
33
34 testScript = ''
35 import difflib
36 machine.wait_for_unit("basic.target")
37 got = machine.succeed("cat /etc/btrbk/local.conf").strip()
38 expect = """
39 backend btrfs-progs-sudo
40 stream_compress no
41 timestamp_format long
42 target ssh://global-target/
43 ssh_user root
44 volume /btrfs
45 snapshot_dir /volume-snapshots
46 target ssh://volume-target/
47 ssh_user root
48 subvolume @subvolume
49 snapshot_dir /subvolume-snapshots
50 target ssh://subvolume-target/
51 ssh_user root
52 """.strip()
53 print(got)
54 if got != expect:
55 diff = difflib.unified_diff(expect.splitlines(keepends=True), got.splitlines(keepends=True), fromfile="expected", tofile="got")
56 print("".join(diff))
57 assert got == expect
58 '';
59}