{ config, lib, pkgs, ... }: with lib; let inherit (pkgs) ipfs runCommand makeWrapper; cfg = config.services.ipfs; ipfsFlags = toString ([ #(optionalString cfg.autoMount "--mount") (optionalString cfg.autoMigrate "--migrate") (optionalString cfg.enableGC "--enable-gc") (optionalString (cfg.serviceFdlimit != null) "--manage-fdlimit=false") (optionalString (cfg.defaultMode == "offline") "--offline") (optionalString (cfg.defaultMode == "norouting") "--routing=none") ] ++ cfg.extraFlags); defaultDataDir = if versionAtLeast config.system.stateVersion "17.09" then "/var/lib/ipfs" else "/var/lib/ipfs/.ipfs"; # Wrapping the ipfs binary with the environment variable IPFS_PATH set to dataDir because we can't set it in the user environment wrapped = runCommand "ipfs" { buildInputs = [ makeWrapper ]; } '' mkdir -p "$out/bin" makeWrapper "${ipfs}/bin/ipfs" "$out/bin/ipfs" \ --set IPFS_PATH ${cfg.dataDir} \ --prefix PATH : /run/wrappers/bin ''; commonEnv = { environment.IPFS_PATH = cfg.dataDir; path = [ wrapped ]; serviceConfig.User = cfg.user; serviceConfig.Group = cfg.group; }; baseService = recursiveUpdate commonEnv { wants = [ "ipfs-init.service" ]; preStart = '' ipfs --local config Addresses.API ${cfg.apiAddress} ipfs --local config Addresses.Gateway ${cfg.gatewayAddress} '' + optionalString false/*cfg.autoMount*/ '' ipfs --local config Mounts.FuseAllowOther --json true ipfs --local config Mounts.IPFS ${cfg.ipfsMountDir} ipfs --local config Mounts.IPNS ${cfg.ipnsMountDir} '' + concatStringsSep "\n" (collect isString (mapAttrsRecursive (path: value: # Using heredoc below so that the value is never improperly quoted '' read value <