The /boot partition is 100% full and this creates an error when `sudo nixos-rebuild switch`

error:

building the system configuration... 

updating GRUB 2 menu...
cannot copy /nix/store/4bxj8hkr809zsjzj892gmmlcqyfzxs5f-initrd-linux-zen-6.12.2/initrd to /boot/kernels/4bxj8hkr809zsjzj892gmmlcqyfzxs5f-initrd-linux-zen-6.12.2-initrd.tmp: No space left on device 
Failed to install bootloader 
warning: error(s) occurred while switching to the new configuration 

I used to solve this with rm /boot/kernels, but now it stopped working.

configuration.nix:

{
  config,
  pkgs,
  catppuccin,
  inputs,
  ...
}: {
  imports = [
    ./hardware-configuration.nix
    ./packages.nix
  ];

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

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

  catppuccin = {
    tty.enable = true;
    grub.enable = true;
    # plymouth.enable = true;
  };

  boot.loader = {
    # systemd-boot.enable = true;
    efi = {
      canTouchEfiVariables = true;
      efiSysMountPoint = "/boot";
    };
    grub = {
      devices = ["nodev"];
      enable = true;
      efiSupport = true;
      useOSProber = false;
    };
  };
  # boot.plymouth.enable = 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.
  services.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"
      "libvirtd"
    ];
    shell = pkgs.nushell;
  };

  nixpkgs.config.allowUnfree = true;

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

hardware-configuration.nix:

{
  config,
  lib,
  pkgs,
  modulesPath,
  ...
}:

{
  imports = [
    (modulesPath + "/installer/scan/not-detected.nix")
  ];

  boot.kernelPackages = pkgs.linuxPackages_zen;
  # boot.kernelPackages = pkgs.linuxPackages_xanmod;

  boot.initrd.availableKernelModules = [
    "nvme"
    "xhci_pci"
    "uas"
    "usb_storage"
    "sd_mod"
  ];
  boot.initrd.kernelModules = [
    "nvidia"
    "nvidia_modeset"
    "nvidia_drm"
    "nvidia_uvm"
  ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/78657e37-f633-480f-9ff6-1172f749eacc";
    fsType = "ext4";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/AA5A-6F14";
    fsType = "vfat";
    options = [
      "fmask=0077"
      "dmask=0077"
    ];
  };

  swapDevices = [
    { device = "/dev/disk/by-uuid/f294c9c7-b577-4ec6-9bad-e6b7111773d6"; }
  ];

  networking.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;

  hardware.graphics.enable = true;
  hardware.graphics.enable32Bit = true;

  services.xserver.videoDrivers = [ "nvidia" ];
  hardware.nvidia.modesetting.enable = true;
  hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;
  hardware.nvidia.open = false;

  hardware.nvidia.prime = {
    offload = {
      enable = true;
      enableOffloadCmd = true;
    };

    amdgpuBusId = "PCI:5:0:0";
    nvidiaBusId = "PCI:1:0:0";
  };
}

so most likly you have to much generations in /boot.
try the following:

1. sudo nix-collect-garbage  --delete-older-than 14d
2. sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 14d

If you want that automatically with the garbage collector do the following:

  nix.gc = {
    automatic = true;
    dates = "weekly";
    options = "--delete-older-than 14d";
  };

That didn’t help, nix-env --list-generations outputs:

  17 2025-01-20 16:29:48 (current)

how big is your boot partition?

I used the installer and it made it with 537 MB

have you changed your bootloader from systemd boot to grub before trying to rebuild

No, but I wanted to use plymouth and when I encountered the error I commented it out

Ok try this:
first list the generations:

nix-env --list-generations
and
nixos-rebuild list-generations

Also maybe post the output of them
If you see that there are very much of them run the previous commands but with a lower date:

1. sudo nix-collect-garbage  --delete-older-than 2d
2. sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 2d
1 Like

nix-env showed only 1 generation, but nixos-rebuild list-generations showed older generations that used an outdated kernel, which took up too much space in the /boot partition.

1 Like