Proper way to build a remote system with flakes

I simplified what I copied from nixos-generators’ README (by copying this instead) and got this to work:

# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.17)
{

  description = "Imagen de NixOS y administración de computadoras en Digital Ocean";

  inputs = {
    nixos-generators.url = "github:nix-community/nixos-generators";
    flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*";

    nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*";
  };

  outputs =
    {
      self,
      flake-schemas,
      nixpkgs,
      nixos-generators,
    }:
    let
      supportedPlatforms = [ "x86_64-linux" ];

      forEachSupportedPlatforms =
        f:
        nixpkgs.lib.genAttrs supportedPlatforms (
          system:
          f {
            inherit system;
            pkgs = import nixpkgs { inherit system; };
          }
        );
    in
    {
      schemas = flake-schemas.schemas;

      devShells = forEachSupportedPlatforms (
        { pkgs, ... }:
        {
          default = pkgs.mkShell {
            packages = with pkgs; [
              nixpkgs-fmt
            ];
          };
        }
      );

      packages = forEachSupportedPlatforms (
        { system, pkgs }:
        {
          digital-ocean = nixos-generators.nixosGenerate {
            system = system;
            modules = [
              ./image/image.nix
            ];
            format = "do";
          };
        }
      );
    };
}
1 Like