From 0dddbb77345901e91d5111c28e29a5b3c471a870 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 29 Feb 2024 02:34:48 -0500 Subject: [PATCH] feat(nas): make snapraid module --- devices/nas/modules/mergerfs.nix | 18 +++++----- devices/nas/modules/snapraid.nix | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 devices/nas/modules/snapraid.nix diff --git a/devices/nas/modules/mergerfs.nix b/devices/nas/modules/mergerfs.nix index c184c3d..d98599a 100644 --- a/devices/nas/modules/mergerfs.nix +++ b/devices/nas/modules/mergerfs.nix @@ -37,55 +37,55 @@ in { ]; }; - "3tb-1" = { + "d1 3tb-1" = { mountPoint = "/mnt/drives/3tb1"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N1236473-part1"; }; - "3tb-2" = { + "d2 3tb-2" = { mountPoint = "/mnt/drives/3tb2"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N1233153-part1"; }; - "4tb-1" = { + "d3 4tb-1" = { mountPoint = "/mnt/drives/4tb1"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD40EZAZ-19SF3B0_WD-WX32D81DE8RD-part1"; }; - "4tb-2" = { + "d4 4tb-2" = { mountPoint = "/mnt/drives/4tb2"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD40EZAZ-19SF3B0_WD-WX32D81DE6Z0-part1"; }; - "8tb-1" = { + "d5 8tb-1" = { mountPoint = "/mnt/drives/8tb1"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD8003FFBX-68B9AN0_VAJ99UDL-part1"; }; - "8tb-2 parity0" = { + "p0 8tb-2" = { mountPoint = "/mnt/drives/parity0"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD8003FFBX-68B9AN0_VDGL4HZD-part1"; }; - "8tb-3 parity1" = { + "p1 8tb-3" = { mountPoint = "/mnt/drives/parity1"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD80EFZZ-68BTXN0_WD-CA13WUYK-part1"; }; - "8tb-4" = { + "d6 8tb-4" = { mountPoint = "/mnt/drives/8tb4"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD80EAZZ-00BKLB0_WD-CA1AVU7K-part1"; }; - "8tb-5" = { + "d7 8tb-5" = { mountPoint = "/mnt/drives/8tb5"; fsType = "ext4"; device = "/dev/disk/by-id/ata-WDC_WD80EAZZ-00BKLB0_WD-CA1GN0GK-part1"; diff --git a/devices/nas/modules/snapraid.nix b/devices/nas/modules/snapraid.nix new file mode 100644 index 0000000..8fe9b79 --- /dev/null +++ b/devices/nas/modules/snapraid.nix @@ -0,0 +1,58 @@ +{ + config, + lib, + ... +}: let + inherit + (lib) + attrValues + filterAttrs + hasPrefix + listToAttrs + mapAttrs + optionalString + substring + toInt + ; + + parityDrives = filterAttrs (n: v: hasPrefix "p" n) config.fileSystems; + dataDrives = filterAttrs (n: v: hasPrefix "d" n) config.fileSystems; +in { + snapraid = { + enable = true; + + dataDisks = listToAttrs (attrValues (mapAttrs (n: fs: { + name = substring 0 2 n; + value = fs.mountPoint; + }) + dataDrives)); + + parityFiles = attrValues (mapAttrs (n: fs: "${fs.mountPoint}/snapraid.${ + let + i = (toInt (substring 1 1 n)) + 1; + in + optionalString (i != 1) "${toString i}-" + }parity") + parityDrives); + + contentFiles = + ["/var/snapraid/content"] + ++ map (fs: "${fs.mountPoint}/content") (attrValues dataDrives); + + exclude = [ + "*.bak" + "*.unrecoverable" + "/tmp/" + "/lost+found/" + ".AppleDouble" + "._AppleDouble" + ".DS_Store" + ".Thumbs.db" + ".fseventsd" + ".Spotlight-V100" + ".TemporaryItems" + ".Trashes" + ".AppleDB" + ]; + }; +}