Edited snapraid.nix to get correct mounts.
This commit is contained in:
@@ -497,6 +497,7 @@ EOF
|
||||
if [[ "$CONTENT_DISK_NUMBER" -eq 1 && "$PARITY_DISK_NUMBER" -eq 0 ]]; then
|
||||
export j="1"
|
||||
export CONTENT_DISK_ID="${DATA_DISKS_ID[0]}"
|
||||
if [[ "${DATA_DISKS_TYPE[0]}" == "HDD" ]]; then export ALLOW_DISCARDS="false"; else export ALLOW_DISCARDS="true"; fi
|
||||
(envsubst < "templates/nix-config/disks/content.nix") >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
sed -i "s|/mnt/content-1|/mnt/data-storage|" final-nix-config/etc/nixos/disks/disko.nix
|
||||
# Mirror configuration
|
||||
@@ -507,23 +508,42 @@ EOF
|
||||
# SnapRAID configuration
|
||||
elif [[ "$CONTENT_DISK_NUMBER" -gt 1 ]]; then
|
||||
# Enable SnapRAID
|
||||
cp -avu templates/nix-config/disks/snapraid.nix final-nix-config/etc/nixos/disks/
|
||||
cp -avu templates/nix-config/disks/pcr-check.nix final-nix-config/etc/nixos/disks/
|
||||
sed -i "s|# ./disks/snapraid.nix| ./disks/snapraid.nix|" final-nix-config/etc/nixos/configuration.nix
|
||||
|
||||
MERGERFS_MOUNTS=""
|
||||
SNAPRAID_CONTENT_FILES=""
|
||||
SNAPRAID_DATA_DISKS=""
|
||||
|
||||
j=0
|
||||
for i in $(seq 0 $(($CONTENT_DISK_NUMBER - 1))); do
|
||||
export j=$((j + 1))
|
||||
export CONTENT_DISK_ID="${DATA_DISKS_ID[${i}]}"
|
||||
if [[ "${DATA_DISKS_TYPE[${i}]}" == "HDD" ]]; then export ALLOW_DISCARDS="false"; else export ALLOW_DISCARDS="true"; fi
|
||||
(envsubst < "templates/nix-config/disks/content.nix") >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
MERGERFS_MOUNTS+="/mnt/content-${j}:"
|
||||
SNAPRAID_CONTENT_FILES+=" \"/mnt/content-${j}/snapraid.content\""$'\n'
|
||||
SNAPRAID_DATA_DISKS+=" d${j} = \"/mnt/content-${j}\";"$'\n'
|
||||
done
|
||||
echo -e "\n✅ Generated $CONTENT_DISK_NUMBER data disk configuration(s)."
|
||||
|
||||
export MERGERFS_MOUNTS=${MERGERFS_MOUNTS%:}
|
||||
export SNAPRAID_CONTENT_FILES
|
||||
export SNAPRAID_DATA_DISKS
|
||||
|
||||
SNAPRAID_PARITY_FILES=""
|
||||
j=0
|
||||
for i in $(seq $CONTENT_DISK_NUMBER $((${#DATA_DISKS_ID[@]} - 1))); do
|
||||
export j=$((j + 1))
|
||||
export PARITY_DISK_ID="${DATA_DISKS_ID[${i}]}"
|
||||
if [[ "${DATA_DISKS_TYPE[${i}]}" == "HDD" ]]; then export ALLOW_DISCARDS="false"; else export ALLOW_DISCARDS="true"; fi
|
||||
(envsubst < "templates/nix-config/disks/parity.nix") >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
SNAPRAID_PARITY_FILES+=" \"/mnt/parity-${j}/snapraid.parity\""$'\n'
|
||||
done
|
||||
echo -e "\n✅ Generated $PARITY_DISK_NUMBER parity disk configuration(s)."
|
||||
|
||||
export SNAPRAID_PARITY_FILES
|
||||
envsubst < templates/nix-config/disks/snapraid.nix > final-nix-config/etc/nixos/disks/snapraid.nix
|
||||
fi
|
||||
# Close the disko.nix block
|
||||
cat <<'EOF' >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
initrdUnlock = false;
|
||||
settings = {
|
||||
keyFile = "/etc/secrets/disks/content-disk-${j}";
|
||||
allowDiscards = true;
|
||||
allowDiscards = ${ALLOW_DISCARDS:-false};
|
||||
};
|
||||
content = {
|
||||
type = "filesystem";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
initrdUnlock = false;
|
||||
settings = {
|
||||
keyFile = "/etc/secrets/disks/parity-disk-${j}";
|
||||
allowDiscards = true;
|
||||
allowDiscards = ${ALLOW_DISCARDS:-false};
|
||||
};
|
||||
content = {
|
||||
type = "filesystem";
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
{ 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 <--
|
||||
in
|
||||
|
||||
### --> MergerFS setup
|
||||
{
|
||||
fileSystems."/mnt/data-storage" = {
|
||||
@@ -27,7 +12,7 @@ in
|
||||
"cache.files=off"
|
||||
"moveonenospc=true"
|
||||
"category.create=mfs"
|
||||
"srcmounts=${lib.strings.concatStringsSep ":" contentDiskMounts}"
|
||||
"srcmounts=MERGERFS_MOUNTS"
|
||||
];
|
||||
};
|
||||
### MergerFS setup <--
|
||||
@@ -35,9 +20,15 @@ in
|
||||
### --> 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" ];
|
||||
contentFiles = [
|
||||
SNAPRAID_CONTENT_FILES
|
||||
];
|
||||
parityFiles = [
|
||||
SNAPRAID_PARITY_FILES
|
||||
];
|
||||
dataDisks = {
|
||||
SNAPRAID_DATA_DISKS
|
||||
};
|
||||
};
|
||||
### SnapRAID setup <--
|
||||
}
|
||||
Reference in New Issue
Block a user