summary refs log tree commit diff
path: root/nixos/modules/services/network-filesystems/ipfs.nix
diff options
context:
space:
mode:
authorKevin Cox <kevincox@kevincox.ca>2021-09-08 10:50:36 -0400
committerKevin Cox <kevincox@kevincox.ca>2021-09-08 12:17:22 -0400
commitaf354d20497d68d104b84d888260ca60e66c6683 (patch)
treeace6599b82846c3b684786deef4fd6f94133c0ba /nixos/modules/services/network-filesystems/ipfs.nix
parent91d2ebe422fa7f3745c7ef7b73dde8dbb2a0a382 (diff)
downloadnixpkgs-af354d20497d68d104b84d888260ca60e66c6683.tar
nixpkgs-af354d20497d68d104b84d888260ca60e66c6683.tar.gz
nixpkgs-af354d20497d68d104b84d888260ca60e66c6683.tar.bz2
nixpkgs-af354d20497d68d104b84d888260ca60e66c6683.tar.lz
nixpkgs-af354d20497d68d104b84d888260ca60e66c6683.tar.xz
nixpkgs-af354d20497d68d104b84d888260ca60e66c6683.tar.zst
nixpkgs-af354d20497d68d104b84d888260ca60e66c6683.zip
nixos.ipfs: Fix startup after unclean shutdown.
Fixes https://github.com/NixOS/nixpkgs/issues/135684
Diffstat (limited to 'nixos/modules/services/network-filesystems/ipfs.nix')
-rw-r--r--nixos/modules/services/network-filesystems/ipfs.nix18
1 files changed, 11 insertions, 7 deletions
diff --git a/nixos/modules/services/network-filesystems/ipfs.nix b/nixos/modules/services/network-filesystems/ipfs.nix
index 57f5f6b006c..3a01c06edc3 100644
--- a/nixos/modules/services/network-filesystems/ipfs.nix
+++ b/nixos/modules/services/network-filesystems/ipfs.nix
@@ -12,6 +12,11 @@ let
     (optionalString (cfg.defaultMode == "norouting") "--routing=none")
   ] ++ cfg.extraFlags);
 
+  profile =
+    if cfg.localDiscovery
+    then "local-discovery"
+    else "server";
+
   splitMulitaddr = addrRaw: lib.tail (lib.splitString "/" addrRaw);
 
   multiaddrToListenStream = addrRaw:
@@ -236,14 +241,13 @@ in
       environment.IPFS_PATH = cfg.dataDir;
 
       preStart = ''
-        if [[ ! -f ${cfg.dataDir}/config ]]; then
-          ipfs init ${optionalString cfg.emptyRepo "-e"} \
-            ${optionalString (! cfg.localDiscovery) "--profile=server"}
+        if [[ ! -f "$IPFS_PATH/config" ]]; then
+          ipfs init ${optionalString cfg.emptyRepo "-e"} --profile=${profile}
         else
-          ${if cfg.localDiscovery
-            then "ipfs --offline config profile apply local-discovery"
-            else "ipfs --offline config profile apply server"
-          }
+          # After an unclean shutdown this file may exist which will cause the config command to attempt to talk to the daemon. This will hang forever if systemd is holding our sockets open.
+          rm -vf "$IPFS_PATH/api"
+
+          ipfs --offline config profile apply ${profile}
         fi
       '' + optionalString cfg.autoMount ''
         ipfs --offline config Mounts.FuseAllowOther --json true