1
0

pkgs/nixfiles: move nixfiles-auto-install to pkg

This commit is contained in:
2023-10-20 23:45:43 +02:00
parent b9af028fa7
commit 24b8e750b5
5 changed files with 78 additions and 68 deletions

View File

@@ -0,0 +1,9 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "nixfiles-auto-install";
text = builtins.readFile ./nixfiles-auto-install.sh;
runtimeInputs = with pkgs; [
nixfiles-generate-config
];
}

View File

@@ -0,0 +1,65 @@
#!/usr/bin/env bash
set -euo pipefail
hostname=host${RANDOM}
echo "[I] Deploying with hostname ${hostname}"
device=""
for dev in "/dev/vda" "/dev/sda"; do
if [[ -b $dev ]]; then
device=$dev
break
fi
done
while [[ $# -gt 0 ]]; do
case $1 in
--hostname)
hostname=$2
shift
shift
;;
*)
echo "unknown option: $1"
exit 1
;;
esac
done
echo "[I] Formatting disk"
if [[ -z $device ]]; then
echo "[E] No device to install to"
exit 1
fi
echo "[I] Using ${device}"
parted --script $device mklabel gpt
parted --script $device disk_set pmbr_boot on
parted --script $device mkpart boot 0% 512M
parted --script $device set 1 bios_grub on
parted --script $device mkpart root 512M 100%
echo "[I] Creating file system"
mkfs.ext4 -F ${device}2
echo "[I] Mount file system"
mount ${device}2 /mnt
echo "[I] Generate NixOS configuration"
nixfiles-generate-config --root /mnt --hostname "${hostname}"
sed -i "s~# boot\.loader\.grub\.device = \"/dev/sda\";~boot\.loader\.grub\.device = \"${device}\";~g" "/mnt/etc/nixos/hosts/${hostname}/configuration.nix"
echo "[I] Install NixOS"
nixos-install --flake "/mnt/etc/nixos#${hostname}" --root /mnt --no-root-password

View File

@@ -3,6 +3,7 @@ self: super: {
flask-excel = self.python3.pkgs.callPackage ./flask-excel {};
iot-data = self.python3.pkgs.callPackage ./iot-data {};
nixfiles-add-secret = self.callPackage ./nixfiles/nixfiles-add-secret.nix {};
nixfiles-auto-install = self.callPackage ./nixfiles/nixfiles-auto-install.nix {};
nixfiles-generate-backup-secrets = self.callPackage ./nixfiles/nixfiles-generate-backup-secrets.nix {};
nixfiles-generate-config = self.callPackage ./nixfiles/nixfiles-generate-config.nix {};
nixfiles-updated-inputs = self.callPackage ./nixfiles/nixfiles-updated-inputs.nix {};