From 481164fb67e35987de90f39c11418aa37fb72215 Mon Sep 17 00:00:00 2001 From: "Simon R. - fantomitechno" Date: Fri, 24 Jul 2026 13:14:29 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20ZFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 5 +++ hosts/conseil/default.nix | 4 +- hosts/conseil/disko-config.nix | 80 ++++++++++++++++++++++++++++++++++ hosts/conseil/zfs.nix | 15 +++++++ modules/nas/default.nix | 28 +++++------- modules/nas/s3.nix | 26 ++++++----- 6 files changed, 127 insertions(+), 31 deletions(-) create mode 100644 hosts/conseil/disko-config.nix create mode 100644 hosts/conseil/zfs.nix diff --git a/flake.nix b/flake.nix index 2642b14..daff111 100644 --- a/flake.nix +++ b/flake.nix @@ -54,6 +54,11 @@ inputs.lucide-src.follows = ""; inputs.mermaid-src.follows = ""; }; + + disko = { + url = "github:nix-community/disko?tag=v1.20.16"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = diff --git a/hosts/conseil/default.nix b/hosts/conseil/default.nix index 7c8c56c..bf85eff 100644 --- a/hosts/conseil/default.nix +++ b/hosts/conseil/default.nix @@ -6,12 +6,14 @@ { imports = [ ./hardware-configuration.nix + ./zfs.nix + ../server.nix ] ++ builtins.map (i: ../../modules/${i}) ([ "caddy" - "metrix/prometheus.nix" "nas" + "metrix/prometheus.nix" ]); # Bootloader diff --git a/hosts/conseil/disko-config.nix b/hosts/conseil/disko-config.nix new file mode 100644 index 0000000..2568441 --- /dev/null +++ b/hosts/conseil/disko-config.nix @@ -0,0 +1,80 @@ +{ + disko.devices = { + main.device = "/dev/sdx"; + disk = { + ssd = { + type = "disk"; + device = "/dev/sdx"; + content = { + type = "gpt"; + partitions = { + ESP = { + size = "64M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + hdd1 = { + type = "disk"; + device = "/dev/sdy"; + content = { + type = "gpt"; + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "storage"; + }; + }; + }; + }; + }; + hdd2 = { + type = "disk"; + device = "/dev/sdz"; + content = { + type = "gpt"; + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "storage"; + }; + }; + }; + }; + }; + }; + zpool = { + storage = { + type = "zpool"; + mode = "raidz1"; + mountpoint = "/data"; + + datasets = { + dataset = { + type = "zfs_fs"; + mountpoint = "/storage/dataset"; + }; + }; + }; + }; + }; +} diff --git a/hosts/conseil/zfs.nix b/hosts/conseil/zfs.nix new file mode 100644 index 0000000..87779d6 --- /dev/null +++ b/hosts/conseil/zfs.nix @@ -0,0 +1,15 @@ +{ flakes, ... }: +{ + imports = [ + flakes.inputs.disko.nixosModules.disko + ./disko-config.nix + ]; + + boot.initrd.supportedFilesystems = { + zfs = true; + }; + services.zfs = { + trim.enable = true; + autoScrub.enable = true; + }; +} diff --git a/modules/nas/default.nix b/modules/nas/default.nix index 7694436..c880b17 100644 --- a/modules/nas/default.nix +++ b/modules/nas/default.nix @@ -1,36 +1,28 @@ { ... }: { - imports = [ - ./s3.nix - ]; - - services.nfs.server = { - enable = true; - statdPort = 4000; - lockdPort = 4001; - mountdPort = 4002; - exports = '' - /data 172.16.10.0/24(insecure,rw,sync,crossmnt,fsid=0) 172.16.20.0/24(insecure,rw,sync,crossmnt,fsid=0) 172.16.30.0/24(insecure,rw,sync,crossmnt,fsid=0) - ''; + services = { + nfs.server = { + enable = true; + statdPort = 4000; + lockdPort = 4001; + mountdPort = 4002; + exports = '' + /data 172.16.10.0/24(insecure,rw,sync,crossmnt,fsid=0) 172.16.20.0/24(insecure,rw,sync,crossmnt,fsid=0) 172.16.30.0/24(insecure,rw,sync,crossmnt,fsid=0) + ''; + }; }; networking.firewall = { enable = true; # for NFSv3; view with `rpcinfo -p` allowedTCPPorts = [ - 111 - 2049 4000 4001 4002 - 20048 ]; allowedUDPPorts = [ - 111 - 2049 4000 4001 4002 - 20048 ]; }; } diff --git a/modules/nas/s3.nix b/modules/nas/s3.nix index 5f851b6..7272389 100644 --- a/modules/nas/s3.nix +++ b/modules/nas/s3.nix @@ -1,20 +1,22 @@ { pkgs, ... }: { - services.garage = { - enable = true; + services = { + garage = { + enable = true; - package = pkgs.garage; + package = pkgs.garage; - settings = { - metadata_dir = "/var/lib/garage/meta"; - data_dir = "/var/lib/garage/data"; + settings = { + metadata_dir = "/var/lib/garage/meta"; + data_dir = "/var/lib/garage/data"; - s3_api = { - api_bind_addr = "127.0.0.1:4010"; - s3_region = "garage"; - }; + s3_api = { + api_bind_addr = "127.0.0.1:4010"; + s3_region = "garage"; + }; - s3_web = { - bind_addr = "127.0.0.1:4011"; + s3_web = { + bind_addr = "127.0.0.1:4011"; + }; }; }; }; -- 2.51.2