-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
85 lines (75 loc) · 3.2 KB
/
Makefile
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
78
79
80
81
82
83
84
85
# https://github.com/mitchellh/nixos-config/blob/main/Makefile
# Connectivity info for Linux VM
NIXADDR ?= unset
NIXPORT ?= 22
NthIXUSER ?= eden
# Settings
NIXBLOCKDEVICE ?= sda
# Get the path to this Makefile and directory
MAKEFILE_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
# The name of the nixosConfiguration in the flake
NIXNAME ?= vm-dev
# SSH options that are used. These aren't meant to be overridden but are
# reused a lot so we just store them up here.
SSH_OPTIONS=-o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
# This is just to make sure that just running make does not execute bootstrap0
top:
echo "This is nyx"
# bootstrap a brand new VM. The VM should have NixOS ISO on the CD drive
# and just set the password of the root user to "root". This will install
# NixOS. After installing NixOS, you must reboot and set the root password
# for the next step.
vm/bootstrap0:
ssh $(SSH_OPTIONS) -p$(NIXPORT) root@$(NIXADDR) " \
parted /dev/$(NIXBLOCKDEVICE) -- mklabel gpt; \
parted /dev/$(NIXBLOCKDEVICE) -- mkpart primary 512MiB -8GiB; \
parted /dev/$(NIXBLOCKDEVICE) -- mkpart primary linux-swap -8GiB 100\%; \
parted /dev/$(NIXBLOCKDEVICE) -- mkpart ESP fat32 1MiB 512MiB; \
parted /dev/$(NIXBLOCKDEVICE) -- set 3 esp on; \
mkfs.ext4 -L nixos /dev/$(NIXBLOCKDEVICE)1; \
mkswap -L swap /dev/$(NIXBLOCKDEVICE)2; \
mkfs.fat -F 32 -n boot /dev/$(NIXBLOCKDEVICE)3; \
mount /dev/disk/by-label/nixos /mnt; \
mkdir -p /mnt/boot; \
mount /dev/disk/by-label/boot /mnt/boot; \
nixos-generate-config --root /mnt; \
sed --in-place '/system\.stateVersion = .*/a \
nix.package = pkgs.nixVersions.latest;\n \
nix.extraOptions = \"experimental-features = nix-command flakes\";\n \
services.openssh.enable = true;\n \
services.openssh.passwordAuthentication = true;\n \
services.openssh.permitRootLogin = \"yes\";\n \
users.users.root.initialPassword = \"root\";\n \
nix.binaryCaches = [ \"https://nix-community.cachix.org\" \"https://edeneast.cachix.org\" ];\n \
nix.binaryCachePublicKeys = [ \n \
\"cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM=\"\n \
\"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=\"\n \
\"edeneast.cachix.org-1:a4tKrKZgZXXXYhDytg/Z3YcjJ04oz5ormt0Ow6OpExc=\"\n \
];\n \
' /mnt/etc/nixos/configuration.nix; \
nixos-install --no-root-passwd; \
reboot; \
"
# after bootstrap0, run this to finalize. After this, do everything else
# in the VM unless secrets change.
vm/bootstrap:
NIXUSER=root $(MAKE) vm/copy
NIXUSER=root $(MAKE) vm/switch
ssh $(SSH_OPTIONS) -p$(NIXPORT) root@$(NIXADDR) " \
sudo reboot; \
"
# copy the Nix configurations into the VM.
vm/copy:
rsync -av -e 'ssh $(SSH_OPTIONS) -p$(NIXPORT)' \
--exclude='.git/' \
--exclude='.git-crypt/' \
--exclude='docs/' \
--exclude='windows/' \
--rsync-path="sudo rsync" \
$(MAKEFILE_DIR)/ $(NIXUSER)@$(NIXADDR):/nyx-config
# run the nixos-rebuild switch command. This does NOT copy files so you
# have to run vm/copy before.
vm/switch:
ssh $(SSH_OPTIONS) -p$(NIXPORT) $(NIXUSER)@$(NIXADDR) " \
sudo NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-rebuild switch --flake \"/nyx-config#${NIXNAME}\" \
"