2016-03-14 03:21:33 +03:00
|
|
|
#! /usr/bin/env bash
|
2016-03-14 12:59:18 +03:00
|
|
|
|
2017-03-04 18:22:37 +03:00
|
|
|
# More info at: https://github.com/elitak/nixos-infect
|
2016-03-14 12:59:18 +03:00
|
|
|
|
2017-02-14 12:25:42 +03:00
|
|
|
set -e -o pipefail
|
2017-01-25 02:39:15 +03:00
|
|
|
|
2016-03-14 08:09:30 +03:00
|
|
|
makeConf() {
|
2017-02-14 12:25:42 +03:00
|
|
|
# Skip everything if main config already present
|
|
|
|
[[ -e /etc/nixos/configuration.nix ]] && return 0
|
2016-04-09 22:39:35 +03:00
|
|
|
# NB <<"EOF" quotes / $ ` in heredocs, <<EOF does not
|
2016-03-14 12:59:18 +03:00
|
|
|
mkdir -p /etc/nixos
|
2019-07-07 20:09:47 +03:00
|
|
|
# Prevent grep for sending error code 1 (and halting execution) when no lines are selected : https://www.unix.com/man-page/posix/1P/grep
|
2021-06-09 23:45:06 +03:00
|
|
|
local IFS=$'\n'
|
2021-07-31 20:32:35 +03:00
|
|
|
for trypath in /root/.ssh/authorized_keys /home/$SUDO_USER/.ssh/authorized_keys $HOME/.ssh/authorized_keys; do
|
2020-02-20 02:22:02 +03:00
|
|
|
[[ -r "$trypath" ]] \
|
|
|
|
&& keys=$(sed -E 's/^.*((ssh|ecdsa)-[^[:space:]]+)[[:space:]]+([^[:space:]]+)([[:space:]]*.*)$/\1 \3\4/' "$trypath") \
|
|
|
|
&& break
|
|
|
|
done
|
2018-12-08 02:16:00 +03:00
|
|
|
local network_import=""
|
|
|
|
|
2020-11-24 03:47:55 +03:00
|
|
|
[[ -n "$doNetConf" ]] && network_import="./networking.nix # generated at runtime by nixos-infect"
|
2016-03-14 12:59:18 +03:00
|
|
|
cat > /etc/nixos/configuration.nix << EOF
|
2016-03-14 23:28:14 +03:00
|
|
|
{ ... }: {
|
2016-03-14 08:09:30 +03:00
|
|
|
imports = [
|
|
|
|
./hardware-configuration.nix
|
2018-12-08 02:16:00 +03:00
|
|
|
$network_import
|
2017-04-19 02:25:42 +03:00
|
|
|
$NIXOS_IMPORT
|
2016-03-14 08:09:30 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
boot.cleanTmpDir = true;
|
2022-04-20 11:17:21 +03:00
|
|
|
zramSwap.enable = ${zramswap};
|
2022-11-15 06:30:52 +03:00
|
|
|
networking.hostName = "$(hostname -s)";
|
|
|
|
networking.domain = "$(hostname -d)";
|
2016-03-14 23:28:14 +03:00
|
|
|
services.openssh.enable = true;
|
2020-02-20 02:22:02 +03:00
|
|
|
users.users.root.openssh.authorizedKeys.keys = [$(while read -r line; do echo -n "
|
|
|
|
\"$line\" "; done <<< "$keys")
|
2016-03-14 23:28:14 +03:00
|
|
|
];
|
2016-03-14 08:09:30 +03:00
|
|
|
}
|
|
|
|
EOF
|
2021-06-09 23:45:06 +03:00
|
|
|
|
|
|
|
if isEFI; then
|
|
|
|
bootcfg=$(cat << EOF
|
|
|
|
boot.loader.grub = {
|
|
|
|
efiSupport = true;
|
|
|
|
efiInstallAsRemovable = true;
|
|
|
|
device = "nodev";
|
|
|
|
};
|
|
|
|
fileSystems."/boot" = { device = "$esp"; fsType = "vfat"; };
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
else
|
|
|
|
bootcfg=$(cat << EOF
|
|
|
|
boot.loader.grub.device = "$grubdev";
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
2022-11-09 19:19:00 +03:00
|
|
|
availableKernelModules=('"ata_piix"' '"uhci_hcd"' '"xen_blkfront"')
|
|
|
|
if isX86_64; then
|
|
|
|
availableKernelModules+=('"vmw_pvscsi"')
|
|
|
|
fi
|
|
|
|
|
2017-02-17 05:51:05 +03:00
|
|
|
# If you rerun this later, be sure to prune the filesSystems attr
|
2016-03-14 12:59:18 +03:00
|
|
|
cat > /etc/nixos/hardware-configuration.nix << EOF
|
2021-01-01 09:50:30 +03:00
|
|
|
{ modulesPath, ... }:
|
2016-06-22 22:45:38 +03:00
|
|
|
{
|
2021-01-01 09:50:30 +03:00
|
|
|
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
|
2021-06-09 23:45:06 +03:00
|
|
|
$bootcfg
|
2022-11-09 19:19:00 +03:00
|
|
|
boot.initrd.availableKernelModules = [ ${availableKernelModules[@]} ];
|
2021-05-04 09:21:50 +03:00
|
|
|
boot.initrd.kernelModules = [ "nvme" ];
|
2021-06-09 23:45:06 +03:00
|
|
|
fileSystems."/" = { device = "$rootfsdev"; fsType = "$rootfstype"; };
|
2022-04-20 11:17:21 +03:00
|
|
|
$swapcfg
|
2016-03-14 08:09:30 +03:00
|
|
|
}
|
2016-04-09 22:39:35 +03:00
|
|
|
EOF
|
2019-05-05 21:23:09 +03:00
|
|
|
|
2020-12-26 08:35:33 +03:00
|
|
|
[[ -n "$doNetConf" ]] && makeNetworkingConf || true
|
2018-12-08 02:16:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
makeNetworkingConf() {
|
2017-02-14 11:37:47 +03:00
|
|
|
# XXX It'd be better if we used procfs for all this...
|
2016-04-09 22:39:35 +03:00
|
|
|
local IFS=$'\n'
|
2017-04-10 18:50:09 +03:00
|
|
|
eth0_name=$(ip address show | grep '^2:' | awk -F': ' '{print $2}')
|
2017-04-15 19:55:08 +03:00
|
|
|
eth0_ip4s=$(ip address show dev "$eth0_name" | grep 'inet ' | sed -r 's|.*inet ([0-9.]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|')
|
|
|
|
eth0_ip6s=$(ip address show dev "$eth0_name" | grep 'inet6 ' | sed -r 's|.*inet6 ([0-9a-f:]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|' || '')
|
|
|
|
gateway=$(ip route show dev "$eth0_name" | grep default | sed -r 's|default via ([0-9.]+).*|\1|')
|
2018-07-13 01:02:14 +03:00
|
|
|
gateway6=$(ip -6 route show dev "$eth0_name" | grep default | sed -r 's|default via ([0-9a-f:]+).*|\1|' || true)
|
2017-04-15 19:55:08 +03:00
|
|
|
ether0=$(ip address show dev "$eth0_name" | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|')
|
2017-04-10 18:50:09 +03:00
|
|
|
|
|
|
|
eth1_name=$(ip address show | grep '^3:' | awk -F': ' '{print $2}')||true
|
|
|
|
if [ -n "$eth1_name" ];then
|
2017-04-15 19:55:08 +03:00
|
|
|
eth1_ip4s=$(ip address show dev "$eth1_name" | grep 'inet ' | sed -r 's|.*inet ([0-9.]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|')
|
|
|
|
eth1_ip6s=$(ip address show dev "$eth1_name" | grep 'inet6 ' | sed -r 's|.*inet6 ([0-9a-f:]+)/([0-9]+).*|{ address="\1"; prefixLength=\2; }|' || '')
|
|
|
|
ether1=$(ip address show dev "$eth1_name" | grep link/ether | sed -r 's|.*link/ether ([0-9a-f:]+) .*|\1|')
|
2017-04-10 18:50:09 +03:00
|
|
|
interfaces1=<< EOF
|
|
|
|
$eth1_name = {
|
2018-03-23 23:37:49 +03:00
|
|
|
ipv4.addresses = [$(for a in "${eth1_ip4s[@]}"; do echo -n "
|
2017-04-10 18:50:09 +03:00
|
|
|
$a"; done)
|
|
|
|
];
|
2018-03-23 23:37:49 +03:00
|
|
|
ipv6.addresses = [$(for a in "${eth1_ip6s[@]}"; do echo -n "
|
2017-04-10 18:50:09 +03:00
|
|
|
$a"; done)
|
|
|
|
];
|
|
|
|
EOF
|
2018-07-13 01:02:14 +03:00
|
|
|
extraRules1="ATTR{address}==\"${ether1}\", NAME=\"${eth1_name}\""
|
2017-04-10 18:50:09 +03:00
|
|
|
else
|
|
|
|
interfaces1=""
|
|
|
|
extraRules1=""
|
|
|
|
fi
|
|
|
|
|
2020-12-11 01:29:38 +03:00
|
|
|
readarray nameservers < <(grep ^nameserver /etc/resolv.conf | sed -r \
|
|
|
|
-e 's/^nameserver[[:space:]]+([0-9.a-fA-F:]+).*/"\1"/' \
|
|
|
|
-e 's/127[0-9.]+/8.8.8.8/' \
|
|
|
|
-e 's/::1/8.8.8.8/' )
|
2020-11-24 03:47:55 +03:00
|
|
|
|
|
|
|
if [[ "$eth0_name" = eth* ]]; then
|
2018-07-12 21:38:36 +03:00
|
|
|
predictable_inames="usePredictableInterfaceNames = lib.mkForce false;"
|
|
|
|
else
|
|
|
|
predictable_inames="usePredictableInterfaceNames = lib.mkForce true;"
|
|
|
|
fi
|
2016-04-09 22:39:35 +03:00
|
|
|
cat > /etc/nixos/networking.nix << EOF
|
2018-07-12 21:38:36 +03:00
|
|
|
{ lib, ... }: {
|
2016-04-09 22:39:35 +03:00
|
|
|
# This file was populated at runtime with the networking
|
|
|
|
# details gathered from the active system.
|
|
|
|
networking = {
|
2020-11-25 01:54:15 +03:00
|
|
|
nameservers = [ ${nameservers[@]} ];
|
2016-04-09 22:39:35 +03:00
|
|
|
defaultGateway = "${gateway}";
|
|
|
|
defaultGateway6 = "${gateway6}";
|
2018-06-10 02:25:27 +03:00
|
|
|
dhcpcd.enable = false;
|
2018-07-12 21:38:36 +03:00
|
|
|
$predictable_inames
|
2016-04-09 22:39:35 +03:00
|
|
|
interfaces = {
|
2017-04-10 18:50:09 +03:00
|
|
|
$eth0_name = {
|
2018-03-24 19:29:49 +03:00
|
|
|
ipv4.addresses = [$(for a in "${eth0_ip4s[@]}"; do echo -n "
|
2016-04-09 22:39:35 +03:00
|
|
|
$a"; done)
|
|
|
|
];
|
2018-03-24 19:29:49 +03:00
|
|
|
ipv6.addresses = [$(for a in "${eth0_ip6s[@]}"; do echo -n "
|
2016-04-09 22:39:35 +03:00
|
|
|
$a"; done)
|
|
|
|
];
|
2019-10-11 10:32:54 +03:00
|
|
|
ipv4.routes = [ { address = "${gateway}"; prefixLength = 32; } ];
|
2021-05-04 09:32:42 +03:00
|
|
|
ipv6.routes = [ { address = "${gateway6}"; prefixLength = 128; } ];
|
2016-04-09 22:39:35 +03:00
|
|
|
};
|
2017-04-10 18:50:09 +03:00
|
|
|
$interfaces1
|
2016-04-09 22:39:35 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
services.udev.extraRules = ''
|
2018-07-12 21:38:36 +03:00
|
|
|
ATTR{address}=="${ether0}", NAME="${eth0_name}"
|
2017-04-10 18:50:09 +03:00
|
|
|
$extraRules1
|
2016-04-09 22:39:35 +03:00
|
|
|
'';
|
|
|
|
}
|
2016-03-14 08:09:30 +03:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2022-04-20 11:17:21 +03:00
|
|
|
checkExistingSwap() {
|
|
|
|
SWAPSHOW=$(swapon --show --noheadings --raw)
|
|
|
|
zramswap=true
|
|
|
|
swapcfg=""
|
|
|
|
if [[ -n "$SWAPSHOW" ]]; then
|
|
|
|
SWAP_DEVICE="${SWAPSHOW%% *}"
|
|
|
|
if [[ "$SWAP_DEVICE" == "/dev/"* ]]; then
|
|
|
|
zramswap=false
|
|
|
|
swapcfg="swapDevices = [ { device = \"${SWAP_DEVICE}\"; } ];"
|
|
|
|
NO_SWAP=true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-03-14 08:09:30 +03:00
|
|
|
makeSwap() {
|
2017-04-15 19:52:39 +03:00
|
|
|
swapFile=$(mktemp /tmp/nixos-infect.XXXXX.swp)
|
2017-04-15 19:50:01 +03:00
|
|
|
dd if=/dev/zero "of=$swapFile" bs=1M count=$((1*1024))
|
|
|
|
chmod 0600 "$swapFile"
|
|
|
|
mkswap "$swapFile"
|
|
|
|
swapon -v "$swapFile"
|
2017-03-04 18:22:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
removeSwap() {
|
2020-11-24 03:47:55 +03:00
|
|
|
swapoff -a
|
|
|
|
rm -vf /tmp/nixos-infect.*.swp
|
2016-03-14 08:09:30 +03:00
|
|
|
}
|
|
|
|
|
2022-11-10 01:23:49 +03:00
|
|
|
isX86_64() {
|
2022-11-09 19:19:00 +03:00
|
|
|
[[ "$(uname -m)" == "x86_64" ]]
|
|
|
|
}
|
|
|
|
|
2021-06-09 23:45:06 +03:00
|
|
|
isEFI() {
|
|
|
|
[ -d /sys/firmware/efi ]
|
|
|
|
}
|
|
|
|
|
|
|
|
findESP() {
|
|
|
|
esp=""
|
|
|
|
for d in /boot/EFI /boot/efi /boot; do
|
|
|
|
[[ ! -d "$d" ]] && continue
|
|
|
|
[[ "$d" == "$(df "$d" --output=target | sed 1d)" ]] \
|
|
|
|
&& esp="$(df "$d" --output=source | sed 1d)" \
|
|
|
|
&& break
|
|
|
|
done
|
|
|
|
[[ -z "$esp" ]] && { echo "ERROR: No ESP mount point found"; return 1; }
|
|
|
|
for uuid in /dev/disk/by-uuid/*; do
|
|
|
|
[[ $(readlink -f "$uuid") == "$esp" ]] && echo $uuid && return 0
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-02-14 04:30:42 +03:00
|
|
|
prepareEnv() {
|
2021-06-09 23:45:06 +03:00
|
|
|
# $esp and $grubdev are used in makeConf()
|
|
|
|
if isEFI; then
|
|
|
|
esp="$(findESP)"
|
|
|
|
else
|
2021-12-31 08:58:42 +03:00
|
|
|
for grubdev in /dev/vda /dev/sda /dev/xvda /dev/nvme0n1 ; do [[ -e $grubdev ]] && break; done
|
2021-06-09 23:45:06 +03:00
|
|
|
fi
|
2020-02-14 04:04:27 +03:00
|
|
|
|
|
|
|
# Retrieve root fs block device
|
|
|
|
# (get root mount) (get partition or logical volume)
|
|
|
|
rootfsdev=$(mount | grep "on / type" | awk '{print $1;}')
|
2021-06-09 23:45:06 +03:00
|
|
|
rootfstype=$(df $rootfsdev --output=fstype | sed 1d)
|
2016-08-18 15:23:42 +03:00
|
|
|
|
2017-02-14 04:30:42 +03:00
|
|
|
# DigitalOcean doesn't seem to set USER while running user data
|
|
|
|
export USER="root"
|
|
|
|
export HOME="/root"
|
2016-03-14 08:09:30 +03:00
|
|
|
|
2020-04-05 23:31:17 +03:00
|
|
|
# Nix installer tries to use sudo regardless of whether we're already uid 0
|
|
|
|
#which sudo || { sudo() { eval "$@"; }; export -f sudo; }
|
|
|
|
# shellcheck disable=SC2174
|
|
|
|
mkdir -p -m 0755 /nix
|
|
|
|
}
|
|
|
|
|
|
|
|
fakeCurlUsingWget() {
|
2017-02-14 11:18:59 +03:00
|
|
|
# Use adapted wget if curl is missing
|
2020-04-05 23:31:17 +03:00
|
|
|
which wget && { \
|
2017-02-14 11:18:59 +03:00
|
|
|
curl() {
|
|
|
|
eval "wget $(
|
|
|
|
(local isStdout=1
|
|
|
|
for arg in "$@"; do
|
|
|
|
case "$arg" in
|
|
|
|
"-o")
|
|
|
|
echo "-O";
|
|
|
|
isStdout=0
|
|
|
|
;;
|
|
|
|
"-O")
|
|
|
|
isStdout=0
|
|
|
|
;;
|
|
|
|
"-L")
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$arg"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done;
|
|
|
|
[[ $isStdout -eq 1 ]] && echo "-O-"
|
|
|
|
)| tr '\n' ' '
|
|
|
|
)"
|
|
|
|
}; export -f curl; }
|
|
|
|
}
|
|
|
|
|
|
|
|
req() {
|
|
|
|
type "$1" > /dev/null 2>&1 || which "$1" > /dev/null 2>&1
|
2017-02-14 04:30:42 +03:00
|
|
|
}
|
2016-03-14 08:09:30 +03:00
|
|
|
|
2017-02-14 04:30:42 +03:00
|
|
|
checkEnv() {
|
2021-06-09 23:45:06 +03:00
|
|
|
[[ "$(whoami)" == "root" ]] || { echo "ERROR: Must run as root"; return 1; }
|
|
|
|
|
2017-02-14 11:18:59 +03:00
|
|
|
# Perform some easy fixups before checking
|
2020-04-05 23:31:17 +03:00
|
|
|
# TODO prevent multiple calls to apt-get update
|
2021-06-09 23:45:06 +03:00
|
|
|
(which dnf && dnf install -y perl-Digest-SHA) || true # Fedora 24
|
2017-04-10 18:50:09 +03:00
|
|
|
which bzcat || (which yum && yum install -y bzip2) \
|
2019-07-07 20:09:47 +03:00
|
|
|
|| (which apt-get && apt-get update && apt-get install -y bzip2) \
|
2019-05-05 21:23:09 +03:00
|
|
|
|| true
|
2020-07-23 19:54:14 +03:00
|
|
|
which xzcat || (which yum && yum install -y xz-utils) \
|
|
|
|
|| (which apt-get && apt-get update && apt-get install -y xz-utils) \
|
|
|
|
|| true
|
2020-04-05 23:31:17 +03:00
|
|
|
which curl || fakeCurlUsingWget \
|
|
|
|
|| (which apt-get && apt-get update && apt-get install -y curl) \
|
|
|
|
|| true
|
2017-02-14 11:18:59 +03:00
|
|
|
|
2021-06-09 23:45:06 +03:00
|
|
|
req curl || req wget || { echo "ERROR: Missing both curl and wget"; return 1; }
|
|
|
|
req bzcat || { echo "ERROR: Missing bzcat"; return 1; }
|
|
|
|
req xzcat || { echo "ERROR: Missing xzcat"; return 1; }
|
|
|
|
req groupadd || { echo "ERROR: Missing groupadd"; return 1; }
|
|
|
|
req useradd || { echo "ERROR: Missing useradd"; return 1; }
|
|
|
|
req ip || { echo "ERROR: Missing ip"; return 1; }
|
|
|
|
req awk || { echo "ERROR: Missing awk"; return 1; }
|
|
|
|
req cut || req df || { echo "ERROR: Missing coreutils (cut, df)"; return 1; }
|
2022-11-15 06:31:49 +03:00
|
|
|
|
|
|
|
# On some versions of Oracle Linux these have the wrong permissions,
|
|
|
|
# which stops sshd from starting when NixOS boots
|
|
|
|
chmod 600 /etc/ssh/ssh_host_*_key
|
2017-02-14 04:30:42 +03:00
|
|
|
}
|
2016-03-14 08:09:30 +03:00
|
|
|
|
2017-02-14 04:30:42 +03:00
|
|
|
infect() {
|
2017-02-14 11:18:59 +03:00
|
|
|
# Add nix build users
|
|
|
|
# FIXME run only if necessary, rather than defaulting true
|
2017-02-17 05:51:05 +03:00
|
|
|
groupadd nixbld -g 30000 || true
|
2020-11-24 03:47:55 +03:00
|
|
|
for i in {1..10}; do
|
|
|
|
useradd -c "Nix build user $i" -d /var/empty -g nixbld -G nixbld -M -N -r -s "$(which nologin)" "nixbld$i" || true
|
|
|
|
done
|
2017-02-17 05:51:05 +03:00
|
|
|
# TODO use addgroup and adduser as fallbacks
|
|
|
|
#addgroup nixbld -g 30000 || true
|
|
|
|
#for i in {1..10}; do adduser -DH -G nixbld nixbld$i || true; done
|
2016-03-14 08:09:30 +03:00
|
|
|
|
2022-04-03 20:22:32 +03:00
|
|
|
curl -L https://nixos.org/nix/install | sh
|
2016-09-07 21:36:01 +03:00
|
|
|
|
2017-04-15 19:57:55 +03:00
|
|
|
# shellcheck disable=SC1090
|
2017-02-14 04:30:42 +03:00
|
|
|
source ~/.nix-profile/etc/profile.d/nix.sh
|
2016-03-14 08:09:30 +03:00
|
|
|
|
2022-06-13 02:18:23 +03:00
|
|
|
[[ -z "$NIX_CHANNEL" ]] && NIX_CHANNEL="nixos-22.05"
|
2017-02-14 04:30:42 +03:00
|
|
|
nix-channel --remove nixpkgs
|
|
|
|
nix-channel --add "https://nixos.org/channels/$NIX_CHANNEL" nixos
|
|
|
|
nix-channel --update
|
2016-03-14 08:09:30 +03:00
|
|
|
|
2022-04-20 11:17:21 +03:00
|
|
|
export NIXOS_CONFIG="${NIXOS_CONFIG:-/etc/nixos/configuration.nix}"
|
2016-08-18 15:23:42 +03:00
|
|
|
|
2017-02-14 04:30:42 +03:00
|
|
|
nix-env --set \
|
|
|
|
-I nixpkgs=$HOME/.nix-defexpr/channels/nixos \
|
|
|
|
-f '<nixpkgs/nixos>' \
|
|
|
|
-p /nix/var/nix/profiles/system \
|
|
|
|
-A system
|
2016-08-18 15:23:42 +03:00
|
|
|
|
2017-02-14 04:30:42 +03:00
|
|
|
# Remove nix installed with curl | bash
|
|
|
|
rm -fv /nix/var/nix/profiles/default*
|
|
|
|
/nix/var/nix/profiles/system/sw/bin/nix-collect-garbage
|
2016-08-18 15:23:42 +03:00
|
|
|
|
2017-02-14 11:18:59 +03:00
|
|
|
# Reify resolv.conf
|
|
|
|
[[ -L /etc/resolv.conf ]] && mv -v /etc/resolv.conf /etc/resolv.conf.lnk && cat /etc/resolv.conf.lnk > /etc/resolv.conf
|
2017-02-14 04:30:42 +03:00
|
|
|
|
2017-02-14 11:18:59 +03:00
|
|
|
# Stage the Nix coup d'état
|
2017-02-14 04:30:42 +03:00
|
|
|
touch /etc/NIXOS
|
2022-04-20 11:17:21 +03:00
|
|
|
echo etc/nixos >> /etc/NIXOS_LUSTRATE
|
2017-02-14 11:18:59 +03:00
|
|
|
echo etc/resolv.conf >> /etc/NIXOS_LUSTRATE
|
|
|
|
echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE
|
2022-07-11 20:25:21 +03:00
|
|
|
(cd / && ls etc/ssh/ssh_host_*_key* || true) >> /etc/NIXOS_LUSTRATE
|
2017-02-14 04:30:42 +03:00
|
|
|
|
2017-02-14 12:25:42 +03:00
|
|
|
rm -rf /boot.bak
|
2021-06-09 23:45:06 +03:00
|
|
|
isEFI && umount "$esp"
|
2022-04-20 11:17:21 +03:00
|
|
|
|
|
|
|
mv -v /boot /boot.bak || { cp -a /boot /book.bak ; rm -rf /boot/* ; umount /boot ; }
|
2021-06-09 23:45:06 +03:00
|
|
|
if isEFI; then
|
2022-04-20 11:17:21 +03:00
|
|
|
mkdir -p /boot
|
2021-06-09 23:45:06 +03:00
|
|
|
mount "$esp" /boot
|
|
|
|
find /boot -depth ! -path /boot -exec rm -rf {} +
|
|
|
|
fi
|
2017-02-14 12:25:42 +03:00
|
|
|
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
|
2017-02-14 04:30:42 +03:00
|
|
|
}
|
2016-08-18 15:23:42 +03:00
|
|
|
|
2022-12-20 08:26:47 +03:00
|
|
|
if [[ "$PROVIDER" = "digitalocean" ]] || [[ "$PROVIDER" = "servarica" ]]; then
|
|
|
|
doNetConf=y # some providers require detailed network config to be generated
|
|
|
|
fi
|
2020-08-21 18:57:57 +03:00
|
|
|
|
2021-06-09 23:45:06 +03:00
|
|
|
checkEnv
|
2017-02-14 04:30:42 +03:00
|
|
|
prepareEnv
|
2022-04-20 11:17:21 +03:00
|
|
|
checkExistingSwap
|
2022-01-03 20:26:23 +03:00
|
|
|
if [[ -z "$NO_SWAP" ]]; then
|
|
|
|
makeSwap # smallest (512MB) droplet needs extra memory!
|
|
|
|
fi
|
2017-02-14 11:18:59 +03:00
|
|
|
makeConf
|
|
|
|
infect
|
2022-01-03 20:26:23 +03:00
|
|
|
if [[ -z "$NO_SWAP" ]]; then
|
|
|
|
removeSwap
|
|
|
|
fi
|
2019-05-05 21:23:09 +03:00
|
|
|
|
|
|
|
if [[ -z "$NO_REBOOT" ]]; then
|
|
|
|
reboot
|
|
|
|
fi
|