nixos-generators
nixos-generators copied to clipboard
Allow generating image using existing nixosSystem
Accepts a new paramater nixosSystem if not null use extendModules rather than creating a new nixosSystem.
Have you seen https://github.com/nix-community/nixos-generators/pull/241 It allows you to add all formats to your system by importing a single module. I believe https://github.com/nix-community/nixos-generators/pull/241 is even more ergonomic.
I may be missing something, but all the module does is let you include a variety of format that can be built. My personal opinion is that it tightly couples the image generation to the system generation. I'm not sure if or why this would be desirable.
Here is my simple use case,
radius-lab-vm = nixos-generators.nixosGenerate {
inherit system pkgs;
nixosSystem = self.nixosConfigurations.radius-lab;
format = "vm";
modules = [
{ virtualisation = {
memorySize = 4096;
qemu.networkingOptions = [
"-net user,hostfwd=udp::1812-:1812"
];
};
}
];
};
I can modify and tweak the VM generatotion, and the system config remains agnostic. If #241 can do this as simply as this patch can, you've sold me.
Your example reminds me that a missing feature of #241 is to pass your own modules. I'll add that asap. Assuming we have that features, then the whole flake could look like this:
flake.nix
{
#...
outputs = {self, nixos-generators, ...} @ inputs: {
nixosConfigurations.radius-lab = {config, pkgs, ...}: {
imports = [
nixos-generators.nixosModules.all-formats
];
# all you normal system config here
# nixos-generators options for all possible formats
formats.vm = {
virtualisation = {
memorySize = 4096;
qemu.networkingOptions = [
"-net user,hostfwd=udp::1812-:1812"
];
};
};
};
};
# this line is just an alias, instead of an extra function call
radius-lab-vm = self.nixosConfigurations.system.formats.vm;
}
Why is this better?
Instead of expressing your nixos-generators format in an ad-hoc style, this makes your settings become part of the module system.
One could, for example express the formats
settings in an extra module and thereby make it portable
Another person could re-use your nixos-generators format from your github by just simply importing the module.
It's also simpler for you to share it between different machines or projects.
So that sounds like it would be awesome, and probably would supersede #185 for my use cases. How close did #241 get to actually being able to do what you suggest? To start with nix flake show github:nix-community/nixos-generators
doesn't seem to show that the all-formats
module is exposed. Would the module work like you describe above if it was exposed as is?
I just opened https://github.com/nix-community/nixos-generators/pull/256 which implements the customization options similar to the example above and also allows adding new formats.
It now also exposes nixosModules.all-formats