How to customize grub.cfg?

I searched on the internet for how to configure GRUB in the nix config but I found nothing except that you can use already packaged themes in grub.

I think that just editing the grub.cfg is not an option as NixOS will probably overwrite it on the next rebuild.

I’d like to change the order of the default entries or remove them, add custom entries, set a background, disable the timeout, and so on…

Do I have to write my own theme for that or is there a simple way to just have my own grub config file where NixOS can then insert the image paths?

Thank you

Hello so I would recommend to look at the grub options here:
https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=grub
For themes this is how I have done it for my grub:

  boot = {# Bootloader
    loader = {
      efi.canTouchEfiVariables = true;
      grub ={
        enable = true;
        device = "nodev";
        efiSupport = true;
        useOSProber = true;
        theme = "${
          (pkgs.fetchFromGitHub {
            owner = "semimqmo";
            repo = "sekiro_grub_theme";
            rev = "1affe05f7257b72b69404cfc0a60e88aa19f54a6";
            hash = "sha256-wTr5S/17uwQXkWwElqBKIV1J3QUP6W2Qx2Nw0SaM7Qk=";
          })
        }/Sekiro";
      };
      timeout = 10;
    };
  };

If you have more questions feel free to ask
Options you wanted:
to use an image as a background: boot.loader.grub.splashImage
to add custom entries:boot.loader.grub.extraEntries
to change the timeout: boot.loader.timeout

If the default entries you want to remove are NixOS generations, take a look at Garbage Collection, where you can remove certain generations and remove them from the boot menu.

Is there a way to rearrange the pre-configured entries?

boot.loader.grub.extraEntriesBeforeNixOS

If you want your Entries before the Default
If you want that your extra Entries at the end there was something here:

But for me this won’t work (the last comment is from me).
Other than that there is not really much you can do considering the rearrangement of the pre configured entries.
Only when you put all the Entries (exept the default) in the extraEntry Option. The order in there is kept and will be displayed in GRUB.