From 8c9034e5797d6cd59fceaa326a636158e70db986 Mon Sep 17 00:00:00 2001 From: obadz Date: Sat, 4 Mar 2017 15:22:46 +0000 Subject: [PATCH 1/2] remove swap partitions before rebooting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should help keep /old-root a bit smaller… --- nixos-infect | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nixos-infect b/nixos-infect index 13214d6..429bf7f 100755 --- a/nixos-infect +++ b/nixos-infect @@ -145,11 +145,19 @@ EOF makeSwap() { # TODO check currently available swapspace first - swapFile=`mktemp` + swapFile=`mktemp /tmp/nixos-infect.XXXXX.swp` dd if=/dev/zero of=$swapFile bs=1M count=$((1*1024)) chmod 0600 $swapFile mkswap $swapFile - swapon $swapFile + swapon -v $swapFile +} + +removeSwap() { + for swapFile in /tmp/nixos-infect.*.swp + do + swapoff -v $swapFile + rm -vf $swapFile + done } prepareEnv() { @@ -260,4 +268,5 @@ checkEnv makeConf makeSwap # smallest (512MB) droplet needs extra memory! infect +removeSwap reboot From 2e513bee28719915fd054395fc373a236592fb3d Mon Sep 17 00:00:00 2001 From: obadz Date: Sat, 4 Mar 2017 15:22:37 +0000 Subject: [PATCH 2/2] move doc into README.md (and modify example user-data to include a NIX_CHANNEL version) --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ nixos-infect | 45 +-------------------------------------------- 2 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..41ea186 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +This script aims to install NixOS on Digital Ocean droplets +(starting from one of the distros that Digital Ocean supports out of the box) + +These are the only supported Digital Ocean images: + +- Fedora 24 x64 +- Ubuntu 16.04 x64 +- Debian 8.5 x64 + +YMMV with any other hoster + image combination. + +nixos-infect is so named because of the high likelihood of rendering a system +inoperable. Use with caution and preferably only on newly-provisioned +systems. + +*WARNING NB*: This script wipes out the targeted host's root filesystem when it +runs to completion. Any errors halt execution. It's advised to run with +`bash -x` to help debug, as often a failed run leaves the system in an +inconsistent state, requiring a rebuild (in DigitalOcean panel: Droplet +Settings -> "Destroy" -> "Rebuild from original"). + +*TO USE:* +- Add any custom config you want (see notes below) +- Deploy the droplet indicated at the top of the file, enable ipv6, add your ssh key +- cat customConfig.optional nixos-infect | ssh root@targethost + +Alternatively, use the user data mechamism by supplying the lines between the following +cat and EOF in the Digital Ocean Web UI (or HTTP API): + +```yaml +#cloud-config + +runcmd: + - curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | NIX_CHANNEL=nixos-16.09 bash 2>&1 | tee /tmp/infect.log +``` +Potential tweaks: +- `/etc/nixos/{,hardware-}configuration.nix`: rudimentary mostly static config +- `/etc/nixos/networking.nix`, networking settings determined at runtime tweak + if no ipv6, different number of adapters, etc. + +Motivation for this script: nixos-assimilate should supplant this script +entirely, if it's ever completed. nixos-in-place was quite broken when I +tried it, and also took a pretty janky approach that was substantially more +complex than this (although it supported more platforms): it didn't install +to root (/nixos instead), left dregs of the old filesystem (almost always +unnecessary since starting from a fresh deployment), and most importantly, +simply didn't work for me! (old system was being because grub wasnt properly +reinstalled) diff --git a/nixos-infect b/nixos-infect index 429bf7f..3c718df 100755 --- a/nixos-infect +++ b/nixos-infect @@ -1,49 +1,6 @@ #! /usr/bin/env bash -# These are the only supported Digital Ocean images: -# -# Fedora 24 x64 -# Ubuntu 16.04 x64 -# Debian 8.5 x64 -# -# YMMV with any other hoster + image combination. - -# nixos-infect is so named because of the high likelihood of rendering a system -# inoperable. Use with caution and preferably only on newly-provisioned -# systems. -# -# WARNING NB This script wipes out the targeted host's root filesystem when it -# runs to completion. Any errors halt execution. It's advised to run with -# `bash -x` to help debug, as often a failed run leaves the system in an -# inconsistent state, requiring a rebuild (in DigitalOcean panel: Droplet -# Settings -> "Destroy" -> "Rebuild from original"). -# -# TO USE: -# - Add any custom config you want (see notes below) -# - Deploy the droplet indicated at the top of the file, enable ipv6, add your ssh key -# - cat customConfig.optional nixos-infect | ssh root@targethost -# -# Alternatively, use the user data mechamism by supplying the following lines (without >) -# in the Digital Ocean Web UI (or HTTP API): -# -# > #cloud-config -# > -# > runcmd: -# > - curl https://raw.githubusercontent.com/elitak/nixos-infect/master/nixos-infect | bash 2>&1 | tee /tmp/infect.log -# -# Potential tweaks: -# /etc/nixos/{,hardware-}configuration.nix : rudimentary mostly static config -# /etc/nixos/networking.nix, networking settings determined at runtime -# tweak if no ipv6, different number of adapters, etc. -# -# Motivation for this script: nixos-assimilate should supplant this script -# entirely, if it's ever completed. nixos-in-place was quite broken when I -# tried it, and also took a pretty janky approach that was substantially more -# complex than this (although it supported more platforms): it didn't install -# to root (/nixos instead), left dregs of the old filesystem (almost always -# unnecessary since starting from a fresh deployment), and most importantly, -# simply didn't work for me! (old system was being because grub wasnt properly -# reinstalled) +# More info at: https://github.com/elitak/nixos-infect set -e -o pipefail