Difference Between Cloud-Init and Autoinstall – Ubuntu

cloud-initdebconfdevopspreseedUbuntu

So I have been trying to essentially install Nixos from the official site with a Cloud-Init for Ubuntu Server 22.04. I want to really understand how to install packages that I potentially might have to compile or other ways of installing packages like with Curl or Wget within in the user-data.yaml file.

So far I have a user-data.yaml in which I am trying to use runcmd: to install Nox via the recommended way from there site.

My whole config is below and at the bottom is the runcmd: which I just can't get to install. The whole file looks like this.

#cloud-config
autoinstall:
  version: 1
  locale: en_GB.UTF-8
  refresh-installer:
    update: true
  keyboard:
    layout: "gb"
  apt:
    geoip: true
  identity:
    hostname: ubuntu-server
    password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
    username: ubuntu
  storage:
    layout:
      name: lvm
      match:
        size: largest
  packages:
    - libreoffice
    - sway
    - i3
    - kitty
  snaps:
    - name: firefox
  timezone: geoip
  manage_resolv_conf: true
  resolv_conf:
    nameservers:
      - 1.1.1.3
      - 8.8.8.8
  updates: all
  runcmd:
    - [mkdir, -m, 0755, /nix]
    - [chown, ubuntu, /nix]
    - [wget, "https://nixos.org/nix/install"]
    - [bash, install, --daemon]

If you run the installer via the command line you get prompt if you want to make the dir '/nix' hence the command for it. I'm at my wits end!

I have tried for the past 7 hours to get this package manager installed so I can install Wayland which would be a lot easier to install from here than installing it from source if I was to use RunCmd: the whole time.

Which from what I understand is the way to run bash commands

So far I have tried:

  • Puting it to root so no \s\s before the runcmd: keyword
  • Trying the commands in quotes like "sh -c 'curl ....'"
  • Puting it in brackets like `[sh, -c, curl, "https://nixos.org/down…/install", |, bash]
  • Other configuration of it in brackets like `[bash, -c, 'curl "https://nixos.org/down…/install" | bash'] *So many configurations!!
  • Gone onto GitHub and search for examples of other people using runcmd:
  • Following a DigitalOcean guide on Cloud-Init with runcmd: examples
  • Read the reference for Cloud-init
  • Read the reference for Autoinstall
  • read the reference for Curtin

And I just don't know what to do next…

I'm using Qemu to test these configs with an Ubuntu 22.04 Jammy Server ISO.

How do I just install stuff from a setup file that has an install script from the web?

Thanks 🙂

Best Answer

I was struggling with the same thing for hours!

Here's what seems to work (at least for me), so try this;

#cloud-config
autoinstall:
   version: 1
   ...
   user-data:
      runcmd:
        - mkdir -m 0755 /nix
        - chown ubuntu /nix
        - wget "https://nixos.org/nix/install"
        - bash install --daemon

Not sure about the brackets. My command worked without them so try that first for better readability.

https://ubuntu.com/server/docs/install/autoinstall-reference#user-data