server: add linode profile init

This commit is contained in:
ooks-io 2024-10-29 16:44:09 +11:00
parent db7b83037f
commit 3c0188a701
10 changed files with 170 additions and 22 deletions

View file

@ -1,14 +1,16 @@
{
config,
lib,
pkgs,
config,
...
}: let
inherit (builtins) attrValues;
inherit (lib) mkForce mkIf;
inherit (lib) mkForce getExe' mkIf;
inherit (config.ooknet.server) profile;
in {
config = mkIf (profile == "linode") {
services.qemuGuest.enable = true;
networking = {
tempAddresses = "disabled";
usePredictableInterfaceNames = mkForce false;
@ -17,43 +19,76 @@ in {
useDHCP = true;
};
};
fileSystems."/" = {
device = "/dev/sda";
fsType = "ext4";
autoResize = true;
};
swapDevices = [{device = "/dev/sdb";}];
boot = {
kernelPackages = pkgs.linuxPackages_latest;
kernelModules = [];
# LISH console support
kernelParams = ["console=ttys0,19200n8"];
kernelParams = ["console=ttyS0,19200n8"];
extraModulePackages = [];
growPartition = true;
initrd = {
availableKernelModules = ["virtio_pci" "virtio_scsi" "ahci" "sd_mod"];
kernelModules = [];
availableKernelModules = [
# modules generated by nixos-generate-config
"virtio_pci"
"virtio_scsi"
"ahci"
"sd_mod"
# qemu guest modules
"virtio_net"
"virtio_mmio"
"virtio_blk"
"virtio_scsi"
"9p"
"9pnet_virtio"
];
kernelModules = [
"virtio_balloon"
"virtio_console"
"virtio_rng"
"virtio_gpu"
];
};
loader = {
grub = {
enable = true;
device = "/dev/sda";
device = "nodev";
forceInstall = true;
copyKernels = true;
fsIdentifier = "provided";
fsIdentifier = "label";
splashImage = null;
extraConfig = ''
serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1;
terminal_input serial;
terminal_output serial
'';
extraInstallCommands = "${getExe' pkgs.coreutils "ln"} -fs /boot/grub /boot/grub2";
};
timeout = mkForce 10;
# disable base settings
efi.canTouchEfiVariables = mkForce false;
systemd-boot.enable = mkForce false;
};
};
environment.systemPackages = attrValues {
inherit
(pkgs)
inetutils
mtr
sysstat
linode-cli
;
environment = {
systemPackages = attrValues {
inherit
(pkgs)
inetutils
mtr
sysstat
linode-cli
;
};
};
};
}

View file

@ -0,0 +1,60 @@
{
pkgs,
lib,
...
}: let
inherit (lib) mkForce getExe';
in {
boot = {
kernelPackages = pkgs.linuxPackages_latest;
kernelModules = [];
# LISH console support
kernelParams = ["console=ttyS0,19200n8"];
extraModulePackages = [];
growPartition = true;
initrd = {
availableKernelModules = [
# modules generated by nixos-generate-config
"virtio_pci"
"virtio_scsi"
"ahci"
"sd_mod"
# qemu guest modules
"virtio_net"
"virtio_mmio"
"virtio_blk"
"virtio_scsi"
"9p"
"9pnet_virtio"
];
kernelModules = [
"virtio_balloon"
"virtio_console"
"virtio_rng"
"virtio_gpu"
];
};
loader = {
grub = {
enable = true;
device = "nodev";
forceInstall = true;
copyKernels = true;
fsIdentifier = "label";
splashImage = null;
extraConfig = ''
serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1;
terminal_input serial;
terminal_output serial
'';
extraInstallCommands = "${getExe' pkgs.coreutils "ln"} -fs /boot/grub /boot/grub2";
};
timeout = mkForce 10;
# disable base settings
efi.canTouchEfiVariables = mkForce false;
systemd-boot.enable = mkForce false;
};
};
}

View file

@ -0,0 +1,7 @@
{
imports = [
./boot.nix
./networking.nix
./file-system.nix
];
}

View file

@ -0,0 +1,8 @@
{
fileSystems."/" = {
device = "/dev/sda";
fsType = "ext4";
autoResize = true;
};
swapDevices = [{device = "/dev/sdb";}];
}

View file

@ -0,0 +1,12 @@
{lib, ...}: let
inherit (lib) mkForce;
in {
networking = {
tempAddresses = "disabled";
usePredictableInterfaceNames = mkForce false;
interfaces.eth0 = {
tempAddress = "disabled";
useDHCP = true;
};
};
}

View file

@ -0,0 +1,8 @@
{
imports = [
./image.nix
./base
];
system.stateVersion = "24.11";
}

View file

@ -0,0 +1,23 @@
{
pkgs,
lib,
inputs,
config,
...
}: let
make-disk-image = import "${inputs.nixpkgs}/nixos/lib/make-disk-image.nix";
in {
system.build.image = make-disk-image {
inherit lib pkgs config;
partitionTableType = "none";
name = "linode-image";
format = "raw";
# Linode requires the image to be gzip'd
# unzipped image cannot exceed 6gb
postVM = ''
${pkgs.gzip}/bin/gzip -6 -c -- $diskImage > \
$out/nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.img.gz
rm $diskImage
'';
};
}