summaryrefslogtreecommitdiffstats
path: root/nixos/tests/gocryptfs.nix
blob: 763e1c1407fa50864037c8e86af39463955121f8 (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
{
  name = "gocryptfs";
  meta = {
    maintainers = [ ];
  };

  nodes.machine =
    { pkgs, ... }:
    {

      environment.systemPackages = [
        pkgs.gocryptfs
        pkgs.openssl
      ];

      programs.fuse.enable = true;

      specialisation.fstab-test.configuration = {
        # This can't be fileSytems, as the qemu machinery doesn't honor it.
        virtualisation.fileSystems."/plain" = {
          device = "/encrypted";
          fsType = "fuse.gocryptfs";
          options = [
            "nofail"
            "allow_other"
            "passfile=/tmp/password.txt"
          ];
        };
      };
    };

  testScript = ''
    # Initialize a gocryptfs filesystem and mount it
    machine.succeed("openssl rand -base64 32 > /tmp/password.txt")
    machine.succeed("mkdir -p /encrypted /plain")
    machine.succeed("gocryptfs -init /encrypted  -passfile /tmp/password.txt -quiet")
    machine.succeed("gocryptfs /encrypted /plain  -passfile /tmp/password.txt -quiet")

    # Drop a canary file and unmount
    machine.succeed("echo success > /plain/data.txt")
    machine.succeed("fusermount -u /plain")

    # Switch to a specialisation that has this in /etc/fstab
    machine.succeed("/run/current-system/specialisation/fstab-test/bin/switch-to-configuration switch")

    # Wait for mounts
    machine.wait_for_unit("local-fs.target")

    # Sometimes gocryptfs files are slow to appear
    machine.wait_for_file("/plain/data.txt")

    # Ensure the canary is alive
    machine.succeed("grep -q success /plain/data.txt")

  '';
}