diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix index 60822b5b547..cd320c5c462 100644 --- a/nixos/modules/services/network-filesystems/ipfs.nix +++ b/nixos/modules/services/network-filesystems/ipfs.nix @@ -1,15 +1,19 @@ { config, lib, pkgs, ... }: - with lib; - let inherit (pkgs) ipfs runCommand makeWrapper; cfg = config.services.ipfs; - ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}''; + 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); - # Before Version 17.09, ipfs would always use "/var/lib/ipfs/.ipfs" as it's dataDir defaultDataDir = if versionAtLeast config.system.stateVersion "17.09" then "/var/lib/ipfs" else "/var/lib/ipfs/.ipfs"; @@ -17,11 +21,48 @@ let # 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} + makeWrapper "${ipfs}/bin/ipfs" "$out/bin/ipfs" \ + --set IPFS_PATH ${cfg.dataDir} \ + --prefix PATH : /run/wrappers/bin ''; -in -{ + + 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 <