ipfs: nixpkgs-fmt

+56 -43
+56 -43
nixos/modules/services/network-filesystems/ipfs.nix
··· 5 opt = options.services.ipfs; 6 7 ipfsFlags = toString ([ 8 - (optionalString cfg.autoMount "--mount") 9 - (optionalString cfg.enableGC "--enable-gc") 10 - (optionalString (cfg.serviceFdlimit != null) "--manage-fdlimit=false") 11 - (optionalString (cfg.defaultMode == "offline") "--offline") 12 (optionalString (cfg.defaultMode == "norouting") "--routing=none") 13 ] ++ cfg.extraFlags); 14 15 splitMulitaddr = addrRaw: lib.tail (lib.splitString "/" addrRaw); 16 17 - multiaddrToListenStream = addrRaw: let 18 addr = splitMulitaddr addrRaw; 19 s = builtins.elemAt addr; 20 - in if s 0 == "ip4" && s 2 == "tcp" 21 - then "${s 1}:${s 3}" 22 else if s 0 == "ip6" && s 2 == "tcp" 23 - then "[${s 1}]:${s 3}" 24 else if s 0 == "unix" 25 - then "/${lib.concatStringsSep "/" (lib.tail addr)}" 26 else null; # not valid for listen stream, skip 27 28 - multiaddrToListenDatagram = addrRaw: let 29 addr = splitMulitaddr addrRaw; 30 s = builtins.elemAt addr; 31 - in if s 0 == "ip4" && s 2 == "udp" 32 - then "${s 1}:${s 3}" 33 else if s 0 == "ip6" && s 2 == "udp" 34 - then "[${s 1}]:${s 3}" 35 else null; # not valid for listen datagram, skip 36 37 - in { 38 39 ###### interface 40 ··· 65 66 dataDir = mkOption { 67 type = types.str; 68 - default = if versionAtLeast config.system.stateVersion "17.09" 69 - then "/var/lib/ipfs" 70 - else "/var/lib/ipfs/.ipfs"; 71 description = "The data dir for IPFS"; 72 }; 73 ··· 137 These are applied last, so may override configuration set by other options in this module. 138 Keep in mind that this configuration is stateful; i.e., unsetting anything in here does not reset the value to the default! 139 ''; 140 - default = {}; 141 example = { 142 Datastore.StorageMax = "100GB"; 143 Discovery.MDNS.Enabled = false; ··· 153 extraFlags = mkOption { 154 type = types.listOf types.str; 155 description = "Extra flags passed to the IPFS daemon"; 156 - default = []; 157 }; 158 159 localDiscovery = mkOption { ··· 168 type = types.nullOr types.int; 169 default = null; 170 description = "The fdlimit for the IPFS systemd unit or <literal>null</literal> to have the daemon attempt to manage it"; 171 - example = 64*1024; 172 }; 173 174 startWhenNeeded = mkOption { ··· 235 ipfs --offline config Mounts.IPFS ${cfg.ipfsMountDir} 236 ipfs --offline config Mounts.IPNS ${cfg.ipnsMountDir} 237 '' + concatStringsSep "\n" (collect 238 - isString 239 - (mapAttrsRecursive 240 - (path: value: 241 - # Using heredoc below so that the value is never improperly quoted 242 - '' 243 - read value <<EOF 244 - ${builtins.toJSON value} 245 - EOF 246 - ipfs --offline config --json "${concatStringsSep "." path}" "$value" 247 - '') 248 - ({ Addresses.API = cfg.apiAddress; 249 - Addresses.Gateway = cfg.gatewayAddress; 250 - Addresses.Swarm = cfg.swarmAddress; 251 - } // 252 - cfg.extraConfig)) 253 - ); 254 serviceConfig = { 255 - ExecStart = ["" "${cfg.package}/bin/ipfs daemon ${ipfsFlags}"]; 256 User = cfg.user; 257 Group = cfg.group; 258 } // optionalAttrs (cfg.serviceFdlimit != null) { LimitNOFILE = cfg.serviceFdlimit; }; ··· 263 systemd.sockets.ipfs-gateway = { 264 wantedBy = [ "sockets.target" ]; 265 socketConfig = { 266 - ListenStream = let 267 fromCfg = multiaddrToListenStream cfg.gatewayAddress; 268 - in [ "" ] ++ lib.optional (fromCfg != null) fromCfg; 269 - ListenDatagram = let 270 fromCfg = multiaddrToListenDatagram cfg.gatewayAddress; 271 - in [ "" ] ++ lib.optional (fromCfg != null) fromCfg; 272 }; 273 }; 274 ··· 276 wantedBy = [ "sockets.target" ]; 277 # We also include "%t/ipfs.sock" because there is no way to put the "%t" 278 # in the multiaddr. 279 - socketConfig.ListenStream = let 280 fromCfg = multiaddrToListenStream cfg.apiAddress; 281 - in [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg; 282 }; 283 284 };
··· 5 opt = options.services.ipfs; 6 7 ipfsFlags = toString ([ 8 + (optionalString cfg.autoMount "--mount") 9 + (optionalString cfg.enableGC "--enable-gc") 10 + (optionalString (cfg.serviceFdlimit != null) "--manage-fdlimit=false") 11 + (optionalString (cfg.defaultMode == "offline") "--offline") 12 (optionalString (cfg.defaultMode == "norouting") "--routing=none") 13 ] ++ cfg.extraFlags); 14 15 splitMulitaddr = addrRaw: lib.tail (lib.splitString "/" addrRaw); 16 17 + multiaddrToListenStream = addrRaw: 18 + let 19 addr = splitMulitaddr addrRaw; 20 s = builtins.elemAt addr; 21 + in 22 + if s 0 == "ip4" && s 2 == "tcp" 23 + then "${s 1}:${s 3}" 24 else if s 0 == "ip6" && s 2 == "tcp" 25 + then "[${s 1}]:${s 3}" 26 else if s 0 == "unix" 27 + then "/${lib.concatStringsSep "/" (lib.tail addr)}" 28 else null; # not valid for listen stream, skip 29 30 + multiaddrToListenDatagram = addrRaw: 31 + let 32 addr = splitMulitaddr addrRaw; 33 s = builtins.elemAt addr; 34 + in 35 + if s 0 == "ip4" && s 2 == "udp" 36 + then "${s 1}:${s 3}" 37 else if s 0 == "ip6" && s 2 == "udp" 38 + then "[${s 1}]:${s 3}" 39 else null; # not valid for listen datagram, skip 40 41 + in 42 + { 43 44 ###### interface 45 ··· 70 71 dataDir = mkOption { 72 type = types.str; 73 + default = 74 + if versionAtLeast config.system.stateVersion "17.09" 75 + then "/var/lib/ipfs" 76 + else "/var/lib/ipfs/.ipfs"; 77 description = "The data dir for IPFS"; 78 }; 79 ··· 143 These are applied last, so may override configuration set by other options in this module. 144 Keep in mind that this configuration is stateful; i.e., unsetting anything in here does not reset the value to the default! 145 ''; 146 + default = { }; 147 example = { 148 Datastore.StorageMax = "100GB"; 149 Discovery.MDNS.Enabled = false; ··· 159 extraFlags = mkOption { 160 type = types.listOf types.str; 161 description = "Extra flags passed to the IPFS daemon"; 162 + default = [ ]; 163 }; 164 165 localDiscovery = mkOption { ··· 174 type = types.nullOr types.int; 175 default = null; 176 description = "The fdlimit for the IPFS systemd unit or <literal>null</literal> to have the daemon attempt to manage it"; 177 + example = 64 * 1024; 178 }; 179 180 startWhenNeeded = mkOption { ··· 241 ipfs --offline config Mounts.IPFS ${cfg.ipfsMountDir} 242 ipfs --offline config Mounts.IPNS ${cfg.ipnsMountDir} 243 '' + concatStringsSep "\n" (collect 244 + isString 245 + (mapAttrsRecursive 246 + (path: value: 247 + # Using heredoc below so that the value is never improperly quoted 248 + '' 249 + read value <<EOF 250 + ${builtins.toJSON value} 251 + EOF 252 + ipfs --offline config --json "${concatStringsSep "." path}" "$value" 253 + '') 254 + ({ 255 + Addresses.API = cfg.apiAddress; 256 + Addresses.Gateway = cfg.gatewayAddress; 257 + Addresses.Swarm = cfg.swarmAddress; 258 + } // 259 + cfg.extraConfig)) 260 + ); 261 serviceConfig = { 262 + ExecStart = [ "" "${cfg.package}/bin/ipfs daemon ${ipfsFlags}" ]; 263 User = cfg.user; 264 Group = cfg.group; 265 } // optionalAttrs (cfg.serviceFdlimit != null) { LimitNOFILE = cfg.serviceFdlimit; }; ··· 270 systemd.sockets.ipfs-gateway = { 271 wantedBy = [ "sockets.target" ]; 272 socketConfig = { 273 + ListenStream = 274 + let 275 fromCfg = multiaddrToListenStream cfg.gatewayAddress; 276 + in 277 + [ "" ] ++ lib.optional (fromCfg != null) fromCfg; 278 + ListenDatagram = 279 + let 280 fromCfg = multiaddrToListenDatagram cfg.gatewayAddress; 281 + in 282 + [ "" ] ++ lib.optional (fromCfg != null) fromCfg; 283 }; 284 }; 285 ··· 287 wantedBy = [ "sockets.target" ]; 288 # We also include "%t/ipfs.sock" because there is no way to put the "%t" 289 # in the multiaddr. 290 + socketConfig.ListenStream = 291 + let 292 fromCfg = multiaddrToListenStream cfg.apiAddress; 293 + in 294 + [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg; 295 }; 296 297 };