Modularizing my flake.nix

Hello all,

I’m fairly new to nix and have a simple example that I’m trying to break out into files.

This is my initial flake that works:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05-small";
  inputs.disko.url = "github:nix-community/disko";
  inputs.disko.inputs.nixpkgs.follows = "nixpkgs";
  inputs.deploy-rs.url = "github:serokell/deploy-rs";

  outputs = { self, nixpkgs, disko, deploy-rs, ... } @ inputs:
  {
    nixosConfigurations.hetzner-cloud = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./hardware-configuration.nix
        disko.nixosModules.disko
        ./configuration.nix
      ];
    };

    deploy.nodes.hetzner-cloud = {
      hostname = “A.B.C.D”;
      profiles.system = {
        user = "root";
        path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.hetzner-cloud;
      };
    };
  };
}

Now what I would like to do is extract the config and deploy section and import it like so:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05-small";
  inputs.disko.url = "github:nix-community/disko";
  inputs.disko.inputs.nixpkgs.follows = "nixpkgs";
  inputs.deploy-rs.url = "github:serokell/deploy-rs";

  outputs = { self, nixpkgs, disko, deploy-rs, ... } @ inputs:
  {
    imports = [
      ./hetzner-cloud.nix
    ];
  };
}

and create a hetzner-cloud.nix file like this:

    nixosConfigurations.hetzner-cloud = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./hardware-configuration.nix
        disko.nixosModules.disko
        ./configuration.nix
      ];
    };

    deploy.nodes.hetzner-cloud = {
      hostname = "A.B.C.D";
      profiles.system = {
        user = "root";
        path = deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.hetzner-cloud;
      };
    };

But then when I run nixos-anywhere using the same command nixos-anywhere --flake .#hetzner-cloud --build-on-remote root@A.B.C.D it errors out during the disko script section:

### Building disko script ###
error: flake 'path:/source' does not provide attribute 'packages.aarch64-linux.nixosConfigurations."hetzner-cloud".config.system.build.diskoScript', 'legacyPackages.aarch64-linux.nixosConfigurations."hetzner-cloud".config.system.build.diskoScript' or 'nixosConfigurations."hetzner-cloud".config.system.build.diskoScript'

I am running the command from a M2 Mac and I am assuming it is some sort of inheritance issue or something but I have no idea where to look. I have tried including the inputs up top to no avail. What is import doing that is breaking the command?

Thank you in advance.

Hetzner seems to have some ARM machines.
Are you sure that the target server is x86_64?

It’s a nix error, not related to the architecture of the machine.
Basically it’s saying disko was somehow not configured correctly, though I don’t use disko and can’t answer how to fix it.

https://github.com/zendo/nsworld/blob/8e635f5a6e7d8aa783531c652dd6be7562c5d830/hosts/deployment.nix

It’s my repo based on flake-parts, maybe help for you.