2023-04-14 02:43:41 +02:00
|
|
|
{ lib, ...} : {
|
2022-07-24 20:49:05 +02:00
|
|
|
name = "kubo";
|
2023-04-14 02:43:41 +02:00
|
|
|
meta = with lib.maintainers; {
|
2023-04-14 01:49:48 +02:00
|
|
|
maintainers = [ mguentner Luflosi ];
|
2016-11-26 20:07:01 +01:00
|
|
|
};
|
|
|
|
|
2023-04-14 16:37:32 +02:00
|
|
|
nodes.machine = { config, ... }: {
|
2022-07-24 20:49:05 +02:00
|
|
|
services.kubo = {
|
2020-05-08 11:48:47 +02:00
|
|
|
enable = true;
|
2020-06-17 22:19:01 +02:00
|
|
|
# Also will add a unix domain socket socket API address, see module.
|
|
|
|
startWhenNeeded = true;
|
2022-10-04 12:44:48 +02:00
|
|
|
settings.Addresses.API = "/ip4/127.0.0.1/tcp/2324";
|
2022-03-17 16:40:54 +01:00
|
|
|
dataDir = "/mnt/ipfs";
|
2020-05-08 11:48:47 +02:00
|
|
|
};
|
2023-04-14 02:26:32 +02:00
|
|
|
users.users.alice = {
|
|
|
|
isNormalUser = true;
|
2023-04-14 16:37:32 +02:00
|
|
|
extraGroups = [ config.services.kubo.group ];
|
2023-04-14 02:26:32 +02:00
|
|
|
};
|
2016-11-26 20:07:01 +01:00
|
|
|
};
|
|
|
|
|
2023-04-14 16:37:32 +02:00
|
|
|
nodes.fuse = { config, ... }: {
|
2022-07-24 20:49:05 +02:00
|
|
|
services.kubo = {
|
2022-04-16 21:14:26 +02:00
|
|
|
enable = true;
|
|
|
|
autoMount = true;
|
|
|
|
};
|
2023-04-14 16:37:32 +02:00
|
|
|
users.users.alice = {
|
|
|
|
isNormalUser = true;
|
|
|
|
extraGroups = [ config.services.kubo.group ];
|
|
|
|
};
|
|
|
|
users.users.bob = {
|
|
|
|
isNormalUser = true;
|
|
|
|
};
|
2022-04-16 21:14:26 +02:00
|
|
|
};
|
|
|
|
|
2016-11-26 20:07:01 +01:00
|
|
|
testScript = ''
|
2020-05-08 11:48:47 +02:00
|
|
|
start_all()
|
2017-08-30 15:20:10 +02:00
|
|
|
|
2023-04-14 02:26:32 +02:00
|
|
|
with subtest("Automatic socket activation"):
|
|
|
|
ipfs_hash = machine.succeed(
|
|
|
|
"echo fnord0 | su alice -l -c 'ipfs add --quieter'"
|
|
|
|
)
|
|
|
|
machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord0")
|
|
|
|
|
|
|
|
machine.stop_job("ipfs")
|
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
with subtest("IPv4 socket activation"):
|
|
|
|
machine.succeed("ipfs --api /ip4/127.0.0.1/tcp/2324 id")
|
|
|
|
ipfs_hash = machine.succeed(
|
|
|
|
"echo fnord | ipfs --api /ip4/127.0.0.1/tcp/2324 add --quieter"
|
|
|
|
)
|
|
|
|
machine.succeed(f"ipfs cat /ipfs/{ipfs_hash.strip()} | grep fnord")
|
2020-06-11 23:59:38 +02:00
|
|
|
|
2020-06-17 22:19:01 +02:00
|
|
|
machine.stop_job("ipfs")
|
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
with subtest("Unix domain socket activation"):
|
|
|
|
ipfs_hash = machine.succeed(
|
|
|
|
"echo fnord2 | ipfs --api /unix/run/ipfs.sock add --quieter"
|
|
|
|
)
|
|
|
|
machine.succeed(
|
|
|
|
f"ipfs --api /unix/run/ipfs.sock cat /ipfs/{ipfs_hash.strip()} | grep fnord2"
|
|
|
|
)
|
2022-03-17 16:40:54 +01:00
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
with subtest("Setting dataDir works properly with the hardened systemd unit"):
|
|
|
|
machine.succeed("test -e /mnt/ipfs/config")
|
|
|
|
machine.succeed("test ! -e /var/lib/ipfs/")
|
2022-04-16 21:14:26 +02:00
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
with subtest("FUSE mountpoint"):
|
2023-04-14 16:37:32 +02:00
|
|
|
fuse.fail("echo a | su bob -l -c 'ipfs add --quieter'")
|
2023-04-14 02:46:22 +02:00
|
|
|
# The FUSE mount functionality is broken as of v0.13.0 and v0.17.0.
|
|
|
|
# See https://github.com/ipfs/kubo/issues/9044.
|
|
|
|
# Workaround: using CID Version 1 avoids that.
|
|
|
|
ipfs_hash = fuse.succeed(
|
2023-04-14 16:37:32 +02:00
|
|
|
"echo fnord3 | su alice -l -c 'ipfs add --quieter --cid-version=1'"
|
2023-04-14 02:46:22 +02:00
|
|
|
).strip()
|
2023-02-06 01:35:29 +01:00
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
fuse.succeed(f"cat /ipfs/{ipfs_hash} | grep fnord3")
|
2023-02-06 01:35:29 +01:00
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
with subtest("Unmounting of /ipns and /ipfs"):
|
|
|
|
# Force Kubo to crash and wait for it to restart
|
|
|
|
fuse.systemctl("kill --signal=SIGKILL ipfs.service")
|
|
|
|
fuse.wait_for_unit("ipfs.service", timeout = 30)
|
2022-04-16 21:14:26 +02:00
|
|
|
|
2023-04-14 02:46:22 +02:00
|
|
|
fuse.succeed(f"cat /ipfs/{ipfs_hash} | grep fnord3")
|
2020-05-08 11:48:47 +02:00
|
|
|
'';
|
2023-04-14 02:43:41 +02:00
|
|
|
}
|