1{ lib, ... }:
2{
3 name = "kubo-fuse";
4 meta = with lib.maintainers; {
5 maintainers = [
6 mguentner
7 Luflosi
8 ];
9 };
10
11 nodes.machine =
12 { config, ... }:
13 {
14 services.kubo = {
15 enable = true;
16 autoMount = true;
17 };
18 users.users.alice = {
19 isNormalUser = true;
20 extraGroups = [ config.services.kubo.group ];
21 };
22 users.users.bob = {
23 isNormalUser = true;
24 };
25 };
26
27 testScript = ''
28 start_all()
29
30 with subtest("Create a file for testing"):
31 machine.succeed("echo 'fnord3' > /tmp/test.txt")
32
33
34 with subtest("/ipfs/ FUSE mountpoint"):
35 machine.fail("su bob -l -c 'ipfs add --quieter' < /tmp/test.txt")
36 # The FUSE mount functionality is broken as of v0.13.0. This is still the case with v0.29.0.
37 # See https://github.com/ipfs/kubo/issues/9044.
38 # Workaround: using CID Version 1 avoids that.
39 ipfs_hash = machine.succeed(
40 "echo fnord3 | su alice -l -c 'ipfs add --quieter --cid-version=1'"
41 ).strip()
42
43 machine.succeed(f"diff /tmp/test.txt /ipfs/{ipfs_hash}")
44
45
46 with subtest("/mfs/ FUSE mountpoint"):
47 with subtest("Write the test file in three different ways"):
48 machine.succeed("cp /tmp/test.txt /mfs/test-1.txt")
49 machine.succeed("su alice -c 'ipfs files write --create /test-2.txt < /tmp/test.txt'")
50 machine.succeed(f"ipfs files cp /ipfs/{ipfs_hash} /test-3.txt")
51
52 with subtest("Show the files (for debugging)"):
53 # Different hashes for the different ways of adding the file to the MFS probably come from different linking structures of the merkle tree. Copying the file to /mfs with `cp` is even non-deterministic.
54 machine.succeed("ipfs files ls --long >&2")
55 machine.succeed("ls -l /mfs >&2")
56
57 with subtest("Check that everyone has permission to read the file (because of Mounts.FuseAllowOther)"):
58 machine.succeed("su alice -c 'cat /mfs/test-1.txt' | grep fnord3")
59 machine.succeed("su bob -c 'cat /mfs/test-1.txt' | grep fnord3")
60
61 with subtest("Check the file contents"):
62 machine.succeed("diff /tmp/test.txt /mfs/test-1.txt")
63 machine.succeed("diff /tmp/test.txt /mfs/test-2.txt")
64 machine.succeed("diff /tmp/test.txt /mfs/test-3.txt")
65
66 with subtest("Check the CID extended attribute"):
67 output = machine.succeed(
68 "getfattr --only-values --name=ipfs_cid /mfs/test-3.txt"
69 ).strip()
70 assert ipfs_hash == output, f"Expected {ipfs_hash} but got {output}"
71
72
73 with subtest("Unmounting of /ipns, /ipfs and /mfs"):
74 # Force Kubo to crash and wait for it to restart
75 machine.systemctl("kill --signal=SIGKILL ipfs.service")
76 machine.wait_for_unit("ipfs.service", timeout = 30)
77
78 machine.succeed(f"diff /tmp/test.txt /ipfs/{ipfs_hash}")
79 machine.succeed("diff /tmp/test.txt /mfs/test-3.txt")
80 '';
81}