nix-community / nixos-generators

Collection of image builders [maintainer=@Lassulus]
MIT License
1.76k stars 136 forks source link

Expose nixdeploy as nix function in flake for automatic builds #94

Open mkg20001 opened 3 years ago

mkg20001 commented 3 years ago

Basically being able to do something like this

outputs = { nixdeploy, nixpkgs }: 
  {
    defaultPackage = nixdeploy.format.lxc { configuration = ./configuration.nix; nixpkgs = nixpkgs; };
  }
mayl commented 2 years ago

I just want to +1 this concept. I'm not sure if it's already possible, but I'd love to be able to do something like this where I can just nix build .# and my outputs are VM images.

mayl commented 2 years ago

So I'm somewhat out of my depth, but I added a nixosGenerate function to my fork which I'm testing here. It works basically like you suggest

outputs = { system, nixpkgs, nixosGenerate }: {
  lxcImage = nixosGenerate{ 
    inherit system pkgs;
    modules = [ ./configuration.nix ];
    format = "lxc";
  };
}

I can run commands like nix build .#lxcImage and result is populated with the image.

This seems to work for several of the formats I've tried, but again I feel a little out of my depth. I opened #119 for comment.