#!/bin/sh set -o errexit set -o nounset IS_VAGRANT_BUILD=${IS_VAGRANT_BUILD:-no} # TODO: allow selection of device DEVICE=/dev/$(test -b /dev/vda && echo vda || echo sda) # TODO: calculate swap-size: round(sqrt(RAM)) SWAP_SIZE=${SWAP_SIZE:-2G} ROOTFS_SIZE=${ROOTFS_SIZE:-1T} function customize_configuration { # enable ssh sed -i s/"# services.openssh.enable"/services.openssh.enable/ /mnt/etc/nixos/configuration.nix # remove the last closing curling bracket, so we can more easily add a block of text sed -i 's/^}$//' /mnt/etc/nixos/configuration.nix cat >> /mnt/etc/nixos/configuration.nix <> /mnt/etc/nixos/configuration.nix <> /mnt/etc/nixos/configuration.nix } setup_vagrant() { packer_http=$(cat .packer_http) curl -f "$packer_http/configuration.nix" > /mnt/etc/nixos/configuration.nix curl -f "$packer_http/vagrant.nix" > /mnt/etc/nixos/vagrant.nix echo "{}" > /mnt/etc/nixos/vagrant-hostname.nix echo "{}" > /mnt/etc/nixos/vagrant-network.nix echo "{ networking.hostId = \"$(head -c 8 /etc/machine-id)\"; }" > /mnt/etc/nixos/host-id.nix } generate_authorized_keys() { if [ -f /etc/ssh/authorized_keys.d/root ]; then cat /etc/ssh/authorized_keys.d/root | awk 'NF {print "\"" $0 "\"" }' fi if [ -f /root/.ssh/authorized_keys ]; then cat /root/.ssh/authorized_keys | awk 'NF {print "\"" $0 "\"" }' fi } function setup_disk { UEFI=$(test -d /sys/firmware/efi && echo 1 || echo 0) if [ ${UEFI} -eq 1 ]; then sfdisk ${DEVICE} <