Bluetooth service fails when /var/lib/bluetooth is a symlink

Hi,
I’m currently playing around with a temporary root filesystem. To not lose all my connected bluetooth devices on boot I tried to symlink the /var/lib/bluetooth directory to a persistent location like this:

{
  systemd.tmpfiles.rules = [
    "L /var/lib/bluetooth - - - - /persist/var/lib/bluetooth"
  ];
}

But this results in bluetooth.service failing with

Apr 14 23:00:28 nixps (uetoothd)[25990]: bluetooth.service: Failed to set up special execution directory in /var/lib: Not a directory
Apr 14 23:00:28 nixps (uetoothd)[25990]: bluetooth.service: Failed at step STATE_DIRECTORY spawning /nix/store/sl9xzfjrrs3k47apx1zs533cji9625y4-bluez-5.66/libexec/bluetooth/bluetoothd: Not a directory

It seems like the service does not like symlinks. Is there another way to somehow link this directory somewhere into /persist or tell the service to write there?

Thanks in advance for your help

Okay so I did not find out why the tmpfile solution did not work, but I found another solution with the
impermanence community module. It uses bind mounts instead of symlinks which the bluetooth service does not notice:

let
  impermanence = builtins.fetchTarball {
    url = "https://github.com/nix-community/impermanence/archive/master.tar.gz";
    sha256 = "0hpp8y80q688mvnq8bhvksgjb6drkss5ir4chcyyww34yax77z0l";
  };
in {
  imports = [ "${impermanence}/nixos.nix" ];
  environment.persistence."/persist" = {
    hideMounts = true;
    directories = [
      "/var/lib/bluetooth"
    ];
  };
}
2 Likes