From 6f74a75ba3f550515898ea0ad33b2773e7db0e76 Mon Sep 17 00:00:00 2001 From: Jakob Lechner Date: Thu, 17 Jul 2025 02:15:29 +0200 Subject: [PATCH] Add host pbx --- hosts/default.nix | 5 ++ hosts/pbx/configuration.nix | 58 ++++++++++++++++++++++ hosts/pbx/disko.nix | 95 +++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 hosts/default.nix create mode 100644 hosts/pbx/configuration.nix create mode 100644 hosts/pbx/disko.nix diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..9f86f5b --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,5 @@ +_inputs: { + pbx = { + system = "x86_64-linux"; + }; +} diff --git a/hosts/pbx/configuration.nix b/hosts/pbx/configuration.nix new file mode 100644 index 0000000..852e654 --- /dev/null +++ b/hosts/pbx/configuration.nix @@ -0,0 +1,58 @@ +{ config, lib, pkgs, ... }: + +{ + imports = [ + ./disko.nix + ../../users/jalr + ]; + + weinturm = { + impermanence = { + enable = true; + rootDevice = config.disko.devices.disk.disk1.content.partitions.nixos.device; + }; + zram.enable = true; + }; + + networking = { + hostName = "pbx"; + useDHCP = lib.mkDefault true; + }; + + boot = { + initrd = { + availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ]; + }; + + kernelModules = [ "kvm-intel" ]; + kernelParams = [ + "console=ttyS0,115200" + "console=tty1" + ]; + + loader = { + efi = { + efiSysMountPoint = "/boot/efis/disk1"; + canTouchEfiVariables = false; + }; + generationsDir.copyKernels = true; + grub = { + devices = [ "/dev/sda" "/dev/sdb" ]; + efiInstallAsRemovable = true; + copyKernels = true; + efiSupport = true; + zfsSupport = true; + extraConfig = '' + serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 + terminal_input --append serial + terminal_output --append serial + ''; + extraInstallCommands = '' + ${pkgs.coreutils-full}/bin/cp -r ${config.boot.loader.efi.efiSysMountPoint}/EFI /boot/efis/disk2 + ''; + }; + }; + }; + + system.stateVersion = "25.05"; # Did you read the comment? +} diff --git a/hosts/pbx/disko.nix b/hosts/pbx/disko.nix new file mode 100644 index 0000000..30a34be --- /dev/null +++ b/hosts/pbx/disko.nix @@ -0,0 +1,95 @@ +{config, ...}: let + cfg = config.disko; + mkEfiPartition = mountpoint: { + size = "1024M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + inherit mountpoint; + mountOptions = [ + "uid=0" "gid=0" "fmask=0077" "dmask=0077" + "nodev" "nosuid" "noexec" + "x-systemd.idle-timeout=1min" "x-systemd.automount" "noauto" "nofail" "noatime" "X-mount.mkdir" + ]; + }; + }; +in { + disko.devices = { + disk = { + disk1 = { + type = "disk"; + device = "/dev/sda"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for grub MBR + }; + ESP = mkEfiPartition "/boot/efis/disk1"; + nixos = { + size = "100%"; + }; + }; + }; + }; + disk2 = { + type = "disk"; + device = "/dev/sdb"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for grub MBR + }; + ESP = mkEfiPartition "/boot/efis/disk2"; + nixos = { + size = "100%"; + content = let + thisPartition = cfg.devices.disk.disk2.content.partitions.nixos.device; + mirror = cfg.devices.disk.disk1.content.partitions.nixos.device; + in { + type = "btrfs"; + extraArgs = [ + "-f" + "-d raid1" + "${mirror}" + ]; + postCreateHook = '' + mountpoint="$(mktemp -d)" + mount "${thisPartition}" "$mountpoint" -o subvol=/ || mount "${mirror}" "$mountpoint" -o subvol=/ + trap 'umount "$mountpoint"; rmdir "$mountpoint"' EXIT + btrfs subvolume snapshot -r $mountpoint/root $mountpoint/root-blank + ''; + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = ["compress-force=zstd:1" "noatime"]; + }; + "/home" = { + mountpoint = "/home"; + mountOptions = ["compress-force=zstd:1" "noatime" "nodev" "nosuid"]; + }; + "/nix" = { + mountpoint = "/nix"; + mountOptions = ["compress-force=zstd:1" "noatime" "nodev"]; + }; + "/log" = { + mountpoint = "/var/log"; + mountOptions = ["compress-force=zstd:1" "noatime" "nodev" "nosuid"]; + }; + "/persist" = { + mountpoint = "/persist"; + mountOptions = ["compress-force=zstd:1" "noatime" "nodev" "nosuid"]; + }; + }; + }; + }; + }; + }; + }; + }; + }; +}