Hi everyone,
I’m trying to generate VM-Images with nixos-generators. Because I want to have finer control, I want to use customFormats, but I can’t get it to work. I’m fairly new to Nix and Flakes, therefore it is probably some stupid mistake I’m making. Any advice is appreciated, thank you all in advance.
flake.nix
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.05";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
qcow2_imp = {
url = "../modules/qcow2.nix";
flake = false;
};
};
outputs = { self, nixpkgs, nixos-generators, qcow2_imp, ... }:
{
packages.x86_64-linux = {
vbox = nixos-generators.nixosGenerate {
system = "x86_64-linux";
format = "virtualbox";
};
qemu = nixos-generators.nixosGenerate {
system = "x86_64-linux";
format = "qcow2";
customFormats = { qcow2 = qcow2_imp; };
};
hyperv = nixos-generators.nixosGenerate {
system = "x86_64-linux";
format = "hyperv";
};
default = self.packages.x86_64-linux.vbox;
};
};
}
qcow2.nix (copied from the examples on github)
{
config,
lib,
pkgs,
modulesPath,
...
}: {
# for virtio kernel drivers
imports = [
"${toString modulesPath}/profiles/qemu-guest.nix"
];
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
autoResize = true;
fsType = "ext4";
};
boot.growPartition = true;
boot.kernelParams = ["console=ttyS0"];
boot.loader.grub.device =
if (pkgs.stdenv.system == "x86_64-linux")
then (lib.mkDefault "/dev/vda")
else (lib.mkDefault "nodev");
boot.loader.grub.efiSupport = lib.mkIf (pkgs.stdenv.system != "x86_64-linux") (lib.mkDefault true);
boot.loader.grub.efiInstallAsRemovable = lib.mkIf (pkgs.stdenv.system != "x86_64-linux") (lib.mkDefault true);
boot.loader.timeout = 0;
system.build.qcow = import "${toString modulesPath}/../lib/make-disk-image.nix" {
inherit lib config pkgs;
diskSize = 8192;
format = "qcow2";
partitionTableType = "hybrid";
};
formatAttr = "qcow2";
fileExtension = ".qcow2";
}
error message
warning: Git tree '/home/kakn/Dokumente/Repositories/reproducibledevenvironments' is dirty
warning: updating lock file '/home/kakn/Dokumente/Repositories/reproducibledevenvironments/base-config/flake.lock':
• Updated input 'qcow2_imp':
'path:/nix/store/8pxxvq5g97q16fys82x2qvysgwdcjaxc-source/modules/qcow2.nix?lastModified=1&narHash=sha256-LiqQe/qigVi6Otl%2BY2gL3/Wc/4vFyHMVrg862rvnCiE%3D' (1970-01-01)
→ 'path:/nix/store/2q02n99779d96939mm1anra5vi4zc709-source/modules/qcow2.nix?lastModified=1&narHash=sha256-LiqQe/qigVi6Otl%2BY2gL3/Wc/4vFyHMVrg862rvnCiE%3D' (1970-01-01)
warning: Git tree '/home/kakn/Dokumente/Repositories/reproducibledevenvironments' is dirty
error:
… while evaluating the attribute 'config.system.build."${(image).config.formatAttr}"'
at /nix/store/c8aplaf4cij0zr4bca19y1k2vi9qhslz-source/lib/modules.nix:326:9:
325| options = checked options;
326| config = checked (removeAttrs config [ "_module" ]);
| ^
327| _module = checked (config._module);
… while calling the 'seq' builtin
at /nix/store/c8aplaf4cij0zr4bca19y1k2vi9qhslz-source/lib/modules.nix:326:18:
325| options = checked options;
326| config = checked (removeAttrs config [ "_module" ]);
| ^
327| _module = checked (config._module);
(stack trace truncated; use '--show-trace' to show the full trace)
error: The option `lastModified' does not exist. Definition values:
- In `/nix/store/c8aplaf4cij0zr4bca19y1k2vi9qhslz-source/flake.nix': 1