Whats wrong? `/etc/nixos/configuration.nix' has an unsupported attribute `boot'

Happened during a nixos-rebuild, I’m pretty sure I didn’t mess up anything, and I just changed a value in

Module `/etc/nixos/configuration.nix' has an unsupported attribute `boot'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top le
vel instead, or move all of them (namely: boot environment fonts hardware home-manager i18n networking nix nixpkgs programs security services sound system time users virtualisation xdg zramSwap) into the explici
t `config' attribute.
1 Like

Could you show your configuration file? You’ve clearly made some mistake, hard to argue with the tool that interprets your code :wink:

I’ve searched for all occurrences of boot
opened in two editor
and even looked for unicode hidden chars (maybe a zwnj be in the boot causing issue),
this is all of my lines starting with boot

other lines are still needed as well?

  boot.loader.grub = {
    extraConfig = "set theme=($drive2)${pkgs.breeze-grub}/grub/themes/breeze/theme.txt"; # fix
    splashImage = null;
  };
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.efi.efiSysMountPoint = "/boot/efi";
  boot.initrd.secrets = {
    "/crypto_keyfile.bin" = null;
  };
  boot.initrd.luks.devices."luks-x".device = "/dev/disk/by-uuid/x";
  boot.initrd.luks.devices."luks-x".keyFile = "/crypto_keyfile.bin";
  boot.kernelPackages = pkgs.linuxPackages_latest;
  boot.supportedFilesystems = [ "ntfs" ];

isn’t the msg its printing contradicting? what can ever cause it even!

this is my configuration.nix start:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      <home-manager/nixos>
    ];

  nix.settings.experimental-features = [ "nix-command" "flakes" ];
  # nix.readOnlyStore = false;
  nix.extraOptions = ''
    plugin-files = ${pkgs.nix-doc}/lib/libnix_doc_plugin.so
  '';

  boot.loader.grub = {
    extraConfig = "set theme=($drive2)${pkgs.breeze-grub}/grub/themes/breeze/theme.txt"; # fix
    splashImage = null;
  };
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.efi.efiSysMountPoint = "/boot/efi";

  zramSwap = {
    enable = true;
    numDevices = 2;
    swapDevices = 1;
    memoryPercent = 50;
  };

  # Setup keyfile
  boot.initrd.secrets = {
    "/crypto_keyfile.bin" = null;
  };

  # Enable swap on luks
  boot.initrd.luks.devices."luks-x".device = "/dev/disk/by-uuid/x";
  boot.initrd.luks.devices."luks-x".keyFile = "/crypto_keyfile.bin";

  boot.kernelPackages = pkgs.linuxPackages_latest;

  boot.supportedFilesystems = [ "ntfs" ];

So, nixos modules alllow two syntaxes:

{
  imports = [ <some imports> ];
  my-favorite-option = true;
}

and

{
  imports = [ <some imports> ];
  options = { <some custom options> };
  config = {
    my-favorite-option = true;
  };
}

This can be confusing, but the latter syntax is used to define custom options, whereas the former is just used to set them. config in the latter should contain any options the module sets, and usually contains a whole bunch of conditionals so that it changes based on what is set with the options.

The way it works is that if you omit options and config, all keys will simply be treated as if they were in config.

However, if you define a config and try to set options at the same time, nix won’t be able to distinguish between these two modes, and you get the error message you have.

The reason it talks about boot is simply because it’s the first problem it encountered.

Thus, while looking for boot is nice and all, I really need to see your full config file to se where you went wrong. You probably added an options or config somewhere :slight_smile:

7 Likes

Right, I wish the output would have mentioned to look for option and config clearly
the following line, caused me this issue
config.firefox.enablePlasmaBrowserIntegration = true;

Thanks for descriptive respond!

1 Like

To be fair, it literally says:

This is caused by introducing a top-level config' or options’ attribute.

I suppose it could use fewer technical terms to describe that, I imagine new users may be confused by “top-level” and “attribute”.

Far from the worst error message, though.

1 Like

I expected by top level it means, out of the main double curly brackets, but yep its probably due to my noob-ness