-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlustrate-from-backup.sh
77 lines (62 loc) · 2.2 KB
/
lustrate-from-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Automatic lustrate script for Oracle OCI Ubuntu machines
# Usage:
# ./lustrate-from-backup.sh <hostname>
#
# This assumes the following:
#
# - Nix is already installed, in single-user mode
# curl -L https://nixos.org/nix/install | sh
# (restart shell after running)
#
# - nixos config is present at ~/nixos-infra (and is a flake)
#
# - to avoid running out of ram, make sure the host system has at least 4GB of swap
# (set up a swap file if necessary)
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <nixos-hostname>"
exit 1
fi
set -e
shopt -s dotglob
cd ~/nixos-infra
echo "[MEOW] copy this to /etc/nixos"
set +e
sudo mkdir -p /etc/nixos
sudo rm -r /etc/nixos/*
sudo cp -r ./* /etc/nixos
set -e
echo "[MEOW] setting up nix channels"
nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs
nix-channel --update
echo "[MEOW] install nixos-install-tools"
nix-env -f '<nixpkgs>' -iA nixos-install-tools
echo "[MEOW] building system configuration \"$1\""
config_name=$1
nix build .#nixosConfigurations.${config_name}.config.system.build.toplevel --extra-experimental-features nix-command --extra-experimental-features flakes
echo "[MEOW] setting system profile to the newly built system"
link_path=$(readlink -f ./result)
echo "system = $link_path"
nix-env --profile /nix/var/nix/profiles/system --set "$link_path"
echo "[MEOW] creting /run/current-system symlink"
sudo ln -sfn /nix/var/nix/profiles/system /run/current-system
# nix is root nyow ------
echo "[MEOW] changing ownership of /nix"
sudo chown -R 0:0 /nix
echo "[MEOW] changing os gender marker and setting NIXOS_LUSTRATE"
sudo touch /etc/NIXOS
sudo touch /etc/NIXOS_LUSTRATE
echo etc/nixos | sudo tee -a /etc/NIXOS_LUSTRATE
echo root/.nix-defexpr/channels | sudo tee -a /etc/NIXOS_LUSTRATE
# :3
set +e
echo "[MEOW] nuking /boot :3"
echo "(i assume you already have a backup dork)"
sudo rm -rf /boot
set -e
# needs to be ran twice for some reason to install the boot entries properly
echo "[MEOW] switching to configuration"
sudo NIXOS_INSTALL_BOOTLOADER=1 /nix/var/nix/profiles/system/bin/switch-to-configuration boot
echo "==================="
echo "MEOW! lustration complete!"
echo "now, make sure the boot entries are set up correctly and reboot!"