2022-02-05 21:42:36 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
2022-10-15 12:06:25 +03:00
|
|
|
cfg = config.services.kubo;
|
2022-02-05 21:42:36 +02:00
|
|
|
ipfsApi = pkgs.writeTextDir "api" "/ip4/127.0.0.1/tcp/5001";
|
|
|
|
in {
|
2022-10-15 12:06:25 +03:00
|
|
|
services.kubo = {
|
2022-02-05 21:42:36 +02:00
|
|
|
enable = true;
|
|
|
|
localDiscovery = true;
|
|
|
|
autoMount = true;
|
|
|
|
startWhenNeeded = false;
|
|
|
|
enableGC = true;
|
|
|
|
extraFlags = [ "--enable-pubsub-experiment" "--enable-namesys-pubsub" ];
|
2022-10-30 15:10:57 +02:00
|
|
|
settings = {
|
|
|
|
Addresses.Swarm = [
|
|
|
|
"/ip4/0.0.0.0/tcp/4001"
|
|
|
|
"/ip4/0.0.0.0/tcp/110"
|
|
|
|
];
|
2022-02-05 21:42:36 +02:00
|
|
|
Bootstrap = [
|
2022-09-24 14:34:35 +03:00
|
|
|
"/ip4/95.216.8.12/tcp/110/p2p/Qmd7QHZU8UjfYdwmjmq1SBh9pvER9AwHpfwQvnvNo3HBBo"
|
2022-02-05 21:42:36 +02:00
|
|
|
"/ip4/51.38.87.150/tcp/4001/p2p/12D3KooWDUgNsoLVauCDpRAo54mc4whoBudgeXQnZZK2iVYhBLCN"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-30 02:48:29 +03:00
|
|
|
systemd.services.ipfs = {
|
|
|
|
environment.LIBP2P_FORCE_PNET = "1";
|
|
|
|
serviceConfig = {
|
2022-09-25 21:35:52 +03:00
|
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
2022-03-30 02:48:29 +03:00
|
|
|
ReadWritePaths = lib.mkForce [ ];
|
|
|
|
};
|
|
|
|
};
|
2022-02-05 21:42:36 +02:00
|
|
|
systemd.sockets = {
|
|
|
|
ipfs-api.enable = false;
|
|
|
|
ipfs-gateway.enable = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
variables.IPFS_PATH = lib.mkForce "${ipfsApi}";
|
|
|
|
shellAliases = {
|
|
|
|
ipfs-admin = "doas -u ${cfg.user} env IPFS_PATH=${cfg.dataDir} ipfs";
|
|
|
|
f = "ipfs files";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-09-25 21:35:52 +03:00
|
|
|
networking.firewall.allowedTCPPorts = [ 110 4001 ];
|
2022-02-05 21:42:36 +02:00
|
|
|
|
|
|
|
environment.systemPackages = lib.singleton (pkgs.writeShellScriptBin "share" ''
|
|
|
|
PATH=${cfg.package}/bin:$PATH
|
|
|
|
set -e
|
|
|
|
cid=$(ipfs add -Qrp --pin=false "$@")
|
|
|
|
test -n $cid || exit 0
|
|
|
|
echo -e "\n\n IPFS path: /ipfs/$cid"
|
|
|
|
echo -e " Web link: https://$(ipfs cid base32 $cid).ipfs.privatevoid.net\n"
|
|
|
|
'');
|
|
|
|
networking.networkmanager.dispatcherScripts = [{
|
|
|
|
source = pkgs.writeShellScript "nm-ipfs-reconnect.sh" ''
|
|
|
|
[[ "$2" != "up" ]] && exit 0
|
|
|
|
PATH=${pkgs.systemd}/bin:${pkgs.findutils}/bin:${cfg.package}/bin:$PATH
|
|
|
|
export IPFS_PATH=${ipfsApi}
|
|
|
|
systemctl is-active ipfs.service || exit 0
|
|
|
|
case $1 in
|
|
|
|
wl*|en*)
|
|
|
|
ipfs swarm peers | xargs -P4 -n1 timeout 3 ipfs swarm disconnect
|
|
|
|
ipfs bootstrap | xargs -P4 -n1 timeout 10 ipfs swarm connect
|
|
|
|
esac
|
|
|
|
exit 0
|
|
|
|
'';
|
|
|
|
type = "basic";
|
|
|
|
}];
|
|
|
|
}
|