about summary refs log tree commit diff
path: root/justfile
blob: 94877a04ba15c609696da56524b116014984630c (plain) (blame)
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
SSH_OPTIONS := "-o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"

nixdisk := "vda"
nixaddr := ""

# update dependencies
update-deps:
	nix flake update --commit-lock-file

# build (and only build) the configuration for darwin
build-darwin:
	darwin-rebuild build --flake .#$(hostname -s)

# build and switch the configuration for darwin
switch-darwin:
	darwin-rebuild switch --flake .#$(hostname -s)

# a simple check to ensure the nix configuration is OK
test-nix:
	nix flake check
	nix develop -c echo OK

# run various formatting tools
fmt:
	nix fmt

build-wildcat:
	nixos-rebuild build --target-host fcuny.net --build-host fcuny.net --fast --use-remote-sudo --use-substitutes --flake .#wildcat

switch-wildcat:
	nixos-rebuild switch --target-host fcuny.net --build-host fcuny.net --fast --use-remote-sudo --use-substitutes --flake .#wildcat

vm-bootstrap:
	#!/usr/bin/env bash
	set -euxo pipefail
	ssh {{SSH_OPTIONS}} root@{{nixaddr}} " \
		parted /dev/{{nixdisk}} -- mklabel gpt; \
		parted /dev/{{nixdisk}} -- mkpart primary 512MB 100%; \
		parted /dev/{{nixdisk}} -- mkpart ESP fat32 1MB 512MB; \
		parted /dev/{{nixdisk}} -- set 2 esp on; \
		sleep 1; \
		mkfs.ext4 -L nixos /dev/{{nixdisk}}1; \
		mkfs.fat -F 32 -n boot /dev/{{nixdisk}}2; \
		sleep 1; \
		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.extraOptions = \"experimental-features = nix-command flakes\";\n \
			services.openssh.enable = true;\n \
			services.openssh.settings.PasswordAuthentication = true;\n \
			services.openssh.settings.PermitRootLogin = \"yes\";\n \
			users.users.root.initialPassword = \"root\";\n \
		' /mnt/etc/nixos/configuration.nix; \
		nixos-install --no-root-passwd && reboot; \
	"

vm-copy:
	#!/usr/bin/env bash
	rsync -av -e 'ssh {{SSH_OPTIONS}}' \
		--exclude='.git/' \
		--exclude='result' \
		--rsync-path="sudo rsync" \
		$(dirname justfile)/ root@{{nixaddr}}:/nix-config