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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@
in
image.config.system.build.${image.config.formatAttr};

# example usage in flakes:
# outputs = { self, nixpkgs, nixos-generators, ... }: {
# server = nixos-generators.nixosGenerateMulti {
# system = "x86_64-linux";
# modules = [./configuration.nix];
# } {
# "vm" = { modules = [./qemuConfig.nix] };
# "vmware" = { modules = [./vmwareConfig.nix] };
# };
# }
#
# Builds multiple formats, based on common config. Takes a "default"
# attribute set of parameters which are the same as for `nixos-generate`
# and a second attribute set for each format. The format specific
# attribute should have a name which matches a valid nixos-generators
# format, and have attributes which are merged with the provided defaults.
# Generally, the format overrides the default with the exception that
# modules are concatenated. Each format is then available by name.
#
# In the above example server.vm or server.vmware would build the qemu
# vm or vmware formats, respectively.
nixosGenerateMulti = baseArgs: formatArgs:
let
formats = nixpkgs.lib.attrNames formatArgs;
mkFinalArgs = format: (nixpkgs.lib.recursiveUpdate baseArgs formatArgs.${format}) // { format = format; modules = baseArgs.modules ++ (formatArgs.${format}.modules or [ ]); };
formatImage = format: (self.nixosGenerate (mkFinalArgs format));
mkFormatAttr = format: nixpkgs.lib.nameValuePair format (formatImage format);
in
builtins.listToAttrs (map mkFormatAttr formats);

}

//
Expand Down