How to create a custom Digital Ocean virtualization image

Hello, I would like to be able to update DigitalOceanImage configuration with some SSH keys and packages and I’m unsure of the best way to do this. Here is what I have:

{ pkgs ? import <nixpkgs> {} }:
let
  config = {
    imports = [ <nixpkgs/nixos/modules/virtualisation/digital-ocean-image.nix> ];
  };
in
(pkgs.nixos config).digitalOceanImage

# updates I want to apply to digitalOceanImage
updates = {
  environment.systemPackages = with pkgs; [
    curl
    git
    gvisor
    overmind
    docker
    kubo
    grpcurl
  ];
  # ] ++ [ lasr_node ];

  # Add your SSH key and comment your username/system-name
  users.users.root.openssh.authorizedKeys.keys = [
    # eureka-cpu
    "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINQ66bGgeELzU/wZjpYxSlKIgMoROQxPx76vGdpS3lwc github.eureka@gmail.com" # dev-one
    "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAsUzc7Wg9FwImAMPc61K/zO9gvUDJVHwQ0+GTrO1mqJ github.eureka@gmail.com" # critter-tank
  ];
};

Basically I’m trying to do this: NixOS in the Cloud, step-by-step: part 1 · Justinas Stankevičius

but without having to use morph to update the deployment. I know exactly what needs to be on the machine and I’d like to just update the configuration before creating the image.

I’ve tried a few things, but I don’t quire understand how to give the configuration.nix to the part that builds the image. I’m assuming there is a way to pass the config to the image builder, but I’m not sure how.

this options field seems to be what I’m looking for, but I don’t know how to access it: virtualisation.digitalOceanImage.configFile

Shout out to @K900 for the solution:

{ pkgs ? import <nixpkgs> { } }:
let config = {
  imports = [ <nixpkgs/nixos/modules/virtualisation/digital-ocean-image.nix> ];
  services.foo.enable = true;
};
in
(pkgs.nixos config).digitalOceanImage
1 Like