about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorLuflosi <luflosi@luflosi.de>2023-12-02 23:52:09 +0100
committerLuflosi <luflosi@luflosi.de>2023-12-15 23:36:08 +0100
commitd4fcb44dcc6153ef982bd7fa87dca97bd3142796 (patch)
tree8688f971391f834be432f11a661aaabd2decf420 /nixos
parent271235e3891e6825fd7dbe94d45e229e41283b3a (diff)
downloadnixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.tar
nixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.tar.gz
nixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.tar.bz2
nixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.tar.lz
nixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.tar.xz
nixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.tar.zst
nixlib-d4fcb44dcc6153ef982bd7fa87dca97bd3142796.zip
nixos/kubo: fix potential panic on startup
This fixes a panic of the kubo daemon which could occur under certain conditions when the daemon was starting.
It was caused by the `ipfs.service` unit not depending on the `ipfs-api.socket` and `ipfs-gateway.socket` units with `Wants=`. This allows the `ipfs.service` to be started manually or by `nixos-rebuild` without the sockets being set up before that. When that happens, the daemon won't know about these sockets and will only use what is set in `services.kubo.settings.Addresses.Gateway` and `services.kubo.settings.Addresses.API`. By default the `API` is an empty list in NixOS though. The daemon doesn't like this at all and panics on startup, see https://github.com/ipfs/kubo/issues/10056.
With this commit, starting `ipfs.service` will first set up the two sockets before starting the actual service.
Adding the `Sockets=` option implicitly adds a `Wants=` for the sockets and this is exactly what we need. See https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Implicit%20Dependencies . This can be checked with `systemctl show ipfs.service`.

This should probably be upstreamed to the unit file in the Kubo repo.

The problem can be reproduced in the following way:
- Add `services.kubo.enable = true` to `/etc/nixos/configuration.nix`
- `sudo nixos-rebuild switch` (this may already fail, not sure why it's not deterministic for me)
- `sudo systemctl stop ipfs-api.socket`
- `sudo systemctl stop ipfs-gateway.socket`
- `sudo systemctl stop ipfs.service`
- `sudo systemctl start ipfs.service`

Fixes #248447.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/network-filesystems/kubo.nix2
1 files changed, 2 insertions, 0 deletions
diff --git a/nixos/modules/services/network-filesystems/kubo.nix b/nixos/modules/services/network-filesystems/kubo.nix
index fbf9b32a2b25..e0b3fb0f36a7 100644
--- a/nixos/modules/services/network-filesystems/kubo.nix
+++ b/nixos/modules/services/network-filesystems/kubo.nix
@@ -361,6 +361,8 @@ in
         Group = cfg.group;
         StateDirectory = "";
         ReadWritePaths = optionals (!cfg.autoMount) [ "" cfg.dataDir ];
+        # Make sure the socket units are started before ipfs.service
+        Sockets = [ "ipfs-gateway.socket" "ipfs-api.socket" ];
       } // optionalAttrs (cfg.serviceFdlimit != null) { LimitNOFILE = cfg.serviceFdlimit; };
     } // optionalAttrs (!cfg.startWhenNeeded) {
       wantedBy = [ "default.target" ];