1
0
Prechádzať zdrojové kódy

feat(odin): some file system stuffs

Zander Hawke 9 mesiacov pred
rodič
commit
ec47920640

+ 20 - 23
hosts/odin/disko.nix

@@ -1,11 +1,11 @@
 { inputs, lib, ... }:
 
 let
-  storageDisks = [
-    "ata-ST8000VN002-2ZM188_WPV023WG"
-    "ata-ST8000VN002-2ZM188_WPV07RMA"
-    "ata-ST8000VN002-2ZM188_WPV020CG"
-  ];
+  disks = {
+    parity1 = "ata-ST8000VN002-2ZM188_WPV023WG";
+    data1 = "ata-ST8000VN002-2ZM188_WPV07RMA";
+    data2 = "ata-ST8000VN002-2ZM188_WPV020CG";
+  };
 in
 
 {
@@ -71,28 +71,25 @@ in
         };
       };
 
-    } // lib.listToAttrs (lib.imap1
-      (i: diskId: {
-        name = "storage${toString i}";
-        value = {
-          type = "disk";
-          device = "/dev/disk/by-id/${diskId}";
-          content = {
-            type = "gpt";
-            partitions = {
-              primary = {
-                size = "100%";
-                content = {
-                  type = "filesystem";
-                  format = "xfs";
-                  mountpoint = "/mnt/disk${toString i}";
-                  mountOptions = [ "defaults" "noatime" ];
-                };
+    } // lib.attrsets.mapAttrs
+      (name: value: {
+        type = "disk";
+        device = "/dev/disk/by-id/${value}";
+        content = {
+          type = "gpt";
+          partitions = {
+            primary = {
+              size = "100%";
+              content = {
+                type = "filesystem";
+                format = "xfs";
+                mountpoint = "/mnt/${name}";
+                mountOptions = [ "defaults" "noatime" ];
               };
             };
           };
         };
       })
-      storageDisks);
+      disks;
   };
 }

+ 33 - 0
hosts/odin/install.sh

@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+# Create a temporary directory
+temp=$(mktemp -d)
+
+# Function to cleanup temporary directory on exit
+cleanup() {
+  rm -rf "$temp"
+}
+trap cleanup EXIT
+
+# Create the directory where sshd expects to find the host keys
+install -d -m755 "$temp/persist/etc/ssh"
+install -d -m755 "$temp/etc/ssh"
+
+# Decrypt your private key from the password store and copy it to the temporary directory
+cat ./ssh_host_ed25519_key.txt > "$temp/persist/etc/ssh/ssh_host_ed25519_key"
+cat ./ssh_host_rsa_key.txt > "$temp/persist/etc/ssh/ssh_host_rsa_key"
+cat ./ssh_host_ed25519_key.txt > "$temp/etc/ssh/ssh_host_ed25519_key"
+cat ./ssh_host_rsa_key.txt > "$temp/etc/ssh/ssh_host_rsa_key"
+
+# Set the correct permissions so sshd will accept the key
+chmod 600 "$temp/persist/etc/ssh/ssh_host_ed25519_key"
+chmod 600 "$temp/persist/etc/ssh/ssh_host_rsa_key"
+chmod 600 "$temp/etc/ssh/ssh_host_ed25519_key"
+chmod 600 "$temp/etc/ssh/ssh_host_rsa_key"
+
+# Install NixOS to the host system with our secrets
+# --disko-mode mount \
+nix run github:nix-community/nixos-anywhere -- \
+  --extra-files "$temp" \
+  --flake .#odin \
+  --target-host [email protected]

+ 1 - 1
hosts/odin/mergerfs.nix

@@ -6,7 +6,7 @@
   ];
 
   fileSystems."/mnt/storage" = {
-    device = "/mnt/disk2:/mnt/disk3";
+    device = "/mnt/data*";
     options = [
       "category.create=mfs"
       "defaults"

+ 1 - 0
hosts/odin/services/default.nix

@@ -2,6 +2,7 @@
 
 {
   imports = [
+    ./snapraid.nix
     ./tailscale.nix
     # ./immich.nix
     # ./snapraid.nix

+ 14 - 0
hosts/odin/services/snapraid.nix

@@ -0,0 +1,14 @@
+{
+  services.snapraid = {
+    enable = true;
+    parityFiles = [ "/mnt/parity1/snapraid.parity" ];
+    dataDisks = {
+      data1 = "/mnt/data1/";
+      data2 = "/mnt/data2/";
+    };
+    contentFiles = [
+      "/mnt/data1/snapraid.content"
+      "/mnt/data2/snapraid.content"
+    ];
+  };
+}

+ 3 - 3
hosts/odin/system.nix

@@ -45,9 +45,9 @@
       in
       {
         disks = [
-          devices.storage1.device
-          devices.storage2.device
-          devices.storage3.device
+          devices.parity1.device
+          devices.data1.device
+          devices.data2.device
         ];
         pwmPaths = [
           "/sys/class/hwmon/hwmon2/pwm1:20:0"