From e72cd89d99b221b6a77f61784c0ffa78ff45f004 Mon Sep 17 00:00:00 2001 From: Scott Stephens Date: Mon, 19 Dec 2022 23:31:13 -0600 Subject: [PATCH] Add support for AWS Lightsail (#125) Co-authored-by: Eric Litak --- README.md | 9 +++++++++ nixos-infect | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) mode change 100755 => 100644 nixos-infect diff --git a/README.md b/README.md index 6b95bdf..59ed2d7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ This script has successfully been tested on at least the follow hosting provider * [Cockbox](https://cockbox.org) * [Google Cloud Platform](https://cloud.google.com/) * [Contabo](https://contabo.com) +* [AWS Lightsail](https://aws.amazon.com/lightsail/) * [Windcloud](https://windcloud.de/) * [Clouding.io](https://clouding.io) @@ -244,6 +245,13 @@ Tested on Cloud VPS. Contabo sets the hostname to something like `vmi######.cont |------------|-----------------|-----------|----------| |Ubuntu | 22.04 |**success**|2022-09-26| +### AWS Lightsail +Make sure to set `PROVIDER="lightsail"`. + +Setting a root ssh key manually is not necessary, the key provided as part of the instance launch process will be used. + +If you run into issues, debug using the most similar ec2 instance that is on the Nitro platform. Nitro platform instances have a serial console that allow you to troubleshoot boot issues, and Lightsail instances are just EC2 with a different pricing model and UI. + ### Windcloud Tested on vServer. The network configuration seems to be important so the same tweaks as for DigitalOcean are necessary (see above). #### Tested on @@ -259,6 +267,7 @@ Requires the same static network settings that Digital Ocean does. #### Tested on |Distribution| Name | Status | test date| |------------|-----------------|-----------|----------| +|Debian | 11.4 |**success**|2022-12-12| |Ubuntu | 20.04 | success |2022-11-26| ### Clouding.io diff --git a/nixos-infect b/nixos-infect old mode 100755 new mode 100644 index ce98e18..5210b22 --- a/nixos-infect +++ b/nixos-infect @@ -7,6 +7,13 @@ set -e -o pipefail makeConf() { # Skip everything if main config already present [[ -e /etc/nixos/configuration.nix ]] && return 0 + + # Lightsail config is not like the others + if [ "$PROVIDER" = "lightsail" ]; then + makeLightsailConf + return 0 + fi + # NB <<"EOF" quotes / $ ` in heredocs, < /etc/nixos/configuration.nix << EOF +{ config, pkgs, modulesPath, ... }: +{ + imports = [ "\${modulesPath}/virtualisation/amazon-image.nix" ]; +} +EOF +} + makeNetworkingConf() { # XXX It'd be better if we used procfs for all this... local IFS=$'\n' @@ -318,6 +335,12 @@ infect() { # Reify resolv.conf [[ -L /etc/resolv.conf ]] && mv -v /etc/resolv.conf /etc/resolv.conf.lnk && cat /etc/resolv.conf.lnk > /etc/resolv.conf + # Set label of root partition + if [ -n "$newrootfslabel" ]; then + echo "Setting label of $rootfsdev to $newrootfslabel" + e2label "$rootfsdev" "$newrootfslabel" + fi + # Stage the Nix coup d'état touch /etc/NIXOS echo etc/nixos >> /etc/NIXOS_LUSTRATE @@ -337,6 +360,8 @@ infect() { /nix/var/nix/profiles/system/bin/switch-to-configuration boot } +[ "$PROVIDER" = "digitalocean" ] && doNetConf=y # digitalocean requires detailed network config to be generated +[ "$PROVIDER" = "lightsail" ] && newrootfslabel="nixos" if [[ "$PROVIDER" = "digitalocean" ]] || [[ "$PROVIDER" = "servarica" ]]; then doNetConf=y # some providers require detailed network config to be generated fi