Skip to content

Commit

Permalink
nixos/kubo: fix potential panic on startup
Browse files Browse the repository at this point in the history
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 ipfs/kubo#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 NixOS#248447.
  • Loading branch information
Luflosi authored and Lainera committed Dec 20, 2023
1 parent d45a488 commit ddd6c82
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nixos/modules/services/network-filesystems/kubo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand Down

0 comments on commit ddd6c82

Please sign in to comment.