From e1880e476ea11d44b9679caaab9f5505b5bebf77 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Tue, 15 Feb 2022 16:20:40 -0500 Subject: [PATCH] ipfs: add "modes" --- modules/ipfs.nix | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/modules/ipfs.nix b/modules/ipfs.nix index 5bbbb31..59238b1 100644 --- a/modules/ipfs.nix +++ b/modules/ipfs.nix @@ -1,17 +1,30 @@ { config, lib, pkgs, ... }: let cfg = config.sconfig.ipfs; + + modes = { + server = { + Swarm.DisableNatPortMap = true; # Disable UPnP + AutoNAT.ServiceMode = "disabled"; # maybe change this to "enabled" ? + Routing.Type = "dhtclient"; # maybe change this to "dht" ? + Swarm.ConnMgr.HighWater = 900; + Swarm.ConnMgr.LowWater = 600; + }; + desktop = { + Swarm.DisableNatPortMap = true; # Disable UPnP + AutoNAT.ServiceMode = "disabled"; + Routing.Type = "dhtclient"; + Swarm.ConnMgr.HighWater = 300; + Swarm.ConnMgr.LowWater = 50; + }; + }; + in { options.sconfig.ipfs = { enable = lib.mkEnableOption "Turn on IPFS"; - - lowpower = lib.mkOption { - type = lib.types.bool; - default = false; - description = "enable the 'lowpower' profile in IPFS."; - }; + mode = lib.mkOption { type = lib.types.enum [ "server" "desktop" ]; }; }; @@ -20,19 +33,15 @@ in services.ipfs = { enable = true; emptyRepo = true; + extraConfig = modes.${cfg.mode}; gatewayAddress = "/ip4/127.0.0.1/tcp/8001"; # Had issues without fdlimit. 65536 value taken from nixpkgs example serviceFdlimit = 65536; }; - systemd.services.ipfs = { - preStart = lib.mkAfter (lib.optionalString cfg.lowpower '' - ipfs --offline config profile apply lowpower - ''); - postStart = '' - chmod g+r /var/lib/ipfs/config - ''; - }; + systemd.services.ipfs.postStart = '' + chmod g+r /var/lib/ipfs/config + ''; }; }