Very new to Nix, still struggling to intuitively understand some concepts, sorry if there are stupid questions.
I am trying to make a builder of vm, and an iso image with my custom configuration, which has included a few containers defined in configuration.nix, and what’s important, the images have to be baked in and automatically started after installation, with zero user input and no network requirements.
After some trial and error I came up with a boilerplate snippet that kinda works:
{
description = "Minimal NixOS installation media";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
outputs = { self, nixpkgs }: {
nixosConfigurations = {
iso = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({ pkgs, modulesPath, ... }: {
imports = [
# switch between building an installer iso and qemu vm
(modulesPath + "/installer/cd-dvd/installation-cd-graphical-calamares-gnome.nix")
#(modulesPath + "/virtualisation/qemu-vm.nix")
];
environment.systemPackages = [ pkgs.neovim ];
virtualisation.containers.enable = true;
virtualisation = {
podman = {
enable = true;
defaultNetwork.settings.dns_enabled = true;
};
oci-containers.containers = {
test = {
image = "test";
imageFile = fetchTree {
type = "file";
url = "file:///home/<me>/Documents/Nix-ISO/test.tar";
};
autoStart = false;
};
};
};
nix = {
settings.experimental-features = ["nix-command" "flakes"];
extraOptions = "experimental-features = nix-command flakes";
};
})
];
};
};
};
}
And I’d like to continue to build on top of that. However, there are problems:
- When I build a VM, the service fails to load image due to
no space left on device
(it is only creating 1024Mb sized root volume for some reason regardless of settings) andconfig.virtualisation.diskSize
does not affect produced volume size even though it probably should. However, the rest works as expected. - When I build an ISO, the installer contains the tarball with an image as expected, but fails to start a service due to
no space left on device
, again, as expected. However, when I run the installer and finish the installation, the result operating system does not have a tarball copied there, nor does it reflect any config I included in the flake. Looks like the flake parameters only affect the installer and nothing does pass to an installed os. - And finally, the installer is not airgap ready. It still reaches out to the internet to get nixpkgs, but I want all the dependencies already included and no attempts to update them no matter what, I want a frozen in time build
Any idea what is the right approach to achieve all that? What am I doing wrong here?