bootable targets: drive, pxe
This commit is contained in:
parent
2d4cf0b147
commit
9c0e1c011a
11 changed files with 88 additions and 64 deletions
9
bootable/common.nix
Normal file
9
bootable/common.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
boot = {
|
||||||
|
initrd.systemd.tpm2.enable = false;
|
||||||
|
loader.timeout = 0;
|
||||||
|
};
|
||||||
|
imports = [ ../common.nix ];
|
||||||
|
services.getty.autologinUser = "root";
|
||||||
|
systemd.tpm2.enable = false;
|
||||||
|
}
|
||||||
12
bootable/drive.nix
Normal file
12
bootable/drive.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
fileSystems = {
|
||||||
|
"/".device = "/dev/disk/by-label/bootdrive-root";
|
||||||
|
"/boot".device = "/dev/disk/by-label/bootdrive-esp";
|
||||||
|
};
|
||||||
|
hardware.enableAllHardware = true;
|
||||||
|
imports = [
|
||||||
|
../mods/fs.nix
|
||||||
|
./common.nix
|
||||||
|
];
|
||||||
|
networking.hostName = "nixos-bootdrive";
|
||||||
|
}
|
||||||
|
|
@ -11,11 +11,9 @@
|
||||||
device = "10.2.0.1:/";
|
device = "10.2.0.1:/";
|
||||||
fsType = "nfs4";
|
fsType = "nfs4";
|
||||||
};
|
};
|
||||||
hardware.enableAllHardware = true;
|
|
||||||
imports = [
|
imports = [
|
||||||
../common.nix
|
./common.nix
|
||||||
./ethernet.nix
|
./ethernet.nix
|
||||||
];
|
];
|
||||||
networking.hostName = "nixos-pxeboot";
|
networking.hostName = "nixos-bootpxe";
|
||||||
services.getty.autologinUser = "root";
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,20 +13,7 @@
|
||||||
kernelModules = [ "kvm-amd" ];
|
kernelModules = [ "kvm-amd" ];
|
||||||
kernelParams = [ "ttm.pages_limit=3014656" ];
|
kernelParams = [ "ttm.pages_limit=3014656" ];
|
||||||
};
|
};
|
||||||
fileSystems = {
|
fileSystems."/boot".device = "/dev/disk/by-uuid/2610-A769";
|
||||||
"/" = {
|
|
||||||
device = "/dev/mapper/root";
|
|
||||||
fsType = "ext4";
|
|
||||||
};
|
|
||||||
"/boot" = {
|
|
||||||
device = "/dev/disk/by-uuid/2610-A769";
|
|
||||||
fsType = "vfat";
|
|
||||||
options = [
|
|
||||||
"dmask=0077"
|
|
||||||
"fmask=0077"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||||
swapDevices = [
|
swapDevices = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
{
|
{
|
||||||
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree;
|
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-tree;
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
|
nixos-bootdrive = nixpkgs.lib.nixosSystem { modules = [ ./bootable/drive.nix ]; };
|
||||||
|
nixos-bootpxe = nixpkgs.lib.nixosSystem { modules = [ ./bootable/pxe.nix ]; };
|
||||||
nixos-desktop = nixpkgs.lib.nixosSystem {
|
nixos-desktop = nixpkgs.lib.nixosSystem {
|
||||||
modules = [
|
modules = [
|
||||||
./desktop/configuration.nix
|
./desktop/configuration.nix
|
||||||
|
|
@ -38,7 +40,6 @@
|
||||||
sops-nix.nixosModules.sops
|
sops-nix.nixosModules.sops
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
nixos-pxeboot = nixpkgs.lib.nixosSystem { modules = [ ./pxeboot/configuration.nix ]; };
|
|
||||||
nixos-server = nixpkgs.lib.nixosSystem {
|
nixos-server = nixpkgs.lib.nixosSystem {
|
||||||
modules = [
|
modules = [
|
||||||
./server/configuration.nix
|
./server/configuration.nix
|
||||||
|
|
|
||||||
13
install.sh
13
install.sh
|
|
@ -1,15 +1,12 @@
|
||||||
gdisk $DISK
|
gdisk $DISK
|
||||||
mkfs.fat -F 32 $ESPPART
|
mkfs.fat -F 32 -n $HOST-esp $ESPPART
|
||||||
cryptsetup luksFormat $ROOTPART
|
cryptsetup luksFormat $ROOTPART
|
||||||
cryptsetup open $ROOTPART root
|
cryptsetup open $ROOTPART root
|
||||||
mkfs.ext4 /dev/mapper/root
|
mkfs.ext4 -L $HOST-root /dev/mapper/root
|
||||||
mount /dev/mapper/root /mnt
|
mount /dev/mapper/root /mnt
|
||||||
mount $ESPPART --mkdir -o umask=077 /mnt/boot
|
mount --mkdir $ESPPART /mnt/boot
|
||||||
mkdir -p /mnt/var/lib
|
mkdir -p /mnt/var/lib
|
||||||
mkswap -F -s $SWAPSIZE /mnt/var/swapfile
|
|
||||||
swapon /mnt/var/swapfile
|
|
||||||
# restore backup
|
# restore backup
|
||||||
nixos-generate-config --root /mnt --show-hardware-config > /mnt/etc/nixos/$HOSTNAME/hardware.nix
|
nixos-install --no-root-passwd --no-channel-copy --flake "/mnt/etc/nixos#nixos-$HOST"
|
||||||
nixos-install --no-root-passwd --no-channel-copy --flake "/mnt/etc/nixos#nixos-$HOSTNAME"
|
|
||||||
sbctl enroll-keys --yolo
|
sbctl enroll-keys --yolo
|
||||||
systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+2+7 $ROOTPART
|
systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=0+2+7 $ROOTPART
|
||||||
|
|
|
||||||
15
mods/fs.nix
Normal file
15
mods/fs.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
fileSystems = {
|
||||||
|
"/" = {
|
||||||
|
fsType = "ext4";
|
||||||
|
options = [ "noatime" ];
|
||||||
|
};
|
||||||
|
"/boot" = {
|
||||||
|
fsType = "vfat";
|
||||||
|
options = [
|
||||||
|
"noatime"
|
||||||
|
"umask=0077"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -4,12 +4,10 @@
|
||||||
kernelModules = [ "amneziawg" ];
|
kernelModules = [ "amneziawg" ];
|
||||||
loader.limine.secureBoot.enable = true;
|
loader.limine.secureBoot.enable = true;
|
||||||
};
|
};
|
||||||
fileSystems = {
|
fileSystems."/".device = "/dev/mapper/root";
|
||||||
"/".options = [ "noatime" ];
|
|
||||||
"/boot".options = [ "noatime" ];
|
|
||||||
};
|
|
||||||
imports = [
|
imports = [
|
||||||
../common.nix
|
../common.nix
|
||||||
|
./fs.nix
|
||||||
./pxeboot.nix
|
./pxeboot.nix
|
||||||
./vps-init.nix
|
./vps-init.nix
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
{ config, pkgs, ... }: {
|
{ config, pkgs, ... }: {
|
||||||
environment.systemPackages = [ pkgs.grub2_efi ];
|
|
||||||
networking = {
|
networking = {
|
||||||
firewall = {
|
firewall = {
|
||||||
allowedTCPPorts = [
|
allowedTCPPorts = [
|
||||||
|
|
@ -30,6 +29,7 @@
|
||||||
slave-ethernet.connection = {
|
slave-ethernet.connection = {
|
||||||
controller = "br0";
|
controller = "br0";
|
||||||
id = "slave-ethernet";
|
id = "slave-ethernet";
|
||||||
|
port-type = "bridge";
|
||||||
type = "ethernet";
|
type = "ethernet";
|
||||||
};
|
};
|
||||||
static-bridge = {
|
static-bridge = {
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
};
|
};
|
||||||
services = {
|
services = {
|
||||||
dnsmasq.settings = {
|
dnsmasq.settings = {
|
||||||
bind-interfaces = true;
|
bind-dynamic = true;
|
||||||
dhcp-boot = "efi/boot/BOOTX64.EFI";
|
dhcp-boot = "efi/boot/BOOTX64.EFI";
|
||||||
dhcp-range = [
|
dhcp-range = [
|
||||||
"10.2.0.2,10.2.255.254,12h"
|
"10.2.0.2,10.2.255.254,12h"
|
||||||
|
|
@ -73,22 +73,42 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
systemd = {
|
systemd = {
|
||||||
services.pxeboot = {
|
services = {
|
||||||
path = with pkgs; [
|
pxeboot = {
|
||||||
nix
|
before = [ "nfs-server.service" ];
|
||||||
nixos-install
|
path = [ pkgs.util-linux ];
|
||||||
util-linux
|
preStop = ''
|
||||||
];
|
cd /srv/pxe
|
||||||
script = ''
|
mountpoint -q export && umount export
|
||||||
(printf '{\n boot.initrd.availableKernelModules = [\n'
|
'';
|
||||||
cd ${config.boot.kernelPackages.kernel.modules}/lib/modules/*/kernel/drivers/net/ethernet
|
requiredBy = [ "nfs-server.service" ];
|
||||||
find -type f | sed 's/^.*\/\([^.]*\).*$/ "\1"/' | sort
|
script = ''
|
||||||
printf ' ];\n}') > /etc/nixos/pxeboot/ethernet.nix
|
cd /srv/pxe
|
||||||
cd /srv/pxe
|
if [ ! -e export ]; then
|
||||||
nixos-install --flake "/etc/nixos#nixos-pxeboot" \
|
systemctl start pxeboot-install
|
||||||
--no-channel-copy --no-root-passwd --root $PWD/nixos
|
fi
|
||||||
mountpoint -q export || mount -B --mkdir nixos export
|
mountpoint -q export || mount -B --mkdir nixos export
|
||||||
'';
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
RemainAfterExit = true;
|
||||||
|
Type = "oneshot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
pxeboot-install = {
|
||||||
|
path = with pkgs; [
|
||||||
|
nix
|
||||||
|
nixos-install
|
||||||
|
];
|
||||||
|
script = ''
|
||||||
|
(printf '{\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}') > /etc/nixos/pxeboot/ethernet.nix
|
||||||
|
nixos-install --flake "/etc/nixos#nixos-pxeboot" \
|
||||||
|
--no-channel-copy --no-root-passwd --root /srv/pxe/nixos
|
||||||
|
'';
|
||||||
|
# delete --no-channel-copy later
|
||||||
|
};
|
||||||
};
|
};
|
||||||
tmpfiles.rules = [ "d /srv/pxe/nixos/boot" ];
|
tmpfiles.rules = [ "d /srv/pxe/nixos/boot" ];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,6 @@
|
||||||
"memmap=0x4000%0xbfb7a000-4"
|
"memmap=0x4000%0xbfb7a000-4"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
fileSystems = {
|
fileSystems."/boot".device = "/dev/disk/by-uuid/86F4-A8F1";
|
||||||
"/" = {
|
|
||||||
device = "/dev/mapper/root";
|
|
||||||
fsType = "ext4";
|
|
||||||
};
|
|
||||||
"/boot" = {
|
|
||||||
device = "/dev/disk/by-uuid/86F4-A8F1";
|
|
||||||
fsType = "vfat";
|
|
||||||
options = [
|
|
||||||
"dmask=0077"
|
|
||||||
"fmask=0077"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue