diff --git a/devices/nas/default.nix b/devices/nas/default.nix index a44b857..6eb1075 100644 --- a/devices/nas/default.nix +++ b/devices/nas/default.nix @@ -3,6 +3,7 @@ imports = [ ./modules/arion ./modules/borgbackup.nix + ./modules/mergerfs.nix ./modules/nfs.nix ]; } diff --git a/devices/nas/modules/mergerfs.nix b/devices/nas/modules/mergerfs.nix new file mode 100644 index 0000000..a02cdd1 --- /dev/null +++ b/devices/nas/modules/mergerfs.nix @@ -0,0 +1,116 @@ +{ + config, + pkgs, + ... +}: let + inherit (config.sops) secrets; + + fsPkgs = with pkgs; [fuse mergerfs sshfs]; + + sshfsOpts = [ + "IdentityFile=${secrets.sshfs.path}" + + "allow_other" # for non-root access + "_netdev" # requires network to mount + "x-systemd.automount" # mount on demand + + # Handle connection drops better + "ServerAliveInterval=15" + "reconnect" + "defaults" + ]; +in { + programs.ssh.knownHosts = { + "10.0.0.121".publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDs4eTQxAU+/B3B3AYXbTeRIZGk6lUKlykWrZZ07r3NMIJkleEE7i5KgW8QeeWVLFG8Thi4jyVferM7tPILA//Q6GXNDQ3ioYHExG33d/yIRGStD3rEizAv0LkDHavZ33VDNEOkBLQ22eeB7cCaQvsUoCbryo6w3mSQO5PDH9RE44XrOaSCbLvjhst5Z9gXPtrJsBcvOFUpdwz5gIHIqTFo6fQpmzxYkY5GrMaqMB75Xh2MQNkIZteC2MMPgIH9Vz+Q3CnzyiXEzoYaUtT0//sXnydagWWt9xf+KJ34Oz0r1Jtn2ihgJZmA7NrO5zATZVq6qQHdhry3xL1PpvY7U5Zx"; + }; + + system.fsPackages = fsPkgs; + environment.systemPackages = fsPkgs; + + fileSystems = { + "MergerFS Data" = { + mountPoint = "/data"; + fsType = "fuse.mergerfs"; + device = "/mnt/drives/?tb*"; + options = [ + "cache.files=partial" + "allow_other" + "category.create=lfs" + "minfreespace=50G" + "fsname=mergerfs" + ]; + }; + + "3tb-1" = { + mountPoint = "/mnt/drives/3tb1"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/3tb-1"; + # device = "/dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N1236473-part1"; + }; + + "3tb-2" = { + mountPoint = "/mnt/drives/3tb2"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/3tb-2"; + # device = "/dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WMC4N1233153-part1"; + }; + + "4tb-1" = { + mountPoint = "/mnt/drives/4tb1"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/4tb-1"; + # device = "/dev/disk/by-id/ata-WDC_WD40EZAZ-19SF3B0_WD-WX32D81DE8RD-part1"; + }; + + "4tb-2" = { + mountPoint = "/mnt/drives/4tb2"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/4tb-2"; + # device = "/dev/disk/by-id/ata-WDC_WD40EZAZ-19SF3B0_WD-WX32D81DE6Z0-part1"; + }; + + "8tb-1" = { + mountPoint = "/mnt/drives/8tb1"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/8tb-1"; + # device = "/dev/disk/by-id/ata-WDC_WD8003FFBX-68B9AN0_VAJ99UDL-part1"; + }; + + "8tb-2 parity0" = { + mountPoint = "/mnt/drives/parity0"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/parity0"; + # device = "/dev/disk/by-id/ata-WDC_WD8003FFBX-68B9AN0_VDGL4HZD-part1"; + }; + + "8tb-3 parity1" = { + mountPoint = "/mnt/drives/parity1"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/parity1"; + # device = "/dev/disk/by-id/ata-WDC_WD80EFZZ-68BTXN0_WD-CA13WUYK-part1"; + }; + + "8tb-4" = { + mountPoint = "/mnt/drives/8tb4"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/8tb-4"; + # device = "/dev/disk/by-id/ata-WDC_WD80EAZZ-00BKLB0_WD-CA1AVU7K-part1"; + }; + + "8tb-5" = { + mountPoint = "/mnt/drives/8tb5"; + fsType = "sshfs"; # "ext4"; + options = sshfsOpts; + device = "root@10.0.0.121:/drives/8tb-5"; + # device = "/dev/disk/by-id/ata-WDC_WD80EAZZ-00BKLB0_WD-CA1GN0GK-part1"; + }; + }; +} diff --git a/flake.lock b/flake.lock index 10693fa..40f25b1 100644 --- a/flake.lock +++ b/flake.lock @@ -1274,11 +1274,11 @@ "sops-nix": "sops-nix" }, "locked": { - "lastModified": 1708231529, - "narHash": "sha256-BAYVOr3jmamIAR8E/PZxcSM33do0JCsUFiuMO04HRXQ=", + "lastModified": 1708281692, + "narHash": "sha256-MwEtc7/Q9zOAXkN90mJB19spwDJg1wKq9QE27EQ47Kk=", "ref": "refs/heads/main", - "rev": "98afa3adce5e38f91f9c733c154784aabbba00d5", - "revCount": 40, + "rev": "82e860c8bd9a3c634e73478fd0dd537f09c48c97", + "revCount": 41, "type": "git", "url": "ssh://git@git.nelim.org/matt1432/nixos-secrets" },