Flakes - how to automatically set machine hostname to `nixosConfiguration` name

I have something like this in my flake:

...
outputs = { self, nixpkgs, ... }: {
  nixosConfigurations = nixpkgs.lib.genAttrs ["arbitrary-name"] (hostName: nixpkgs.lib.nixosSystem {
      modules = [
        { networking.hostName = hostName; }
        ./host/${hostName}/configuration.nix
      ];
  ...
  });
};

On mobile now so there may be some mistakes in there.

2 Likes