Autostart of KeePassXC conflicts with gpg smartcard

I have a Nitrokey USB smartcard. I use gpg --card-status to check if it is working (if gpg is configured correctly). With my current NixOS configuration, this works.

But if I add the following snippet to start KeePassXC on login with GNOME, this changes.

{ config, pkgs, lib, ... }:
{
  home-manager.users.yoda = { osConfig, config, pkgs, ... }: {
    home.file.keepassxc = {
      target = ".config/autostart/" + "org.keepassxc.KeePassXC" + ".desktop";
      source = (pkgs.keepassxc + "/share/applications/" + "org.keepassxc.KeePassXC" + ".desktop");
    };
  };
}

After a reboot, KeePassXC is started on login. But gpg --card-status gives the following message, which is the same as if no smartcard is attached:

gpg: selecting card failed: No such device
gpg: OpenPGP card not available: No such device

I have no idea how I could debug this further … Any help is welcome.

In case this hepls, my NixOS configuration is public.

I have multiple modules (nix-git/modules at main - privacy1st/nix-git - Codeberg.org) that get imported in my main configuration file (nix-git/hosts/yodaTux/configuration.nix at main - privacy1st/nix-git - Codeberg.org).

The autostart snipped is from this module (nix-git/modules/autostart.nix at main - privacy1st/nix-git - Codeberg.org) and my gpg/smartcard is configured in a separate module (https://codeberg.org/privacy1st/nix-git/src/branch/main/modules/nitrokey-ssh-gpg.nix).

It was a timing issue between pcscd and scdaemon using the internal ccid driver. More details are provided here: Troubleshooting - Nitrokey Documentation

I was able to resolve this issue by adding this to my Home Manager configuration:

    programs.gpg = {
      enable = true;
      scdaemonSettings = {
        disable-ccid = true;
      };
    };