Begin getting base setup implemented

This commit is contained in:
Kaare Hoff Skovgaard 2025-07-05 15:35:58 +02:00
parent 453099b068
commit 84f6e1a93f
Signed by: khs
GPG key ID: C7D890804F01E9F0
11 changed files with 425 additions and 0 deletions

View file

@ -0,0 +1,20 @@
{ inputs, pkgs, ... }:
pkgs.nixosTest {
name = "hetzner-will-boot";
nodes.machine =
{ ... }:
{
imports = [ inputs.self.nixosModules.default ];
khscodes.hetzner = {
enable = true;
ipv6-addr = "dead:beef:cafe::1";
};
system.stateVersion = "25.05";
};
testScript = ''
machine.start(allow_reboot = True)
machine.wait_for_unit("multi-user.target")
ipv6 = machine.succeed("ip addr")
assert "dead:beef:cafe::1" in ipv6
'';
}

View file

@ -0,0 +1,59 @@
{ ... }:
{
disko-root-lvm =
{
diskName,
device,
espSize ? "500M",
bootPartName ? "ESP",
rootPartName ? "primary",
volumeGroupName ? "mainpool",
rootLvName ? "root",
}:
{
devices.disk = {
"${diskName}" = {
inherit device;
type = "disk";
content = {
type = "gpt";
partitions = {
"${bootPartName}" = {
size = espSize;
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
"${rootPartName}" = {
size = "100%";
content = {
type = "lvm_pv";
vg = volumeGroupName;
};
};
};
};
};
};
devices.lvm_vg = {
"${volumeGroupName}" = {
type = "lvm_vg";
lvs = {
"${rootLvName}" = {
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
mountOptions = [ "defaults" ];
};
};
};
};
};
};
}

View file

@ -0,0 +1,57 @@
{
config,
lib,
system,
...
}:
let
cfg = config.khscodes.hetzner;
in
{
options.khscodes.hetzner = {
enable = lib.mkEnableOption "Enables the machine as a hetzner machine";
ipv6-addr = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "IPv6 address of the server, for now detecting this from the server itself is not supported";
default = null;
};
diskName = lib.mkOption {
type = lib.types.str;
default = "nixos";
description = "Name of the root disk device";
};
};
config = lib.mkIf cfg.enable {
disko = lib.khscodes.disko-root-lvm {
device = "/dev/sda";
diskName = cfg.diskName;
};
boot.tmp.cleanOnBoot = lib.mkDefault true;
boot.initrd.kernelModules = lib.mkIf (system == "aarch64-linux") [ "virtio_gpu" ];
boot.kernelParams = lib.mkIf (system == "aarch64-linux") [ "console=tty" ];
zramSwap.enable = lib.mkDefault true;
khscodes.systemd-boot.enable = lib.mkDefault true;
khscodes.qemu-guest.enable = true;
networking = {
useDHCP = false;
useNetworkd = false;
};
systemd.network = {
enable = true;
networks."10-enp1s0" = {
matchConfig.Name = [
"eth0"
"enp1s0"
];
networkConfig = {
DHCP = "ipv4";
};
routes = [ { Gateway = "fe80::1"; } ];
linkConfig.RequiredForOnline = "routable";
address = lib.mkIf (cfg.ipv6-addr != null) [ cfg.ipv6-addr ];
};
};
};
}

View file

@ -0,0 +1,16 @@
{
config,
lib,
modulesPath,
...
}:
let
cfg = config.khscodes.hetzner;
in
{
options.khscodes.qemu-guest = {
enable = lib.mkEnableOption "Configures machine with NixOS profile for qemu guest";
};
config = lib.mkIf cfg.enable (import "${modulesPath}/profiles/qemu-guest.nix" { });
}

View file

@ -0,0 +1,4 @@
{ config, lib, ... }:
{
}

View file

@ -0,0 +1,32 @@
{ config, lib, ... }:
let
cfg = config.khscodes.systemd-boot;
in
{
options.khscodes.systemd-boot = {
enable = lib.mkEnableOption "Enables booting using systemd";
configuration-limit = lib.mkOption {
type = lib.types.int;
description = "";
default = 5;
};
};
config = lib.mkIf cfg.enable {
boot = {
loader = {
systemd-boot = {
enable = true;
configurationLimit = cfg.configuration-limit;
};
grub = {
enable = false;
};
efi = {
canTouchEfiVariables = true;
efiSysMountPoint = "/boot";
};
};
};
};
}

View file

@ -0,0 +1,6 @@
{
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
}

View file

@ -0,0 +1,5 @@
{ config, lib, ... }:
{
khscodes.hetzner.enable = true;
system.stateVersion = "25.05";
}