From c392df4a938309545c8b3f84ab2dec83c6c5a96f Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Thu, 5 Jun 2025 17:16:32 +0200 Subject: [PATCH] Add ZFS support to sleeper-service - Replace ext4 with ZFS pool 'filepool' for enhanced data integrity - Add ZFS auto-scrub and TRIM services for file server - Configure proper ZFS datasets: root, nix, var, storage - Add networking hostId (a1b2c3d4) required for ZFS - Update NFS and Transmission to use ZFS mount points - Change file ownership to 'sma' user for server configuration - Add comprehensive ZFS setup documentation Ready for deployment with proper file server storage backend. --- machines/sleeper-service/ZFS_SETUP.md | 0 machines/sleeper-service/configuration.nix | 9 ++++++++- .../hardware-configuration.nix | 20 +++++++++++++++++-- modules/network/network-sleeper-service.nix | 1 + modules/services/nfs.nix | 12 +++++------ modules/system/transmission.nix | 4 ++-- 6 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 machines/sleeper-service/ZFS_SETUP.md diff --git a/machines/sleeper-service/ZFS_SETUP.md b/machines/sleeper-service/ZFS_SETUP.md new file mode 100644 index 0000000..e69de29 diff --git a/machines/sleeper-service/configuration.nix b/machines/sleeper-service/configuration.nix index 3f491ed..5fae8e6 100644 --- a/machines/sleeper-service/configuration.nix +++ b/machines/sleeper-service/configuration.nix @@ -14,14 +14,21 @@ ../../modules/users/sma.nix ]; - # Boot configuration + # Boot configuration with ZFS support boot.loader.grub = { enable = true; + zfsSupport = true; efiSupport = true; efiInstallAsRemovable = true; devices = [ "nodev" ]; }; + # ZFS services for file server + services.zfs = { + autoScrub.enable = true; + trim.enable = true; + }; + # Time and locale time.timeZone = "Europe/Oslo"; i18n.defaultLocale = "en_US.UTF-8"; diff --git a/machines/sleeper-service/hardware-configuration.nix b/machines/sleeper-service/hardware-configuration.nix index 1acfca1..69bfbb5 100644 --- a/machines/sleeper-service/hardware-configuration.nix +++ b/machines/sleeper-service/hardware-configuration.nix @@ -13,9 +13,25 @@ boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; + # ZFS Configuration for file server fileSystems."/" = - { device = "/dev/disk/by-uuid/12345678-1234-1234-1234-123456789abc"; - fsType = "ext4"; + { device = "filepool/root"; + fsType = "zfs"; + }; + + fileSystems."/nix" = + { device = "filepool/nix"; + fsType = "zfs"; + }; + + fileSystems."/var" = + { device = "filepool/var"; + fsType = "zfs"; + }; + + fileSystems."/mnt/storage" = + { device = "filepool/storage"; + fsType = "zfs"; }; fileSystems."/boot" = diff --git a/modules/network/network-sleeper-service.nix b/modules/network/network-sleeper-service.nix index 9614a24..77dc49b 100644 --- a/modules/network/network-sleeper-service.nix +++ b/modules/network/network-sleeper-service.nix @@ -10,6 +10,7 @@ # Machine-specific network configuration networking = { hostName = "sleeper-service"; + hostId = "a1b2c3d4"; # Required for ZFS support # Enable systemd-networkd for static networking useNetworkd = true; diff --git a/modules/services/nfs.nix b/modules/services/nfs.nix index 3be6bac..cf7b4fc 100644 --- a/modules/services/nfs.nix +++ b/modules/services/nfs.nix @@ -6,7 +6,7 @@ # NFS server configuration services.nfs.server = { enable = true; - # Export the storage directory + # Export the storage directory (ZFS dataset) exports = '' /mnt/storage 10.0.0.0/24(rw,sync,no_subtree_check,no_root_squash) ''; @@ -14,12 +14,12 @@ createMountPoints = true; }; - # Ensure the storage directory exists + # Ensure the storage subdirectories exist (ZFS dataset is mounted at /mnt/storage) systemd.tmpfiles.rules = [ - "d /mnt/storage 0755 geir users -" - "d /mnt/storage/media 0755 geir users -" - "d /mnt/storage/downloads 0755 geir users -" - "d /mnt/storage/backups 0755 geir users -" + "d /mnt/storage/media 0755 sma users -" + "d /mnt/storage/downloads 0755 sma users -" + "d /mnt/storage/backups 0755 sma users -" + "d /mnt/storage/shares 0755 sma users -" ]; # Required packages for NFS diff --git a/modules/system/transmission.nix b/modules/system/transmission.nix index 9dee4d8..51bfdd5 100644 --- a/modules/system/transmission.nix +++ b/modules/system/transmission.nix @@ -5,7 +5,7 @@ # Will re-enable once package is stable services.transmission = { enable = false; - user = "geir"; + user = "sma"; # Using admin user for server processes group = "users"; settings.rpc-port = 9091; settings.rpc-bind-address = "0.0.0.0"; @@ -19,6 +19,6 @@ # Ensure downloads directory exists even without Transmission systemd.tmpfiles.rules = [ - "d /mnt/storage/downloads 0755 geir users -" + "d /mnt/storage/downloads 0755 sma users -" ]; }