Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduces nixosGenerateMulti #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mayl
Copy link
Contributor

@mayl mayl commented Oct 28, 2022

In my workflow I often prototype and test in qemu and then when I'm happy I build one or more "deployable" formats like virualbox .ova, vmware etc. Currently, my flake.nix gets repetitious as I have to duplicate the arguments for each call to nixosGenerate for each format. This nixosGenerateMulti function is written to allow me to define multiple formats with a shared common base config, but allowing for per format overrides. This allows me to both share the base config among all the different formats I want to build it in, as well as adds a point where I can write a format specific module which I share among multiple base configs.

Appreciate any input.

@pgronkievitz
Copy link

are you sure it's necessary? You can define common modules in let expression and just append format-specific modules afterwards

@mayl
Copy link
Contributor Author

mayl commented Nov 10, 2022

If I understand what you mean it's something like this:

{
inputs = {
  nixpkgs.url = ...
  flakeInput1 = ...
  ...
};

outputs = {self, nixpkgs, flakeInput1, ...}: {
  server = let 
    serverModules = [ ./configuration.nix flakeInput1.nixosModules.module ];
    specialArgs = self;
  in {
    vm = nixos-generators.nixosGenerate { system = "x86_64-linux"; modules = serverModules ++ [ ./vmModule]; format="vm"; };
    virtualbox = nixos-generators.nixosGenerate { system = "x86_64-linux"; modules = serverModules ++ [ ./virtualboxModule]; format = "virtualbox"; };
 };
};
}

I agree this works, but it's tedious in practice. Keeping the output attribute name consistent with the format is manual, and you wind up copy pasting a lot of the arguments to nixosGenerate around. You could put an attribute set of the common arguments in the let expression, but then you need to merge your modules and format arguments in which neither // nor lib.recursiveUpdate really do satisfactorily. The tedium compounds when you have multiple machines all with multiple formats defined in the same flake.

So I agree, it's not necessary, but like the rest of nixos-generators it's meant to be a convenience. It may be that my use case is too niche to have this merged, but unless I misunderstand you I don't think what you suggest scratches my particular itch...

@JeremiahSecrist
Copy link
Contributor

I would find this very useful given my usage as well! I often find myself needing multiple targets, or multi changing targets over time. This would aid in simplification of my flake as of current state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants