nixos-generators icon indicating copy to clipboard operation
nixos-generators copied to clipboard

custom Formats in Flakes broken

Open kknoepfle opened this issue 2 years ago • 3 comments

When I try to generate VM-Images with custom Formats in a flake file, I get the following error:

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

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

{
  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";
}

Im using the nix multiuser install under ubuntu and Im fairly new to nix and flakes, therefore it might be a mistake on my side. Thank you all in advance.

kknoepfle avatar Nov 08 '23 13:11 kknoepfle

I'm not a 100% sure, but are all your files added to git? The nix flake mechanism only copies files to the store that have been added to git, so if you have new files that haven't been added yet that can be a problem because they won't be in the nix sandbox for the build to find them. I'm basing this on the "lastModified" attribute being how things are named when there isn't a commit hash to use and the git warnings at the very top.

mayl avatar Nov 08 '23 14:11 mayl

@mayl Yes all files are added with git add ., and just now I have also tried committing them, but I get the same error.

kknoepfle avatar Nov 08 '23 14:11 kknoepfle

ah I answered this on discourse, is this issue here still relevant?

Lassulus avatar Nov 21 '23 18:11 Lassulus