How to disable some panels in GNOME control center

The panels can be disabled by remove the corresponding desktop files according to Is it possible to remove items from "System Settings" - Ask Ubuntu. But it’s not easy on NixOS. I tried to add a dummy package with empty desktop files. But it doesn’t work. Maybe it’s easier to create a wrapper for GNOME control center.

What exactly did you try?

    (pkgs.writeTextFile {
      name = "gnome-online-accounts-panel";
      text = "";
      destination = "/share/applications/gnome-online-accounts-panel.desktop";
    })

Add this to systemPackages, then the gnome-online-accounts-panel.desktop in current-system will be an empty file. But the panel is still there. I tested patching the package and it does work by removing the file. But I don’t want to add another minute when I rebuilding the system so I’ll use a wrapper.

      gnome = super.gnome // {
        gnome-control-center = super.runCommand "gnome-control-center" { } ''
          mkdir -p $out
          ${super.xorg.lndir}/bin/lndir -silent ${super.gnome.gnome-control-center} $out
          rm $out/share/applications/gnome-{online-accounts,sharing}-panel.desktop
        '';
      };

This doesn’t work either. I guess it looks at the original path.

Right, try copying the files and then seding the original path for the new one.

      gnome = super.gnome // {
        gnome-control-center = super.runCommand "gnome-control-center" { } ''
          cp -R ${super.gnome.gnome-control-center} $out
          chmod -R +w $out
          rm $out/share/applications/gnome-{online-accounts,sharing}-panel.desktop
          find $out -type f -exec sed -i -e "s|${super.gnome.gnome-control-center}|$out|g" {} \;
        '';
      };
    })

This doesn’t work either.

I know why it didn’t work. The path must has same length so the name should match. This is the working code:

      gnome = super.gnome // {
        gnome-control-center = super.runCommand "${super.gnome.gnome-control-center.name}" { } ''
          cp -R ${super.gnome.gnome-control-center} $out
          chmod -R +w $out
          rm $out/share/applications/gnome-{online-accounts,sharing}-panel.desktop
          find $out -type f -exec sed -i -e "s|${super.gnome.gnome-control-center}|$out|g" {} \;
        '';
      };