nixos-generators icon indicating copy to clipboard operation
nixos-generators copied to clipboard

Should formats that don't support bootloaders `lib.mkForce` disable them?

Open b- opened this issue 1 year ago • 1 comments

A number of the generated formats that are supported by nixos-generators don't use or support bootloaders, for example Docker, kexec, or lxc. I would like to propose that for those in particular where "installing grub" absolutely doesn't make any sense we set options like boot.loader.grub.enable = lib.mkForce false and boot.loader.systemd-boot.enable = lib.mkForce false.

This may fall squarely into idiot-proofing, but think it would improve the overall user experience because reusing an existing configuration will be easier.

I would be happy to make a PR, but I wanted to make a proposal via an Issue first before I put any effort into it, in case anyone else disagrees or has a different idea as to how this could or should be achieved.

Instead of a full PR, let me provide inline an example of what I have in mind:

# nixos-generators/formats/proxmox-lxc.nix
{modulesPath, config, lib, ...}: {
  imports = [
    "${toString modulesPath}/virtualisation/proxmox-lxc.nix"
  ];
  formatAttr = "tarball";
  fileExtension = ".tar.xz";
  boot.loader.grub.enable = lib.mkForce false;
  boot.loader.systemd-boot.enable = lib.mkForce false;
}

My thought process is that if installing a bootloader is impossible or otherwise makes no sense in a format provided by nixos-generators then adding such a setting mkForce'd to off will make reusing an existing NixOS configuration easier — for example if I wanted to package up into Docker something I was testing as a VM, I wouldn't have to touch existing bootloader settings.

Some of the formats such as kexec already disable grub (https://github.com/nix-community/nixos-generators/blob/0aa24e93f75370454f0e03747b6836ac2a2c9fca/formats/kexec.nix#L86C1-L87C1) but I think that not using lib.mkDefault or lib.mkForce in these situations might cause more confusion and frustration than not, since the resulting conflict error might not even make it clear what in your configuration is causing a conflict.

Maybe there should be some higher-up NixOS option we can toggle like boot.loader.enable that itself would override options like boot.loader.systemd-boot.enable and boot.loader.grub.enable? I'm not sure…

I understand that in general the Nix Community is pretty strongly opinionated against Nix being pretty opinionated, but given that nixos-generators is mostly a sugary wrapping around existing modules in <nixpkgs>, maybe adding a little more idiot-proofing sugar might help things? 😄 Just to be clear, I am NOT trying to impose using any particular bootloader or not on anyone in any situation, at all. I just think that bootloaders should be forcibly disabled for formats in which a bootloader inherently absolutely does not make sense.

b- avatar Feb 18 '24 22:02 b-

sounds like a good idea. Although I'm (very) slowly trying to move most of the code here to nixpkgs itself. But until that is finished we can add those overrides here

Lassulus avatar Feb 20 '24 03:02 Lassulus