depot/third_party/nixpkgs/nixos/tests/snapper.nix
Default email bcb2f287e1 Project import generated by Copybara.
GitOrigin-RevId: d603719ec6e294f034936c0d0dc06f689d91b6c3
2024-06-20 20:27:18 +05:30

38 lines
1.3 KiB
Nix

import ./make-test-python.nix ({ ... }:
{
name = "snapper";
nodes.machine = { pkgs, lib, ... }: {
boot.initrd.postDeviceCommands = ''
${pkgs.btrfs-progs}/bin/mkfs.btrfs -f -L aux /dev/vdb
'';
virtualisation.emptyDiskImages = [ 4096 ];
virtualisation.fileSystems = {
"/home" = {
device = "/dev/disk/by-label/aux";
fsType = "btrfs";
};
};
services.snapper.configs.home.SUBVOLUME = "/home";
services.snapper.filters = "/nix";
};
testScript = { nodes, ... }: let
inherit (nodes.machine.services.snapper) snapshotRootOnBoot;
in ''
machine.succeed("btrfs subvolume create /home/.snapshots")
machine.succeed("snapper -c home list")
machine.succeed("snapper -c home create --description empty")
machine.succeed("echo test > /home/file")
machine.succeed("snapper -c home create --description file")
machine.succeed("snapper -c home status 1..2")
machine.succeed("snapper -c home undochange 1..2")
machine.fail("ls /home/file")
machine.succeed("snapper -c home delete 2")
machine.succeed("systemctl --wait start snapper-timeline.service")
machine.succeed("systemctl --wait start snapper-cleanup.service")
machine.${if snapshotRootOnBoot then "succeed" else "fail"}("systemctl cat snapper-boot.service")
'';
})