A node now starts without any region (it only helps others connect, and prints a hint). The owner's sign-in link leads straight to the Regions page when none is followed, visitors get a notice instead of an empty search, and status always lists regions as an array. The Docker image no longer pins Bonn, the NixOS module no longer requires regions, and the VM test now starts without any, chooses the first region over the API and checks it survives a restart. README and the init hint follow. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
180 lines
5.5 KiB
Nix
180 lines
5.5 KiB
Nix
self:
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
cfg = config.services.allmende;
|
|
exe = lib.getExe cfg.package;
|
|
|
|
# `allmende init` and `recover` run as the service's user and need a terminal
|
|
# (they show and check the recovery phrase), so they are not part of the unit.
|
|
admin = pkgs.writeShellScriptBin "allmende-admin" ''
|
|
exec sudo -u allmende env ALLMENDE_DATA=${lib.escapeShellArg cfg.dataDir} ${exe} "$@"
|
|
'';
|
|
|
|
args =
|
|
[
|
|
"run"
|
|
"--http"
|
|
cfg.httpAddress
|
|
"--listen"
|
|
"/ip4/0.0.0.0/tcp/${toString cfg.p2pPort}"
|
|
"--listen"
|
|
"/ip4/0.0.0.0/udp/${toString cfg.p2pPort}/quic-v1"
|
|
]
|
|
++ lib.optional cfg.public "--public"
|
|
++ lib.optional (!cfg.defaultBootstrap) "--no-default-bootstrap"
|
|
++ lib.concatMap (r: [
|
|
"--region"
|
|
r
|
|
]) cfg.regions
|
|
++ lib.concatMap (b: [
|
|
"--bootstrap"
|
|
b
|
|
]) cfg.bootstrap
|
|
++ cfg.extraArgs;
|
|
in
|
|
{
|
|
options.services.allmende = {
|
|
enable = lib.mkEnableOption "an Allmende node (a free, distributed marketplace for homes)";
|
|
|
|
package = lib.mkOption {
|
|
type = lib.types.package;
|
|
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
defaultText = lib.literalExpression "allmende.packages.\${system}.default";
|
|
description = "The allmende package to run.";
|
|
};
|
|
|
|
regions = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [ ];
|
|
example = [ "u1j" ];
|
|
description = ''
|
|
Regions to start with: 3-character geohashes, each about 100 to 150 km
|
|
wide. `u1j` is Bonn, `u1h` Cologne, `u1x` Hamburg. Leave it empty and
|
|
the owner chooses by place name in the browser instead ("My listings"
|
|
> "Regions"); that choice is kept in `regions.json` in
|
|
{option}`dataDir` and wins over this list from then on (delete the file
|
|
to go back to it).
|
|
'';
|
|
};
|
|
|
|
bootstrap = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [ ];
|
|
example = [ "/ip4/203.0.113.5/tcp/4001/p2p/12D3KooW..." ];
|
|
description = "Extra peers to connect to: /p2p/<peer id> multiaddrs or /dnsaddr/<name>.";
|
|
};
|
|
|
|
defaultBootstrap = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
description = "Also use the built-in bootstrap name (allmende.stinnesbeck.com).";
|
|
};
|
|
|
|
public = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = ''
|
|
This machine is reachable from the internet: serve the DHT and relay for
|
|
nodes behind a NAT. Turn it on for a bootstrap node, and publish the TXT
|
|
records the node prints (see `journalctl -u allmende`) in DNS.
|
|
'';
|
|
};
|
|
|
|
httpAddress = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "127.0.0.1:8080";
|
|
description = ''
|
|
Where the web UI and API listen. The same port serves the owner API,
|
|
which the admin token protects, so keep it on loopback and put a TLS
|
|
reverse proxy in front for public use.
|
|
'';
|
|
};
|
|
|
|
p2pPort = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 4001;
|
|
description = "Port other nodes connect to, over TCP and over UDP (QUIC).";
|
|
};
|
|
|
|
openFirewall = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = "Open the peer-to-peer port ({option}`p2pPort`, TCP and UDP) in the firewall.";
|
|
};
|
|
|
|
dataDir = lib.mkOption {
|
|
type = lib.types.path;
|
|
default = "/var/lib/allmende";
|
|
description = "Where keys, the admin token, the chosen regions and the database live.";
|
|
};
|
|
|
|
extraArgs = lib.mkOption {
|
|
type = lib.types.listOf lib.types.str;
|
|
default = [ ];
|
|
example = [ "--no-mdns" ];
|
|
description = "Further arguments for `allmende run`.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
users.users.allmende = {
|
|
isSystemUser = true;
|
|
group = "allmende";
|
|
home = cfg.dataDir;
|
|
description = "Allmende node";
|
|
};
|
|
users.groups.allmende = { };
|
|
|
|
systemd.tmpfiles.rules = [ "d ${cfg.dataDir} 0700 allmende allmende -" ];
|
|
|
|
# One-time setup, because it shows the recovery phrase:
|
|
# sudo allmende-admin init && sudo systemctl start allmende
|
|
# The unit is skipped (not failed) until that has happened.
|
|
systemd.services.allmende = {
|
|
description = "Allmende node";
|
|
wantedBy = [ "multi-user.target" ];
|
|
wants = [ "network-online.target" ];
|
|
after = [ "network-online.target" ];
|
|
unitConfig.ConditionPathExists = "${cfg.dataDir}/admin.token";
|
|
environment.ALLMENDE_DATA = cfg.dataDir;
|
|
serviceConfig = {
|
|
ExecStart = "${exe} ${lib.escapeShellArgs args}";
|
|
User = "allmende";
|
|
Group = "allmende";
|
|
Restart = "on-failure";
|
|
RestartSec = "5s";
|
|
|
|
NoNewPrivileges = true;
|
|
PrivateTmp = true;
|
|
PrivateDevices = true;
|
|
ProtectSystem = "strict";
|
|
ProtectHome = true;
|
|
ReadWritePaths = [ cfg.dataDir ];
|
|
ProtectKernelTunables = true;
|
|
ProtectKernelModules = true;
|
|
ProtectControlGroups = true;
|
|
RestrictSUIDSGID = true;
|
|
LockPersonality = true;
|
|
# libp2p reads the network interfaces over netlink to find its addresses.
|
|
RestrictAddressFamilies = [
|
|
"AF_INET"
|
|
"AF_INET6"
|
|
"AF_UNIX"
|
|
"AF_NETLINK"
|
|
];
|
|
};
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.p2pPort ];
|
|
networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [ cfg.p2pPort ]; # QUIC
|
|
|
|
environment.systemPackages = [ admin ];
|
|
};
|
|
}
|