Update Makefile & move bootstrap to a separate script.

This commit is contained in:
Dmitry Voronin 2024-07-31 23:43:50 +03:00
parent cfd4e65408
commit dccabe82e4
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
5 changed files with 80 additions and 75 deletions

41
Bootstrap.sh Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Install nixos to specified drive. To be run from Live ISO.
# Usage: ./Bootstrap.sh <DRIVE> [HOST]
target="${1}"
host="${2}"
if [[ "${target}" = "" ]]; then
printf "Usage: bootstrap_nixos <DRIVE> [HOST]\n"
return 2
fi
# Create partitions.
parted -s "${target}" mktable gpt
parted -s "${target}" mkpart primary 0% 512MB
parted -s "${target}" mkpart primary 512MB 100%
parted -s "${target}" name 1 NIXBOOT
parted -s "${target}" name 2 NIXROOT
parted -s "${target}" set 1 esp on
# Format.
mkfs.fat -F 32 /dev/disk/by-partlabel/NIXBOOT
mkfs.ext4 -F /dev/disk/by-partlabel/NIXROOT
# Mount.
mount /dev/disk/by-partlabel/NIXROOT /mnt
mkdir /mnt/boot
mount /dev/disk/by-partlabel/NIXBOOT /mnt/boot
# Generate config.
nixos-generate-config --root /mnt
# Install.
cd /mnt
if [[ "${host}" = "" ]]; then
printf "Warning: Installing basic system.\n"
nixos-install
else
printf "Installing ${host}...\n"
nixos-install --no-root-password --no-channel-copy --flake "${_nix_system_config}#${host}"
fi

View file

@ -1,44 +1,53 @@
options = --option eval-cache false --fallback
flake = .
.PHONY: boot
boot:
nixos-rebuild boot $(options) --flake $(flake)
.PHONY: reboot
reboot: boot
reboot
.PHONY: switch
switch:
nixos-rebuild switch $(options) --flake $(flake)
.PHONY: update
update:
nix flake update
.PHONY: live
live:
nix build -o live $(options) $(flake)#nixosConfigurations.live.config.system.build.isoImage
.PHONY: android
android:
nix-on-droid switch --flake $(flake)
cp ~/.termux/_font.ttf ~/.termux/font.ttf
cp ~/.termux/_colors.properties ~/.termux/colors.properties
.PHONY: check
boot:
nixos-rebuild boot $(options) --flake $(flake)
boot-vanilla:
mv /etc/nix/nix.conf /etc/nix/nix.conf_
nixos-rebuild boot $(options) --flake $(flake)
mv /etc/nix/nix.conf_ /etc/nix/nix.conf
check:
nix flake check
.PHONY: trace
trace:
nix flake check --show-trace
# HACK: https://github.com/nix-community/home-manager/issues/5589
fix-hm-root:
mv /etc/nix/nix.conf /etc/nix/nix.conf_
systemctl restart home-manager-root.service
mv /etc/nix/nix.conf_ /etc/nix/nix.conf
install-nix:
sh <(curl -L https://nixos.org/nix/install) --no-daemon
install-hm:
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
live:
nix build -o live $(options) $(flake)#nixosConfigurations.live.config.system.build.isoImage
reboot: boot
reboot
.PHONY: show
show:
nix flake show
.PHONY: verify
switch:
nixos-rebuild switch $(options) --flake $(flake)
trace:
nix flake check --show-trace
update:
nix flake update
verify:
git verify-commit HEAD

View file

@ -1,6 +1,6 @@
{ pkgs, lib, ... }: with lib; let
url = "https://i.imgur.com/GTrVpFh.jpeg";
sha256 = "1nn3ns14py4hf6ya50a84g0za4civd6mzg86a4z4k79sf7m23wza";
url = "https://i.imgur.com/4lqm0AZ.jpeg";
sha256 = "1bkc2rm1jy0bva9z78rq9a5gchwa61ns1gn59kdp1k63brawhx62";
forceContrastText = false;
in {
options = {

View file

@ -3,6 +3,6 @@
in {
text = ''
unbind-key C-b
bind -n ${mod}-r source-file /etc/tmux.conf
bind -n ${mod}-r source-file ~/.config/tmux/tmux.conf
'';
}

View file

@ -1,45 +0,0 @@
{ ... }: {
text = ''
# Install nixos to specified drive. To be run from Live ISO.
# Usage: bootstrap_nixos <DRIVE> [HOST]
function bootstrap_nixos() {
local target="''${1}"
local host="''${2}"
if [[ "''${target}" = "" ]]; then
help bootstrap_nixos
return 2
fi
# Create partitions.
parted -s "''${target}" mktable gpt
parted -s "''${target}" mkpart primary 0% 512MB
parted -s "''${target}" mkpart primary 512MB 100%
parted -s "''${target}" name 1 NIXBOOT
parted -s "''${target}" name 2 NIXROOT
parted -s "''${target}" set 1 esp on
# Format.
mkfs.fat -F 32 /dev/disk/by-partlabel/NIXBOOT
mkfs.ext4 -F /dev/disk/by-partlabel/NIXROOT
# Mount.
mount /dev/disk/by-partlabel/NIXROOT /mnt
mkdir /mnt/boot
mount /dev/disk/by-partlabel/NIXBOOT /mnt/boot
# Generate config.
nixos-generate-config --root /mnt
# Install.
cd /mnt
if [[ "''${host}" = "" ]]; then
_warn "Warning: Installing basic system."
nixos-install
else
_info "Installing ''${host}..."
nixos-install --no-root-password --no-channel-copy --flake "''${_nix_system_config}#''${host}"
fi
}
'';
}