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

custom Formats in Flakes broken #280

Open
kknoepfle opened this issue Nov 8, 2023 · 3 comments
Open

custom Formats in Flakes broken #280

kknoepfle opened this issue Nov 8, 2023 · 3 comments

Comments

@kknoepfle
Copy link

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 kknoepfle changed the title custom Formats in Flake broken custom Formats in Flakes broken Nov 8, 2023
@mayl
Copy link
Contributor

mayl commented Nov 8, 2023

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.

@kknoepfle
Copy link
Author

kknoepfle commented Nov 8, 2023

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

@Lassulus
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants