Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Last active August 4, 2017 11:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cleverca22/75e3db4dabeff05b743e9be77a2341b9 to your computer and use it in GitHub Desktop.
Save cleverca22/75e3db4dabeff05b743e9be77a2341b9 to your computer and use it in GitHub Desktop.
justdoit
<?php
switch (strtolower($_GET['mac'])) {
case '00:1c:23:16:4b:b3';
?>
#!ipxe
sanboot iscsi:192.168.2.11:::1:iqn.2016-01.laptop-root
<?php
break;
default;
case '08:00:27:15:bd:7b';
case '08:00:27:1f:4d:5a';
if ($_GET['version'] == '') {
?>
#!ipxe
chain tftp://192.168.2.61/undionly.kpxe
<?php
} else {
?>
#!ipxe
chain http://c2d.localnet/netboot/netboot.ipxe
<?php
}
break;
}
{ pkgs, ... }:
let
justdoit = pkgs.writeScriptBin "justdoit" ''
#!${pkgs.stdenv.shell}
dd if=/dev/zero of=/dev/sda bs=512 count=10000
sfdisk /dev/sda <<EOF
label: dos
device: /dev/sda
unit: sectors
/dev/sda1 : start= 2048, size=3145728, type=83
EOF
mkfs.ext4 /dev/sda1
mount -v /dev/sda1 /mnt
nixos-generate-config --root /mnt
cp -v ${./target-config.nix} /mnt/etc/nixos/configuration.nix
nixos-install -j 4
umount /mnt
'';
in {
imports = [ <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix> ];
environment.systemPackages = [ justdoit ];
}
subnet 192.168.2.0 netmask 255.255.255.0 {
option domain-search "localnet";
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.2.255;
option routers 192.168.2.1;
option domain-name-servers 192.168.2.1, 8.8.8.8, 8.8.4.4;
range 192.168.2.100 192.168.2.200;
next-server 192.168.2.61;
if exists user-class and option user-class = "iPXE" {
filename "http://c2d.localnet/boot.php?mac=${net0/mac}&asset=${asset:uristring}&version=${builtin/version}";
} else {
filename = "undionly.kpxe";
}
}
clever@c2d /var/www/c2d $ nix-build netboot.nix -o netboot
let
pkgs = import <nixpkgs> {};
build = (import <nixpkgs/nixos> { configuration = ./configuration.nix; }).config.system.build;
in
pkgs.symlinkJoin {
name="netboot";
paths=[
build.netbootRamdisk
build.kernel
build.netbootIpxeScript
];
}
{ config, pkgs, ... }:
{
imports = [ ./hardware-configuration.nix ];
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.device = "/dev/sda";
networking.hostName = "autoinstall";
users.users.root.initialPassword = "root";
users.mutableUsers = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment