From 74dab0c38de9518a9a6c28571ed8961e6934c9cc Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 5 Jul 2024 16:31:58 +0100 Subject: [PATCH] nebula zfs configuration and post-install-setup script --- hosts/common/disks/zfs/post-install-setup.sh | 3 + hosts/common/disks/zfs/zspeed.nix | 73 ++++++++++++++++++++ hosts/nebula/default.nix | 10 +-- 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100755 hosts/common/disks/zfs/post-install-setup.sh create mode 100644 hosts/common/disks/zfs/zspeed.nix diff --git a/hosts/common/disks/zfs/post-install-setup.sh b/hosts/common/disks/zfs/post-install-setup.sh new file mode 100755 index 0000000..444f71d --- /dev/null +++ b/hosts/common/disks/zfs/post-install-setup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko ./zspeed.nix diff --git a/hosts/common/disks/zfs/zspeed.nix b/hosts/common/disks/zfs/zspeed.nix new file mode 100644 index 0000000..ead5709 --- /dev/null +++ b/hosts/common/disks/zfs/zspeed.nix @@ -0,0 +1,73 @@ +{ + disko.devices = { + disk = { + x = { + type = "disk"; + device = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0"; + content = { + type = "gpt"; + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "zspeed"; + }; + }; + }; + }; + }; + y = { + type = "disk"; + device = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi3"; + content = { + type = "gpt"; + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "zspeed"; + }; + }; + }; + }; + }; + }; + zpool = { + zspeed = { + type = "zpool"; + mode = "mirror"; + rootFsOptions = { + "compression" = "zstd-4"; + "com.sun:auto-snapshot" = "false"; + "xattr" = "sa"; + "atime" = "off"; + }; + options = { + "ashift" = "13"; + }; + postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zspeed@blank$' || zfs snapshot zspeed@blank"; + + datasets = { + postgres = { + type = "zfs_volume"; + size = "10G -s"; + options = { + "com.sun:auto-snapshot:daily" = "true"; + "volblocksize" = "8k"; + }; + }; + lxc = { + type = "zfs_volume"; + size = "10G -s"; + options = { + "com.sun:auto-snapshot:daily" = "true"; + "volblocksize" = "8k"; + }; + }; + }; + }; + }; + }; +} diff --git a/hosts/nebula/default.nix b/hosts/nebula/default.nix index 9d341d1..366c277 100644 --- a/hosts/nebula/default.nix +++ b/hosts/nebula/default.nix @@ -1,11 +1,10 @@ -{ inputs, config, lib, pkgs, outputs, ... }: +{ inputs, ... }: let # Disko setup fsType = "btrfs"; # one of ext4 or btrfs. Use btrfs if using impermanence - dev = "/dev/sda"; # depends on target hardware + dev = "/dev/disk/by-id/ata-QEMU_HARDDISK_QM00005"; # depends on target hardware encrypted = false; # currrently only applies to btrfs impermanence = false; # currrently only applies to btrfs - btrfsMountDevice = if encrypted then "/dev/mapper/crypted" else "/dev/root_vg/root"; user = "admin"; in { @@ -14,7 +13,7 @@ in # Create users for this host ../common/users/${user} - # Disk configuration + # Root disk configuration inputs.disko.nixosModules.disko (import ../common/disks { device = dev; impermanence = impermanence; fsType = fsType; encrypted = encrypted; }) @@ -24,7 +23,7 @@ in # Import optional options ../common/optional/openssh.nix - + ../common/optional/lxd ]; @@ -45,6 +44,7 @@ in boot.supportedFilesystems = [ "zfs" ]; boot.zfs.forceImportRoot = false; networking.hostId = "18aec5d7"; + boot.zfs.extraPools = [ "zspeed" ]; services.libinput.enable = true; }