Сan't change bootloader to grub

I changed bootloader to grub in the configuration and sudo nixos-rebuild boot --flake ~/NixOS/ --install-bootloader doesn’t give any error, but when I reboot systemd-boot opens where my new nixos generation is missing
Here’s my config:

{
  config,
  pkgs,
  catppuccin,
  ...
}:

{
  imports = [
    ./hardware-configuration.nix
  ];

  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];

  nix.gc = {
    automatic = true;
    dates = "weekly";
    options = "-d";
  };

  console.catppuccin.enable = true;
  boot.loader.grub = {
    efiSupport = true;
    efiInstallAsRemovable = true;
    device = "nodev";
    catppuccin.enable = true;
  };
  # boot.loader.systemd-boot.enable = true;
  # boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "nixos";

  networking.networkmanager.enable = true;

  time.timeZone = "Europe/Moscow";

  i18n.defaultLocale = "ru_RU.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "ru_RU.UTF-8";
    LC_IDENTIFICATION = "ru_RU.UTF-8";
    LC_MEASUREMENT = "ru_RU.UTF-8";
    LC_MONETARY = "ru_RU.UTF-8";
    LC_NAME = "ru_RU.UTF-8";
    LC_NUMERIC = "ru_RU.UTF-8";
    LC_PAPER = "ru_RU.UTF-8";
    LC_TELEPHONE = "ru_RU.UTF-8";
    LC_TIME = "ru_RU.UTF-8";
  };

  services.xserver.enable = true;

  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;
  services.xserver.displayManager.gdm.wayland = true;

  services.xserver.xkb = {
    layout = "us";
    variant = "";
  };

  # Enable sound with pipewire.
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
  };

  users.users.inari = {
    isNormalUser = true;
    description = "Maxim";
    extraGroups = [
      "networkmanager"
      "wheel"
    ];
    shell = pkgs.fish;
  };
  programs.fish.enable = true;

  nixpkgs.config.allowUnfree = true;

  environment.systemPackages = with pkgs; [
    home-manager
    zed-editor
    blackbox-terminal
    nixd
    nautilus
    gnome-boxes
    gnome-calculator
    gnome-disk-utility
    fragments
    nautilus-open-in-blackbox
    heroic
    gnome-tweaks
    protonup
    solaar
    ollama-cuda
    bat
    ripgrep
    fzf
    zoxide
    devenv
    eza
    telegram-desktop
    oh-my-posh
    nixfmt-rfc-style
    fd
    dua
    epapirus-icon-theme
    zen-browser
    catnap
    yazi
    nil

    gnomeExtensions.dash-to-dock
    gnomeExtensions.blur-my-shell
    gnomeExtensions.appindicator
    gnomeExtensions.vitals
    gnomeExtensions.gsconnect
    gnomeExtensions.clipboard-indicator
    gnomeExtensions.rounded-window-corners-reborn
    gnomeExtensions.solaar-extension
  ];
  programs.nix-ld.enable = true;

  programs.steam.enable = true;
  programs.steam.gamescopeSession.enable = true;
  programs.gamemode.enable = true;

  nixpkgs.config.packageOverrides = pkgs: {
    zen-browser = pkgs.callPackage ./nonNixPackages/zen-browser/default.nix { };
    catnap = pkgs.callPackage ./nonNixPackages/catnap/default.nix { };
  };

  services.ollama.enable = true;

  fonts.packages = with pkgs; [
    jetbrains-mono
    fira-code-nerdfont
  ];

  services.gnome.core-utilities.enable = false;
  environment.gnome.excludePackages = [ pkgs.gnome-tour ];
  services.xserver.excludePackages = [ pkgs.xterm ];
  services.xserver.desktopManager.xterm.enable = false;
  documentation.nixos.enable = false;
  programs.nano.enable = false;

  system.stateVersion = "24.05"; # Did you read the comment?

}

Also how do I clean up /boot? when nixos-rebuild switch I get an error that there is not enough memory there

I don’t know how to solve your GRUB problem, but for this:

/boot gets a copy of all kernels and initrds needed for every one of your system generations. You can list your system generations on NixOS with:

sudo nix-env --list-generations -p /nix/var/nix/profiles/system

And clean up ones you no longer want to keep around with nix-env --delete-generations. (That won’t remove things from the Nix store until your next GC, but it will remove entries from your boot menu and prevent you from rolling back to the deleted generations.)

At the end of the nixOS live usb installer it says “all options can be changed after you reboot into your new nixOS system, EXCEPT FOR THE BOOT LOADER” this means you have to mount your internal disk from the live USB and change the bootloader in the config BEFORE first boot, because some weird stuff happens on first boot that locks your boot-loader to a certain one “such as system-D”. Your only solution now is to back up your config and other important files and reinstall nixos REMEMBERING THIS TIME to change it before first boot.

When you enable grub, it does not delete systemd-boot or its files. That’s why it’s still installed and that’s why the motherboard firmware is still booting it by default. You can just delete everything in /boot/ and re-run nixos-rebuild --install-bootloader.

Finally, why are you switching to grub? My personal opinion is that grub is never the right choice when UEFI is the setup. Just curious.

It’s a matter of personal preference, some people like grubs features such as custom themes. Also I did not know it was possible to switch to grub that way, tysm for educating me about nixOS I am also a noob.

When I tried nixos in a virtual machine, I changed the bootloader

In a virtual machine the default bootloader is already grub so changing grub to grub would of course be successful. you are now running nixos on bare metal right?

In that case the default is systemd boot for bare metal and your trying to change it to grub, which from my understanding is not possible after first boot, but elvish jerricos comment suggests otherwise, so give his suggestion a shot and tell us if it was successful please :slight_smile:

It can be done, this problem has already been solved in linux - NixOS using systemd-boot instead of grub, although it is disabled in nix config file - Super User

Gives an error:

cannot close /boot/grub/grub.cfg.tmp: No space left on device
Failed to install bootloader
warning: error(s) occurred while switching to the new configuration

I just deleted everything from /boot and the system automatically switched to grub