Skip to content

Instantly share code, notes, and snippets.

@lheckemann
Created April 17, 2017 08:58
Show Gist options
  • Save lheckemann/e302b8cb560e6a319a65d197d40dcee8 to your computer and use it in GitHub Desktop.
Save lheckemann/e302b8cb560e6a319a65d197d40dcee8 to your computer and use it in GitHub Desktop.
{ 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