104 lines
2.6 KiB
Nix
104 lines
2.6 KiB
Nix
{ config, pkgs, ... }: {
|
|
networking = {
|
|
firewall = {
|
|
allowedTCPPorts = [ 2049 ];
|
|
allowedUDPPorts = [
|
|
547
|
|
67
|
|
69
|
|
];
|
|
};
|
|
nat = {
|
|
enable = true;
|
|
enableIPv6 = true;
|
|
internalInterfaces = [ "br0" ];
|
|
};
|
|
networkmanager.ensureProfiles.profiles = {
|
|
slave-ethernet.connection = {
|
|
controller = "br0";
|
|
id = "slave-ethernet";
|
|
port-type = "bridge";
|
|
type = "ethernet";
|
|
};
|
|
static-bridge = {
|
|
bridge.stp = false;
|
|
connection = {
|
|
id = "static-bridge";
|
|
interface-name = "br0";
|
|
type = "bridge";
|
|
};
|
|
ipv4 = {
|
|
addresses = "10.2.0.1/16";
|
|
method = "manual";
|
|
};
|
|
ipv6 = {
|
|
addresses = "fc02::1/64";
|
|
method = "manual";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
services = {
|
|
dnsmasq = {
|
|
enable = true;
|
|
settings = {
|
|
bind-dynamic = true;
|
|
dhcp-boot = "efi/boot/BOOTX64.EFI";
|
|
dhcp-range = [
|
|
"10.2.0.2,10.2.255.254,12h"
|
|
"fc02::2,fc02::ffff:ffff:ffff:ffff,12h"
|
|
];
|
|
enable-ra = true;
|
|
enable-tftp = true;
|
|
interface = "br0";
|
|
port = 0;
|
|
tftp-root = "/srv/pxe/nixos/boot";
|
|
};
|
|
};
|
|
nfs.server = {
|
|
enable = true;
|
|
exports."/srv/pxe/export"."10.2.0.0/16" = [
|
|
"fsid=0"
|
|
"no_root_squash"
|
|
"rw"
|
|
];
|
|
};
|
|
};
|
|
systemd = {
|
|
services = {
|
|
pxeboot = {
|
|
before = [ "nfs-server.service" ];
|
|
path = [ pkgs.util-linux ];
|
|
preStop = ''
|
|
cd /srv/pxe
|
|
mountpoint -q export && umount export
|
|
'';
|
|
requiredBy = [ "nfs-server.service" ];
|
|
script = ''
|
|
cd /srv/pxe
|
|
[ ! -e export ] && systemctl start pxeboot-install
|
|
mountpoint -q export || mount -B --mkdir nixos export
|
|
'';
|
|
serviceConfig = {
|
|
RemainAfterExit = true;
|
|
Type = "oneshot";
|
|
};
|
|
};
|
|
pxeboot-install = {
|
|
path = with pkgs; [
|
|
nix
|
|
nixos-install
|
|
];
|
|
script = ''
|
|
(printf '# Auto generated\n{\n boot.initrd.availableKernelModules = [\n'
|
|
cd ${config.boot.kernelPackages.kernel.modules}/lib/modules/*/kernel/drivers/net/ethernet
|
|
find -type f | sed 's/^.*\/\([^.]*\).*$/ "\1"/' | sort
|
|
printf ' ];\n}\n') > /etc/nixos/bootable/ethernet.nix
|
|
nixos-install --flake "/etc/nixos#nixos-bootpxe" \
|
|
--no-channel-copy --no-root-passwd --root /srv/pxe/nixos
|
|
'';
|
|
};
|
|
};
|
|
tmpfiles.rules = [ "d /srv/pxe/nixos/boot" ];
|
|
};
|
|
}
|