summaryrefslogtreecommitdiff
path: root/modules/xnet/disk
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2024-11-23 16:36:43 -0500
committerKleidi Bujari <mail@4kb.net>2024-11-23 16:36:43 -0500
commit3ccc7e784a0ed5b19910ab856f6d9774a6f27956 (patch)
tree94addd02f98d39a4be92c19ecffc641bfcfd2f89 /modules/xnet/disk
parent89a1c051423994f62341d72424dc7c1e86fbe231 (diff)
downloaddepot-3ccc7e784a0ed5b19910ab856f6d9774a6f27956.tar.gz
depot-3ccc7e784a0ed5b19910ab856f6d9774a6f27956.tar.bz2
depot-3ccc7e784a0ed5b19910ab856f6d9774a6f27956.zip
Initial scaffolding and layout
Set up the modules of the flake. At this time, the flake is split into modules and machines. Considering that additional top-level sections -- such as packages and shells -- will also be added, it might make sense to keep all nix related things in one top-level directory, alongside the flake.nix file. This is all under the assumption that later amendments to the project will introduce other tech, such as terraform.
Diffstat (limited to 'modules/xnet/disk')
-rw-r--r--modules/xnet/disk/boot.nix13
-rw-r--r--modules/xnet/disk/default.nix113
-rw-r--r--modules/xnet/disk/layouts/mirror.nix43
-rw-r--r--modules/xnet/disk/layouts/single.nix29
4 files changed, 198 insertions, 0 deletions
diff --git a/modules/xnet/disk/boot.nix b/modules/xnet/disk/boot.nix
new file mode 100644
index 0000000..65be2f3
--- /dev/null
+++ b/modules/xnet/disk/boot.nix
@@ -0,0 +1,13 @@
+{ lib, ... }:
+let
+ inherit (lib) mkDefault;
+in
+{
+ boot = {
+ loader.systemd-boot.enable = true;
+ initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "sd_mod" "sdhci_pci" ];
+ kernelModules = [ "kvm-intel" "kvm-amd" ];
+ swraid.mdadmConf = "MAILADDR = nobody@example.com";
+ tmp.cleanOnBoot = mkDefault true;
+ };
+}
diff --git a/modules/xnet/disk/default.nix b/modules/xnet/disk/default.nix
new file mode 100644
index 0000000..aca6ae2
--- /dev/null
+++ b/modules/xnet/disk/default.nix
@@ -0,0 +1,113 @@
+{ config, lib, modulesPath, ... }:
+let
+ cfg = config.xnet.disk;
+ commonOpts = {
+ acltype = "posixacl";
+ atime = "off";
+ compression = "on";
+ normalization = "formD";
+ relatime = "off";
+ xattr = "sa";
+ "com.sun:auto-snapshot" = "false";
+ };
+
+ inherit (lib) mkOption mkDefault mkIf types;
+in
+{
+ imports = [
+ ./boot.nix
+ (modulesPath + "/installer/scan/not-detected.nix")
+ ];
+
+ options.xnet.disk = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Apply xnet-standard ZFS disk layout.";
+ };
+
+ device = mkOption {
+ type = types.str;
+ description = "Underlying device that build the root ZFS pool.";
+ };
+
+ extraDatasets = mkOption { };
+ };
+
+ config = mkIf cfg.enable {
+ networking.hostId = builtins.substring 0 8
+ (builtins.hashString "md5" config.networking.hostName);
+
+ services.zfs = {
+ autoScrub.enable = true;
+ trim.enable = true;
+ };
+
+ zramSwap.enable = mkDefault true;
+
+ boot = {
+ kernelParams = [ "nohibernate" "elevator=none" ];
+ supportedFilesystems = [ "vfat" "zfs" ];
+ zfs.devNodes = "/dev/disk/by-partuuid";
+ };
+
+ disko.devices = (import ./layouts/single.nix cfg.device) // {
+ nodev."/" = {
+ fsType = "tmpfs";
+ mountOptions = [ "defaults" "size=2G" "mode=755" ];
+ };
+
+ zpool.zroot = {
+ type = "zpool";
+ options = {
+ ashift = "12";
+ autotrim = "on";
+ };
+
+ datasets = {
+ "local" = {
+ type = "zfs_fs";
+ options = commonOpts;
+ };
+
+ "local/reserved" = {
+ type = "zfs_fs";
+ options = {
+ refreservation = "10G";
+ mountpoint = "none";
+ };
+ };
+
+ "local/nix" = {
+ type = "zfs_fs";
+ mountpoint = "/nix";
+ options.mountpoint = "legacy";
+ };
+
+ "local/certs" = {
+ type = "zfs_fs";
+ mountpoint = "/certs";
+ options.mountpoint = "legacy";
+ };
+
+ "persist" = {
+ type = "zfs_fs";
+ mountpoint = "/persist";
+ options = { mountpoint = "legacy"; } // commonOpts;
+ };
+
+ "persist/data" = {
+ type = "zfs_fs";
+ mountpoint = "/persist/data";
+ options.mountpoint = "legacy";
+ };
+ } // cfg.extraDatasets;
+ };
+ };
+
+ users.groups.backup = {
+ members = [ config.services.syncoid.group ];
+ gid = 2001;
+ };
+ };
+}
diff --git a/modules/xnet/disk/layouts/mirror.nix b/modules/xnet/disk/layouts/mirror.nix
new file mode 100644
index 0000000..5a9835b
--- /dev/null
+++ b/modules/xnet/disk/layouts/mirror.nix
@@ -0,0 +1,43 @@
+devices: {
+ disk = builtins.listToAttrs (map
+ (device: {
+ name = device;
+ value = {
+ type = "disk";
+ device = "/dev/${device}";
+ content = {
+ type = "gpt";
+ partitions = {
+ ESP = {
+ size = "1G";
+ type = "EF00";
+ content = {
+ type = "mdraid";
+ name = "boot";
+ };
+ };
+ ZFS = {
+ size = "100%";
+ content = {
+ type = "zfs";
+ pool = "zroot";
+ };
+ };
+ };
+ };
+ };
+ })
+ devices);
+ mdadm = {
+ boot = {
+ type = "mdadm";
+ level = 1;
+ metadata = "1.0";
+ content = {
+ type = "filesystem";
+ format = "vfat";
+ mountpoint = "/boot";
+ };
+ };
+ };
+}
diff --git a/modules/xnet/disk/layouts/single.nix b/modules/xnet/disk/layouts/single.nix
new file mode 100644
index 0000000..b779a39
--- /dev/null
+++ b/modules/xnet/disk/layouts/single.nix
@@ -0,0 +1,29 @@
+device: {
+ disk = {
+ "${device}" = {
+ type = "disk";
+ device = "/dev/${device}";
+ content = {
+ type = "gpt";
+ partitions = {
+ ESP = {
+ size = "1G";
+ type = "EF00";
+ content = {
+ type = "filesystem";
+ format = "vfat";
+ mountpoint = "/boot";
+ };
+ };
+ ZFS = {
+ size = "100%";
+ content = {
+ type = "zfs";
+ pool = "zroot";
+ };
+ };
+ };
+ };
+ };
+ };
+}