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