72 lines
1.8 KiB
Nix
72 lines
1.8 KiB
Nix
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
### --> SnapRAID disks research
|
|
contentDiskMounts = lib.attrsets.attrNames (
|
|
lib.attrsets.filterAttrs (name: value: lib.strings.hasPrefix "/mnt/content-" name) config.fileSystems
|
|
);
|
|
parityDiskMounts = lib.attrsets.attrNames (
|
|
lib.attrsets.filterAttrs (name: value: lib.strings.hasPrefix "/mnt/parity-" name) config.fileSystems
|
|
);
|
|
snapraidDataDisks = lib.lists.foldl'
|
|
(acc: path: acc // { "d${toString (acc.i + 1)}" = path; i = acc.i + 1; })
|
|
{ i = 0; }
|
|
contentDiskMounts;
|
|
### SnapRAID disks research <--
|
|
|
|
### --> Spindown disks
|
|
hardDrives = [ ${DISK_ID_LIST[@]} ];
|
|
### Spindown disks <--
|
|
in
|
|
|
|
|
|
|
|
|
|
### --> MergerFS setup
|
|
{
|
|
fileSystems."/mnt/data-storage" = {
|
|
device = "mergerfs";
|
|
fsType = "fuse";
|
|
options = [
|
|
"defaults"
|
|
"allow_other"
|
|
"use_ino"
|
|
"cache.files=off"
|
|
"moveonenospc=true"
|
|
"category.create=mfs"
|
|
"srcmounts=${lib.strings.concatStringsSep ":" contentDiskMounts}"
|
|
];
|
|
};
|
|
### MergerFS setup <--
|
|
|
|
|
|
|
|
### --> SnapRAID setup
|
|
services.snapraid = {
|
|
enable = true;
|
|
contentFiles = map (disk: "${disk}/snapraid.content") contentDiskMounts;
|
|
parityFiles = map (disk: "${disk}/snapraid.parity") parityDiskMounts;
|
|
dataDisks = builtins.removeAttrs snapraidDataDisks [ "i" ];
|
|
};
|
|
### SnapRAID setup <--
|
|
|
|
|
|
|
|
### --> Disk spindown
|
|
systemd.services.hd-idle = {
|
|
description = "External HD spin down daemon";
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
ExecStart =
|
|
let
|
|
idleTime = toString 1800;
|
|
hardDriveParameter = lib.strings.concatMapStringsSep " " (x: "-a ${x} -i ${idleTime}") hardDrives;
|
|
in
|
|
"${pkgs.hd-idle}/bin/hd-idle -i 0 ${hardDriveParameter}";
|
|
};
|
|
};
|
|
### Disk spindown <--
|
|
|
|
} |