Created
April 17, 2017 08:58
-
-
Save lheckemann/e302b8cb560e6a319a65d197d40dcee8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, ... }: | |
let | |
justdoit = pkgs.writeScriptBin "justdoit" '' | |
#!${stdenv.shell} | |
set -ex | |
sfdisk /dev/sda <<EOF | |
label: dos | |
device: /dev/sda | |
unit: sectors | |
/dev/sda1 : start=2048, type=83 | |
EOF | |
mkfs.ext4 /dev/sda1 | |
mount -v /dev/sda1 /mnt | |
nixos-generate-config --root /mnt | |
for addr_path in /sys/class/net/*/address ; do | |
read addr < $addr_path | |
tentative_hostname=$(grep "$addr" "${./ethers}" | awk '{ print $2 }') | |
[[ -n $tentative_hostname ]] && target_hostname=$tentative_hostname | |
done | |
[[ -z $target_hostname ]] && target_hostname=unknown | |
echo "** Hostname is $target_hostname" | |
sed "s/@HOSTNAME_HERE@/$target_hostname/" ${./target-config.nix} > /mnt/etc/nixos/configuration.nix | |
nixos-install | |
umount /mnt | |
reboot | |
''; | |
in | |
{ | |
imports = [ <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix> ]; | |
environment.systemPackages = [ justdoit ]; | |
services.openssh.enable = true; | |
users.users.root.authorizedKeys.keys = [ (builtins.readFile ./keys/deploy.pub) ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment